-
Notifications
You must be signed in to change notification settings - Fork 0
/
drawingframe1.pas
1196 lines (1069 loc) · 36.9 KB
/
drawingframe1.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
//Copyright (c) 2012 by Donald R. Ziesig
//
//Donald.at.Ziesig.org
//
//This file is part of MagicTracks.
//
//MagicTracks 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 3 of the License, or
//(at your option) any later version.
//
//MagicTracks 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.
//
//You should have received a copy of the GNU General Public License
//along with MagicTracks. If not, see <http://www.gnu.org/licenses/>.
unit DrawingFrame1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, ExtCtrls, StdCtrls, Menus,
DrawingCommon1, Drawing1, DrawingObject1, ThreePoint1;
type
{ TDrawingFrame }
TDrawingFrame = class(TFrame)
MenuItem1: TMenuItem;
MenuItem2: TMenuItem;
PaintBox1: TPaintBox;
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
Panel4: TPanel;
Panel5: TPanel;
PopupMenu1: TPopupMenu;
Ruler_XPB: TPaintBox;
Ruler_YPB: TPaintBox;
procedure MenuItem1Click(Sender: TObject);
procedure MenuItem2Click(Sender: TObject);
procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure PaintBox1MouseEnter(Sender: TObject);
procedure PaintBox1MouseLeave(Sender: TObject);
procedure PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure PaintBox1Paint(Sender: TObject);
procedure PaintBox1Resize(Sender: TObject);
procedure Ruler_XPBMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Ruler_XPBMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Ruler_XPBMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Ruler_YPBMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Ruler_YPBMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Ruler_YPBMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Ruler_YPBPaint(Sender: TObject);
procedure Ruler_XPBPaint(Sender: TObject);
private
{ private declarations }
fBoxType : TDrawingBox;
fDrawing : TDrawing;
// Ruler Mouse ops;
vXMouseDown : Boolean;
vXStart : Double;
vYMouseDown : Boolean;
vYStart : Double;
vMouseJustEntered : Boolean;
vMouseLastX : Double;
vMouseXPixels : Integer;
vMouseLastY : Double;
vMouseYPixels : Integer;
vMouseOverGuide1X,
vMouseOverGuide1Y,
vMouseOverGuide2X,
vMouseOverGuide2Y : Boolean;
vMouseGuide1XStart,
vMouseGuide1YStart,
vMouseGuide2XStart,
vMouseGuide2YStart : Double;
vMouseGuide1XTracking,
vMouseGuide1YTracking,
vMouseGuide2XTracking,
vMouseGuide2YTracking : Boolean;
vMouseDownX,
vMouseDownY : Integer;
vMouseDown : Boolean;
vMoveObject : Boolean;
vDrawingObjects : TDrawingObjectRaster;
vMouseInPaintBox : Boolean;
vRecursionDepth : Integer;
vTempPosition : T3Point;
function GetGuide1X: Double;
function GetGuide1Y: Double;
function GetGuide2X: Double;
function GetGuide2Y: Double;
procedure PaintRulerBackground( RulerPB : TPaintBox );
procedure PaintDrawingBackground;
procedure PaintDrawing;
procedure SetBoxType(const AValue: TDrawingBox);
procedure SetDrawing(const AValue: TDrawing);
function MouseX( X : Integer ) : Double; // Returns Mouse X in DRAWING coords.
function MouseY( Y : Integer ) : Double;
procedure MousePosition( var Position : T3Point; X, Y : Integer );
function PixelsX( X : Double ) : Integer;
function PixelsY( Y : Double ) : Integer;
procedure SetGuide1X(const AValue: Double);
procedure SetGuide1Y(const AValue: Double);
procedure SetGuide2X(const AValue: Double);
procedure SetGuide2Y(const AValue: Double);
public
{ public declarations }
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
procedure PositionLowerLeft;
procedure Invalidate; override;
function DrawingObject( X, Y : Integer) : TDrawingObjectReference; overload;
procedure DrawingObject( X, Y : Integer; Obj : TDrawingObject; Reference : Integer ); overload;
property BoxType : TDrawingBox read fBoxType write SetBoxType;
property Drawing : TDrawing read fDrawing write SetDrawing;
property Guide1X : Double read GetGuide1X write SetGuide1X;
property Guide1Y : Double read GetGuide1Y write SetGuide1Y;
property Guide2X : Double read GetGuide2X write SetGuide2X;
property Guide2Y : Double read GetGuide2Y write SetGuide2Y;
end;
implementation
{$R *.lfm}
uses
Common1, Graphics, UnitConversion1{, Preferences1, Math,
DrawingSetFrame1, Internals1}, CanvasStack1;
const
RulerHackColor = clGreen;
type
TInchesDraw = ( idInchesPlusFractions,
idInchesOnly,
idSixInches,
idFeet,
idTenFeet );
const
InchesDraw : array [0..MaxZoom] of TInchesDraw =
( idInchesPlusFractions, idInchesPlusFractions, idInchesPlusFractions, idInchesPlusFractions,
idInchesPlusFractions, idInchesPlusFractions, idInchesOnly, idInchesOnly,
idInchesOnly, idInchesOnly, idSixInches, idSixInches,
idSixInches, idSixInches, idSixInches, idSixInches,
idFeet, idFeet, idTenFeet, idTenFeet );
{ TDrawingFrame }
procedure TDrawingFrame.PaintRulerBackground(RulerPB: TPaintBox);
var
RulerRect : TRect;
begin
{ Setup and draw the ruler background }
if fDrawing = nil then exit;
RulerRect := RectToOrigin(RulerPB.BoundsRect );
RulerPB.Canvas.Brush.Color := clYellow;
RulerPB.Canvas.Brush.Style := bsSolid;
RulerPB.Canvas.Pen.Width := 1;
RulerPB.Canvas.Pen.Style := psSolid;
RulerPB.Canvas.Pen.Color := clBlack;
RulerPB.Canvas.Rectangle(RulerRect);
end;
function TDrawingFrame.PixelsX(X: Double): Integer;
begin
Result := MicronsToPixels( X - fDrawing.MinX[BoxType], fDrawing.Preferences );
end;
function TDrawingFrame.PixelsY(Y: Double): Integer;
begin
Result := MicronsToPixels( Y - fDrawing.MinY[BoxType], fDrawing.Preferences );
end;
procedure TDrawingFrame.PaintDrawingBackground;
var
DrawingRect : TRect;
ApproxGridPixels : Integer;
I, J, JJ : Integer;
X, OldX : Integer;
Y, OldY : Integer;
XX, YY : Double;
// oldColor : TColor;
// oldPenStyle : TPenStyle;
begin
{ Setup and draw the drawing background }
if fDrawing = nil then exit;
DrawingRect := RectToOrigin(PaintBox1.BoundsRect );
PaintBox1.Canvas.Brush.Color := clWhite;
PaintBox1.Canvas.Brush.Style := bsSolid;
PaintBox1.Canvas.Pen.Width := 1;
PaintBox1.Canvas.Pen.Style := psSolid;
PaintBox1.Canvas.Pen.Color := clBlack;
PaintBox1.Canvas.Rectangle( DrawingRect );
if fDrawing.Preferences.ShowGrid then
begin
{ See if the grid is worthwile }
ApproxGridPixels := MicronsToPixels( fDrawing.Preferences.GridSpacingMicrons, fDrawing.Preferences );
if ApproxGridPixels >= 10 then { can't tell them apart }
begin
CanvasStack.Push( PaintBox1.Canvas);
// oldColor := PaintBox1.Canvas.Pen.Color;
PaintBox1.Canvas.Pen.Color := clBlack;
XX := PixelsToMicrons(-1,Drawing.Preferences);
OldX := Floor( XX / fDrawing.Preferences.GridSpacingMicrons);
for I := 0 to Pred(Ruler_XPB.Width) do
begin
XX := PixelsToMicrons(I,Drawing.Preferences);
X := Floor( XX / fDrawing.Preferences.GridSpacingMicrons);
if (X <> OldX) then
begin
OldX := X;
YY := PixelsToMicrons(PaintBox1.Height,Drawing.Preferences);
OldY := Floor( YY / fDrawing.Preferences.GridSpacingMicrons );
for J := Pred(Ruler_YPB.Height) downto 0 do
begin
JJ := pred(PaintBox1.Height) - J;
YY := PixelsToMicrons(JJ,Drawing.Preferences);
Y := Floor( YY / fDrawing.Preferences.GridSpacingMicrons );
if (Y <> OldY) then
begin
OldY := Y;
PaintBox1.Canvas.MoveTo( I, J );
PaintBox1.Canvas.LIneTo( I+1, J+1 );
end;
end;
end;
end;
CanvasStack.Pop( PaintBox1.Canvas);
end;
end;
// Draw the guides
CanvasStack.Push( PaintBox1.Canvas);
X := PaintBox1.Width;
Y := PaintBox1.Height;
PaintBox1.Canvas.Pen.Style := psDashDot;
I := PixelsX( Guide2X );
J := PixelsY( Guide2Y );
PaintBox1.Canvas.MoveTo( I, 0);
PaintBox1.Canvas.LineTo( I, Y);
PaintBox1.Canvas.MoveTo( 0, Y-J);
PaintBox1.Canvas.LineTo( X, Y-J);
PaintBox1.Canvas.Pen.Style := psDash;
I := PixelsX( Guide1X );
J := PixelsY( Guide1Y );
PaintBox1.Canvas.MoveTo( I, 0);
PaintBox1.Canvas.LineTo( I, Y);
PaintBox1.Canvas.MoveTo( 0, Y-J);
PaintBox1.Canvas.LineTo( X, Y-J);
CanvasStack.Pop( PaintBox1.Canvas);
end;
procedure TDrawingFrame.PaintBox1Paint(Sender: TObject);
begin
if Drawing = nil then exit;
PaintDrawingBackground;
PaintDrawing;
end;
procedure TDrawingFrame.PaintBox1Resize(Sender: TObject);
var
W, H : Integer;
L : Integer;
begin
W := PaintBox1.Width;
H := PaintBox1.Height;
InternalsForm1.PutEvent('Resize ' + Name, 'W x H: ' + IntToStr(W) + ' x ' + IntToStr(H));
L := H * W;
InternalsForm1.PutEvent('Paintbox size ' + Name, IntToStr(L));
vDrawingObjects.Resize( W, H );
end;
procedure TDrawingFrame.PaintDrawing;
begin
// Draw the Active Layers of the Drawing;
vDrawingObjects.Reset;
Drawing.Draw( Self );
end;
constructor TDrawingFrame.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
vDrawingObjects := TDrawingObjectRaster.Create;
vMouseInPaintBox := False;
vRecursionDepth := 0;
vTempPosition := T3Point.Create;
vMoveObject := False;
end;
destructor TDrawingFrame.Destroy;
begin
vDrawingObjects.Free;
vTempPosition.Free;
inherited Destroy;
end;
function TDrawingFrame.DrawingObject(X, Y: Integer): TDrawingObjectReference;
begin
Result := vDrawingObjects.DrawingObject( X, Y );
end;
procedure TDrawingFrame.DrawingObject(X, Y: Integer; Obj : TDrawingObject; Reference : Integer );
begin
vDrawingObjects.DrawingObject( X, Y, Obj, Reference );
end;
function TDrawingFrame.GetGuide1X: Double;
begin
case BoxType of
XY : Result := Drawing.Guide1X;
XZ : Result := Drawing.Guide1X;
YZ : Result := Drawing.Guide1Y;
end;
end;
function TDrawingFrame.GetGuide1Y: Double;
begin
case BoxType of
XY : Result := Drawing.Guide1Y;
XZ : Result := Drawing.Guide1Z;
YZ : Result := Drawing.Guide1Z;
end;
end;
function TDrawingFrame.GetGuide2X: Double;
begin
case BoxType of
XY : Result := Drawing.Guide2X;
XZ : Result := Drawing.Guide2X;
YZ : Result := Drawing.Guide2Y;
end;
end;
function TDrawingFrame.GetGuide2Y: Double;
begin
case BoxType of
XY : Result := Drawing.Guide2Y;
XZ : Result := Drawing.Guide2Z;
YZ : Result := Drawing.Guide2Z;
end;
end;
procedure TDrawingFrame.Invalidate;
begin
PaintBox1.Invalidate;
end;
procedure TDrawingFrame.MenuItem1Click(Sender: TObject);
begin
Guide1X := MouseX( vMouseDownX );
Guide1Y := MouseY( vMouseDownY );
TDrawingSetFrame( Owner ).Invalidate;
end;
procedure TDrawingFrame.MenuItem2Click(Sender: TObject);
begin
Guide2X := MouseX( vMouseDownX );
Guide2Y := MouseY( vMouseDownY );
TDrawingSetFrame( Owner ).Invalidate;
end;
procedure TDrawingFrame.MousePosition(var Position: T3Point; X, Y: Integer);
var
YPrime : Integer;
begin
YPrime := PaintBox1.Height - Y;
case BoxType of
XY:
begin
Position.X := PixelsToMicrons( X, fDrawing.Preferences) + fDrawing.MinX[BoxType];
Position.Y := PixelsToMicrons( YPrime, fDrawing.Preferences) + fDrawing.MinY[BoxType];
Position.Z := 0.0;
end;
XZ:
begin
Position.X := PixelsToMicrons( X, fDrawing.Preferences) + fDrawing.MinX[BoxType];
Position.Y := 0.0;
Position.Z := PixelsToMicrons( YPrime, fDrawing.Preferences) + fDrawing.MinY[BoxType];
end;
YZ:
begin
Position.X := 0.0;
Position.Y := PixelsToMicrons( X, fDrawing.Preferences) + fDrawing.MinX[BoxType];
Position.Z := PixelsToMicrons( YPrime, fDrawing.Preferences) + fDrawing.MinY[BoxType];
end;
end;
end;
function TDrawingFrame.MouseX(X: Integer): Double;
var
XX, Spacing : Double;
I : Integer;
begin
Result := PixelsToMicrons( X, fDrawing.Preferences) + fDrawing.MinX[BoxType];
if fDrawing.Preferences.SnapToGrid then
begin
Spacing := fDrawing.Preferences.GridSpacingMicrons;
XX := Result / Spacing;
I := Round(XX);
Result := (I * Spacing);
end;
end;
function TDrawingFrame.MouseY(Y: Integer): Double;
var
XX, Spacing : Double;
I : Integer;
begin
Result := PixelsToMicrons( Y, fDrawing.Preferences) + fDrawing.MinY[BoxType];
if fDrawing.Preferences.SnapToGrid then
begin
Spacing := fDrawing.Preferences.GridSpacingMicrons;
XX := Result / Spacing;
I := Round(XX);
Result := (I * Spacing);
end;
end;
procedure TDrawingFrame.PaintBox1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
Obj : TDrawingObjectReference;
DoInvalidate : Boolean;
begin
MousePosition(vTempPosition, X, Y );
DoInvalidate := False;
if Button = mbRight then
begin
// Set Guide to current X Y
vMouseDownX := X;
Y := pred(PaintBox1.Height) - Y;
vMouseDownY := Y;
PopupMenu1.PopUp;
exit;
end;
if Button = mbLeft then
begin
Obj := DrawingObject(X, Y);
if Obj.Obj = nil then
begin
fDrawing.Layers.Deselect;
DoInvalidate := True;
end
else
begin
if Obj.Obj.Selected then
vMoveObject := True
else
if not vMouseDown then
begin
if not (ssCtrl in Shift) then
begin
fDrawing.Layers.Deselect;
Obj.Obj.Select;
end
else
Obj.Obj.ToggleSelect;
vMouseDown := true;
DoInvalidate := True;
end;
end;
end;
if vMouseOverGuide1X then
begin
vMouseGuide1XStart := MouseX( X );
vMouseGuide1XTracking := True;
end
else if vMouseOverGuide1Y then
begin
vMouseGuide1YStart := MouseY( Y );
vMouseGuide1YTracking := True;
end
else if vMouseOverGuide2X then
begin
vMouseGuide2XStart := MouseX( X );
vMouseGuide2XTracking := True;
end
else if vMouseOverGuide2Y then
begin
vMouseGuide2YStart := MouseY( Y );
vMouseGuide2YTracking := True;
end;
if DoInvalidate then
TDrawingSetFrame( Owner ).Invalidate;
end;
procedure TDrawingFrame.PaintBox1MouseEnter(Sender: TObject);
begin
if fDrawing = nil then exit;
vMouseJustEntered := True;
vMouseInPaintBox := True;
end;
procedure TDrawingFrame.PaintBox1MouseLeave(Sender: TObject);
var
PM : TPenMode;
OldColor : TColor;
begin
if fDrawing = nil then exit;
vMouseInPaintBox := False;
PM := Ruler_XPB.Canvas.Pen.Mode;
OldColor := Ruler_XPB.Canvas.Pen.Color;
Ruler_XPB.Canvas.Pen.Color := RulerHackColor;
Ruler_XPB.Canvas.Pen.Mode := pmNotXOR;
Ruler_XPB.Canvas.MoveTo(vMouseXPixels,0);
Ruler_XPB.Canvas.LineTo(vMouseXPixels,Ruler_XPB.Height);
Ruler_XPB.Canvas.Pen.Mode := PM;
Ruler_XPB.Canvas.Pen.Color := OldColor;
PM := Ruler_YPB.Canvas.Pen.Mode;
OldColor := Ruler_YPB.Canvas.Pen.Color;
Ruler_YPB.Canvas.Pen.Color := RulerHackColor;
Ruler_YPB.Canvas.Pen.Mode := pmNotXOR;
Ruler_YPB.Canvas.MoveTo(0,pred(PaintBox1.Height) - vMouseYPixels);
Ruler_YPB.Canvas.LineTo(Ruler_YPB.Height,pred(PaintBox1.Height) - vMouseYPixels);
Ruler_YPB.Canvas.Pen.Mode := PM;
Ruler_YPB.Canvas.Pen.Color := OldColor;
end;
procedure TDrawingFrame.PaintBox1MouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
const
Thresh = 1; // Temp for development
var
PM : TPenMode;
OldColor : TColor;
DG1X, DG1Y : Double;
DG2X, DG2Y : Double;
DX1, DX2, DY1, DY2 : Double;
YPrime : Integer;
Obj : TDrawingObjectReference;
CurrentPosition,
DeltaPosition : T3Point;
DoInvalidate : Boolean;
begin
if fDrawing = nil then exit;
if not vMouseInPaintBox then exit;
if VRecursionDepth > 0 then exit;
DoInvalidate := False;
CurrentPosition := T3Point.Create;
DeltaPosition := T3Point.Create;
MousePosition(CurrentPosition,X,Y);
DeltaPosition.Assign( CurrentPosition );
DeltaPosition.Sub( vTempPosition );
vTempPosition.Assign(CurrentPosition);
if vMoveObject then
begin
fDrawing.MoveSelected(DeltaPosition);
DoInvalidate := true;
end;
try
Inc(vRecursionDepth);
OldColor := Ruler_XPB.Canvas.Pen.Color;
Ruler_XPB.Canvas.Pen.Color := RulerHackColor;
Ruler_YPB.Canvas.Pen.Color := RulerHackColor;
if not vMouseJustEntered then
begin
PM := Ruler_XPB.Canvas.Pen.Mode;
Ruler_XPB.Canvas.Pen.Mode := pmNotXOR;
Ruler_XPB.Canvas.MoveTo(vMouseXPixels,0);
Ruler_XPB.Canvas.LineTo(vMouseXPixels,Ruler_XPB.Height);
Ruler_XPB.Canvas.Pen.Mode := PM;
PM := Ruler_YPB.Canvas.Pen.Mode;
Ruler_YPB.Canvas.Pen.Mode := pmNotXOR;
Ruler_YPB.Canvas.MoveTo(0,pred(PaintBox1.Height) - vMouseYPixels);
Ruler_YPB.Canvas.LineTo(Ruler_YPB.Height,pred(PaintBox1.Height) - vMouseYPixels);
Ruler_YPB.Canvas.Pen.Mode := PM;
end;
vMouseJustEntered := False;
vMouseLastX := MouseX( X );
vMouseXPixels := MicronsToPixels( vMouseLastX - fDrawing.MinX[fBoxType], fDrawing.Preferences );
PM := Ruler_XPB.Canvas.Pen.Mode;
Ruler_XPB.Canvas.Pen.Mode := pmNotXOR;
Ruler_XPB.Canvas.MoveTo(vMouseXPixels,0);
Ruler_XPB.Canvas.LineTo(vMouseXPixels,Ruler_XPB.Height);
Ruler_XPB.Canvas.Pen.Mode := PM;
YPrime := pred(PaintBox1.Height) - Y;
vMouseLastY := MouseY( YPrime );
vMouseYPixels := MicronsToPixels( vMouseLastY - fDrawing.MinY[fBoxType], fDrawing.Preferences );
PM := Ruler_YPB.Canvas.Pen.Mode;
Ruler_YPB.Canvas.Pen.Mode := pmNotXOR;
Ruler_YPB.Canvas.MoveTo(0,pred(PaintBox1.Height) - vMouseYPixels);
Ruler_YPB.Canvas.LineTo(Ruler_YPB.Height,pred(PaintBox1.Height) - vMouseYPixels);
Ruler_YPB.Canvas.Pen.Mode := PM;
Ruler_XPB.Canvas.Pen.Color := OldColor;
Ruler_YPB.Canvas.Pen.Color := OldColor;
// Check if Mouse is over one of the guides (starting with 1)
vMouseOverGuide1X := false;
vMouseOverGuide1y := false;
vMouseOverGuide2X := false;
vMouseOverGuide2Y := false;
DG1X := Guide1X;
DG1Y := Guide1Y;
DG2X := Guide2X;
DG2Y := Guide2Y;
DX1 := MicronsToPixels(vMouseLastX - DG1X, fDrawing.Preferences );
DY1 := MicronsToPixels(vMouseLastY - DG1Y, fDrawing.Preferences );
DX2 := MicronsToPixels(vMouseLastX - DG2X, fDrawing.Preferences );
DY2 := MicronsToPixels(vMouseLastY - DG2Y, fDrawing.Preferences );
if abs(DX1) < Thresh then
vMouseOverGuide1X := true
else if abs(DY1) < Thresh then
vMouseOverGuide1Y := true
else if abs(DX2) < Thresh then
vMouseOverGuide2X := true
else if abs(DY2) < Thresh then
vMouseOverGuide2Y := true;
if vMouseOverGuide1X or vMouseOverGuide2X then
PaintBox1.Cursor := crHSplit
else if vMouseOverGuide1Y or vMouseOverGuide2Y then
PaintBox1.Cursor := crVSplit
else
PaintBox1.Cursor := crDefault;
if ssLeft in Shift then
begin
if vMouseGuide1XTracking then
Guide1X := vMouseLastX
else if vMouseGuide1YTracking then
Guide1Y := vMouseLastY
else if vMouseGuide2XTracking then
Guide2X := vMouseLastX
else if vMouseGuide2YTracking then
Guide2Y := vMouseLastY;
DoInvalidate := True;
end;
Obj := DrawingObject(X, Y);
if Obj.Obj <> nil then
begin
if Obj.Obj.Selected then
if Obj.Ref = 0 then
PaintBox1.Cursor := crSize // For moving the object.
else
begin
if Drawing.SelectedCount < 2 then
PaintBox1.Cursor := crCross // For moving handle
end
else
PaintBox1.Cursor := crHandPoint;
end;
finally
CurrentPosition.Free;
DeltaPosition.Free;
Dec(vRecursionDepth);
end;
if DoInvalidate then
TDrawingSetFrame(Owner).Invalidate;
end;
procedure TDrawingFrame.PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
vMouseGuide1XTracking := false;
vMouseGuide1YTracking := false;
vMouseGuide2XTracking := false;
vMouseGuide2YTracking := false;
vMouseDown := false;
vMoveObject := false;
end;
procedure TDrawingFrame.Ruler_XPBMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if fDrawing = nil then exit;
vXMouseDown := Button = mbLeft;
if vXMouseDown then
begin
vXStart := Drawing.MinX[fBoxType] + PixelsToMicrons(X,Drawing.Preferences);
Ruler_XPB.Invalidate;
Invalidate;
end;
end;
procedure TDrawingFrame.Ruler_XPBMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
var
MU : Double;
begin
if vXMouseDown then
begin
MU := PixelsToMicrons(X,Drawing.Preferences);
Drawing.MinX[BoxType] := vXStart - MU;
Ruler_XPB.Invalidate;
Invalidate;
end;
end;
procedure TDrawingFrame.Ruler_XPBMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
vXMouseDown := False;
end;
procedure TDrawingFrame.Ruler_YPBMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
YPrime : Integer;
begin
if fDrawing = nil then exit;
vYMouseDown := Button = mbLeft;
if vYMouseDown then
begin
YPrime := pred(Ruler_YPB.Height) - Y;
vYStart := Drawing.MinY[fBoxType] + PixelsToMicrons(YPrime,Drawing.Preferences);
Ruler_YPB.Invalidate;
Invalidate;
end;
end;
procedure TDrawingFrame.Ruler_YPBMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
var
MU : Double;
YPrime : Integer;
V : Double;
begin
if not vYMouseDown then exit;
YPrime := pred(Ruler_YPB.Height) - Y;
MU := PixelsToMicrons(YPrime,Drawing.Preferences);
V := vYStart - MU;
Drawing.MinY[BoxType] := V;
Ruler_YPB.Invalidate;
Invalidate;
end;
procedure TDrawingFrame.Ruler_YPBMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
vYMouseDown := False;
end;
procedure TDrawingFrame.Ruler_XPBPaint(Sender: TObject);
var
I : Integer;
X, OldX : Integer;
XX : Double;
MX : Double;
DisplayHeight : Integer;
begin
if Drawing = nil then exit;
DisplayHeight := Ruler_XPB.Height;
PaintRulerBackground( Ruler_XPB );
MX := Drawing.MinX[fBoxType];
case InchesDraw[Drawing.Preferences.ZoomIndex] of
idInchesPlusFractions:
begin
XX := PixelsToMicrons(-1,Drawing.Preferences) + MX;
OldX := Floor( XX * MicronsToFt * 48);
for I := 0 to Pred(Ruler_XPB.Width) do
begin
XX := PixelsToMicrons(I,Drawing.Preferences) + MX;
X := Floor( XX * MicronsToFt * 48);
if (X <> OldX) then
begin
OldX := X;
Ruler_XPB.Canvas.MoveTo(I,0);
if (X mod 48) = 0 then
begin
Ruler_XPB.Canvas.Pen.Width := 2; Ruler_XPB.Canvas.MoveTo(I,0);
Ruler_XPB.Canvas.LineTo(I,Trunc(DisplayHeight * 0.67));
Ruler_XPB.Canvas.Pen.Width := 1;
Ruler_XPB.Canvas.TextOut(I+3,Trunc(DisplayHeight * 0.45),IntToStr(X div 48)+'''');
end
else if (X mod 24) = 0 then
begin
Ruler_XPB.Canvas.LineTo(I,Trunc(DisplayHeight * 0.67));
Ruler_XPB.Canvas.TextOut( I+3,Trunc(DisplayHeight * 0.45),
IntToStr(X div 48)+'''' + '6"');
end
else if (X mod 4) = 0 then
Ruler_XPB.Canvas.LineTo(I,Trunc(DisplayHeight * 0.5))
else
Ruler_XPB.Canvas.LineTo(I,Trunc(DisplayHeight * 0.2));
end;
end;
end;
idInchesOnly:
begin
XX := PixelsToMicrons(-1,Drawing.Preferences) + MX;
OldX := Floor( XX * MicronsToFt * 12);
for I := 0 to Pred(Ruler_XPB.Width) do
begin
XX := PixelsToMicrons(I,Drawing.Preferences) + MX;
X := Floor( XX * MicronsToFt * 12);
if (X <> OldX) then
begin
OldX := X;
Ruler_XPB.Canvas.MoveTo(I,0);
if (X mod 6) = 0 then
begin
Ruler_XPB.Canvas.LineTo(I,Trunc(DisplayHeight * 0.5));
end;
if (X mod 12) = 0 then
begin
Ruler_XPB.Canvas.Pen.Width := 2; Ruler_XPB.Canvas.MoveTo(I,0);
Ruler_XPB.Canvas.LineTo(I,Trunc(DisplayHeight * 0.67));
Ruler_XPB.Canvas.Pen.Width := 1; Ruler_XPB.Canvas.MoveTo(I,0);
Ruler_XPB.Canvas.TextOut(I+3,Trunc(DisplayHeight * 0.45),IntToStr(X div 12)+'''');
end
else
Ruler_XPB.Canvas.LineTo(I,Trunc(DisplayHeight * 0.3));
end;
end;
end;
idSixInches:
begin
XX := PixelsToMicrons(-1,Drawing.Preferences) + MX;
OldX := Floor( XX * MicronsToFt * 6);
for I := 0 to Pred(Ruler_XPB.Width) do
begin
XX := PixelsToMicrons(I,Drawing.Preferences) + MX;
X := Floor( XX * MicronsToFt * 6);
if (X <> OldX) then
begin
OldX := X;
Ruler_XPB.Canvas.MoveTo(I,0);
if (X mod 3) = 0 then
begin
Ruler_XPB.Canvas.LineTo(I,Trunc(DisplayHeight * 0.5));
end;
if (X mod 6) = 0 then
begin
Ruler_XPB.Canvas.Pen.Width := 2; Ruler_XPB.Canvas.MoveTo(I,0);
Ruler_XPB.Canvas.LineTo(I,Trunc(DisplayHeight * 0.67));
Ruler_XPB.Canvas.Pen.Width := 1; Ruler_XPB.Canvas.MoveTo(I,0);
Ruler_XPB.Canvas.TextOut(I+3,Trunc(DisplayHeight * 0.45),IntToStr(X div 6)+'''');
end
else
Ruler_XPB.Canvas.LineTo(I,Trunc(DisplayHeight * 0.3));
end;
end;
end;
idFeet:
begin
XX := PixelsToMicrons(-1,Drawing.Preferences) + MX;
OldX := Floor( XX * MicronsToFt * 2);
for I := 0 to Pred(Ruler_XPB.Width) do
begin
XX := PixelsToMicrons(I,Drawing.Preferences) + MX;
X := Floor( XX * MicronsToFt * 2);
if (X <> OldX) then
begin
OldX := X;
Ruler_XPB.Canvas.MoveTo(I,0);
if (X mod 2) = 0 then
begin
Ruler_XPB.Canvas.Pen.Width := 2; Ruler_XPB.Canvas.MoveTo(I,0);
Ruler_XPB.Canvas.LineTo(I,Trunc(DisplayHeight * 0.67));
Ruler_XPB.Canvas.Pen.Width := 1; Ruler_XPB.Canvas.MoveTo(I,0);
Ruler_XPB.Canvas.TextOut(I+3,Trunc(DisplayHeight * 0.45),IntToStr(X div 2)+'''');
end
else
Ruler_XPB.Canvas.LineTo(I,Trunc(DisplayHeight * 0.3));
end;
end;
end;
idTenFeet:
begin
XX := PixelsToMicrons(-1,Drawing.Preferences) + MX;
OldX := Floor( XX * MicronsToFt);
for I := 0 to Pred(Ruler_XPB.Width) do
begin
XX := PixelsToMicrons(I,Drawing.Preferences) + MX;
X := Floor( XX * MicronsToFt);
if (X <> OldX) then
begin
OldX := X;
Ruler_XPB.Canvas.MoveTo(I,0);
if (X mod 10) = 0 then
begin
Ruler_XPB.Canvas.Pen.Width := 2; Ruler_XPB.Canvas.MoveTo(I,0);
Ruler_XPB.Canvas.LineTo(I,Trunc(DisplayHeight * 0.67));
Ruler_XPB.Canvas.Pen.Width := 1; Ruler_XPB.Canvas.MoveTo(I,0);
Ruler_XPB.Canvas.TextOut(I+3,Trunc(DisplayHeight * 0.45),IntToStr(X)+'''');
end
else
Ruler_XPB.Canvas.LineTo(I,Trunc(DisplayHeight * 0.3));
end;
end;
end;
end;
end;
procedure TDrawingFrame.Ruler_YPBPaint(Sender: TObject);
var
I, J : Integer;
X, OldX : Integer;
XX : Double;
MX : Double;
DisplayHeight : Integer;
DisplayWidth : Integer;
begin
if Drawing = nil then exit;
DisplayHeight := Ruler_YPB.Width;
DisplayWidth := Ruler_YPB.Height;
PaintRulerBackground( Ruler_YPB );
MX := Drawing.MinY[fBoxType];
{Note that the ruler's pixel coordinates are inverted vs. the drawing vertical }
{dimension. To make the majority of the code consistent, the index J is }
{is started at the bottom (Height) and decremented to 0. The index I is mapped}
{to be the logical (0 at bottom) coordinates and translated into dimensions }
{ consistent with the user's preferences. Drawing is performed at J. }
case InchesDraw[Drawing.Preferences.ZoomIndex] of
idInchesPlusFractions:
begin
XX := PixelsToMicrons(-1,Drawing.Preferences) + MX;
OldX := Floor( XX * MicronsToFt * 48); { 1/4" tics }
for J := Pred(Ruler_YPB.Height) downto 0 do
begin
I := DisplayWidth - J;
XX := PixelsToMicrons(I,Drawing.Preferences) + MX;
X := Floor( XX * MicronsToFt * 48);
if (X <> OldX) then
begin
OldX := X;
Ruler_YPB.Canvas.MoveTo(DisplayHeight,J);
if (X mod 48) = 0 then
begin