-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathu_MainForm.pas
2634 lines (2165 loc) · 76.6 KB
/
u_MainForm.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
unit u_MainForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, ComCtrls, Buttons, StdCtrls, Spin, ExtDlgs, Grids,
ToolWin, ImgList, ActnList,pngimage, AppEvnts,GDIPOBJ, GDIPAPI, Menus,
System.Actions, System.ImageList;
type
TMainForm = class(TForm)
pcMain: TPageControl;
tsSource: TTabSheet;
tsResult: TTabSheet;
pnRight: TPanel;
pnParams: TPanel;
pnXY: TPanel;
ScrollBox1: TScrollBox;
imgSource: TImage;
ScrollBox2: TScrollBox;
imgResult: TImage;
gbFile: TGroupBox;
gbDimension: TGroupBox;
OpenPictureDialog1: TOpenPictureDialog;
SavePictureDialog1: TSavePictureDialog;
Bevel1: TBevel;
lblX: TLabel;
lblY: TLabel;
lblSize: TLabel;
seSizeY: TSpinEdit;
seSizeX: TSpinEdit;
lblDelta: TLabel;
seDeltaX: TSpinEdit;
seDeltaY: TSpinEdit;
lblCount: TLabel;
seCountX: TSpinEdit;
seCountY: TSpinEdit;
gbResult: TGroupBox;
lblBorder: TLabel;
seBorder: TSpinEdit;
shFrameColor: TShape;
sbFrameColor: TPanel;
GroupBox1: TGroupBox;
ImageList1: TImageList;
ToolBar1: TToolBar;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
ToolButton3: TToolButton;
ToolButton4: TToolButton;
ToolButton5: TToolButton;
ToolButton6: TToolButton;
Panel1: TPanel;
TrackBar1: TTrackBar;
TrackBar2: TTrackBar;
ToolButton7: TToolButton;
sgCards: TStringGrid;
ToolButton8: TToolButton;
chbRoundRect: TCheckBox;
Timer1: TTimer;
tsBuffer: TTabSheet;
ActionList1: TActionList;
Action1: TAction;
Action2: TAction;
Action3: TAction;
Action4: TAction;
Action5: TAction;
Action6: TAction;
ScrollBox3: TScrollBox;
imgBuffer: TImage;
lblDir: TLabel;
lblFile: TLabel;
Label1: TLabel;
seFrameX: TSpinEdit;
seFrameY: TSpinEdit;
chbCuttingLine: TCheckBox;
lblInterval: TLabel;
seInterval: TSpinEdit;
Label2: TLabel;
lblDPI: TLabel;
chkHex: TCheckBox;
tsSelected: TTabSheet;
ScrollBox4: TScrollBox;
img1: TImage;
Shape1: TShape;
img2: TImage;
ApplicationEvents1: TApplicationEvents;
Label3: TLabel;
chbSplit: TCheckBox;
chbMirror: TCheckBox;
seDPI: TSpinEdit;
FrameBox: TPaintBox;
Shape2: TShape;
imgPreview: TImage;
Action7: TAction;
Action8: TAction;
Panel3: TPanel;
chbCorners: TCheckBox;
Splitter1: TSplitter;
Splitter2: TSplitter;
chbDimension: TCheckBox;
chbResult: TCheckBox;
ToolBar3: TToolBar;
tbtLoad: TToolButton;
tbtSaveIni: TToolButton;
tbtRotate: TToolButton;
tbtSave: TToolButton;
ToolButton27: TToolButton;
tbtSplit: TToolButton;
seShift: TSpinEdit;
SpeedButton1: TSpeedButton;
PageScroller1: TPageScroller;
Panel5: TPanel;
TrackBar3: TTrackBar;
cbFrameOrGround: TComboBox;
Panel2: TPanel;
ColorBox1: TColorBox;
ColorBox2: TColorBox;
Panel4: TPanel;
cbAnchor: TComboBox;
ToolBar2: TToolBar;
ToolButton9: TToolButton;
ToolButton10: TToolButton;
ToolButton11: TToolButton;
ToolButton12: TToolButton;
ToolButton13: TToolButton;
ToolButton14: TToolButton;
ToolButton19: TToolButton;
ToolButton18: TToolButton;
ToolButton17: TToolButton;
ToolButton15: TToolButton;
ToolButton16: TToolButton;
ToolButton21: TToolButton;
tbHideLines: TToolButton;
tbOnecard: TToolButton;
ToolButton20: TToolButton;
ToolButton23: TToolButton;
TabSheet1: TTabSheet;
Memo1: TMemo;
procedure imgSourceMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure imgSourceClick(Sender: TObject);
procedure sbSourceClick(Sender: TObject);
procedure sbFrameColorClick(Sender: TObject);
procedure chbRoundRectClick(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Action1Update(Sender: TObject);
procedure Action1Execute(Sender: TObject);
procedure Action2Execute(Sender: TObject);
procedure Action3Execute(Sender: TObject);
procedure Action4Execute(Sender: TObject);
procedure Action5Execute(Sender: TObject);
procedure Action6Execute(Sender: TObject);
procedure sgCardsClick(Sender: TObject);
procedure pcMainChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure seBorderChange(Sender: TObject);
procedure seFrameChange(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure chbCuttingLineClick(Sender: TObject);
procedure imgFrameDblClick(Sender: TObject);
procedure imgFrameStartDrag(Sender: TObject;
var DragObject: TDragObject);
procedure imgFrameMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure seDPIChange(Sender: TObject);
procedure img1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure img1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure img1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
procedure Grid(png: tpngobject;CountX,CountY:integer);
procedure chbMirrorClick(Sender: TObject);
procedure Resetgrid1Click(Sender: TObject);
procedure Autodetect1Click(Sender: TObject);
procedure ToolButton20Click(Sender: TObject);
procedure ToolButton16Click(Sender: TObject);
procedure FrameBoxPaint(Sender: TObject);
procedure ToolButton8Click(Sender: TObject);
procedure seSizeXChange(Sender: TObject);
procedure seSizeYChange(Sender: TObject);
procedure tbOnecardClick(Sender: TObject);
procedure FrameBoxMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Shape2MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure sgCardsSetEditText(Sender: TObject; ACol, ARow: Integer;
const Value: String);
procedure seFrameXChange(Sender: TObject);
procedure seFrameYChange(Sender: TObject);
procedure Action8Execute(Sender: TObject);
procedure Action7Execute(Sender: TObject);
procedure Splitter1Moved(Sender: TObject);
procedure chbCornersClick(Sender: TObject);
procedure chbDimensionClick(Sender: TObject);
procedure chbResultClick(Sender: TObject);
procedure Splitter2Moved(Sender: TObject);
procedure tbtRotateClick(Sender: TObject);
procedure tbtSplitClick(Sender: TObject);
procedure sgCardsSelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
procedure tbHideLinesClick(Sender: TObject);
procedure seShiftChange(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
private
{ Private declarations }
fGetColor:boolean;
p1,p2,p3,p4,p11,p12,p13,p14:TPoint;
fFileName:string;
fMove:TPoint;
Otves:Tpoint;
Img:TGraphic;
FScale: double;
RedRects:array of TRect;
BlueRects:array of TRect;
YellowRects:array of TRect;
GreenStyle:TPenStyle;
ReFrame:boolean;
FStop: Boolean;
FOldCorned:string;
Cntr:TPoint;
procedure RotateBitmapGDIP(Bmp: TBitmap; Degs: Double;
AdjustSize: Boolean; BkColor: TColor = clNone);
procedure SetScale(const Value: double);
procedure SetStop(const Value: Boolean);
public
{ Public declarations }
procedure DrawFrame(x,y:integer;a:double);
procedure DrawCard(x,y,i:integer;a:double; png:TPNGObject);
procedure LoadIniFile(AFilename:string);
procedure SaveIniFile(AFilename:string;AGrid:boolean);
procedure LoadImage(AFilename:string);
procedure DemoCard(x,y,i:integer;a:double;Frm:integer=0);
procedure ScanAuto(x,y:integer);
property Scale:double read FScale write SetScale;
function Zm(P:TPoint):TPoint;
property Stop:Boolean read FStop write SetStop;
procedure CenterAxis(a:double);
procedure CalcCenter;
end;
var
MainForm: TMainForm;
implementation
uses jpeg,math, Types, u_ProgressForm, u_SplitForm, CommCtrl;
{$R *.dfm}
const
StepX:array[1..4] of integer = (1,5,20,100);
StepA:array[1..3] of Double = (0.02,0.1,1.00);
var fDefSpeed:Integer;
procedure TMainForm.imgSourceMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if Shape2.Visible then
begin
Shape2.Height := y+1 - ScrollBox1.VertScrollBar.Position - Shape2.Top;
Shape2.Width := x - ScrollBox1.HorzScrollBar.Position - Shape2.Left;
end;
if pcMain.ActivePage = tsSelected then
begin
pnXY.Caption := IntToStr(x ) + ' / '+ IntToStr(y);
img2.Picture.Bitmap.Canvas.BrushCopy(Rect(0,0,44,71),TImage(Sender).Picture.Bitmap, Rect(x-3,y-4,x+2,y+4),clNone)
end
else begin
pnXY.Caption := IntToStr(Round(x / Scale )) + ' / '+ IntToStr(Round(y / Scale));
img2.Picture.Bitmap.Canvas.BrushCopy(Rect(0,0,44,71),imgSource.Picture.Bitmap, Rect(Round(x / Scale)-3,Round(y / Scale)-4,Round(x / Scale)+2,Round(y / Scale)+4),clNone);
end;
img2.Picture.Bitmap.Canvas.MoveTo(26,0);
img2.Picture.Bitmap.Canvas.LineTo(26,90);
img2.Picture.Bitmap.Canvas.MoveTo(18,0);
img2.Picture.Bitmap.Canvas.LineTo(18,90);
img2.Picture.Bitmap.Canvas.MoveTo(0,36);
img2.Picture.Bitmap.Canvas.LineTo(54,36);
if fGetColor then
begin
shFrameColor.Pen.Color := imgSource.Picture.Bitmap.Canvas.Pixels[round(x/scale),Round(y/scale)];
shFrameColor.Brush.Color := $FFFFFF xor shFrameColor.Pen.Color;
end;
if ssRight in Shift then
begin
ScrollBox1.HorzScrollBar.Position := ScrollBox1.HorzScrollBar.Position - (fMove.X - x)div 2 ;
ScrollBox1.VertScrollBar.Position := ScrollBox1.VertScrollBar.Position - (fMove.Y - y)div 2 ;
fMove.X := x;
fMove.Y := y;
end;
end;
procedure TMainForm.imgSourceClick(Sender: TObject);
begin
Application.ProcessMessages;
fGetColor := False;
sbFrameColor.BevelOuter := bvRaised;
end;
procedure TMainForm.sbSourceClick(Sender: TObject);
begin
if OpenPictureDialog1.Execute then
begin
pcMain.ActivePageIndex := 0;
LoadImage(OpenPictureDialog1.FileName);
CalcCenter;
end;
end;
procedure TMainForm.sbFrameColorClick(Sender: TObject);
begin
fGetColor := NOT fGetColor;
if fGetColor then
sbFrameColor.BevelOuter := bvLowered
else
sbFrameColor.BevelOuter := bvRaised;
end;
procedure TMainForm.chbRoundRectClick(Sender: TObject);
begin
if chbRoundRect.Checked then
shFrameColor.Shape := stRoundRect
else
shFrameColor.Shape := stRectangle;
if (pcMain.ActivePageIndex = 1) then
pcMainChange(nil)
end;
procedure DrawAntialisedLine(Canvas: TCanvas; const AX1, AY1, AX2, AY2: real; const LineColor: TColor);
var
swapped: boolean;
procedure plot(const x, y, c: real);
var
resclr: TColor;
begin
if swapped then
resclr := Canvas.Pixels[round(y), round(x)]
else
resclr := Canvas.Pixels[round(x), round(y)];
resclr := RGB(round(GetRValue(resclr) * (1-c) + GetRValue(LineColor) * c),
round(GetGValue(resclr) * (1-c) + GetGValue(LineColor) * c),
round(GetBValue(resclr) * (1-c) + GetBValue(LineColor) * c));
if swapped then
Canvas.Pixels[round(y), round(x)] := resclr
else
Canvas.Pixels[round(x), round(y)] := resclr;
end;
function rfrac(const x: real): real;
begin
rfrac := 1 - frac(x);
end;
procedure swap(var a, b: real);
var
tmp: real;
begin
tmp := a;
a := b;
b := tmp;
end;
var
x1, x2, y1, y2, dx, dy, gradient, xend, yend, xgap, xpxl1, ypxl1,
xpxl2, ypxl2, intery: real;
x: integer;
begin
x1 := AX1;
x2 := AX2;
y1 := AY1;
y2 := AY2;
dx := x2 - x1;
dy := y2 - y1;
swapped := abs(dx) < abs(dy);
if swapped then
begin
swap(x1, y1);
swap(x2, y2);
swap(dx, dy);
end;
if x2 < x1 then
begin
swap(x1, x2);
swap(y1, y2);
end;
gradient := dy / dx;
xend := round(x1);
yend := y1 + gradient * (xend - x1);
xgap := rfrac(x1 + 0.5);
xpxl1 := xend;
ypxl1 := floor(yend);
plot(xpxl1, ypxl1, rfrac(yend) * xgap);
plot(xpxl1, ypxl1 + 1, frac(yend) * xgap);
intery := yend + gradient;
xend := round(x2);
yend := y2 + gradient * (xend - x2);
xgap := frac(x2 + 0.5);
xpxl2 := xend;
ypxl2 := floor(yend);
plot(xpxl2, ypxl2, rfrac(yend) * xgap);
plot(xpxl2, ypxl2 + 1, frac(yend) * xgap);
for x := round(xpxl1) + 1 to round(xpxl2) - 1 do
begin
plot(x, floor(intery), rfrac(intery));
plot(x, floor(intery) + 1, frac(intery));
intery := intery + gradient;
end;
end;
procedure TMainForm.DrawFrame;
procedure Ellipse(X,Y,A,B: integer; Angle: single);
var
I,S,C,H2,K1,K2,R: single;
X1,X2,Y1,Y2,X3,Y3,X4,Y4,YY: integer;
begin
with FrameBox.Canvas do
begin
I:=(180-Angle)*PI/180;
S:=Sin(I);
C:=Cos(I);
H2:=Sqr(A*S)+Sqr(B*C);
K1:=S*C*(Sqr(A)-Sqr(B))/H2;
K2:=A*B/H2;
YY:=0;
while Sqr(YY)<=H2 do
begin
R:=K2*Sqrt(H2-Sqr(YY));
X1:=Round(K1*YY+R);
X2:=Round(K1*YY-R);
if YY=0 then
begin
Pixels[X+X1,Y+YY]:=Pen.Color;
Pixels[X-X1,Y-YY]:=Pen.Color;
end
else
begin
MoveTo(X+X1,Y+YY);
LineTo(X+X3,Y+YY-1);
MoveTo(X+X2,Y+YY);
LineTo(X+X4,Y+YY-1);
MoveTo(X-X1,Y-YY);
LineTo(X-X3,Y-YY+1);
MoveTo(X-X2,Y-YY);
LineTo(X-X4,Y-YY+1);
end;
X3:=X1;
X4:=X2;
Inc(YY);
end;
H2:=Int(1.99*(YY-Sqrt(H2)));
MoveTo(X+X3,Y+YY-1);
LineTo(X+X3-Round(R),Y+YY-Round(H2));
LineTo(X+X4,Y+YY-1);
MoveTo(X-X3,Y-YY+1);
LineTo(X-X3+Round(R),Y-YY+Round(H2));
LineTo(X-X4,Y-YY+1);
end;
end;
begin
if GreenStyle = psSolid then
begin
FrameBox.Canvas.Pen.Style := psDot;
FrameBox.Canvas.Pen.Color := ColorBox1.Selected;
end
else
begin
FrameBox.Canvas.Pen.Style := psSolid;
FrameBox.Canvas.Pen.Color := ColorBox2.Selected;
end;
GreenStyle := FrameBox.Canvas.Pen.Style;
p1 := Point(x,y);
p2 := Point(x + Round(seSizeX.Value*Cos(a/180*Pi)),y + Round(seSizeX.Value*sin(a/180*Pi)));
p3 := Point(x - Round(seSizeY.Value*Sin(a/180*Pi)),y + Round(seSizeY.Value*Cos(a/180*Pi)));
p4 := Point(x + Round(seSizeX.Value*Cos(a/180*Pi)) - Round(seSizeY.Value*Sin(a/180*Pi))
,y + Round(seSizeX.Value*sin(a/180*Pi) + Round(seSizeY.Value*Cos(a/180*Pi))));
FrameBox.Canvas.Pen.Width := 1;
if chkHex.Checked then
Ellipse(
Round((p1.X + p4.X) * Scale / 2),
Round((p1.Y + p4.Y) * Scale / 2),
Round(max(seSizeX.Value, seSizeY.Value) * Scale/2 ),
Round(max(seSizeX.Value, seSizeY.Value) * Scale/2 ),
a
);
FrameBox.Canvas.Polyline([Zm(p1),Zm(p2),Zm(p4),Zm(p3),Zm(p1)]);
FrameBox.Canvas.Pen.Width := 3;
FrameBox.Canvas.Polyline([Zm(p1),Zm(p2)]);
{
DrawAntialisedLine(FrameBox.Canvas, Zm(p1).X, Zm(p1).y, Zm(p2).X, Zm(p2).y, FrameBox.Canvas.Pen.Color);
DrawAntialisedLine(FrameBox.Canvas, Zm(p4).X, Zm(p4).y, Zm(p2).X, Zm(p2).y, FrameBox.Canvas.Pen.Color);
DrawAntialisedLine(FrameBox.Canvas, Zm(p3).X, Zm(p3).y, Zm(p4).X, Zm(p4).y, FrameBox.Canvas.Pen.Color);
DrawAntialisedLine(FrameBox.Canvas, Zm(p1).X, Zm(p1).y, Zm(p3).X, Zm(p3).y, FrameBox.Canvas.Pen.Color);
}
p11.X := p1.X + Round(seFrameX.Value*Cos(a/180*Pi) - (seFrameY.Value*Sin(a/180*Pi)));
p11.Y := p1.Y + Round(seFrameX.Value*Sin(a/180*Pi) + (seFrameY.Value*Cos(a/180*Pi)));
p12 := Point(p11.X + Round((seSizeX.Value - 2*seFrameX.Value)*Cos(a/180*Pi))
,p11.Y + Round((seSizeX.Value - 2*seFrameX.Value)*sin(a/180*Pi)));
p13 := Point(p11.X - Round((seSizeY.Value - 2*seFrameY.Value ) *Sin(a/180*Pi))
,p11.Y + Round((seSizeY.Value - 2*seFrameY.Value )*Cos(a/180*Pi)));
p14 := Point(p11.X + Round((seSizeX.Value - 2*seFrameX.Value)*Cos(a/180*Pi)) - Round((seSizeY.Value - 2*seFrameY.Value)*Sin(a/180*Pi))
,p11.Y + Round((seSizeX.Value - 2*seFrameX.Value)*sin(a/180*Pi) + Round((seSizeY.Value - 2*seFrameY.Value)*Cos(a/180*Pi))));
if (p1.X<>p11.X) or (p2.X<>p12.X)or (p3.X<>p13.X)or (p4.X<>p14.X)
or (p1.y<>p11.y) or (p2.y<>p12.y)or (p3.y<>p13.y)or (p4.y<>p14.y)
then
FrameBox.Canvas.Polyline([Zm(p11),Zm(p12),Zm(p14),Zm(p13),Zm(p11)]);
if Timer1.Interval = 512 then
if imgPreview.Visible and
(FOldCorned <> sgCards.Rows[sgCards.Row].CommaText + ','+seSizeX.Text + ','+seSizeY.Text+','+seShift.Text)
then
begin
FOldCorned:= sgCards.Rows[sgCards.Row].CommaText+ ','+seSizeX.Text + ','+seSizeY.Text+','+seShift.Text;
DemoCard(StrToIntDef(sgCards.Cells[1, sgCards.Row],0),
StrToIntDef(sgCards.Cells[2, sgCards.Row],0),0,
StrToFloatDef(sgCards.Cells[3, sgCards.Row],0),10);
imgPreview.Picture.Bitmap.Width := imgPreview.Width;
imgPreview.Picture.Bitmap.Height := imgPreview.Height;
imgPreview.Picture.Bitmap.Canvas.BrushCopy(
Rect(0,0,imgPreview.Width div 2,imgPreview.Height div 2),
img1.Picture.Bitmap,
Rect(0,0,imgPreview.Width div 2,imgPreview.Height div 2),-1);
imgPreview.Picture.Bitmap.Canvas.BrushCopy(
Rect(imgPreview.Width div 2 + 1,0,imgPreview.Width,imgPreview.Height div 2),
img1.Picture.Bitmap,
Rect(img1.Width-imgPreview.Width div 2,0,img1.Width,imgPreview.Height div 2),-1);
imgPreview.Picture.Bitmap.Canvas.BrushCopy(
Rect(0,imgPreview.Height div 2+1,imgPreview.Width div 2,imgPreview.Height),
img1.Picture.Bitmap,
Rect(0,img1.Height-imgPreview.Height div 2,imgPreview.Width div 2,Img1.height),-1);
imgPreview.Picture.Bitmap.Canvas.BrushCopy(
Rect(imgPreview.Width div 2 + 1,imgPreview.Height div 2+1,imgPreview.Width,imgPreview.Height),
img1.Picture.Bitmap,
Rect(img1.Width-imgPreview.Width div 2,img1.Height-imgPreview.Height div 2,Img1.Width,Img1.height),-1);
// imgPreview.Invalidate;
end;
end;
procedure TMainForm.Timer1Timer(Sender: TObject);
var
i:integer;
Button: TTBButton;
Btn:TToolButton;
Tmr:integer;
begin
Tmr:=512;
// Timer1.Enabled:=True;
if {pcMain.ActivePageIndex = 0) and}not Shape2.Visible then
begin
DrawFrame(StrToIntDef(sgCards.Cells[1, sgCards.Row],0),
StrToIntDef(sgCards.Cells[2, sgCards.Row],0),
StrToFloatDef(sgCards.Cells[3, sgCards.Row],0));
if Sender = nil then FrameBox.Repaint;
end;
if seDPI.Value > 0 then
lblDPI.Caption := FormatFloat('0.0', 25.4 / seDPI.Value * seSizeX.Value)
+'/' + FormatFloat('0.0', 25.4 / seDPI.Value * seSizeY.value )
+^M + FormatFloat('0.0', 25.4 / seDPI.Value * (seBorder.Value*2 + seSizeX.Value * seCountX.Value + seCountX.Value -1 + seInterval.Value * (seCountX.Value -1)))
+'/' + FormatFloat('0.0', 25.4 / seDPI.Value *(seBorder.Value*2 + seSizeY.Value * seCountY.Value + seCountY.Value -1 + seInterval.Value * (seCountY.Value -1)))
;
if (Sender <> nil) and (GetAsyncKeystate(VK_LBUTTON) shr 31=1) then
for I := 0 to ComponentCount - 1 do
if Components[i] is TToolButton then
begin
Btn := TToolButton(Components[i]);
if Btn.Action <> Nil then
if (Btn.Action as TAction).Category='Move' then
begin
if TToolBar(Btn.Parent).Perform(TB_GETBUTTON, Btn.Index, Longint(@Button)) <> 0 then
begin
if (Button.fsState = 6) then
begin
Btn.Action.Execute;
if Timer1.Interval > 8 then
Tmr := Timer1.Interval div 2;
end;
end;
end;
end;
if Timer1.Interval<>Tmr then
Timer1.Interval:=Tmr;
end;
procedure TMainForm.Action1Update(Sender: TObject);
begin
TAction(Sender).Enabled := (pcMain.ActivePage <> tsResult)
and Timer1.Enabled;
{
GroupBox1.Enabled := (pcMain.Active <> );
GroupBox2.Enabled := (pcMain.ActivePageIndex = 0);
}
sbFrameColor.Enabled := (pcMain.ActivePageIndex = 0);
Label1.Enabled := not chbMirror.Checked;
end;
procedure TMainForm.Action1Execute(Sender: TObject);
begin
sgCards.Cells[1, sgCards.Row] := IntToStr(
StrToIntDef(sgCards.Cells[1, sgCards.Row],0) - Stepx[TrackBar2.Position]
);
CalcCenter;
Timer1Timer(nil)
end;
procedure TMainForm.Action2Execute(Sender: TObject);
begin
sgCards.Cells[1, sgCards.Row] := IntToStr(
StrToIntDef(sgCards.Cells[1, sgCards.Row],0) + Stepx[TrackBar2.Position]
);
CalcCenter;
Timer1Timer(nil)
end;
procedure TMainForm.Action3Execute(Sender: TObject);
begin
sgCards.Cells[2, sgCards.Row] := IntToStr(
StrToIntDef(sgCards.Cells[2, sgCards.Row],0) - Stepx[TrackBar2.Position]
);
CalcCenter;
Timer1Timer(nil)
end;
procedure TMainForm.Action4Execute(Sender: TObject);
begin
sgCards.Cells[2, sgCards.Row] := IntToStr(
StrToIntDef(sgCards.Cells[2, sgCards.Row],0) + Stepx[TrackBar2.Position]
);
CalcCenter;
Timer1Timer(nil)
end;
procedure TMainForm.Action5Execute(Sender: TObject);
var a:double;
begin
a := StrToFloatDef(sgCards.Cells[3, sgCards.Row],0) - Stepa[TrackBar1.Position];
while a>360 do a:=a-360;
while a<-360 do a:=a+360;
sgCards.Cells[3, sgCards.Row] := FloatToStr(a);
if cbAnchor.ItemIndex=1 then
CenterAxis(a);
Timer1Timer(nil)
end;
procedure TMainForm.Action6Execute(Sender: TObject);
var a:double;
begin
a := StrToFloatDef(sgCards.Cells[3, sgCards.Row],0) + Stepa[TrackBar1.Position];
while a>360 do a:=a-360;
while a<-360 do a:=a+360;
sgCards.Cells[3, sgCards.Row] := FloatToStr(a);
if cbAnchor.ItemIndex=1 then
CenterAxis(A);
Timer1Timer(nil)
end;
procedure TMainForm.sgCardsClick(Sender: TObject);
var p0,p1,p2,p3,p4:TPoint;
a:double;
begin
// ScrollBox1.HorzScrollBar.Position := round(StrToIntDef(sgCards.Cells[1, sgCards.Row],0)*Scale)-30;
// ScrollBox1.VertScrollBar.Position := round(StrToIntDef(sgCards.Cells[2, sgCards.Row],0)*Scale)-30;
p1.X := StrToIntDef(sgCards.Cells[1, sgCards.Row],0);
p1.Y := StrToIntDef(sgCards.Cells[2, sgCards.Row],0);
a := StrToFloatDef(sgCards.Cells[3, sgCards.Row],0);
p2 := Point(p1.x + Round(seSizeX.Value*Cos(a/180*Pi)),
p1.y + Round(seSizeX.Value*sin(a/180*Pi)));
p3 := Point(p1.x - Round(seSizeY.Value*Sin(a/180*Pi)),
p1.y + Round(seSizeY.Value*Cos(a/180*Pi)));
p4 := Point(p1.x + Round(seSizeX.Value*Cos(a/180*Pi)) - Round(seSizeY.Value*Sin(a/180*Pi))
,p1.y + Round(seSizeX.Value*sin(a/180*Pi) + Round(seSizeY.Value*Cos(a/180*Pi))));
p0.X := MinIntValue([p1.x,p2.x,p3.x,p4.X]);
p0.Y := MinIntValue([p1.y,p2.y,p3.y,p4.y]);
ScrollBox1.HorzScrollBar.Position := round(p0.X *Scale)-30;
ScrollBox1.VertScrollBar.Position := round(p0.Y *Scale)-30;
pcMainChange(nil);
FrameBox.Repaint;
end;
procedure TMainForm.Grid(png: tpngobject;CountX,CountY:integer);
var i,j:integer;
begin
png.canvas.Rectangle(1,1,png.Width-1, png.Height-1);
for j := 1 to CountY do
png.canvas.Rectangle(1, seBorder.Value +1+ (seSizeY.Value + 1 + seInterval.Value) * (j-1),
png.Width-1, seBorder.Value +1+ seSizeY.Value + (seSizeY.Value + 1 + seInterval.Value) * (j-1));
for i := 1 to CountX do
begin
png.canvas.Rectangle(
seBorder.Value +1 + (seSizeX.Value + 1 + seInterval.Value) * (i-1), 1,
seBorder.Value +1+ seSizeX.Value + (seSizeX.Value + 1 + seInterval.Value) * (i-1),png.Height-1);
for j := 1 to CountY do
png.canvas.Rectangle(
seBorder.Value +1 + (seSizeX.Value + 1 + seInterval.Value) * (i-1),
seBorder.Value +1+ (seSizeY.Value + 1 + seInterval.Value) * (j-1),
seBorder.Value +1+ seSizeX.Value + (seSizeX.Value + 1 + seInterval.Value) * (i-1),
seBorder.Value +1+ seSizeY.Value + (seSizeY.Value + 1 + seInterval.Value) * (j-1));
end;
end;
procedure TMainForm.pcMainChange(Sender: TObject);
var
png: tpngobject;
var i:integer;
begin
Timer1.Enabled := pcMain.ActivePage <> tsResult;
if pcMain.ActivePage = tsResult then
begin
png := tpngobject.createblank(COLOR_RGB, 8,
seBorder.Value*2 + seSizeX.Value * seCountX.Value + seCountX.Value -1 + seInterval.Value * (seCountX.Value -1),
seBorder.Value*2 + seSizeY.Value * seCountY.Value + seCountY.Value -1 + seInterval.Value * (seCountY.Value -1));
// png.TransparentColor := clMaroon;
png.canvas.brush.Style := bsSolid;
if chbCuttingLine.Checked then
png.Canvas.Brush.Color := clWhite
else
png.Canvas.Brush.Color := shFrameColor.pen.color;
png.Canvas.FillRect(Rect(0, 0, png.width, png.height));
png.canvas.pen.color := clBlack;
png.canvas.pen.Width := 3;
png.Canvas.Brush.Style := bsClear;
if seInterval.Value = 0 then
begin
if chbCuttingLine.Checked then
grid(png,seCountX.Value,seCountY.Value);
png.canvas.pen.color := clWhite;
end;
png.canvas.pen.Width := 1;
if chbCuttingLine.Checked then
grid(png,seCountX.Value,seCountY.Value);
for i:= 1 to sgCards.RowCount-1 do
DrawCard(StrToIntDef(sgCards.Cells[1, i],0),
StrToIntDef(sgCards.Cells[2, i],0),
i,
StrToFloatDef(sgCards.Cells[3, i],0), png);
imgResult.Width := png.Width;
imgResult.Height := png.Height;
imgResult.Picture.Graphic := png;
imgResult.Invalidate;
end;
if pcMain.ActivePage = tsSelected then
begin
DemoCard(StrToIntDef(sgCards.Cells[1, sgCards.Row],0),
StrToIntDef(sgCards.Cells[2, sgCards.Row],0),0,
StrToFloatDef(sgCards.Cells[3, sgCards.Row],0),40);
end;
// img2.Visible := pcMain.ActivePage = tsSelected;
end;
Type
T2DFace = Array[0..2] Of TPoint;
procedure TMainForm.DrawCard(x, y, i: integer; a: double; png:TPNGObject);
var OrgPntArray : T2DFace;
r3,r4,BufRect:TRect;
dx,dy:integer;
bmp:TBitmap;
ii,z:Integer;
begin
p1 := Point(x,y);
p2 := Point(x + Round(seSizeX.Value*Cos(a/180*Pi)),y + Round(seSizeX.Value*sin(a/180*Pi)));
p3 := Point(x - Round(seSizeY.Value*Sin(a/180*Pi)),y + Round(seSizeY.Value*Cos(a/180*Pi)));
p4 := Point(x + Round(seSizeX.Value*Cos(a/180*Pi)) - Round(seSizeY.Value*Sin(a/180*Pi))
,y + Round(seSizeX.Value*sin(a/180*Pi) + Round(seSizeY.Value*Cos(a/180*Pi))));
BufRect := Rect(Min(Min(p1.X,p2.X),Min(p3.X,p4.X)),
Min(Min(p1.Y,p2.Y),Min(p3.Y,p4.Y)),
Max(Max(p1.X,p2.x),Max(p3.X,p4.x)),
Max(Max(p1.Y,p2.Y),Max(p3.Y,p4.Y)));
DemoCard(x,y,0,a);
p1 := Point(1+seBorder.Value + (seSizeX.Value+1+seInterval.Value) * ((i-1) mod seCountX.Value) ,
1+seBorder.Value + (seSizeY.Value+1+seInterval.Value) * ((i-1) div seCountX.Value));
p2 := Point(p1.X + seSizeX.Value, p1.Y + seSizeY.Value);
png.Canvas.CopyRect(
Rect(p1.X+1,p1.Y+1, p2.X-1,p2.y-1),
img1.Picture.Bitmap.Canvas,
Rect(0,0,seSizeX.Value-1 ,seSizey.Value-1)
);
if chbRoundRect.Checked and not chbMirror.Checked then
begin
// imgFrame.Canvas.Pen.Width := 1;
png.Canvas.Pen.Color := shFrameColor.pen.color;
png.Canvas.Brush.Color := shFrameColor.pen.color;
png.Canvas.Pen.Style := psSolid;
png.Canvas.Brush.Style := bsSolid;
png.Canvas.Rectangle(Rect(p1.X,p1.Y, p2.X-seFrameX.Value,p1.y+seFrameY.Value));
png.Canvas.Rectangle(Rect(p1.X,p1.Y, p1.X+seFrameX.Value,p2.y));
png.Canvas.Rectangle(Rect(p2.X,p2.Y, p2.X-seFrameX.Value,p1.y));
png.Canvas.Rectangle(Rect(p2.X,p2.Y, p1.X,p2.y-seFrameY.Value));
end;
if chbRoundRect.Checked then
begin
png.Canvas.Pen.Width := Min(seFrameX.Value, seFrameY.Value);
png.Canvas.Pen.Color := shFrameColor.pen.color;
png.Canvas.Pen.Style := psSolid;
png.Canvas.Brush.Style := bsClear;
if seFrameX.Value > seFrameY.Value then
dx := (seFrameX.Value - seFrameY.Value) div 2
else
dx := 0;
if seFrameY.Value > seFrameX.Value then
dy := (seFrameY.Value - seFrameX.Value) div 2
else
dy := 0;
png.Canvas.Rectangle(dx+p1.X+seFrameX.Value div 2,
dy+p1.Y+seFrameY.Value div 2,
p2.X-dx-seFrameX.Value div 2,
p2.y-dy-seFrameY.Value div 2);
png.Canvas.RoundRect(dx+p1.X+seFrameX.Value div 2,
dy+p1.Y+seFrameY.Value div 2,
p2.X-dx-seFrameX.Value div 2,
p2.y-dy-seFrameY.Value div 2,
round(png.Canvas.Pen.Width*2.5),round(png.Canvas.Pen.Width*2.5));
png.Canvas.Brush.Style := bsSolid;
end;
if chbMirror.Checked then
begin
z := seInterval.Value div 2;
for ii := 0 to z do
begin
r3:=Rect(p1.X-seInterval.Value div 2,
p1.Y-ii+0,
p2.X+seInterval.Value div 2,
p1.Y-ii+1);
r4:=Rect(p1.X-seInterval.Value div 2,
p1.Y+ii+1,
p2.X+seInterval.Value div 2,
p1.Y+ii+2);
png.Canvas.CopyRect(r3,png.Canvas,r4);
r3:=Rect(p1.X-seInterval.Value div 2,
p2.Y+ii-1,
p2.X+seInterval.Value div 2,
p2.Y+ii);
r4:=Rect(p1.X-seInterval.Value div 2,
p2.Y-ii-2,
p2.X+seInterval.Value div 2,
p2.Y-ii-1);
png.Canvas.CopyRect(r3,png.Canvas,r4);
end;
for ii := 0 to z do
begin
r3:=Rect(p1.X-ii,
p1.Y-seInterval.Value div 2,
p1.X-ii-1 ,
p2.Y+seInterval.Value div 2);
r4:=Rect(p1.X+ii+1,
p1.Y-seInterval.Value div 2,
p1.X+ii+2,
p2.Y+seInterval.Value div 2);
png.Canvas.CopyRect(r3,png.Canvas,r4);
r3:=Rect(p2.X+ii-1,
p1.Y-seInterval.Value div 2,
p2.X+ii-0 ,
p2.Y+seInterval.Value div 2);
r4:=Rect(p2.X-ii-3,
p1.Y-seInterval.Value div 2,
p2.X-ii-2,
p2.Y+seInterval.Value div 2);
png.Canvas.CopyRect(r3,png.Canvas,r4);
end;
end;
png.Canvas.Pen.Width := 1;
png.Canvas.Brush.Style := bsClear;
if chbCuttingLine.Checked then
begin
// png.Canvas.Rectangle(p1.X,p1.Y, p2.X,p2.y);
png.Canvas.Pen.Color := $FFFFFF;
png.Canvas.Pen.Style := psSolid;
png.Canvas.MoveTo(p1.X+50,p1.Y);
png.Canvas.LineTo(p1.X,p1.Y);
png.Canvas.LineTo(p1.X,p1.Y+50);