Bladeren bron

Merge pull request #109 from bgrabitmap/dev-bgracontrols

Dev bgracontrols
Leandro Diaz 4 jaren geleden
bovenliggende
commit
6d7fff694d

+ 0 - 5
bgracontrols.lpk

@@ -25,11 +25,6 @@
           <VariablesInRegisters Value="True"/>
         </Optimizations>
       </CodeGeneration>
-      <Linking>
-        <Debugging>
-          <GenerateDebugInfo Value="False"/>
-        </Debugging>
-      </Linking>
     </CompilerOptions>
     <Description Value="BGRA Controls is a set of graphical UI elements that you can use with Lazarus LCL applications."/>
     <License Value="Modified LGPL"/>

File diff suppressed because it is too large
+ 569 - 125
bgraimagemanipulation.pas


+ 9 - 18
test/test_bgraimagemanipulation/ProjectBGRAImageManipulationDemo.lpi

@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <CONFIG>
   <ProjectOptions>
-    <Version Value="9"/>
+    <Version Value="11"/>
     <General>
       <SessionStorage Value="InProjectDir"/>
       <MainUnit Value="0"/>
@@ -18,7 +18,6 @@
     <VersionInfo>
       <UseVersionInfo Value="True"/>
       <MinorVersionNr Value="2"/>
-      <StringTable ProductVersion=""/>
     </VersionInfo>
     <BuildModes Count="2">
       <Item1 Name="Debug" Default="True"/>
@@ -51,25 +50,24 @@
               </Win32>
             </Options>
           </Linking>
-          <Other>
-            <CompilerMessages>
-              <UseMsgFile Value="True"/>
-            </CompilerMessages>
-            <CompilerPath Value="$(CompPath)"/>
-          </Other>
         </CompilerOptions>
       </Item2>
     </BuildModes>
     <PublishOptions>
       <Version Value="2"/>
-      <IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
-      <ExcludeFileFilter Value="*.(bak|ppu|o|so);*~;backup"/>
     </PublishOptions>
     <RunParams>
       <local>
-        <FormatVersion Value="1"/>
         <LaunchingApplication PathPlusParams="/usr/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
       </local>
+      <FormatVersion Value="2"/>
+      <Modes Count="1">
+        <Mode0 Name="default">
+          <local>
+            <LaunchingApplication PathPlusParams="/usr/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
+          </local>
+        </Mode0>
+      </Modes>
     </RunParams>
     <RequiredPackages Count="2">
       <Item1>
@@ -83,7 +81,6 @@
       <Unit0>
         <Filename Value="ProjectBGRAImageManipulationDemo.lpr"/>
         <IsPartOfProject Value="True"/>
-        <UnitName Value="ProjectBGRAImageManipulationDemo"/>
       </Unit0>
       <Unit1>
         <Filename Value="unitbgraimagemanipulationdemo.pas"/>
@@ -133,12 +130,6 @@
         </Win32>
       </Options>
     </Linking>
-    <Other>
-      <CompilerMessages>
-        <UseMsgFile Value="True"/>
-      </CompilerMessages>
-      <CompilerPath Value="$(CompPath)"/>
-    </Other>
   </CompilerOptions>
   <Debugging>
     <Exceptions Count="3">

File diff suppressed because it is too large
+ 24 - 502
test/test_bgraimagemanipulation/unitbgraimagemanipulationdemo.lfm


+ 233 - 10
test/test_bgraimagemanipulation/unitbgraimagemanipulationdemo.pas

@@ -52,8 +52,9 @@ interface
 
 uses
   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
-  Buttons, ExtDlgs, ComCtrls, ExtCtrls, BGRAImageManipulation, BGRABitmap,
-  BGRABitmapTypes, BCPanel, BCButton{, BGRATrackBar};
+  Buttons, ExtDlgs, ComCtrls, ExtCtrls, Menus, BGRAImageManipulation,
+  BGRABitmap, BGRABitmapTypes, BCPanel, BCButton, BGRASpeedButton, BCLabel,
+  BCTrackbarUpdown{, BGRATrackBar};
 
 type
 
@@ -61,6 +62,15 @@ type
 
   TFormBGRAImageManipulationDemo = class(TForm)
     Background:        TBCPanel;
+    BCLabel1: TBCLabel;
+    BCLabel2: TBCLabel;
+    BCLabel3: TBCLabel;
+    BCLabel4: TBCLabel;
+    BCLabel5: TBCLabel;
+    BCLabel6: TBCLabel;
+    BCPanelCropAreas: TBCPanel;
+    btBox_Add: TBGRASpeedButton;
+    btBox_Del: TBGRASpeedButton;
     btnSavePictureAll: TBCButton;
     btnShape:          TBCButton;
     btnOpenPicture:    TBCButton;
@@ -70,16 +80,27 @@ type
     btnSetAspectRatio: TBCButton;
     btnRotateLeft:     TBCButton;
     btnRotateRight:    TBCButton;
+    cbBoxList: TComboBox;
     chkFullSize: TCheckBox;
+    edAspectPersonal: TEdit;
     edAspectRatio:     TEdit;
+    edHeight: TBCTrackbarUpdown;
+    edLeft: TBCTrackbarUpdown;
+    edName: TEdit;
+    edTop: TBCTrackbarUpdown;
+    edUnit_Type: TComboBox;
+    edWidth: TBCTrackbarUpdown;
     KeepAspectRatio:   TCheckBox;
     lbAspectRatio:     TLabel;
     lbOptions:         TLabel;
     lbCompression:     TLabel;
+    lbOptions1: TLabel;
     OpenPictureDialog: TOpenPictureDialog;
+    rgAspect: TRadioGroup;
     SavePictureDialog: TSavePictureDialog;
     RateCompression:   TTrackBar;
     SelectDirectoryDialog1: TSelectDirectoryDialog;
+    btApplyAspectRatio: TSpeedButton;
     procedure btnGetAspectRatioFromImageClick(Sender: TObject);
     procedure btnOpenPictureClick(Sender: TObject);
     procedure btnRotateLeftClick(Sender: TObject);
@@ -88,8 +109,28 @@ type
     procedure btnSavePictureClick(Sender: TObject);
     procedure btnSetAspectRatioClick(Sender: TObject);
     procedure KeepAspectRatioClick(Sender: TObject);
+
+    procedure btBox_AddClick(Sender: TObject);
+    procedure btBox_DelClick(Sender: TObject);
+    procedure cbBoxListChange(Sender: TObject);
+    procedure edHeightChange(Sender: TObject; AByUser: boolean);
+    procedure edLeftChange(Sender: TObject; AByUser: boolean);
+    procedure edTopChange(Sender: TObject; AByUser: boolean);
+    procedure edWidthChange(Sender: TObject; AByUser: boolean);
+    procedure FormCreate(Sender: TObject);
+    procedure rgAspectSelectionChanged(Sender: TObject);
+    procedure btApplyAspectRatioClick(Sender: TObject);
+
+    procedure AddedCrop(AOwner: TBGRAImageManipulation; CropArea: TCropArea);
+    procedure DeletedCrop(AOwner: TBGRAImageManipulation; CropArea: TCropArea);
+    procedure ChangedCrop(AOwner: TBGRAImageManipulation; CropArea: TCropArea);
+    procedure SelectedChangedCrop(AOwner: TBGRAImageManipulation; CropArea: TCropArea);
   private
     { private declarations }
+    lastNewBoxNum :Word;
+    changingAspect:Boolean;
+
+    procedure FillBoxUI(ABox :TCropArea);
     procedure SaveCallBack(Bitmap :TBGRABitmap; CropArea: TCropArea);
   public
     { public declarations }
@@ -118,7 +159,11 @@ begin
     // Finally, associate the image into component
     BGRAImageManipulation.Bitmap := Bitmap;
     Bitmap.Free;
-    BGRAImageManipulation.addCropArea(Rect(0,0,100,100));
+    edLeft.MaxValue:=BGRAImageManipulation.Width;
+    edTop.MaxValue:=BGRAImageManipulation.Height;
+    edWidth.MaxValue:=BGRAImageManipulation.Width;
+    edHeight.MaxValue:=BGRAImageManipulation.Height;
+    BGRAImageManipulation.addCropArea(Rect(0,0,120,160));
   end;
 end;
 
@@ -179,7 +224,7 @@ begin
       JpegImage.CompressionQuality := RateCompression.Position;
 
       // And save to file
-      JpegImage.SaveToFile(SelectDirectoryDialog1.FileName+'/'+IntToStr(CropArea.Index));
+      JpegImage.SaveToFile(SelectDirectoryDialog1.FileName+DirectorySeparator+CropArea.Name+'.jpg');
     finally
       JpegImage.Free;
     end;
@@ -187,12 +232,12 @@ end;
 
 procedure TFormBGRAImageManipulationDemo.btnSavePictureAllClick(Sender: TObject);
 begin
-     if SelectDirectoryDialog1.Execute
-     then begin
-                if (chkFullSize.Checked)
-                then Self.BGRAImageManipulation.getAllBitmapsFullSize(@SaveCallBack)
-                else Self.BGRAImageManipulation.getAllBitmaps(@SaveCallBack);
-          end;
+  if SelectDirectoryDialog1.Execute then
+  begin
+    if (chkFullSize.Checked)
+    then Self.BGRAImageManipulation.getAllBitmapsFullSize(@SaveCallBack)
+    else Self.BGRAImageManipulation.getAllBitmaps(@SaveCallBack);
+  end;
 end;
 
 
@@ -215,4 +260,182 @@ begin
   btnSetAspectRatio.Enabled := KeepAspectRatio.Checked;
 end;
 
+procedure TFormBGRAImageManipulationDemo.btBox_AddClick(Sender: TObject);
+var
+   newCropArea :TCropArea;
+
+begin
+  newCropArea :=BGRAImageManipulation.addCropArea(Rect(50, 50, 100, 100), 0 (*, Integer(newBox)*));
+  newCropArea.BorderColor :=VGALime;
+end;
+
+procedure TFormBGRAImageManipulationDemo.btBox_DelClick(Sender: TObject);
+var
+   CropArea :TCropArea;
+   curIndex :Integer;
+
+begin
+  curIndex :=cbBoxList.ItemIndex;
+  CropArea :=TCropArea(cbBoxList.Items.Objects[curIndex]);
+  BGRAImageManipulation.delCropArea(CropArea);
+  cbBoxList.Items.Delete(curIndex);
+(*  if (BGRAImageManipulation.SelectedCropArea <> nil)
+  then cbBoxList.ItemIndex:=BGRAImageManipulation.SelectedCropArea.Index
+  else cbBoxList.ItemIndex:=-1;
+  FillBoxUI(BGRAImageManipulation.SelectedCropArea);*)
+end;
+
+procedure TFormBGRAImageManipulationDemo.cbBoxListChange(Sender: TObject);
+begin
+   BGRAImageManipulation.SelectedCropArea :=TCropArea(cbBoxList.Items.Objects[cbBoxList.ItemIndex]);
+end;
+
+procedure TFormBGRAImageManipulationDemo.edHeightChange(Sender: TObject; AByUser: boolean);
+var
+   CropArea :TCropArea;
+
+begin
+  if AByUser then
+  begin
+    CropArea :=TCropArea(cbBoxList.Items.Objects[cbBoxList.ItemIndex]);
+    CropArea.Height:=edHeight.Value;
+  end;
+end;
+
+procedure TFormBGRAImageManipulationDemo.edLeftChange(Sender: TObject; AByUser: boolean);
+var
+   CropArea :TCropArea;
+
+begin
+  if AByUser then
+  begin
+    CropArea :=TCropArea(cbBoxList.Items.Objects[cbBoxList.ItemIndex]);
+    CropArea.Left :=edLeft.Value;
+  end;
+end;
+
+procedure TFormBGRAImageManipulationDemo.edTopChange(Sender: TObject; AByUser: boolean);
+var
+   CropArea :TCropArea;
+
+begin
+  if AByUser then
+  begin
+    CropArea :=TCropArea(cbBoxList.Items.Objects[cbBoxList.ItemIndex]);
+    CropArea.Top :=edTop.Value;
+  end;
+end;
+
+procedure TFormBGRAImageManipulationDemo.edWidthChange(Sender: TObject; AByUser: boolean);
+var
+   CropArea :TCropArea;
+
+begin
+  if AByUser then
+  begin
+    CropArea :=TCropArea(cbBoxList.Items.Objects[cbBoxList.ItemIndex]);
+    CropArea.Width:=edWidth.Value;
+  end;
+end;
+
+procedure TFormBGRAImageManipulationDemo.FormCreate(Sender: TObject);
+var
+   i :Integer;
+
+begin
+   changingAspect :=False;
+   lastNewBoxNum :=0;
+end;
+
+procedure TFormBGRAImageManipulationDemo.rgAspectSelectionChanged(Sender: TObject);
+begin
+  if changingAspect then Exit;
+
+  Case rgAspect.ItemIndex of
+  0 : BGRAImageManipulation.SelectedCropArea.KeepAspectRatio:=bParent;
+  1 : BGRAImageManipulation.SelectedCropArea.KeepAspectRatio:=bFalse;
+  2 : begin
+           BGRAImageManipulation.SelectedCropArea.KeepAspectRatio:=bTrue;
+           BGRAImageManipulation.SelectedCropArea.AspectRatio:=edAspectPersonal.Text;
+       end;
+  end;
+end;
+
+procedure TFormBGRAImageManipulationDemo.btApplyAspectRatioClick(Sender: TObject);
+begin
+   if BGRAImageManipulation.SelectedCropArea.KeepAspectRatio=bTrue
+   then BGRAImageManipulation.SelectedCropArea.AspectRatio:=edAspectPersonal.Text
+   else begin
+             BGRAImageManipulation.SelectedCropArea.KeepAspectRatio:=bTrue;
+             BGRAImageManipulation.SelectedCropArea.AspectRatio:=edAspectPersonal.Text;
+             changingAspect :=True;
+             rgAspect.ItemIndex :=2;
+             changingAspect :=False;
+        end;
+end;
+
+procedure TFormBGRAImageManipulationDemo.AddedCrop(AOwner: TBGRAImageManipulation; CropArea: TCropArea);
+var
+  curIndex :Integer;
+
+begin
+   curIndex :=BGRAImageManipulation.CropAreas.IndexOf(CropArea);
+   CropArea.Name:='Name '+IntToStr(curIndex);
+   cbBoxList.AddItem(CropArea.Name, CropArea);
+   cbBoxList.ItemIndex:=cbBoxList.Items.IndexOfObject(CropArea);
+   FillBoxUI(CropArea);
+end;
+
+procedure TFormBGRAImageManipulationDemo.DeletedCrop(AOwner: TBGRAImageManipulation; CropArea: TCropArea);
+begin
+  MessageDlg('Deleting Crop Area', 'Deleting '+CropArea.Name, mtInformation, [mbOk], 0);
+end;
+
+procedure TFormBGRAImageManipulationDemo.ChangedCrop(AOwner: TBGRAImageManipulation; CropArea: TCropArea);
+begin
+  if (cbBoxList.Items.Objects[cbBoxList.ItemIndex] = CropArea) then
+  begin
+    FillBoxUI(CropArea);
+  end;
+end;
+
+procedure TFormBGRAImageManipulationDemo.SelectedChangedCrop(AOwner: TBGRAImageManipulation; CropArea: TCropArea);
+var
+   newIndex :Integer;
+begin
+   if (BGRAImageManipulation.SelectedCropArea <> nil)
+   then newIndex :=cbBoxList.Items.IndexOfObject(BGRAImageManipulation.SelectedCropArea) //BGRAImageManipulation.SelectedCropArea.Index;
+   else newIndex :=-1;
+
+   cbBoxList.ItemIndex:=newIndex;
+   FillBoxUI(BGRAImageManipulation.SelectedCropArea);
+end;
+
+procedure TFormBGRAImageManipulationDemo.FillBoxUI(ABox: TCropArea);
+begin
+   if (ABox<>nil)
+   then begin
+           BCPanelCropAreas.Enabled :=True;
+           edName.Text :=ABox.Name;
+           edLeft.Value :=ABox.Left;
+           edTop.Value :=ABox.Top;
+           edWidth.Value :=ABox.Width;
+           edHeight.Value :=ABox.Height;
+
+           //Aspect Ratio
+           changingAspect :=True;
+           Case ABox.KeepAspectRatio of
+           bParent :rgAspect.ItemIndex:=0;
+           bFalse  :rgAspect.ItemIndex:=1;
+           bTrue   :rgAspect.ItemIndex:=2;
+           end;
+           edAspectPersonal.Text:=ABox.AspectRatio;
+           changingAspect:=False;
+
+           //edUnit_Type.ItemIndex :=Integer(ABox^.UnitType);
+        end
+   else BCPanelCropAreas.Enabled :=False;
+end;
+
+
 end.

Some files were not shown because too many files changed in this diff