From 52d404151247a5b155bac265ce215862ff4147cb Mon Sep 17 00:00:00 2001 From: zueuk Date: Sun, 28 Oct 2007 13:24:22 +0000 Subject: [PATCH] fixed "bug" with GetCursorPos preview image can be drag-moved (like in 3D hack, only pan here) --- 2.10/Source/Adjust.dfm | 97 +++++++++++++++-------------- 2.10/Source/Adjust.pas | 135 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 174 insertions(+), 58 deletions(-) diff --git a/2.10/Source/Adjust.dfm b/2.10/Source/Adjust.dfm index e132891..75ee779 100644 --- a/2.10/Source/Adjust.dfm +++ b/2.10/Source/Adjust.dfm @@ -165,10 +165,14 @@ object AdjustForm: TAdjustForm Top = 1 Width = 160 Height = 120 + Cursor = crCross Anchors = [] Center = True IncrementalDisplay = True PopupMenu = QualityPopup + OnMouseDown = PreviewImageMouseDown + OnMouseMove = PreviewImageMouseMove + OnMouseUp = PreviewImageMouseUp end end object PageControl: TPageControl @@ -363,24 +367,6 @@ object AdjustForm: TAdjustForm AutoSize = False Caption = 'Background' end - object pnlMasterScale: TPanel - Left = 232 - Top = 76 - Width = 73 - Height = 21 - Cursor = crHandPoint - Hint = 'Click and drag to change value' - Alignment = taLeftJustify - BevelOuter = bvLowered - Caption = ' Master Scale' - ParentShowHint = False - ShowHint = True - TabOrder = 8 - OnDblClick = DragPanelDblClick - OnMouseDown = DragPanelMouseDown - OnMouseMove = DragPanelMouseMove - OnMouseUp = DragPanelMouseUp - end object pnlGamma: TPanel Left = 4 Top = 4 @@ -392,7 +378,7 @@ object AdjustForm: TAdjustForm Caption = 'Gamma' ParentShowHint = False ShowHint = True - TabOrder = 9 + TabOrder = 8 OnDblClick = DragPanelDblClick OnMouseDown = DragPanelMouseDown OnMouseMove = DragPanelMouseMove @@ -468,24 +454,26 @@ object AdjustForm: TAdjustForm OnExit = txtVibrancyExit OnKeyPress = txtVibrancyKeyPress end + object ColorPanel: TPanel + Left = 72 + Top = 78 + Width = 65 + Height = 21 + Cursor = crHandPoint + BevelOuter = bvLowered + Color = clBlack + TabOrder = 6 + OnClick = ColorPanelClick + end object chkTransparent: TCheckBox - Left = 138 - Top = 79 + Left = 144 + Top = 80 Width = 81 Height = 17 Caption = 'Transparent' Enabled = False - TabOrder = 6 - Visible = False - end - object editPPU: TEdit - Left = 304 - Top = 76 - Width = 75 - Height = 21 TabOrder = 7 - OnExit = editPPUValidate - OnKeyPress = editPPUKeyPress + Visible = False end object pnlBrightness: TPanel Left = 4 @@ -498,7 +486,7 @@ object AdjustForm: TAdjustForm Caption = 'Brightness' ParentShowHint = False ShowHint = True - TabOrder = 10 + TabOrder = 9 OnDblClick = DragPanelDblClick OnMouseDown = DragPanelMouseDown OnMouseMove = DragPanelMouseMove @@ -515,23 +503,12 @@ object AdjustForm: TAdjustForm Caption = 'Vibrancy' ParentShowHint = False ShowHint = True - TabOrder = 11 + TabOrder = 10 OnDblClick = DragPanelDblClick OnMouseDown = DragPanelMouseDown OnMouseMove = DragPanelMouseMove OnMouseUp = DragPanelMouseUp end - object ColorButton: TJvColorButton - Left = 72 - Top = 75 - Width = 57 - Height = 24 - OtherCaption = '&Other...' - Options = [cdFullOpen, cdAnyColor] - OnChange = ColorButtonChange - TabOrder = 12 - TabStop = False - end end object TabSheet3: TTabSheet Caption = 'Gradient' @@ -1028,6 +1005,33 @@ object AdjustForm: TAdjustForm end end end + object pnlMasterScale: TPanel + Left = 280 + Top = 108 + Width = 57 + Height = 21 + Cursor = crHandPoint + Hint = 'Click and drag to change value' + Alignment = taLeftJustify + BevelOuter = bvLowered + Caption = ' Scale' + ParentShowHint = False + ShowHint = True + TabOrder = 2 + OnDblClick = DragPanelDblClick + OnMouseDown = DragPanelMouseDown + OnMouseMove = DragPanelMouseMove + OnMouseUp = DragPanelMouseUp + end + object editPPU: TEdit + Left = 336 + Top = 108 + Width = 49 + Height = 21 + TabOrder = 3 + OnExit = editPPUValidate + OnKeyPress = editPPUKeyPress + end object QualityPopup: TPopupMenu Images = MainForm.Buttons Left = 200 @@ -1057,6 +1061,11 @@ object AdjustForm: TAdjustForm OnClick = mnuInstantPreviewClick end end + object ColorDialog: TColorDialog + Options = [cdFullOpen] + Left = 232 + Top = 16 + end object GradientPopup: TPopupMenu Images = MainForm.Buttons Left = 200 diff --git a/2.10/Source/Adjust.pas b/2.10/Source/Adjust.pas index b1d823f..a4c9557 100644 --- a/2.10/Source/Adjust.pas +++ b/2.10/Source/Adjust.pas @@ -23,7 +23,7 @@ interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, ComCtrls, Buttons, Menus, AppEvnts, - ControlPoint, Cmap, Render, JvExControls, JvColorBox, JvColorButton; + ControlPoint, Cmap, Render; const WM_UPDATE_PARAMS = WM_APP + 5439; @@ -41,6 +41,7 @@ type mnuLowQuality: TMenuItem; mnuMediumQuality: TMenuItem; mnuHighQuality: TMenuItem; + ColorDialog: TColorDialog; PrevPnl: TPanel; PreviewImage: TImage; PageControl: TPageControl; @@ -59,6 +60,7 @@ type txtBrightness: TEdit; scrollVibrancy: TScrollBar; txtVibrancy: TEdit; + ColorPanel: TPanel; TabSheet3: TTabSheet; scrollAngle: TScrollBar; txtAngle: TEdit; @@ -122,8 +124,6 @@ type Bevel2: TBevel; N8: TMenuItem; mnuInstantPreview: TMenuItem; - editPPU: TEdit; - pnlMasterScale: TPanel; pnlZoom: TPanel; pnlXpos: TPanel; pnlYpos: TPanel; @@ -133,7 +133,8 @@ type pnlVibrancy: TPanel; chkResizeMain: TCheckBox; Bevel3: TBevel; - ColorButton: TJvColorButton; + pnlMasterScale: TPanel; + editPPU: TEdit; procedure FormCreate(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure FormDestroy(Sender: TObject); @@ -175,6 +176,7 @@ type procedure scrollZoomChange(Sender: TObject); procedure scrollCenterXChange(Sender: TObject); procedure scrollCenterYChange(Sender: TObject); + procedure ColorPanelClick(Sender: TObject); procedure scrollContrastScroll(Sender: TObject; ScrollCode: TScrollCode; var ScrollPos: Integer); procedure txtGammaEnter(Sender: TObject); @@ -254,7 +256,14 @@ type Shift: TShiftState; X, Y: Integer); procedure DragPanelDblClick(Sender: TObject); procedure FormActivate(Sender: TObject); - procedure ColorButtonChange(Sender: TObject); + + procedure PreviewImageMouseDown(Sender: TObject; Button: TMouseButton; + Shift: TShiftState; X, Y: Integer); + procedure PreviewImageMouseMove(Sender: TObject; Shift: TShiftState; X, + Y: Integer); + procedure PreviewImageMouseUp(Sender: TObject; Button: TMouseButton; + Shift: TShiftState; X, Y: Integer); + procedure PreviewImageDblClick(Sender: TObject); private Resetting: boolean; @@ -269,6 +278,10 @@ type pnlDragValue: double; mousepos: TPoint; + camDragMode, camDragged, camMM: boolean; + camDragPos, camDragOld: TPoint; + camDragValueX, camDragValueY, camSin, camCos: double; + private // gradient stuff Palette, BackupPal: TColorMap; tmpBackupPal: TColorMap; @@ -374,7 +387,7 @@ begin scrollCenterY.Position := 0; end; - ColorButton.Color := cp.background[2] shl 16 + cp.background[1] shl 8 + cp.background[0]; + ColorPanel.color := cp.background[2] shl 16 + cp.background[1] shl 8 + cp.background[0]; //cbColor.text := IntToHex(integer(ColorPanel.Color), 6); GetMainWindowSize; @@ -920,16 +933,22 @@ begin DrawPreview; end; -procedure TAdjustForm.ColorButtonChange(Sender: TObject); +procedure TAdjustForm.ColorPanelClick(Sender: TObject); var col: Longint; begin - col := ColorToRGB(ColorButton.Color); - cp.background[0] := col and 255; - cp.background[1] := col shr 8 and 255; - cp.background[2] := col shr 16 and 255; - DrawPreview; - UpdateFlame(true); + ColorDialog.Color := COlorPanel.Color; + if ColorDialog.Execute then + begin + ColorPanel.Color := ColorDialog.Color; + //cbColor.text := IntToHex(integer(ColorDialog.Color), 6); + col := ColorToRGB(ColorDialog.Color); + cp.background[0] := col and 255; + cp.background[1] := col shr 8 and 255; + cp.background[2] := col shr 16 and 255; + DrawPreview; + UpdateFlame(true); + end; end; procedure TAdjustForm.scrollContrastScroll(Sender: TObject; @@ -1956,7 +1975,8 @@ begin //SetCaptureControl(TControl(Sender)); Screen.Cursor := crHSplit; - GetCursorPos(mousepos); // hmmm + //GetCursorPos(mousepos); // hmmm + mousePos := (Sender as TControl).ClientToScreen(Point(x, y)); pnlDragged := false; end; @@ -2101,5 +2121,92 @@ begin txtAngle.text := FloatToStr(cp.FAngle * 180 / PI); end; +/////////////////////////////////////////////////////////////////////////////// + +procedure TAdjustForm.PreviewImageMouseDown(Sender: TObject; + Button: TMouseButton; Shift: TShiftState; X, Y: Integer); +begin + if Button <> mbLeft then exit; + + camDragValueX := cp.Center[0]; + camDragValueY := cp.Center[1]; + + camDragMode := true; + camDragPos.x := 0; + camDragPos.y := 0; + camDragOld.x := x; + camDragOld.y := y; + camSin := sin(cp.FAngle); + camCos := cos(cp.FAngle); + camMM := false; + //SetCaptureControl(TControl(Sender)); + + Screen.Cursor := crNone; + //GetCursorPos(mousepos); // hmmm + mousePos := (Sender as TControl).ClientToScreen(Point(x, y)); + camDragged := false; +end; + +procedure TAdjustForm.PreviewImageMouseMove(Sender: TObject; + Shift: TShiftState; X, Y: Integer); +var + sc, vx, vy: double; +begin + if camMM then // hack: to skip MouseMove event + begin + camMM:=false; + end + else + if camDragMode and ( (x <> camDragOld.x) or (y <> camDragOld.y) ) then + begin + Inc(camDragPos.x, x - camDragOld.x); + Inc(camDragPos.y, y - camDragOld.y); + + vx := Round6(camDragValueX - (camDragPos.x * camCos - camDragPos.y * camSin) / 200); + vy := Round6(camDragValueY - (camDragPos.x * camSin + camDragPos.y * camCos) / 200); + + cp.center[0] := vx; + txtCenterX.Text := FloatToStr(vx); + txtCenterX.Refresh; + cp.center[1] := vy; + txtCenterY.Text := FloatToStr(vy); + txtCenterY.Refresh; + + SetCursorPos(MousePos.x, MousePos.y); // hmmm + pnlMM:=true; + + camDragged := True; + DrawPreview; + end; +end; + +procedure TAdjustForm.PreviewImageMouseUp(Sender: TObject; + Button: TMouseButton; Shift: TShiftState; X, Y: Integer); +begin + if Button <> mbLeft then exit; + + if camDragMode then + begin + camDragMode := false; + Screen.Cursor := crDefault; + + if camDragged then + begin + UpdateFlame; + camDragged := False; + end; + end; +end; + +procedure TAdjustForm.PreviewImageDblClick(Sender: TObject); +begin + cp.center[0] := 0; + cp.center[1] := 0; + txtCenterX.Text := '0'; + txtCenterY.Text := '0'; + + UpdateFlame; +end; + end.