This repository was archived by the owner on Jan 23, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTools.pas
More file actions
2751 lines (2599 loc) · 76.1 KB
/
Tools.pas
File metadata and controls
2751 lines (2599 loc) · 76.1 KB
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit Tools;
interface
uses
Unit1, Graphics, Windows, Types, Forms, Classes, Unit3, Unit4,
Controls, Unit7, Dialogs, Unit11, Menus, LevelEngine;
const
ddx=0;
ddy=7;
MaxSlope=10/18;
MaxGrassWidth=14/50;
WheelHeight=0.85;
StNum=4;
//
stReady=0;
stEdit=1;
//
stMove=1;
stSelRect=2;
stTransform=3;
//
stOnePoint=1;
stTwoPoints=2;
//
stMovePoint=2;
type
TSVertex=record
x,y:integer;
dx,dy:integer;
Visible:boolean;
end;
TTransArray=array[0..2,0..2] of TPoint;
TCreateObjectTool=class(TTool)
Object_:TEObject;
constructor Create(Par:TLevel);override;
procedure Draw;override;
procedure MouseDown(Shift: TShiftState;nx,ny:integer);override;
procedure MouseMove(Shift: TShiftState;nx,ny:integer);override;
procedure MouseUp(Shift: TShiftState;nx,ny:integer);override;
end;
TCreateVertexTool=class(TTool)
published
constructor Create(Par:TLevel);override;
destructor Destroy;override;
procedure Draw;override;
procedure MouseDown(Shift: TShiftState;nx,ny:integer);override;
procedure MouseMove(Shift: TShiftState;nx,ny:integer);override;
procedure MouseUp(Shift: TShiftState;nx,ny:integer);override;
procedure KeyPressed(key:word);override;
procedure Initialize;
property State:integer read Fstate write Setstate;
protected
procedure Setstate(const Value: integer);override;
private
Poly:TPolygon;
EVertex:integer;
dir:integer;
end;
TSelectTool=class(TTool)
published
constructor Create(Par:TLevel);override;
procedure Initialize(Shift: TShiftState;nx,ny:integer);
procedure Draw;override;
procedure MouseDown(Shift: TShiftState;nx,ny:integer);override;
procedure MouseMove(Shift: TShiftState;nx,ny:integer);override;
procedure MouseUp(Shift: TShiftState;nx,ny:integer);override;
procedure KeyPressed(key:word);override;
procedure ClearSelection;
procedure SelectAll;
procedure SetSelState(sel:boolean);
procedure Replace(tip:integer);
procedure StartTransformation;
property State:integer read Fstate write Setstate;
protected
procedure Setstate(const Value: integer);override;
function GenPoints:TTransArray;
private
x2,y2:integer;
p:^TRPoint;
Centre,VUp,VRight:TRPoint;
im,jm:integer;
MovingT:boolean;
curm:boolean;
corx,cory:double;
end;
TCreatePictureTool=class(TTool)
Picture:TEPicture;
procedure Draw;override;
procedure MouseDown(Shift: TShiftState;nx,ny:integer);override;
procedure MouseMove(Shift: TShiftState;nx,ny:integer);override;
procedure MouseUp(Shift: TShiftState;nx,ny:integer);override;
end;
TZoomRectTool=class(TTool)
procedure Draw;override;
procedure MouseDown(Shift: TShiftState;nx,ny:integer);override;
procedure MouseMove(Shift: TShiftState;nx,ny:integer);override;
procedure MouseUp(Shift: TShiftState;nx,ny:integer);override;
private
x2,y2:integer;
end;
TCreateRectTool=class(TTool)
procedure Draw;override;
procedure MouseDown(Shift: TShiftState;nx,ny:integer);override;
procedure MouseMove(Shift: TShiftState;nx,ny:integer);override;
procedure MouseUp(Shift: TShiftState;nx,ny:integer);override;
private
x2,y2:integer;
end;
TCreateEllipseTool=class(TTool)
procedure Draw;override;
procedure KeyPressed(key:word);override;
procedure MouseDown(Shift: TShiftState;nx,ny:integer);override;
procedure MouseMove(Shift: TShiftState;nx,ny:integer);override;
procedure MouseUp(Shift: TShiftState;nx,ny:integer);override;
private
x2,y2,n:integer;
end;
TCutSplitTool=class(TTool)
published
procedure Draw;override;
procedure KeyPressed(key:word);override;
procedure MouseDown(Shift: TShiftState;nx,ny:integer);override;
procedure MouseMove(Shift: TShiftState;nx,ny:integer);override;
procedure MouseUp(Shift: TShiftState;nx,ny:integer);override;
property State:integer read Fstate write Setstate;
protected
procedure Setstate(const Value: integer);override;
private
invert:boolean;
x2,y2:integer;
pt:array[0..3] of TRPoint;
npol1,npol2,n1,n2:integer;
end;
TPictureTileTool=class(TTool)
Width,Height:integer;
LeftToRight,TopToBottom:boolean;
Picture:TEPicture;
property State:integer read Fstate write Setstate;
procedure Draw;override;
procedure KeyPressed(key:word);override;
procedure MouseDown(Shift: TShiftState;nx,ny:integer);override;
procedure MouseMove(Shift: TShiftState;nx,ny:integer);override;
procedure MouseUp(Shift: TShiftState;nx,ny:integer);override;
private
tWidth,tHeight:double;
rx,ry:double;
Pressed:boolean;
protected
procedure Setstate(const Value: integer);override;
end;
TSplineTool=class(TTool)
private
Fstate: integer;
public
parts:integer;
OnePolygon,DelSpline:boolean;
published
constructor Create(Par:TLevel);override;
destructor Destroy;override;
procedure Draw;override;
procedure MouseDown(Shift: TShiftState;nx,ny:integer);override;
procedure MouseMove(Shift: TShiftState;nx,ny:integer);override;
procedure MouseUp(Shift: TShiftState;nx,ny:integer);override;
procedure KeyPressed(key:word);override;
// procedure Initialize(n,tip:integer);
property State:integer read Fstate write Setstate;
procedure CalculateCoef(P1,P2:TSVertex);
function FindVertex(nx,ny:integer;out sign:integer):integer;
procedure ProcessRightClick(nx,ny:integer);
private
Poly:array of TSVertex;
cur:integer;
signum:integer;
ax,bx,cx,dx,ay,by,cy,dy:double;
x2,y2:integer;
Pressed:boolean;
protected
procedure Setstate(const Value: integer);override;
end;
TPolyOpTool=class(TTool)
DelSource:boolean;
procedure Draw;override;
procedure KeyPressed(key:word);override;
procedure MouseDown(Shift: TShiftState;nx,ny:integer);override;
procedure MouseMove(Shift: TShiftState;nx,ny:integer);override;
procedure MouseUp(Shift: TShiftState;nx,ny:integer);override;
property State:integer read Fstate write Setstate;
procedure PerformOp(or1:integer;or2:integer);
protected
procedure Setstate(const Value: integer);override;
private
n1,n2:integer;
end;
TGrassTool=class(TTool)
public
GHeight:double;
GWidth,Smoothing,CorrectREdge:boolean;
published
constructor Create(Par:TLevel);override;
procedure Draw;override;
procedure KeyPressed(key:word);override;
procedure MouseDown(Shift: TShiftState;nx,ny:integer);override;
procedure MouseMove(Shift: TShiftState;nx,ny:integer);override;
procedure MouseUp(Shift: TShiftState;nx,ny:integer);override;
property State:integer read Fstate write Setstate;
protected
procedure Setstate(const Value: integer);override;
private
n:integer;
end;
implementation
uses Math, SysUtils, DXDraws, Unit6, Unit15, Unit16;
{ TCreateObjectTool }
constructor TCreateObjectTool.Create(Par: TLevel);
begin
Inherited;
Object_.typ:=2;
Object_.TofF:=0;
Object_.AnimNumber:=0;
end;
procedure TCreateObjectTool.Draw;
begin
with Parent do begin
Object_.Pos.x:=GetRX(x);
Object_.Pos.y:=GetRY(y);
DrawObject(Object_);
end;
end;
procedure TCreateObjectTool.MouseDown(Shift: TShiftState;nx, ny: integer);
begin
x:=nx;y:=ny;
with Parent do begin
Modified:=true;
Object_.Pos.x:=GetRX(x);
Object_.Pos.y:=GetRY(y);
AddObject(Object_);
end;
end;
procedure TCreateObjectTool.MouseMove(Shift: TShiftState;nx, ny: integer);
begin
x:=nx;y:=ny;
end;
procedure TCreateObjectTool.MouseUp(Shift: TShiftState;nx, ny: integer);
begin
x:=nx;y:=ny;
end;
{ TCreateVertexTool }
constructor TCreateVertexTool.Create(Par: TLevel);
begin
inherited;
state:=stReady;
Poly.Grass:=0;
Poly.Vertices:=nil;
EVertex:=0;
dir:=1;
end;
destructor TCreateVertexTool.Destroy;
begin
KeyPressed(VK_ESCAPE);
inherited;
end;
procedure TCreateVertexTool.Draw;
var
Points:array of TPoint;
i,s,e,l,ind:integer;
begin
if state=stEdit then with Parent,DXDraw.Surface.Canvas,Poly do begin
SetLength(Points,Length(Vertices));
l:=Length(Vertices);
if dir=-1 then s:=(EVertex+1) mod l else s:=EVertex;
if dir=-1 then e:=EVertex else e:=(EVertex-1+l) mod l;
i:=s;
Brush.Style:=bsClear;
Pen.Style:=psSolid;
repeat
ind:=(i-s+l) mod l;
Points[ind].X:=GetOX(Vertices[i].x);
Points[ind].Y:=GetOY(Vertices[i].y);
i:=(i+1) mod l;
until (i-e+l) mod l=1;
if Grass=0 then Pen.Color:=SwapColors(Palette[lvPoly])
else Pen.Color:=SwapColors(Palette[lvGrass]);
Polyline(Points);
Pen.Style:=psDot;
MoveTo(GetOX(Vertices[e].x),GetOY(Vertices[e].y));
LineTo(GetOX(Vertices[s].x),GetOY(Vertices[s].y));
if HighLightVertices then begin
Pen.Style:=psSolid;
Pen.Color:=SwapColors(Palette[lvHighlight]);
for i:=0 to High(Points) do
Rectangle(Points[i].X-1,Points[i].Y-1,
Points[i].X+2,Points[i].Y+2);
end;
end;
end;
procedure TCreateVertexTool.Initialize;
begin
if state=stEdit then begin
KeyPressed(VK_ESCAPE);
end;
end;
procedure TCreateVertexTool.KeyPressed(key: word);
var
l,i:integer;
p:TPoint;
begin
case key of
VK_RETURN:dir:=-dir;
VK_SPACE:if state=stEdit then with Parent do begin
l:=Length(Poly.Vertices);
//p:=Poly.Vertices[EVertex];
Poly.Vertices[EVertex]:=Poly.Vertices[(EVertex+dir+l) mod l];
//Poly.Vertices[(EVertex-dir+l) mod l]:=p;
EVertex:=(EVertex+dir+l) mod l;
dir:=-dir;
p:=ALEForm.PaintBox1.ClientToScreen(Point(
GetOX(Poly.Vertices[EVertex].x),GetOY(Poly.Vertices[EVertex].y)));
SetCursorPos(p.x,p.y);
end;
VK_ESCAPE:if state=stEdit then begin
if Length(Poly.Vertices)>3 then with Parent do begin
for i:=EVertex to High(Poly.Vertices)-1 do
Poly.Vertices[i]:=Poly.Vertices[i+1];
SetLength(Poly.Vertices,High(Poly.Vertices));
//Modified:=true;
AddPolygon(Poly);
end;
SetLength(Poly.Vertices,0);
state:=stReady;
end;
end;
end;
procedure TCreateVertexTool.MouseDown(Shift: TShiftState;nx, ny: integer);
var
p:TRpoint;
npol,n,tp,i:integer;
begin
if state=stReady then begin
x:=nx;y:=ny;
with Parent do begin
p.x:=GetRX(nx);
p.y:=GetRY(ny);
WhatHere(p,npol,n,tp);
Modified:=true;
if (tp=tpVertex) or (tp=tpPolygon) then begin
//Finalize(Poly.Vertices);
Poly:=Polygons[npol];
DeletePolygon(npol);
SetLength(Poly.Vertices,Length(Poly.Vertices)+1);
for i:=High(Poly.Vertices) downto n+1 do
Poly.Vertices[i]:=Poly.Vertices[i-1];
EVertex:=n;
Poly.Vertices[n]:=p;
dir:=1;
end else begin
SetLength(Poly.Vertices,2);
Poly.Vertices[0].x:=GetRX(nx);
Poly.Vertices[0].y:=GetRY(ny);
Poly.Vertices[1].x:=Poly.Vertices[0].x;
Poly.Vertices[1].y:=Poly.Vertices[0].y;
EVertex:=0;
dir:=1;
Poly.Grass:=0;
end;
end;
state:=stEdit;
end else begin
SetLength(Poly.Vertices,Length(Poly.Vertices)+1);
for i:=High(Poly.Vertices) downto EVertex+1 do
Poly.Vertices[i]:=Poly.Vertices[i-1];
if dir=-1 then EVertex:=(EVertex+1+Length(Poly.Vertices)) mod Length(Poly.Vertices);
end;
end;
procedure TCreateVertexTool.MouseMove(Shift: TShiftState;nx, ny: integer);
begin
if state=stEdit then with Parent do begin
Poly.Vertices[EVertex].x:=GetRX(nx);
Poly.Vertices[EVertex].y:=GetRY(ny);
x:=nx;y:=ny;
end;
end;
procedure TCreateVertexTool.MouseUp(Shift: TShiftState;nx, ny: integer);
begin
//
end;
procedure TCreateVertexTool.Setstate(const Value: integer);
begin
Inherited;
if State=stReady then Parent.InitUndoRedoVisible
else begin
ALEForm.Undo.Enabled:=false;
ALEForm.Redo.Enabled:=false;
end;
end;
{ TSelectTool }
procedure TSelectTool.ClearSelection;
begin
SetSelState(false);
end;
constructor TSelectTool.Create(Par: TLevel);
begin
inherited;
ClearSelection;
end;
procedure TSelectTool.Draw;
var
i,j:integer;
pts:TTransArray;
procedure DrawPoint(i,j:integer);
begin
Parent.DXDraw.Surface.Canvas.Rectangle(
pts[i,j].X-1,pts[i,j].Y-1,pts[i,j].X+2,pts[i,j].Y+2);
end;
procedure DrawLine(i1,j1,i2,j2:integer);
begin
with Parent.DXDraw.Surface.Canvas do begin
MoveTo(pts[i1,j1].X,pts[i1,j1].Y);
LineTo(pts[i2,j2].X,pts[i2,j2].Y);
end;
end;
begin
with Parent,DXDraw.Surface.Canvas do begin
Brush.Bitmap:=nil;
Brush.Color:=Parent.SwapColors(Palette[lvVertex]);
Pen.Style:=psClear;
if ShowPolygons then
for i:=0 to High(Polygons) do with Polygons[i] do
if ShowGrass or (Polygons[i].Grass=0) then
for j:=0 to High(Vertices) do with Vertices[j] do
if Selected then
FillRect(Bounds(GetOX(x)-1,GetOY(y)-1,3,3));
if ShowObjects then
for i:=0 to High(Objects) do with Objects[i].Pos do
if Selected then
FillRect(Bounds(GetOX(x)-1,GetOY(y)-1,3,3));
if ShowPictures or Framepictures then
for i:=0 to High(Pics) do with Pics[i].Pos do
if Selected then
FillRect(Bounds(GetOX(x)-1,GetOY(y)-1,3,3));
if State=stSelRect then begin
Pen.Style:=psSolid;
Pen.Color:=Parent.SwapColors(Palette[lvVertex]);
Brush.Style:=bsClear;
Rectangle(x,y,x2,y2);
end;
if State=stTransform then begin
Pen.Style:=psSolid;
Pen.Color:=Parent.SwapColors(Palette[lvVertex]);
Brush.Style:=bsClear;
pts:=GenPoints;
for i:=0 to 2 do begin
DrawLine(0,i,2,i);
DrawLine(i,0,i,2);
end;
Pen.Color:=Parent.SwapColors(Palette[lvHighlight]);
for i:=0 to 2 do
for j:=0 to 2 do
DrawPoint(i,j);
end;
end;
end;
function TSelectTool.GenPoints: TTransArray;
var
pts:TTransArray;
begin
with Parent do begin
pts[1,1]:=Point(GetOX(Centre.x),GetOY(Centre.y));
pts[1,0]:=Point(GetOX(Centre.x+VUp.x),GetOY(Centre.y+VUp.y));
pts[1,2]:=Point(GetOX(Centre.x-VUp.x),GetOY(Centre.y-VUp.y));
pts[0,1]:=Point(GetOX(Centre.x+VRight.x),GetOY(Centre.y+VRight.y));
pts[2,1]:=Point(GetOX(Centre.x-VRight.x),GetOY(Centre.y-VRight.y));
pts[0,0]:=Point(GetOX(Centre.x+VRight.x+VUp.x),GetOY(Centre.y+VRight.y+VUp.y));
pts[0,2]:=Point(GetOX(Centre.x+VRight.x-VUp.x),GetOY(Centre.y+VRight.y-VUp.y));
pts[2,2]:=Point(GetOX(Centre.x-VRight.x-VUp.x),GetOY(Centre.y-VRight.y-VUp.y));
pts[2,0]:=Point(GetOX(Centre.x-VRight.x+VUp.x),GetOY(Centre.y-VRight.y+VUp.y));
end;
Result:=pts;
end;
procedure TSelectTool.Initialize(Shift: TShiftState;nx,ny:integer);
var
i,j,npol,n,tp,k:integer;
p:TRPoint;
p4:^TRPoint;
p2,p3:TPoint;
gr:word;
changed:boolean;
begin
with Parent do begin
p3:=Point(nx,ny);
p2:=ALEForm.PaintBox1.ClientToScreen(p3);
p.x:=GetRX(nx);
p.y:=GetRY(ny);
WhatHere(p,npol,n,tp);
if (tp<>tpNone) and (tp<>tpPolygon) then begin
case tp of
tpVertex:p4:=@Polygons[npol].Vertices[n];
tpObject:p4:=@Objects[n].Pos;
tpPicture:p4:=@Pics[n].Pos;
else p4:=nil;
end;
if not (ssShift in Shift) and not p4.Selected then
ClearSelection;
x:=nx;y:=ny;
p4.Selected:=true;
end;
case tp of
tpNone:OptionsForm.ShowModal;
tpVertex, tpPolygon: begin
changed:=false;
if ALEForm.Grass1.Checked then
Gr:=1 else Gr:=0;
for i:=0 to High(Polygons) do with Polygons[i] do
for j:=0 to High(Vertices) do with Vertices[j] do
if Selected or (i = npol) then
if Grass<>Gr then begin
changed:=true;
end;
Modified:=Modified or changed;
if changed then
for i:=0 to High(Polygons) do with Polygons[i] do
for j:=0 to High(Vertices) do with Vertices[j] do
if Selected or (i = npol) then Grass:=Gr;
end;
tpPicture:with PictureForm do begin
LoadFromPicture(Pics[n]);
if ShowModal=mrOK then begin
Modified:=true;
for i:=0 to High(Pics) do
if Pics[i].Pos.Selected then
SaveToPicture(Pics[i]);
SortPictures;
end;
end;
tpObject:with ObjectForm do begin
LoadFromObject(Objects[n]);
if ShowModal=mrOK then
for i:=0 to High(Objects) do with Objects[i] do
if Pos.Selected and (typ<>4) then begin
if typ=1 then begin
j:=0;
for k:=0 to High(Objects) do
if Objects[k].typ=1 then inc(j);
end else j:=2;
if j<2 then AddMessage(MessageString[79],iWarning)
else begin
Modified:=true;
SaveToObject(Objects[i]);
end;
end;
end;
end;
Draw;
end;
end;
procedure TSelectTool.KeyPressed(key: word);
var
i,j:integer;
iscopy:integer;
begin
with Parent do
case key of
VK_ESCAPE: if State=stTransform then State:=stReady
else ClearSelection;
VK_DELETE:begin //Óäàëåíèå
Modified:=true;
i:=0;
while i<=High(Polygons) do with Polygons[i] do begin
j:=0;
while j<=High(Vertices) do with Vertices[j] do begin
if Selected then begin
if DeleteVertex(i,j) then begin
dec(i);
break;
end;
end else inc(j);
end;
inc(i);
end;
i:=0;
while i<=High(Objects) do with Objects[i],Pos do begin
if Selected then begin
if not DeleteObject(i) then inc(i);
end else inc(i);
end;
i:=0;
while i<=High(Pics) do with Pics[i].Pos do
if Selected then DeletePicture(i)
else inc(i);
end;
VK_INSERT:begin //Êîïèðîâàíèå
Modified:=true;
for i:=0 to High(Polygons) do with Polygons[i] do begin
iscopy:=0;
for j:=0 to High(Vertices) do with Vertices[j] do
if Selected then inc(iscopy);
if (iscopy>=3) then begin
AddPolygon(Polygons[i]);
j:=0;
while (j<=High(Polygons[i].Vertices)) do begin
if not Polygons[i].Vertices[j].Selected then
DeleteVertex(i,j)
else inc(j);
end;
for j:=0 to High(Polygons[i].Vertices) do begin
Polygons[i].Vertices[j].x:=Polygons[i].Vertices[j].x+ddx/Zoom;
Polygons[i].Vertices[j].y:=Polygons[i].Vertices[j].y+ddy/Zoom;
end;
for j:=0 to High(Polygons[High(Polygons)].Vertices) do
Polygons[High(Polygons)].Vertices[j].Selected:=false;
end;
end;
for i:=0 to High(Objects) do with Objects[i],Pos do
if Selected then
if typ<>4 then begin
AddObject(Objects[i]);
Objects[i].Pos.x:=Objects[i].Pos.x+ddx/Zoom;
Objects[i].Pos.y:=Objects[i].Pos.y+ddy/Zoom;
Objects[High(Objects)].Pos.Selected:=false;
end;
for i:=0 to High(Pics) do
if Pics[i].Pos.Selected then begin
AddPicture(Pics[i]);
Pics[i].Pos.x:=Pics[i].Pos.x+ddx/Zoom;
Pics[i].Pos.y:=Pics[i].Pos.y+ddy/Zoom;
Pics[High(Pics)].Pos.Selected:=false;
end;
//ALEForm.StatusBar1.Panels[3].Text:=IntToStr(Length(Polygons));
end;
end;
end;
procedure TSelectTool.MouseDown(Shift: TShiftState;nx, ny: integer);
var
npol,n,tp,i,j:integer;
pts:TTransArray;
sng:boolean;
//pt:TPoint;
function Near2(p:TPoint):boolean;
begin
Result:=sqrt(sqr(nx-p.x)+sqr(ny-p.y))<Parent.RNear;
end;
begin
with Parent do
if State=stReady then begin
System.New(p);
sng:=SnapToGrid;
SnapToGrid:=false;
p.x:=GetRX(nx);
p.y:=GetRY(ny);
SnapToGrid:=sng;
WhatHere(p^,npol,n,tp);
Dispose(p);
case tp of
tpNone:begin
x:=nx;y:=ny;
x2:=nx;y2:=ny;
State:=stSelRect;
end;
tpVertex, tpObject, tpPicture, tpPolygon: begin
curm:=false;
case tp of
tpVertex, tpPolygon:if ShowPolygons and (ShowGrass or (Polygons[npol].Grass=0)) then p:=@Polygons[npol].Vertices[n] else exit;
tpObject:if ShowObjects then p:=@Objects[n].Pos else exit;
tpPicture:if ShowPictures or Framepictures then p:=@Pics[n].Pos else exit;
end;
if not (ssShift in Shift) and not (ssCtrl in Shift) and not p.Selected then
ClearSelection;
State:=stMove;
x:=nx;y:=ny;
//pt.X:=GetOX(p.x);
//pt.Y:=GetOY(p.y);
corx:=p.x-GetRX(nx);
cory:=p.y-GetRY(ny);
//ClientToScreen(ALEForm.PaintBox1.Handle,pt);
//SetCursorPos(pt.x,pt.y);
if (tp<>tpPolygon) then begin
if not (ssAlt in Shift) then
if (ssCtrl in Shift) then
p.Selected:=not p.Selected
else p.Selected:=true;
end;
if ((ssAlt in Shift) and (tp=tpVertex)) or (tp=tpPolygon) then
for i:=0 to High(Polygons[npol].Vertices) do
if (ssCtrl in Shift) then
Polygons[npol].Vertices[i].Selected:=not Polygons[npol].Vertices[i].Selected
else Polygons[npol].Vertices[i].Selected:=true;
end;
end;
end;
if State=stTransform then begin
pts:=GenPoints;
MovingT:=false;
for i:=0 to 2 do begin
for j:=0 to 2 do
if Near2(pts[i,j]) then begin
MovingT:=true;
break;
end;
if MovingT then break;
end;
if not MovingT then exit;
Parent.Modified:=true;
State:=stTransform;
im:=i;jm:=j;
x:=nx;y:=ny;
end;
end;
procedure TSelectTool.MouseMove(Shift: TShiftState;nx, ny: integer);
var
i,j:integer;
drx,dry,rad,rado,m,cosa,sina,det:double;
r,ro:TRPoint;
VUpo,VRighto:TRPoint;
xy,xx,yx,yy,xd,yd:double;
begin
if (x = nx) and (y = ny) then exit;
x2:=nx;y2:=ny;
with Parent do
if State=stEdit then begin
drx:=-p.x+corx+GetRX(nx);
dry:=-p.y+cory+GetRY(ny);
if ShowPolygons then
for i:=0 to High(Polygons) do with Polygons[i] do
for j:=0 to High(Vertices) do with Vertices[j] do
if Selected then begin
if not curm then begin
Modified:=true;
curm:=true;
end;
x:=x+drx;
y:=y+dry;
end;
if ShowObjects then
for i:=0 to High(Objects) do with Objects[i].Pos do
if Selected then begin
if not curm then begin
Modified:=true;
curm:=true;
end;
x:=x+drx;
y:=y+dry;
end;
if ShowPictures or Framepictures then
for i:=0 to High(Pics) do with Pics[i].Pos do
if Selected then begin
if not curm then begin
Modified:=true;
curm:=true;
end;
x:=x+drx;
y:=y+dry;
end;
x:=x2;y:=y2;
end;
with Parent do
if (State=stTransform) and (MovingT) then begin
VUpo:=VUp;
VRighto:=VRight;
xx:=1;xy:=0;yx:=0;yy:=1;xd:=0;yd:=0;
//Ïåðåíîñ öåíòðà
if (im=1) and (jm=1) then begin
xd:=(x2-x)/Zoom;
yd:=(y2-y)/Zoom;
Centre.x:=Centre.x+xd;
Centre.y:=Centre.y+yd;
end else
//Ïåðåíîñ ñåðåäèí
if (im=1) then begin
VUp.x:=VUp.x-(jm-1)*(x2-x)/Zoom;
VUp.y:=VUp.y-(jm-1)*(y2-y)/Zoom;
end else
if (jm=1) then begin
VRight.x:=VRight.x-(im-1)*(x2-x)/Zoom;
VRight.y:=VRight.y-(im-1)*(y2-y)/Zoom;
end else
//Ïåðåíîñ êðà¸â
if (im=jm) then begin
ro.x:=(im-1)*(VUp.x+VRight.x);
ro.y:=(im-1)*(VUp.y+VRight.y);
rado:=sqrt(ro.x*ro.x+ro.y*ro.y);
r.x:=ro.x-(x2-x)/Zoom;
r.y:=ro.y-(y2-y)/Zoom;
rad:=sqrt(r.x*r.x+r.y*r.y);
if (abs(rad)<1e-10) or (abs(rado)<1e-10) then exit;
m:=rad/rado;
cosa:=(r.x*ro.x+r.y*ro.y)/rad/rado;
sina:=-(r.x*ro.y-r.y*ro.x)/rad/rado;
xx:=m*cosa; xy:=-m*sina;
yx:=m*sina; yy:=m*cosa;
VUp.x:=xx*VUpo.x+xy*VUpo.y;
VUp.y:=yx*VUpo.x+yy*VUpo.y;
VRight.x:=xx*VRighto.x+xy*VRighto.y;
VRight.y:=yx*VRighto.x+yy*VRighto.y;
end else begin
ro.x:=-(im-1)*(VUp.x-VRight.x);
ro.y:=-(im-1)*(VUp.y-VRight.y);
rado:=sqrt(ro.x*ro.x+ro.y*ro.y);
r.x:=ro.x-(x2-x)/Zoom;
r.y:=ro.y-(y2-y)/Zoom;
rad:=sqrt(r.x*r.x+r.y*r.y);
if (abs(rad)<1e-10) or (abs(rado)<1e-10) then exit;
m:=rad/rado;
cosa:=(r.x*ro.x+r.y*ro.y)/rad/rado;
sina:=-(r.x*ro.y-r.y*ro.x)/rad/rado;
xx:=m*cosa; xy:=-m*sina;
yx:=m*sina; yy:=m*cosa;
VUp.x:=xx*VUpo.x+xy*VUpo.y;
VUp.y:=yx*VUpo.x+yy*VUpo.y;
VRight.x:=xx*VRighto.x+xy*VRighto.y;
VRight.y:=yx*VRighto.x+yy*VRighto.y;
end;
if ((im=1) or (jm=1)) and (im*jm<>1) then begin
det:=VUpo.x*VRighto.y-VUpo.y*VRighto.x;
if abs(det)<1e-10 then begin //Ïðåäûäóùèé áûë â îäíó ëèíèþ
end else begin
xx:=1/det*(VUp.x*VRighto.y-VRight.x*VUpo.y);
xy:=1/det*(-VUp.x*VRighto.x+VRight.x*VUpo.x);
yx:=1/det*(VUp.y*VRighto.y-VRight.y*VUpo.y);
yy:=1/det*(-VUp.y*VRighto.x+VRight.y*VUpo.x);
end;
end;
x:=x2;y:=y2;
//Ïðåîáðàçîâíèå âåðøèí
for i:=0 to High(Polygons) do with Polygons[i] do
for j:=0 to High(Vertices) do with Vertices[j] do
if Selected then begin
ro.x:=Vertices[j].x-Centre.x;
ro.y:=Vertices[j].y-Centre.y;
x:=xx*ro.x+xy*ro.y+xd+Centre.x;
y:=yx*ro.x+yy*ro.y+yd+Centre.y;
end;
for i:=0 to High(Objects) do with Objects[i].Pos do
if Selected then begin
ro.x:=Objects[i].Pos.x-Centre.x;
ro.y:=Objects[i].Pos.y-Centre.y;
x:=xx*ro.x+xy*ro.y+xd+Centre.x;
y:=yx*ro.x+yy*ro.y+yd+Centre.y;
end;
for i:=0 to High(Pics) do with Pics[i].Pos do
if Selected then begin
ro.x:=Pics[i].Pos.x-Centre.x;
ro.y:=Pics[i].Pos.y-Centre.y;
x:=xx*ro.x+xy*ro.y+xd+Centre.x;
y:=yx*ro.x+yy*ro.y+yd+Centre.y;
end;
end;
end;
procedure TSelectTool.MouseUp(Shift: TShiftState;nx, ny: integer);
var
r:TRect;
i,j:integer;
begin
with Parent do
if State=stSelRect then begin
x2:=nx;y2:=ny;
if x2>=x then begin
R.Left:=x;
R.Right:=x2;
end else begin
R.Left:=x2;
R.Right:=x;
end;
if y2>=y then begin
R.Top:=y;
R.Bottom:=y2;
end else begin
R.Top:=y2;
R.Bottom:=y;
end;
if ShowPolygons then
for i:=0 to High(Polygons) do with Polygons[i] do
if (ShowGrass or (Polygons[i].Grass<>1)) then
for j:=0 to High(Vertices) do with Vertices[j] do
if PtInRect(r,Point(GetOX(x),GetOY(y))) then begin
if (ssCtrl in Shift) then
Selected:=not Selected
else Selected:=true
end else
if not (ssShift in Shift) and not (ssCtrl in Shift) then Selected:=false;
if ShowObjects then
for i:=0 to High(Objects) do with Objects[i].Pos do
if PtInRect(r,Point(GetOX(x),GetOY(y))) then begin
if (ssCtrl in Shift) then
Selected:=not Selected
else Selected:=true
end else
if not (ssShift in Shift) and not (ssCtrl in Shift) then Selected:=false;
if ShowPictures or Framepictures then
for i:=0 to High(Pics) do with Pics[i].Pos do
if PtInRect(r,Point(GetOX(x),GetOY(y))) then begin
if (ssCtrl in Shift) then
Selected:=not Selected
else Selected:=true
end else
if not (ssShift in Shift) and not (ssCtrl in Shift) then Selected:=false;
end;
MovingT:=false;
if State=stTransform then State:=stTransform;
if State<>stTransform then State:=stReady;
end;
procedure TSelectTool.Replace(tip: integer);
var
mr:integer;
Objct:TEObject;
Pic:TEPicture;
i,j,k:integer;
procedure Add(p:TRpoint);
begin
if tip=0 then begin
Objct.Pos:=p;
Parent.AddObject(Objct);
end else begin
Pic.Pos:=p;
Parent.AddPicture(Pic);
end;
end;
begin
if tip=0 then mr:=ObjectForm.ShowModal
else mr:=PictureForm.ShowModal;
if mr=mrCancel then exit;
if tip=0 then ObjectForm.SaveToObject(Objct)
else PictureForm.SaveToPicture(Pic);
with Parent do begin
Modified:=true;
i:=0;
while i<=High(Polygons) do with Polygons[i] do begin
for j:=0 to High(Vertices) do
if Vertices[j].Selected then Add(Vertices[j]);
j:=0;
while j<=High(Vertices) do with Vertices[j] do begin
if Selected then begin
if DeleteVertex(i,j) then begin
dec(i);
break;
end;
end else inc(j);
end;
inc(i);
end;
i:=0;
while i<=High(Objects) do with Objects[i],Pos do begin
if Selected then begin
if tip=0 then begin
case typ of
1: begin
j:=0;