-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLineTool.pas
2356 lines (2036 loc) · 61.7 KB
/
LineTool.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
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
{+------------------------------------------------------------------------+
| AutoREALM. Copyright (c) 2000, Andrew J. Gryc. |
| |
| This program is free software; you can redistribute it and/or modify |
| it under the terms of the GNU General Public License as published by |
| the Free Software Foundation; either version 2 of the License, or (at |
| your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| General Public License for more details. |
| |
| For a copy of the GNU General Public License, write to the Free |
| Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 02111-1307, USA. |
+------------------------------------------------------------------------+}
unit LineTool;
interface
uses SysUtils, Messages, Classes, Graphics, Controls, Forms, ToolObject,
DrawLines, MapObject, Dialogs, Math, PolygonSides, Geometry, Primitives;
type TNormalLineToolHandler = class(TToolHandler)
public
constructor Create(cv:TCanvas);
procedure Draw(erase:boolean); override;
procedure Done; override;
procedure Add(cx1,cy1,cx2,cy2:Coord); virtual;
end;
{ --- }
type TFractalLineToolHandler = class(TNormalLineToolHandler)
protected
seed:integer;
roughness:integer;
public
procedure Draw(erase:boolean); override;
procedure Add(cx1,cy1,cx2,cy2:Coord); override;
function MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer):boolean; override;
end;
{ --- }
TNormalPolylineToolHandler = class(TToolHandler)
linelist:TList;
continue:TLineContinue;
protected
SnapWhenDone:boolean;
public
procedure Done; override;
procedure Draw(erase:boolean); override;
procedure Cancel; override;
function MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer):boolean; override;
procedure MouseMove(Shift: TShiftState; X,Y: Integer); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
constructor Create(cv:TCanvas);
destructor Destroy; override;
procedure Start; virtual;
procedure Add(list:PCoordArray; count:integer); virtual;
procedure DrawXorPortion; virtual;
procedure SetSeed; virtual;
procedure ClearList;
procedure CreateClosedFigure; override;
procedure CreateOpenFigure; override;
procedure Move(dx,dy:integer); override;
procedure Backspace; override;
end;
{ --- }
TFractalPolylineToolHandler = class(TNormalPolylineToolHandler)
seed,roughness:integer;
public
procedure Draw(erase:boolean); override;
procedure Start; override;
procedure Add(list:PCoordArray; count:integer); override;
procedure DrawXorPortion; override;
procedure SetSeed; override;
end;
{ --- }
TNormalCurveToolHandler = class(TToolHandler)
p1,p2,p3,p4:CoordPoint;
which:integer;
public
procedure Draw(erase:boolean); override;
procedure Done; override;
procedure Cancel; override;
procedure Backspace; override;
function MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer):boolean; override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure Add(sp1,sp2,sp3,sp4:CoordPoint); virtual;
procedure DrawCurve(sp1,sp2,sp3,sp4:CoordPoint); virtual;
constructor Create(cv:TCanvas);
procedure Move(dx,dy:integer); override;
end;
{ --- }
TFractalCurveToolHandler = class(TNormalCurveToolHandler)
public
procedure Add(sp1,sp2,sp3,sp4:CoordPoint); override;
procedure DrawCurve(sp1,sp2,sp3,sp4:CoordPoint); override;
end;
{ --- }
TNormalArcToolHandler = class(TToolHandler)
p1,p2,p3 : CoordPoint;
Which : Integer;
public
procedure Draw(Erase: Boolean); override;
procedure Done; override;
procedure Cancel; override;
procedure Backspace; override;
function MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer): Boolean; override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure Add(sp1,sp2,sp3: CoordPoint); virtual;
procedure DrawCurve(sp1,sp2,sp3: CoordPoint); virtual;
constructor Create(cv: TCanvas);
procedure Move(dx,dy: integer); override;
end;
{ --- }
TPolyCurveToolHandler = class(TNormalCurveToolHandler)
linelist:TList;
continue:TLineContinue;
public
procedure Done; override;
procedure Cancel; override;
function MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer):boolean; override;
constructor Create(cv:TCanvas);
destructor Destroy; override;
procedure AddPoint(pt:CoordPoint);
procedure AddCurve(list:PCoordArray; count:integer); virtual;
procedure AddCurveSection;
procedure Start; virtual;
procedure ClearList;
procedure CreateClosedFigure; override;
procedure CreateOpenFigure; override;
procedure Move(dx,dy:integer); override;
procedure Backspace; override;
procedure MouseMove(Shift: TShiftState; X,Y: Integer); override;
Procedure ForceContinuity(Shift: TShiftState; Var X,Y: Integer); Virtual;
end;
{ --- }
TFractalPolyCurveToolHandler = class(TPolyCurveToolHandler)
protected
seed:integer;
roughness:integer;
public
procedure Start; override;
procedure AddCurve(list:PCoordArray; count:integer); override;
procedure DrawCurve(sp1,sp2,sp3,sp4:CoordPoint); override;
end;
{ --- }
TNormalCircleToolHandler = class(TToolHandler)
private
lastx1,lasty1,lastx2,lasty2:integer;
public
procedure Draw(erase:boolean); override;
procedure Done; override;
procedure Add(cx1,cy1,cx2,cy2:Coord); virtual;
constructor Create(cv:TCanvas);
end;
{ --- }
TRectangleToolHandler = class(TToolHandler)
private
lastx1,lasty1,lastx2,lasty2:integer;
public
procedure Draw(erase:boolean); override;
procedure Done; override;
constructor Create(cv:TCanvas);
end;
{ --- }
TPolygonToolHandler = class(TToolHandler)
private
sides:integer;
initialangle:double;
lastx1,lasty1,lastx2,lasty2:integer;
public
procedure Draw(erase:boolean); override;
procedure Done; override;
procedure Add(cx1,cy1,cx2,cy2:Coord); virtual;
function AskSides:boolean;
constructor Create(cv:TCanvas);
end;
{ --- }
TFreehandLineToolHandler = class(TNormalPolylineToolHandler)
public
procedure Cancel; override;
function MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer):boolean; override;
procedure MouseMove(Shift: TShiftState; X,Y: Integer); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
constructor Create(cv:TCanvas);
procedure CreateClosedFigure; override;
procedure CreateOpenFigure; override;
procedure Done; override;
procedure Backspace; override;
end;
{ --- }
TFreehandFractalToolHandler = class(TFractalPolylineToolHandler)
public
procedure Cancel; override;
function MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer):boolean; override;
procedure MouseMove(Shift: TShiftState; X,Y: Integer); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
constructor Create(cv:TCanvas);
procedure CreateClosedFigure; override;
procedure CreateOpenFigure; override;
procedure Done; override;
procedure Backspace; override;
end;
{ --- }
TChartGridToolHandler = class(TToolHandler)
private
center:CoordPoint;
radius:double;
croprect:CoordRect;
iscropping:boolean;
FinishedCircle:boolean;
allocatedlines,linecount:integer;
linelist:PCoordArray;
public
function AskGrid:boolean;
procedure Draw(erase:boolean); override;
procedure Done; override;
constructor Create(cv:TCanvas);
procedure FreshenLineList;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
function MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer):boolean; override;
procedure MouseMove(Shift: TShiftState; X,Y: Integer); override;
end;
function GetCurrentlySetStyles:StyleAttrib;
implementation
uses Main,ChartGrid,Snap,SettingsDialog,ColorButton,LocalizedStrings;
const fqSmooth = 0;
fqStandard = 1;
fqSelective = 2;
function GetCurrentlySetStyles:StyleAttrib;
Var
Thickness : Coord;
I : Integer;
T1,T2 : Coord;
begin
Result.Line := MainForm.LineStyleComboBox.ItemIndex;
Result.Fill := MainForm.FillPattern.Pattern;
Result.First:= MainForm.BeginLineStyle.ItemIndex;
Result.Last := MainForm.EndLineStyle.ItemIndex;
Val(MainForm.edtLineThickness.Text,Thickness,I);
If I = 0 Then
Begin
Result.FullStyle.Thickness := Thickness;
T1 := Thickness;
T2 := Map.CurrentView.Grid.GraphUnitConvert * Map.CurrentView.Grid.GraphScale;
If T2 <> 0 Then T1 := T1 / T2;
Map.CurrentView.DeltaCoordToScreen(T1,0,T1,T2);
Result.FullStyle.SThickness := T1;
End
Else
Begin
Result.FullStyle.Thickness := 0;
Result.FullStyle.SThickness := 0;
End;
end;
constructor TNormalLineToolHandler.Create(cv:TCanvas);
begin
inherited Create(cv);
AutoPan:=true;
CustomCursor:=crLine;
end;
procedure TNormalLineToolHandler.Draw(erase:boolean);
var oldcolor:TColor;
ex,ey:Coord;
begin
oldcolor:=Canvas.Pen.Color;
Canvas.Pen.Color:=CurrentColor;
if not erase then begin
ApplyScreenSnapsFloat(false,StartX,StartY);
if GetKeyState(VK_SHIFT)<0 then begin
ex:=EndX;
ey:=EndY;
ApplyDirectionalSnap(StartX,StartY,ex,ey);
EndX:=trunc(ex);
EndY:=trunc(ey);
end;
ApplyScreenSnapsFloat(true,EndX,EndY);
end;
DrawLineStyle(Canvas, Round(StartX),Round(StartY),Round(EndX),Round(EndY), GetCurrentlySetStyles);
Canvas.Pen.Color:=oldcolor;
end;
procedure TNormalLineToolHandler.Add(cx1,cy1,cx2,cy2:Coord);
begin
Map.StartAdding(res_linetool_line_add);
Map.AddObject(LinePrimitive.Create(cx1,cy1,cx2,cy2,GetCurrentlySetStyles));
Map.EndAdding;
end;
procedure TNormalLineToolHandler.Done;
var cx1,cx2,cy1,cy2:Coord;
begin
if (StartX=EndX) and (StartY=EndY) then begin
Map.ClearSelection;
Cancel;
exit;
end;
Map.CurrentView.ScreenToCoord(StartX,StartY,cx1,cy1);
ApplySnaps(false,cx1,cy1);
Map.CurrentView.ScreenToCoord(EndX,EndY,cx2,cy2);
if GetKeyState(VK_SHIFT)<0 then ApplyDirectionalSnap(cx1,cy1,cx2,cy2);
ApplySnaps(false,cx2,cy2);
Add(cx1,cy1,cx2,cy2);
inherited Done;
end;
{------------------------------------------------------------------------------------}
procedure TFractalLineToolHandler.Draw(erase:boolean);
var oldcolor:TColor;
continue:TLineContinue;
ex,ey:Coord;
begin
oldcolor:=Canvas.Pen.Color;
{ Canvas.Pen.Color:=clRed;
Canvas.MoveTo(StartX,StartY);
Canvas.LineTo(EndX,EndY); }
Canvas.Pen.Color:=CurrentColor;
if not erase then begin
ApplyScreenSnapsFloat(false,StartX,StartY);
if GetKeyState(VK_SHIFT)<0 then begin
ex:=EndX;
ey:=EndY;
ApplyDirectionalSnap(StartX,StartY,ex,ey);
EndX:=trunc(ex);
EndY:=trunc(ey);
end;
ApplyScreenSnapsFloat(true,EndX,EndY);
end;
continue:=GetLineStyleStart(GetCurrentlySetStyles);
// Reset the fractal seed; Screen snap logic uses a new
// seed when it traverses to find fractal snapping points.
FractalSetSeed(seed);
FractalLine(Canvas,StartX,StartY,EndX,EndY,(distance(startx,starty,endx,endy)*roughness)/1000, continue);
Canvas.Pen.Color:=oldColor;
end;
procedure TFractalLineToolHandler.Add(cx1,cy1,cx2,cy2:Coord);
begin
Map.StartAdding(res_linetool_linef_add);
MainForm.SeedSpin.Value:=(MainForm.SeedSpin.Value+1) and 65535;
Map.AddObject(LinePrimitive.Create(cx1,cy1,cx2,cy2,seed,roughness,GetCurrentlySetStyles));
Map.EndAdding;
end;
function TFractalLineToolHandler.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer):boolean;
begin
seed := MainForm.SeedSpin.Value;
roughness := MainForm.RoughnessTrackBar.Position;
Result:=inherited MouseDown(Button,Shift,X,Y);
end;
{------------------------------------------------------------------------------------}
procedure TNormalPolylineToolHandler.Backspace;
var p:PCoordPoint;
begin
if (linelist.Count=1) then
Cancel
else if (linelist.Count>1) then begin
DrawXorPortion;
p:=PCoordPoint(linelist.Items[linelist.Count-1]);
EndX:=Trunc(p.x);
EndY:=Trunc(p.y);
p:=PCoordPoint(linelist.Items[linelist.Count-2]);
StartX:=Trunc(p.x);
StartY:=Trunc(p.y);
linelist.Delete(linelist.Count-1);
MouseMove([],LastMouseX,LastMouseY);
end;
end;
procedure TNormalPolylineToolHandler.ClearList;
var i:integer;
begin
for i:=0 to linelist.Count-1 do Dispose(linelist.Items[i]);
linelist.Clear;
end;
procedure TNormalPolylineToolHandler.Cancel;
begin
DrawXorPortion;
inherited Cancel;
Done;
end;
procedure TNormalPolylineToolHandler.Add(list:PCoordArray; count:integer);
var lbl:string;
begin
if SnapWhenDone then lbl:= res_linetool_linepoly_add else lbl:=res_linetool_linefree_add;
Map.StartAdding(lbl);
Map.AddObject(PolylinePrimitive.Create(list, count, GetCurrentlySetStyles));
Map.EndAdding;
end;
procedure TNormalPolylineToolHandler.Done;
var cx,cy,lastcx,lastcy:Coord;
i,n,j:integer;
p:PCoordPoint;
list:PCoordArray;
begin
if (linelist.Count=0) then exit;
if (linelist.Count=1) then begin
Map.ClearSelection;
ClearList;
state:=tsOff;
CustomCursor:=crLine1;
exit;
end;
{ Remove duplicate points on top of each other (freehand) }
n:=linelist.Count;
lastcx:=0; lastcy:=0;
GetMem(list,sizeof(CoordPoint)*n);
j:=0;
for i:=0 to n-1 do begin
p:=PCoordPoint(linelist.Items[i]);
Map.CurrentView.ScreenToCoord(p^.x,p^.y,cx,cy);
if SnapWhenDone then ApplySnaps(false,cx,cy);
if (i=0) or ((lastcx<>cx) or (lastcy<>cy)) then begin
list^[j].X := cx;
list^[j].Y := cy;
lastcx:=cx;
lastcy:=cy;
inc(j);
end;
end;
Add(list, j);
ClearList;
inherited Done;
CustomCursor:=crLine1;
end;
constructor TNormalPolylineToolHandler.Create(cv:TCanvas);
begin
inherited Create(cv);
linelist:=TList.Create;
SnapWhenDone:=true;
AutoPan:=true;
CustomCursor:=crLine1;
end;
destructor TNormalPolylineToolHandler.Destroy;
begin
inherited Destroy;
ClearList;
linelist.Destroy;
end;
procedure TNormalPolylineToolHandler.Start;
begin
continue := GetLineStyleStart(GetCurrentlySetStyles);
CustomCursor:=crLine1;
end;
procedure TNormalPolylineToolHandler.Move(dx,dy:integer);
var i:integer;
p:PCoordPoint;
begin
inherited Move(dx,dy);
for i:=0 to linelist.Count-1 do begin
p:=PCoordPoint(linelist.Items[i]);
p^.X := p^.X + dx;
p^.Y := p^.Y + dy;
end;
end;
procedure TNormalPolylineToolHandler.CreateClosedFigure;
var p:PCoordPoint;
x,y:Coord;
begin
if (state=tsStarted) then begin
MainForm.DoInvalidate; // Make sure the ending line is undrawn
p:=PCoordPoint(linelist.Items[0]);
X := p^.X;
Y := p^.Y;
New(p);
p^.X := X;
p^.Y := Y;
linelist.Add(p);
Cancel;
end;
end;
procedure TNormalPolylineToolHandler.CreateOpenFigure;
begin
if (state=tsStarted) then begin
Cancel;
end;
end;
function TNormalPolylineToolHandler.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer):boolean;
var p:PCoordPoint;
ex,ey:Coord;
begin
if (Button=mbRight) then begin
if (state=tsStarted) then begin
if not Settings.AskForShapeClosure.Checked then begin
if (ssShift in Shift) then CreateClosedFigure
else CreateOpenFigure;
end
else
MainForm.ShapePopupMenu.Popup(X,Y);
Result:=true;
end
else begin
Result:=inherited MouseDown(Button, Shift, X, Y);
end;
exit;
end;
if (Button=mbLeft) then begin
case state of
tsOff: begin
Start;
ClearList;
state := tsStarted;
CustomCursor:=crLine1;
end;
tsStarted: begin
CustomCursor:=crLine2;
end;
end;
New(p);
if GetKeyState(VK_SHIFT)<0 then begin
ex:=X;
ey:=Y;
ApplyDirectionalSnap(StartX,StartY,ex,ey);
X:=trunc(ex);
Y:=trunc(ey);
end;
ApplyScreenSnaps(true,X,Y);
p^.X := X;
p^.Y := Y;
linelist.Add(p);
StartX := X;
StartY := Y;
Result:=true;
end
else
Result:=false;
end;
procedure TNormalPolylineToolHandler.DrawXorPortion;
var oldcolor:TColor;
OldMode:TPenMode;
begin
if (EndX<>-1) then begin
OldMode := Canvas.Pen.Mode;
oldcolor:=Canvas.Pen.Color;
Canvas.Pen.Mode := pmNotXor;
Canvas.Pen.Color:=CurrentColor;
continue := GetLineStyleStart(GetCurrentlySetStyles);
// Don't let the begin arrow tip get draw anew for each line segment.
if (linelist.Count>1) then continue.Style.First:=0;
DrawLineContinue(Canvas, StartX,StartY,EndX,EndY, continue);
Canvas.Pen.Color:=oldcolor;
Canvas.Pen.Mode:=OldMode;
end;
end;
procedure TNormalPolylineToolHandler.SetSeed;
begin
end;
procedure TNormalPolylineToolHandler.MouseMove(Shift: TShiftState; X,Y: Integer);
var oldcolor:TColor;
OldMode:TPenMode;
ex,ey:Coord;
begin
HideCrosshair;
if (state=tsStarted) then begin
SetSeed;
OldMode := Canvas.Pen.Mode;
Canvas.Pen.Mode := pmNotXor;
oldcolor:=Canvas.Pen.Color;
Canvas.Pen.Color:=CurrentColor;
DrawXorPortion;
if Pan(X,Y) then begin
Canvas.Pen.Mode := OldMode;
Draw(false);
Canvas.Pen.Mode := pmNotXor;
SetSeed;
end;
EndX := X;
EndY := Y;
if GetKeyState(VK_SHIFT)<0 then begin
ex:=EndX;
ey:=EndY;
ApplyDirectionalSnap(StartX,StartY,ex,ey);
EndX:=trunc(ex);
EndY:=trunc(ey);
end;
ApplyScreenSnapsFloat(true,EndX,EndY);
// Reset the fractal seed; Screen snap logic uses a new
// seed when it traverses to find fractal snapping points.
SetSeed;
DrawXorPortion;
Canvas.Pen.Color:=oldcolor;
Canvas.Pen.Mode:=OldMode;
end;
RefreshCursor;
ShowCrosshair(X,Y);
end;
procedure TNormalPolylineToolHandler.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
// Don't let the default handler do it; we don't want to leave the started state.
end;
procedure TNormalPolylineToolHandler.Draw(erase:boolean);
var i:integer;
x,y:Coord;
p:PCoordPoint;
oldcolor:TColor;
begin
oldcolor:=Canvas.Pen.Color;
Canvas.Pen.Color:=CurrentColor;
if (linelist.Count>0) then begin
continue := GetLineStyleStart(GetCurrentlySetStyles);
p:=PCoordPoint(linelist.Items[0]);
X:=p^.X;
Y:=p^.y;
for i:=1 to linelist.Count-1 do begin
p:=PCoordPoint(linelist.Items[i]);
DrawLineContinue(Canvas, X,Y,p^.X,p^.Y, continue);
X:=p^.X;
Y:=p^.y;
end;
end;
Canvas.Pen.Color:=oldcolor;
end;
{------------------------------------------------------------------------------------}
procedure TFractalPolylineToolHandler.Add(list:PCoordArray; count:integer);
var lbl:string;
begin
if SnapWhenDone then lbl:=res_linetool_linefpoly_add else lbl:=res_linetool_lineffree_add;
Map.StartAdding(lbl);
MainForm.SeedSpin.Value:=(MainForm.SeedSpin.Value+count-1) and 65535;
Map.AddObject(PolylinePrimitive.Create(list, count, seed, roughness, GetCurrentlySetStyles));
Map.EndAdding;
end;
procedure TFractalPolylineToolHandler.Start;
begin
inherited Start;
seed := MainForm.SeedSpin.Value;
roughness := MainForm.RoughnessTrackBar.Position;
end;
procedure TFractalPolylineToolHandler.DrawXorPortion;
var oldcolor:TColor;
OldMode:TPenMode;
continue:TLineContinue;
begin
if (EndX<>-1) then begin
OldMode := Canvas.Pen.Mode;
oldcolor:=Canvas.Pen.Color;
Canvas.Pen.Mode := pmNotXor;
Canvas.Pen.Color:=CurrentColor;
continue:=GetLineStyleStart(GetCurrentlySetStyles);
FractalLine(Canvas,StartX,StartY,EndX,EndY,(distance(StartX,StartY,EndX,EndY)*roughness)/1000, continue);
Canvas.Pen.Color:=oldcolor;
Canvas.Pen.Mode:=OldMode;
end;
end;
procedure TFractalPolylineToolHandler.SetSeed;
begin
FractalSetSeed(seed + linelist.Count - 1);
end;
procedure TFractalPolylineToolHandler.Draw(erase:boolean);
var i:integer;
x,y:Coord;
p:PCoordPoint;
oldcolor:TColor;
begin
oldcolor:=Canvas.Pen.Color;
Canvas.Pen.Color:=CurrentColor;
if (linelist.Count>0) then begin
continue := GetLineStyleStart(GetCurrentlySetStyles);
p:=PCoordPoint(linelist.Items[0]);
X:=p^.X;
Y:=p^.y;
for i:=1 to linelist.Count-1 do begin
p:=PCoordPoint(linelist.Items[i]);
FractalSetSeed(seed + i - 1);
FractalLine(Canvas,X,Y,p^.X,p^.Y,(distance(X,Y,p^.X,p^.Y)*roughness)/1000, continue);
X:=p^.X;
Y:=p^.y;
end;
end;
Canvas.Pen.Color:=oldcolor;
end;
{------------------------------------------------------------------------------------}
procedure TNormalCurveToolHandler.Backspace;
procedure XorDraw;
var OldMode:TPenMode;
begin
OldMode := Canvas.Pen.Mode;
Canvas.Pen.Mode := pmNotXor;
Draw(true);
Canvas.Pen.Mode := OldMode;
end;
begin
if (which>1) then begin
XorDraw;
dec(which);
XorDraw;
end
else
Cancel;
case (which) of
0: CustomCursor:=crCurve1;
1: CustomCursor:=crCurve2;
2: CustomCursor:=crCurve3;
3: CustomCursor:=crCurve4;
end;
end;
constructor TNormalCurveToolHandler.Create(cv:TCanvas);
begin
inherited Create(cv);
AutoPan:=true;
CustomCursor:=crCurve1;
end;
procedure TNormalCurveToolHandler.Add(sp1,sp2,sp3,sp4:CoordPoint);
begin
Map.StartAdding(res_linetool_curve_add);
Map.AddObject(CurvePrimitive.Create(sp1,sp2,sp3,sp4,GetCurrentlySetStyles));
Map.EndAdding;
end;
procedure TNormalCurveToolHandler.Done;
var sp1,sp2,sp3,sp4:CoordPoint;
begin
if (which=3) then begin
Map.CurrentView.ScreenToCoord(trunc(p1.x),trunc(p1.y),sp1.x,sp1.y);
Map.CurrentView.ScreenToCoord(trunc(p2.x),trunc(p2.y),sp2.x,sp2.y);
Map.CurrentView.ScreenToCoord(trunc(p3.x),trunc(p3.y),sp3.x,sp3.y);
Map.CurrentView.ScreenToCoord(trunc(p4.x),trunc(p4.y),sp4.x,sp4.y);
ApplySnaps(false,sp1.x,sp1.y);
ApplySnaps(false,sp2.x,sp2.y);
ApplySnaps(false,sp3.x,sp3.y);
ApplySnaps(false,sp4.x,sp4.y);
Add(sp1,sp2,sp3,sp4);
end;
inherited Done;
end;
procedure TNormalCurveToolHandler.Move(dx,dy:integer);
begin
inherited Move(dx,dy);
p1.x:=p1.x+dx; p1.y:=p1.y+dy;
p2.x:=p2.x+dx; p2.y:=p2.y+dy;
p3.x:=p3.x+dx; p3.y:=p3.y+dy;
p4.x:=p4.x+dx; p4.y:=p4.y+dy;
end;
procedure TNormalCurveToolHandler.Cancel;
begin
inherited Cancel;
which:=0;
CustomCursor:=crCurve1;
end;
procedure TNormalCurveToolHandler.DrawCurve(sp1,sp2,sp3,sp4:CoordPoint);
var continue:TLineContinue;
begin
continue:=GetLineStyleStart(GetCurrentlySetStyles);
DrawBezier(Canvas,sp1,sp2,sp3,sp4,continue);
end;
procedure TNormalCurveToolHandler.Draw(erase:boolean);
begin
if not erase then ApplyScreenSnapsFloat(true,EndX,EndY);
case (which) of
1: DrawCurve(p1,p1,MakeCoordPoint(EndX,EndY),MakeCoordPoint(EndX,EndY));
2: DrawCurve(p1,MakeCoordPoint(EndX,EndY),MakeCoordPoint(EndX,EndY),p4);
3: DrawCurve(p1,p2,MakeCoordPoint(EndX,EndY),p4);
end;
end;
function TNormalCurveToolHandler.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer):boolean;
var OldMode:TPenMode;
begin
if (Button=mbRight) and (state<>tsOff) then begin
Cancel;
Result:=true;
exit;
end;
if (Button=mbLeft) then begin
state := tsStarted;
OldMode := Canvas.Pen.Mode;
Canvas.Pen.Mode := pmNotXor;
Draw(true);
ApplyScreenSnaps(true,x,y);
case (which) of
0: begin
p1.X := X;
p1.Y := y;
CustomCursor:=crCurve2;
end;
1: begin
p4.X := X;
p4.Y := y;
CustomCursor:=crCurve3;
end;
2: begin
p2.X := X;
p2.Y := y;
CustomCursor:=crCurve4;
end;
3: begin
p3.X := X;
p3.Y := y;
Done;
CustomCursor:=crCurve1;
end;
end;
EndX:=X;
EndY:=Y;
which := (which+1) and 3;
Draw(false);
Canvas.Pen.Mode := OldMode;
Result:=true;
end
else
Result:=false;
end;
procedure TNormalCurveToolHandler.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
// Don't let the default handler do it; we don't want to leave the started state.
end;
{------------------------------------------------------------------------------------}
procedure TFractalCurveToolHandler.DrawCurve(sp1,sp2,sp3,sp4:CoordPoint);
var d:double;
continue:TLineContinue;
begin
d := distance(sp1.x,sp1.y,sp2.x,sp2.y) + distance(sp4.x,sp4.y,sp3.x,sp3.y);
FractalSetSeed(MainForm.SeedSpin.Value);
continue:=GetLineStyleStart(GetCurrentlySetStyles);
DrawFractalBezier(Canvas,sp1,sp2,sp3,sp4,(d * MainForm.RoughnessTrackBar.Position)/1000, continue);
end;
procedure TFractalCurveToolHandler.Add;
var seed:integer;
begin
seed:=MainForm.SeedSpin.Value;
Map.StartAdding(res_linetool_curvef_add);
MainForm.SeedSpin.Value:=(seed+1) and 65535;
Map.AddObject(CurvePrimitive.Create(sp1,sp2,sp3,sp4,
seed,MainForm.RoughnessTrackBar.Position, GetCurrentlySetStyles));
Map.EndAdding;
end;
{------------------------------------------------------------------------------------}
Procedure TNormalArcToolHandler.Backspace;
Procedure XorDraw;
Var OldMode: TPenMode;
Begin
OldMode := Canvas.Pen.Mode;
Canvas.Pen.Mode := pmNotXor;
Draw(True);
Canvas.Pen.Mode := OldMode;
End; // XorDraw
Begin
If Which > 1 Then
Begin
XorDraw;
Dec(Which);
XorDraw;
End
Else Cancel;
Case Which Of
0: CustomCursor := crLine;
1: CustomCursor := crLine;
2: CustomCursor := crCurve3;
End; // Case
end; // TNormalArcToolHandler.Backspace
Constructor TNormalArcToolHandler.Create(cv: TCanvas);
Begin
Inherited Create(cv);
AutoPan := True;
CustomCursor := crLine;
End; // TNormalArcToolHandler.Create
Procedure TNormalArcToolHandler.Add(sp1,sp2,sp3: CoordPoint);
Var CX: CoordPoint;
Begin
Map.StartAdding(res_linetool_arc_add);
GetArcCenter(sp1,sp2,sp3,CX.X,CX.Y);
Map.AddObject(PolyCurvePrimitive.Arc(CX,sp2,sp3,GetCurrentlySetStyles));
Map.EndAdding;
End; // TNormalArcToolHandler.Add
Procedure TNormalArcToolHandler.Done;
Var sp1,sp2,sp3: CoordPoint;
Begin
If Which = 2 Then
Begin
Map.CurrentView.ScreenToCoord(trunc(p1.x),trunc(p1.y),sp1.x,sp1.y);
Map.CurrentView.ScreenToCoord(trunc(p2.x),trunc(p2.y),sp2.x,sp2.y);
Map.CurrentView.ScreenToCoord(trunc(p3.x),trunc(p3.y),sp3.x,sp3.y);
ApplySnaps(false,sp1.x,sp1.y);
ApplySnaps(false,sp2.x,sp2.y);
ApplySnaps(false,sp3.x,sp3.y);
Add(sp1,sp2,sp3);
End;