Pārlūkot izejas kodu

Added preview functionality to dialog Adjust curves

Lulu 2 gadi atpakaļ
vecāks
revīzija
b53f8b1c1d

+ 27 - 18
lazpaint/dialog/color/uadjustcurves.lfm

@@ -1,11 +1,11 @@
 object FAdjustCurves: TFAdjustCurves
   Left = 439
-  Height = 326
+  Height = 345
   Top = 193
   Width = 432
   BorderIcons = [biSystemMenu, biMinimize]
   Caption = 'Adjust curves'
-  ClientHeight = 326
+  ClientHeight = 345
   ClientWidth = 432
   KeyPreview = True
   OnCloseQuery = FormCloseQuery
@@ -15,7 +15,7 @@ object FAdjustCurves: TFAdjustCurves
   OnKeyDown = FormKeyDown
   OnShow = FormShow
   Position = poOwnerFormCenter
-  LCLVersion = '1.8.2.0'
+  LCLVersion = '2.2.4.0'
   object TabControl1: TTabControl
     Left = 0
     Height = 289
@@ -33,12 +33,11 @@ object FAdjustCurves: TFAdjustCurves
       'Alpha'
     )
     Align = alClient
-    Anchors = [akLeft, akTop, akRight, akBottom]
     TabOrder = 0
     object vsChart: TBGRAVirtualScreen
       Left = 2
-      Height = 230
-      Top = 57
+      Height = 239
+      Top = 48
       Width = 428
       OnRedraw = vsChartRedraw
       Align = alClient
@@ -53,7 +52,7 @@ object FAdjustCurves: TFAdjustCurves
     object Panel2: TPanel
       Left = 2
       Height = 25
-      Top = 32
+      Top = 23
       Width = 428
       Align = alTop
       ClientHeight = 25
@@ -65,7 +64,6 @@ object FAdjustCurves: TFAdjustCurves
         Top = 0
         Width = 90
         Align = alNone
-        Anchors = [akTop, akLeft]
         EdgeBorders = []
         Images = FMain.ImageList16
         ParentShowHint = False
@@ -98,50 +96,61 @@ object FAdjustCurves: TFAdjustCurves
   end
   object Panel1: TPanel
     Left = 0
-    Height = 37
+    Height = 56
     Top = 289
     Width = 432
     Align = alBottom
     BevelOuter = bvNone
-    ClientHeight = 37
+    ClientHeight = 56
     ClientWidth = 432
     TabOrder = 1
     object Button_Cancel: TButton
       Left = 213
       Height = 22
-      Top = 7
+      Top = 26
       Width = 72
       Anchors = [akLeft, akBottom]
       Cancel = True
-      Caption = 'Cancel'
+      Caption = 'rsCancel'
       ModalResult = 2
       TabOrder = 0
     end
     object Button_OK: TButton
       Left = 149
       Height = 22
-      Top = 7
+      Top = 26
       Width = 59
       Anchors = [akLeft, akBottom]
-      Caption = 'OK'
+      Caption = 'rsOK'
       Default = True
       ModalResult = 1
       OnClick = Button_OKClick
       TabOrder = 1
     end
+    object CheckBox_Preview: TCheckBox
+      Left = 8
+      Height = 19
+      Top = 0
+      Width = 70
+      Caption = 'rsPreview'
+      Checked = True
+      OnChange = CheckBox_PreviewChange
+      State = cbChecked
+      TabOrder = 2
+    end
   end
   object Timer_Thread: TTimer
     Enabled = False
     Interval = 200
     OnTimer = Timer_ThreadTimer
-    left = 62
-    top = 466
+    Left = 62
+    Top = 466
   end
   object Timer_Chart: TTimer
     Enabled = False
     Interval = 20
     OnTimer = Timer_ChartTimer
-    left = 123
-    top = 467
+    Left = 123
+    Top = 467
   end
 end

+ 3 - 2
lazpaint/dialog/color/uadjustcurves.lrj

@@ -3,6 +3,7 @@
 {"hash":26714085,"name":"tfadjustcurves.toolbutton_newcurve.hint","sourcebytes":[68,105,115,99,97,114,100,32,99,117,114,114,101,110,116,32,99,117,114,118,101,32,97,110,100,32,115,116,97,114,116,32,97,32,110,101,119,32,111,110,101],"value":"Discard current curve and start a new one"},
 {"hash":1994857,"name":"tfadjustcurves.toolbutton_removepoint.hint","sourcebytes":[82,101,109,111,118,101,32,115,101,108,101,99,116,101,100,32,112,111,105,110,116,32,40,68,101,108,41],"value":"Remove selected point (Del)"},
 {"hash":179103845,"name":"tfadjustcurves.toolbutton_posterize.hint","sourcebytes":[80,111,115,116,101,114,105,122,101],"value":"Posterize"},
-{"hash":77089212,"name":"tfadjustcurves.button_cancel.caption","sourcebytes":[67,97,110,99,101,108],"value":"Cancel"},
-{"hash":1339,"name":"tfadjustcurves.button_ok.caption","sourcebytes":[79,75],"value":"OK"}
+{"hash":127421996,"name":"tfadjustcurves.button_cancel.caption","sourcebytes":[114,115,67,97,110,99,101,108],"value":"rsCancel"},
+{"hash":497723,"name":"tfadjustcurves.button_ok.caption","sourcebytes":[114,115,79,75],"value":"rsOK"},
+{"hash":126662215,"name":"tfadjustcurves.checkbox_preview.caption","sourcebytes":[114,115,80,114,101,118,105,101,119],"value":"rsPreview"}
 ]}

+ 50 - 1
lazpaint/dialog/color/uadjustcurves.pas

@@ -25,6 +25,7 @@ type
   { TFAdjustCurves }
 
   TFAdjustCurves = class(TForm)
+    CheckBox_Preview: TCheckBox;
     Panel2: TPanel;
     Timer_Chart: TTimer;
     Timer_Thread: TTimer;
@@ -38,6 +39,7 @@ type
     Panel1: TPanel;
     TabControl1: TTabControl;
     procedure Button_OKClick(Sender: TObject);
+    procedure CheckBox_PreviewChange(Sender: TObject);
     procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
     procedure FormDestroy(Sender: TObject);
     procedure FormHide(Sender: TObject);
@@ -104,6 +106,11 @@ type
     procedure DiscardHistogram;
     procedure QueryHistogramRedraw;
     procedure OnTaskEvent({%H-}ASender: TObject; AEvent: TThreadManagerEvent);
+  private
+    FInitializingGui: boolean;
+    FComputedImage: TBGRABitmap;
+    procedure DisplayComputedImage;
+    procedure StoreComputedImage;
   public
     { public declarations }
     function ShowModal: integer; override;
@@ -336,6 +343,13 @@ procedure TFAdjustCurves.FormShow(Sender: TObject);
 begin
   vsChart.DiscardBitmap;
   DiscardHistogram;
+
+  FInitializingGui := True;
+  Button_OK.Caption := rsOK;
+  Button_Cancel.Caption := rsCancel;
+  CheckBox_Preview.Caption := rsPreview;
+  CheckBox_Preview.Checked := True;
+  FInitializingGui := False;
 end;
 
 procedure TFAdjustCurves.TabControl1Change(Sender: TObject);
@@ -428,14 +442,29 @@ procedure TFAdjustCurves.FormDestroy(Sender: TObject);
 begin
   FreeAndNil(FGraphBackgroundLeft);
   FreeAndNil(FGraphBackgroundBottom);
+  FreeAndNil(FComputedImage);
 end;
 
 procedure TFAdjustCurves.Button_OKClick(Sender: TObject);
 begin
+  if not CheckBox_Preview.Checked then DisplayComputedImage;
+
   if not FFilterConnector.ActionDone then FFilterConnector.ValidateAction;
   ModalResult := mrOK;
 end;
 
+procedure TFAdjustCurves.CheckBox_PreviewChange(Sender: TObject);
+begin
+  if FInitializingGui then exit;
+  if CheckBox_Preview.Checked then
+    DisplayComputedImage
+  else
+  begin
+    StoreComputedImage;
+    FFilterConnector.RestoreBackup;
+  end;
+end;
+
 procedure TFAdjustCurves.FormCloseQuery(Sender: TObject; var CanClose: boolean);
 begin
   FThreadManager.Quit;
@@ -947,7 +976,10 @@ begin
       if FThreadManager.ReadyToClose then
         Close
       else
-        if AEvent = tmeCompletedTask then Button_OK.Enabled := true;
+        if AEvent = tmeCompletedTask then begin
+          Button_OK.Enabled := true;
+          CheckBox_Preview.Enabled := true;
+        end;
     end;
   tmeStartingNewTask:
     begin
@@ -955,10 +987,27 @@ begin
       Timer_Thread.Interval := 100;
       Timer_Thread.Enabled := true;
       Button_OK.Enabled := false;
+      FInitializingGui := True;
+      CheckBox_Preview.Enabled := false;
+      CheckBox_Preview.Checked := True;
+      FreeAndNil(FComputedImage);
+      FInitializingGui := False;
     end;
   end;
 end;
 
+procedure TFAdjustCurves.DisplayComputedImage;
+begin
+  if FComputedImage <> nil then
+    FFilterConnector.PutImage(FComputedImage, false, false);
+end;
+
+procedure TFAdjustCurves.StoreComputedImage;
+begin
+  if FComputedImage = nil then
+    FComputedImage := FFilterConnector.ActiveLayer.Duplicate;
+end;
+
 function TFAdjustCurves.ShowModal: integer;
 begin
   if (FFilterConnector = nil) or (FFilterConnector.ActiveLayer = nil) then