-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMoveTo.pas
209 lines (186 loc) · 5.3 KB
/
MoveTo.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
unit MoveTo;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Buttons, StdCtrls, LifeConst, ExtCtrls;
type
TMoveToForm = class(TForm)
Panel1: TPanel;
Bevel1: TBevel;
NW: TSpeedButton;
N: TSpeedButton;
NE: TSpeedButton;
W: TSpeedButton;
CenterButton: TSpeedButton;
E: TSpeedButton;
SW: TSpeedButton;
S: TSpeedButton;
SE: TSpeedButton;
Label1: TLabel;
Label2: TLabel;
NullButton: TSpeedButton;
EditX: TEdit;
EditY: TEdit;
OKMoveButton: TButton;
CancelMoveButton: TButton;
GroupBox1: TGroupBox;
YLabel: TLabel;
XLabel: TLabel;
procedure NWClick(Sender: TObject);
procedure EditXKeyPress(Sender: TObject; var Key: Char);
procedure OKMoveButtonClick(Sender: TObject);
procedure NWMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure EditXChange(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
EditedByUser: boolean;
OldCursorPos: TPoint;
procedure GetDlgSettings;
procedure SaveDlgSettings;
public
X,Y: integer;
BoundingRect: TRect;
end;
var
MoveToForm: TMoveToForm;
implementation
{$R *.DFM}
uses
Prefs, LifeUtil, Unit1;
procedure TMoveToForm.NWClick(Sender: TObject);
begin
SetCursorPos(OldCursorPos.x,OldCursorPos.y);
ModalResult:= TControl(Sender).Tag;
end;
procedure TMoveToForm.EditXKeyPress(Sender: TObject; var Key: Char);
var
OK: boolean;
begin
if not(key in ['0'..'9',#1..#31,'-']) then key:= #0
else EditedByUser:= true;
OK:= true;
try X:= StrToInt(EditX.Text) except OK:= false end;
try Y:= StrToInt(EditY.Text) except OK:= false end;
OkMoveButton.Enabled:= OK;
if key = #27 then ModalResult:= mrCancel
else if (key = #13) and OK then ModalResult:= mrOK;
end;
procedure TMoveToForm.OKMoveButtonClick(Sender: TObject);
var
OK: boolean;
begin
OK:= true;
try X:= StrToInt(EditX.Text) except OK:= false end;
try Y:= StrToInt(EditY.Text) except OK:= false end;
if X > (1024*1024) then X:= (1024*1024)
else if X < -((1024*1024)-1) then x:= -((1024*1024)-1);
if Y > (1024*1024) then Y:= (1024*1024)
else if Y < -((1024*1024)-1) then Y:= -((1024*1024)-1);
if not(Ok) then ModalResult:= mrCancel;
end;
procedure TMoveToForm.NWMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var
MiddleX, MiddleY: integer;
begin
if not EditedByUser then begin
with BoundingRect do begin
MiddleX:= (Right + Left) div 2;
MiddleY:= (Top + Bottom) div 2;
case TControl(Sender).Tag of
idN: begin X:= MiddleX; Y:=Top; end;
idNW:begin X:= Left; Y:=Top; end;
idW: begin X:= Left; Y:=MiddleY; end;
idSW:begin X:= Left; Y:=Bottom-1; end;
idS: begin X:= MiddleX; Y:=Bottom-1; end;
idSE:begin X:= Right-1; Y:=Bottom-1; end;
idE: begin X:= Right-1; Y:=MiddleY; end;
idNE:begin X:= Right-1; Y:=Top; end;
idCenter:begin X:= MiddleX; Y:=MiddleY; end;
idNulCenter: begin X:= 0; Y:= 0; end;
end; {case}
if X > MaxX then x:= x or $FFFF0000;
if y > MaxX then y:= y or $FFFF0000;
if x < MinX then x:= x and $0000ffff;
if y < MinY then y:= y and $0000ffff;
EditX.Text:= IntToStr(x);
EditY.Text:= IntToStr(y);
end; {with}
end;
end;
procedure TMoveToForm.EditXChange(Sender: TObject);
var
okX, okY: boolean;
begin
if TEdit(Sender).Modified and (EditX.Text = '') and (EditY.Text = '') then
EditedByUser:= false;
okX:= true;
try
X:= StrToInt(EditX.Text);
if (X < MinX) or (X > MaxX) then okX:= false
else EditX.Font.Color:= clWindowText;
except okX:= false;
end; {try}
if not okX then EditX.Font.Color:= clRed;
okY:= true;
try
Y:= StrToInt(EditY.Text);
if (Y < MinY) or (Y > MaxY) then okY:= false
else EditY.Font.Color:= clWindowText;
except okY:= false;
end; {try}
if not okY then EditY.Font.Color:= clRed;
OKMoveButton.Enabled:= okX and okY;
end;
procedure TMoveToForm.FormActivate(Sender: TObject);
var
CenterPoint: TPoint;
begin
GetCursorPos(OldCursorPos);
with CenterButton do begin
CenterPoint.x:= Left + (Width div 2);
CenterPoint.y:= Top + (Height div 2);
CenterPoint:= Self.ClientToScreen(CenterPoint);
SetCursorPos(CenterPoint.x,CenterPoint.y);
end; {with}
XLabel.Caption:= Format(cXLabel,[Form1.MyLifeBox.XScroll]);
YLabel.Caption:= Format(cYLabel,[Form1.MyLifeBox.YScroll]);
DRaw(true);
end;
procedure TMoveToForm.FormCreate(Sender: TObject);
begin
GetDlgSettings;
end;
procedure TMoveToForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
SaveDlgSettings;
end;
procedure TMoveToForm.GetDlgSettings;
begin
with OpenReg do try
if OpenKey('MoveTo.pas',DontCreate) then try
Left:= ReadInteger('Left');
Top:= ReadInteger('Top');
except begin
Top:= Screen.Width;
Left:= Screen.Height;
end; {except}
end; {if}
finally Free;
Left:= Min(Left,Screen.Width - Width);
Top:= Min(Top, Screen.Height - Height);
end; {with}
end;
procedure TMoveToForm.SaveDlgSettings;
begin
with OpenReg do try
OpenKey('MoveTo.pas',MakeIt);
WriteInteger('Left',Left);
WriteInteger('Top',Top);
finally Free;
end; {with}
end;
end.