fixed "bug" with GetCursorPos

preview image can be drag-moved (like in 3D hack, only pan here)
This commit is contained in:
zueuk 2007-10-28 13:24:22 +00:00
parent 9c2b72b4b9
commit 52d4041512
2 changed files with 174 additions and 58 deletions

View File

@ -165,10 +165,14 @@ object AdjustForm: TAdjustForm
Top = 1 Top = 1
Width = 160 Width = 160
Height = 120 Height = 120
Cursor = crCross
Anchors = [] Anchors = []
Center = True Center = True
IncrementalDisplay = True IncrementalDisplay = True
PopupMenu = QualityPopup PopupMenu = QualityPopup
OnMouseDown = PreviewImageMouseDown
OnMouseMove = PreviewImageMouseMove
OnMouseUp = PreviewImageMouseUp
end end
end end
object PageControl: TPageControl object PageControl: TPageControl
@ -363,24 +367,6 @@ object AdjustForm: TAdjustForm
AutoSize = False AutoSize = False
Caption = 'Background' Caption = 'Background'
end 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 object pnlGamma: TPanel
Left = 4 Left = 4
Top = 4 Top = 4
@ -392,7 +378,7 @@ object AdjustForm: TAdjustForm
Caption = 'Gamma' Caption = 'Gamma'
ParentShowHint = False ParentShowHint = False
ShowHint = True ShowHint = True
TabOrder = 9 TabOrder = 8
OnDblClick = DragPanelDblClick OnDblClick = DragPanelDblClick
OnMouseDown = DragPanelMouseDown OnMouseDown = DragPanelMouseDown
OnMouseMove = DragPanelMouseMove OnMouseMove = DragPanelMouseMove
@ -468,24 +454,26 @@ object AdjustForm: TAdjustForm
OnExit = txtVibrancyExit OnExit = txtVibrancyExit
OnKeyPress = txtVibrancyKeyPress OnKeyPress = txtVibrancyKeyPress
end 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 object chkTransparent: TCheckBox
Left = 138 Left = 144
Top = 79 Top = 80
Width = 81 Width = 81
Height = 17 Height = 17
Caption = 'Transparent' Caption = 'Transparent'
Enabled = False Enabled = False
TabOrder = 6
Visible = False
end
object editPPU: TEdit
Left = 304
Top = 76
Width = 75
Height = 21
TabOrder = 7 TabOrder = 7
OnExit = editPPUValidate Visible = False
OnKeyPress = editPPUKeyPress
end end
object pnlBrightness: TPanel object pnlBrightness: TPanel
Left = 4 Left = 4
@ -498,7 +486,7 @@ object AdjustForm: TAdjustForm
Caption = 'Brightness' Caption = 'Brightness'
ParentShowHint = False ParentShowHint = False
ShowHint = True ShowHint = True
TabOrder = 10 TabOrder = 9
OnDblClick = DragPanelDblClick OnDblClick = DragPanelDblClick
OnMouseDown = DragPanelMouseDown OnMouseDown = DragPanelMouseDown
OnMouseMove = DragPanelMouseMove OnMouseMove = DragPanelMouseMove
@ -515,23 +503,12 @@ object AdjustForm: TAdjustForm
Caption = 'Vibrancy' Caption = 'Vibrancy'
ParentShowHint = False ParentShowHint = False
ShowHint = True ShowHint = True
TabOrder = 11 TabOrder = 10
OnDblClick = DragPanelDblClick OnDblClick = DragPanelDblClick
OnMouseDown = DragPanelMouseDown OnMouseDown = DragPanelMouseDown
OnMouseMove = DragPanelMouseMove OnMouseMove = DragPanelMouseMove
OnMouseUp = DragPanelMouseUp OnMouseUp = DragPanelMouseUp
end 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 end
object TabSheet3: TTabSheet object TabSheet3: TTabSheet
Caption = 'Gradient' Caption = 'Gradient'
@ -1028,6 +1005,33 @@ object AdjustForm: TAdjustForm
end end
end 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 object QualityPopup: TPopupMenu
Images = MainForm.Buttons Images = MainForm.Buttons
Left = 200 Left = 200
@ -1057,6 +1061,11 @@ object AdjustForm: TAdjustForm
OnClick = mnuInstantPreviewClick OnClick = mnuInstantPreviewClick
end end
end end
object ColorDialog: TColorDialog
Options = [cdFullOpen]
Left = 232
Top = 16
end
object GradientPopup: TPopupMenu object GradientPopup: TPopupMenu
Images = MainForm.Buttons Images = MainForm.Buttons
Left = 200 Left = 200

View File

@ -23,7 +23,7 @@ interface
uses uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, ComCtrls, Buttons, Menus, AppEvnts, StdCtrls, ExtCtrls, ComCtrls, Buttons, Menus, AppEvnts,
ControlPoint, Cmap, Render, JvExControls, JvColorBox, JvColorButton; ControlPoint, Cmap, Render;
const const
WM_UPDATE_PARAMS = WM_APP + 5439; WM_UPDATE_PARAMS = WM_APP + 5439;
@ -41,6 +41,7 @@ type
mnuLowQuality: TMenuItem; mnuLowQuality: TMenuItem;
mnuMediumQuality: TMenuItem; mnuMediumQuality: TMenuItem;
mnuHighQuality: TMenuItem; mnuHighQuality: TMenuItem;
ColorDialog: TColorDialog;
PrevPnl: TPanel; PrevPnl: TPanel;
PreviewImage: TImage; PreviewImage: TImage;
PageControl: TPageControl; PageControl: TPageControl;
@ -59,6 +60,7 @@ type
txtBrightness: TEdit; txtBrightness: TEdit;
scrollVibrancy: TScrollBar; scrollVibrancy: TScrollBar;
txtVibrancy: TEdit; txtVibrancy: TEdit;
ColorPanel: TPanel;
TabSheet3: TTabSheet; TabSheet3: TTabSheet;
scrollAngle: TScrollBar; scrollAngle: TScrollBar;
txtAngle: TEdit; txtAngle: TEdit;
@ -122,8 +124,6 @@ type
Bevel2: TBevel; Bevel2: TBevel;
N8: TMenuItem; N8: TMenuItem;
mnuInstantPreview: TMenuItem; mnuInstantPreview: TMenuItem;
editPPU: TEdit;
pnlMasterScale: TPanel;
pnlZoom: TPanel; pnlZoom: TPanel;
pnlXpos: TPanel; pnlXpos: TPanel;
pnlYpos: TPanel; pnlYpos: TPanel;
@ -133,7 +133,8 @@ type
pnlVibrancy: TPanel; pnlVibrancy: TPanel;
chkResizeMain: TCheckBox; chkResizeMain: TCheckBox;
Bevel3: TBevel; Bevel3: TBevel;
ColorButton: TJvColorButton; pnlMasterScale: TPanel;
editPPU: TEdit;
procedure FormCreate(Sender: TObject); procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormDestroy(Sender: TObject); procedure FormDestroy(Sender: TObject);
@ -175,6 +176,7 @@ type
procedure scrollZoomChange(Sender: TObject); procedure scrollZoomChange(Sender: TObject);
procedure scrollCenterXChange(Sender: TObject); procedure scrollCenterXChange(Sender: TObject);
procedure scrollCenterYChange(Sender: TObject); procedure scrollCenterYChange(Sender: TObject);
procedure ColorPanelClick(Sender: TObject);
procedure scrollContrastScroll(Sender: TObject; procedure scrollContrastScroll(Sender: TObject;
ScrollCode: TScrollCode; var ScrollPos: Integer); ScrollCode: TScrollCode; var ScrollPos: Integer);
procedure txtGammaEnter(Sender: TObject); procedure txtGammaEnter(Sender: TObject);
@ -254,7 +256,14 @@ type
Shift: TShiftState; X, Y: Integer); Shift: TShiftState; X, Y: Integer);
procedure DragPanelDblClick(Sender: TObject); procedure DragPanelDblClick(Sender: TObject);
procedure FormActivate(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 private
Resetting: boolean; Resetting: boolean;
@ -269,6 +278,10 @@ type
pnlDragValue: double; pnlDragValue: double;
mousepos: TPoint; mousepos: TPoint;
camDragMode, camDragged, camMM: boolean;
camDragPos, camDragOld: TPoint;
camDragValueX, camDragValueY, camSin, camCos: double;
private // gradient stuff private // gradient stuff
Palette, BackupPal: TColorMap; Palette, BackupPal: TColorMap;
tmpBackupPal: TColorMap; tmpBackupPal: TColorMap;
@ -374,7 +387,7 @@ begin
scrollCenterY.Position := 0; scrollCenterY.Position := 0;
end; 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); //cbColor.text := IntToHex(integer(ColorPanel.Color), 6);
GetMainWindowSize; GetMainWindowSize;
@ -920,16 +933,22 @@ begin
DrawPreview; DrawPreview;
end; end;
procedure TAdjustForm.ColorButtonChange(Sender: TObject); procedure TAdjustForm.ColorPanelClick(Sender: TObject);
var var
col: Longint; col: Longint;
begin begin
col := ColorToRGB(ColorButton.Color); 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[0] := col and 255;
cp.background[1] := col shr 8 and 255; cp.background[1] := col shr 8 and 255;
cp.background[2] := col shr 16 and 255; cp.background[2] := col shr 16 and 255;
DrawPreview; DrawPreview;
UpdateFlame(true); UpdateFlame(true);
end;
end; end;
procedure TAdjustForm.scrollContrastScroll(Sender: TObject; procedure TAdjustForm.scrollContrastScroll(Sender: TObject;
@ -1956,7 +1975,8 @@ begin
//SetCaptureControl(TControl(Sender)); //SetCaptureControl(TControl(Sender));
Screen.Cursor := crHSplit; Screen.Cursor := crHSplit;
GetCursorPos(mousepos); // hmmm //GetCursorPos(mousepos); // hmmm
mousePos := (Sender as TControl).ClientToScreen(Point(x, y));
pnlDragged := false; pnlDragged := false;
end; end;
@ -2101,5 +2121,92 @@ begin
txtAngle.text := FloatToStr(cp.FAngle * 180 / PI); txtAngle.text := FloatToStr(cp.FAngle * 180 / PI);
end; 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. end.