-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathPaintForm.pas
More file actions
4402 lines (3650 loc) · 110 KB
/
PaintForm.pas
File metadata and controls
4402 lines (3650 loc) · 110 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 PaintForm;
{$SCOPEDENUMS ON}
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.BaseImageCollection,
Vcl.ImageCollection, System.ImageList, Vcl.ImgList, Vcl.VirtualImageList,
Vcl.ComCtrls, Vcl.ToolWin, Vcl.ActnMan, Vcl.ActnCtrls, Vcl.ActnMenus,
Vcl.TitleBarCtrls, Vcl.PlatformDefaultStyleActnCtrls, System.Actions,
Vcl.ActnList, Vcl.StdActns, Vcl.ExtActns, Vcl.StdCtrls, Vcl.ExtCtrls,
Vcl.Buttons, Vcl.Imaging.pngimage, Cod.Visual.Button, Cod.VarHelpers,
Cod.Files, Types, Cod.Graphics, Cod.Math, MenuForm, FullscreenForm,
Thumbnailform, Vcl.ExtDlgs, SaveForm, UITypes, Cod.ColorUtils, Cod.StringUtils,
Cod.Types, Cod.SysUtils, Vcl.Clipbrd, Cod.SysExtras, Cod.ByteUtils,
Imaging.jpeg, Imaging.GIFImg, IniFiles, IOUtils, PropertiesForm,
Vcl.Menus, Math, Cod.Dialogs.PrintDlg, ShellAPI, Cod.FileDrop;
type
TToolType = (None, Select, Pencil, Fill, Text, Eraser, ColorPick, Zoom, Brush, Shape);
TSelectionMode = (None, Creating, Exists);
TSelectionType = (Rectangular, FreeForm);
TCloseMode = (Succeed, Fail, Escape);
TImageType = (Bitmap, PNG, Jpeg, Gif);
TCornerPos = (TopLeft, TopRight, BottomLeft, BottomRight);
TUnit = (Pixel, Cm, Inch);
TMsPaint = class(TForm)
ActionManager1: TActionManager;
Action1: TAction;
TitleBarPanel1: TTitleBarPanel;
Action2: TAction;
Action3: TAction;
Action4: TAction;
VirtualImageList16: TVirtualImageList;
ImageCollection1: TImageCollection;
ToolBar16: TToolBar;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
ToolButton3: TToolButton;
ToolButton5: TToolButton;
ToolButton6: TToolButton;
Panel1: TPanel;
Panel2: TPanel;
StatusBar: TPanel;
PaintBox2: TPaintBox;
PaintBox3: TPaintBox;
PaintBox4: TPaintBox;
PaintBox5: TPaintBox;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
Label13: TLabel;
Label14: TLabel;
Label15: TLabel;
CButton1: CButton;
Panel4: TPanel;
Page_Home: TPanel;
Panel5: TPanel;
Panel11: TPanel;
Panel12: TPanel;
Panel13: TPanel;
Panel14: TPanel;
SpeedButton9: TSpeedButton;
SpeedButton11: TSpeedButton;
Page_View: TPanel;
Label16: TLabel;
Label17: TLabel;
Panel6: TPanel;
SpeedButton2: TSpeedButton;
SpeedButton1: TSpeedButton;
SpeedButton5: TSpeedButton;
Panel7: TPanel;
Panel8: TPanel;
SpeedButton3: TSpeedButton;
SpeedButton4: TSpeedButton;
Panel9: TPanel;
Panel10: TPanel;
Panel15: TPanel;
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
CheckBox3: TCheckBox;
Panel16: TPanel;
SpeedButton10: TSpeedButton;
SpeedButton12: TSpeedButton;
Label18: TLabel;
Panel17: TPanel;
Panel18: TPanel;
Panel19: TPanel;
SpeedButton13: TSpeedButton;
SpeedButton14: TSpeedButton;
Panel20: TPanel;
SpeedButton15: TSpeedButton;
SpeedButton16: TSpeedButton;
Label19: TLabel;
SpeedButton17: TSpeedButton;
Panel21: TPanel;
Panel22: TPanel;
Label20: TLabel;
Label21: TLabel;
Panel23: TPanel;
Panel24: TPanel;
Panel25: TPanel;
SpeedButton21: TSpeedButton;
SpeedButton22: TSpeedButton;
Label22: TLabel;
Panel26: TPanel;
SpeedButton19: TSpeedButton;
SpeedButton18: TSpeedButton;
SpeedButton20: TSpeedButton;
SpeedButton23: TSpeedButton;
SpeedButton24: TSpeedButton;
SpeedButton25: TSpeedButton;
Panel3: TPanel;
ScrollBox1: TScrollBox;
CanvasHolder: TPanel;
DrawBox: TPaintBox;
PaintBox7: TPaintBox;
PaintBox8: TPaintBox;
SavePictureDialog1: TSavePictureDialog;
CornerSize: TShape;
LeftSize: TShape;
TopSize: TShape;
DotsSize: TShape;
SizePreview: TTimer;
Title: TLabel;
PaintBox1: TPaintBox;
Page_Text: TPanel;
Label24: TLabel;
Label25: TLabel;
Panel30: TPanel;
Panel31: TPanel;
Panel32: TPanel;
SpeedButton29: TSpeedButton;
SpeedButton30: TSpeedButton;
Panel33: TPanel;
SpeedButton31: TSpeedButton;
SpeedButton32: TSpeedButton;
Panel34: TPanel;
Panel35: TPanel;
Font_List: TComboBox;
Font_Size: TComboBox;
Font_Bold: TSpeedButton;
Font_Italic: TSpeedButton;
Font_Underline: TSpeedButton;
Font_Striked: TSpeedButton;
CanvasUpdater: TTimer;
InvisibleEdit: TMemo;
OpenPictureDialog1: TOpenPictureDialog;
ImageList1: TImageList;
Text_View: TLabel;
Label23: TLabel;
Panel27: TPanel;
Panel28: TPanel;
Panel29: TPanel;
SpeedButton26: TSpeedButton;
ColorPicker: TPanel;
Panel37: TPanel;
SpeedButton27: TSpeedButton;
SpeedButton28: TSpeedButton;
Colors_Container: TPanel;
Panel42: TPanel;
SpeedButton8: TSpeedButton;
SpeedButton34: TSpeedButton;
SpeedButton35: TSpeedButton;
SpeedButton36: TSpeedButton;
SpeedButton37: TSpeedButton;
SpeedButton38: TSpeedButton;
SpeedButton39: TSpeedButton;
SpeedButton40: TSpeedButton;
SpeedButton41: TSpeedButton;
SpeedButton42: TSpeedButton;
Panel43: TPanel;
SpeedButton43: TSpeedButton;
SpeedButton44: TSpeedButton;
SpeedButton45: TSpeedButton;
SpeedButton46: TSpeedButton;
SpeedButton47: TSpeedButton;
SpeedButton48: TSpeedButton;
SpeedButton49: TSpeedButton;
SpeedButton50: TSpeedButton;
SpeedButton51: TSpeedButton;
SpeedButton52: TSpeedButton;
Panel44: TPanel;
SpeedButton53: TSpeedButton;
SpeedButton54: TSpeedButton;
SpeedButton55: TSpeedButton;
SpeedButton56: TSpeedButton;
SpeedButton57: TSpeedButton;
SpeedButton58: TSpeedButton;
SpeedButton59: TSpeedButton;
SpeedButton60: TSpeedButton;
SpeedButton61: TSpeedButton;
SpeedButton62: TSpeedButton;
SpeedButton63: TSpeedButton;
ColorDialog1: TColorDialog;
Label28: TLabel;
Label29: TLabel;
Panel36: TPanel;
Panel41: TPanel;
Panel46: TPanel;
SpeedButton66: TSpeedButton;
SpeedButton67: TSpeedButton;
Label30: TLabel;
Panel45: TPanel;
Panel47: TPanel;
CheckBox4: TCheckBox;
Panel48: TPanel;
Panel49: TPanel;
SpeedButton6: TSpeedButton;
SpeedButton7: TSpeedButton;
SpeedButton64: TSpeedButton;
SpeedButton65: TSpeedButton;
SpeedButton68: TSpeedButton;
SpeedButton69: TSpeedButton;
SpeedButton70: TSpeedButton;
SpeedButton71: TSpeedButton;
Panel50: TPanel;
SpeedButton72: TSpeedButton;
SpeedButton73: TSpeedButton;
Panel51: TPanel;
Panel52: TPanel;
SpeedButton74: TSpeedButton;
SpeedButton75: TSpeedButton;
SpeedButton76: TSpeedButton;
SpeedButton77: TSpeedButton;
SpeedButton78: TSpeedButton;
SpeedButton79: TSpeedButton;
SpeedButton80: TSpeedButton;
SpeedButton81: TSpeedButton;
SpeedButton82: TSpeedButton;
SpeedButton83: TSpeedButton;
Panel53: TPanel;
PaintBox9: TPaintBox;
TrackBar2: TTrackBar;
ActionCopy: TAction;
ActionCut: TAction;
ActionSelectAll: TAction;
ActionPasteClipboard: TAction;
ActionClipboardFile: TAction;
Panel54: TPanel;
SpeedButton84: TSpeedButton;
SpeedButton85: TSpeedButton;
Panel55: TPanel;
SpeedButton86: TSpeedButton;
Panel56: TPanel;
Panel57: TPanel;
SpeedButton87: TSpeedButton;
SpeedButton88: TSpeedButton;
SpeedButton89: TSpeedButton;
Panel58: TPanel;
SpeedButton90: TSpeedButton;
SpeedButton91: TSpeedButton;
SpeedButton92: TSpeedButton;
SpeedButton93: TSpeedButton;
SpeedButton94: TSpeedButton;
Panel59: TPanel;
SpeedButton95: TSpeedButton;
SpeedButton96: TSpeedButton;
SpeedButton97: TSpeedButton;
SpeedButton98: TSpeedButton;
BrushTick: TTimer;
SpeedButton99: TSpeedButton;
Panel60: TPanel;
PaintBox6: TPaintBox;
Label1: TLabel;
Label3: TLabel;
TrackBar1: TTrackBar;
CButton2: CButton;
CButton3: CButton;
CPrintDialog1: CPrintDialog;
ActionPrint: TAction;
PaintBox10: TPaintBox;
Page_Print: TPanel;
Label2: TLabel;
Label31: TLabel;
Panel62: TPanel;
SpeedButton100: TSpeedButton;
SpeedButton101: TSpeedButton;
SpeedButton102: TSpeedButton;
Panel63: TPanel;
Panel64: TPanel;
SpeedButton103: TSpeedButton;
Panel65: TPanel;
Panel66: TPanel;
SpeedButton105: TSpeedButton;
SpeedButton106: TSpeedButton;
Panel67: TPanel;
Label32: TLabel;
ImageList2: TImageList;
PopupMenu1: TPopupMenu;
Cut1: TMenuItem;
Copy1: TMenuItem;
Paste1: TMenuItem;
N1: TMenuItem;
Crop1: TMenuItem;
SelectAll1: TMenuItem;
Delete1: TMenuItem;
N2: TMenuItem;
Rotate1: TMenuItem;
Flip1: TMenuItem;
InvertColor1: TMenuItem;
RotateRight1: TMenuItem;
Rotateright901: TMenuItem;
Rotate1801: TMenuItem;
FlipHorizonta1: TMenuItem;
FlipVertical1: TMenuItem;
SpeedButton104: TSpeedButton;
ImageList3: TImageList;
AnimateKeys: TTimer;
Action5: TAction;
Label27: TLabel;
procedure FormCreate(Sender: TObject);
procedure PaintBox2Paint(Sender: TObject);
procedure ClickPB(Sender: TObject);
procedure ExpandFile(Sender: TObject);
procedure PaintBox5Paint(Sender: TObject);
procedure ScrollBox1MouseWheel(Sender: TObject; Shift: TShiftState;
WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
procedure DrawBoxPaint(Sender: TObject);
procedure DrawBoxMouseLeave(Sender: TObject);
procedure DrawBoxMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure TrackBar1Change(Sender: TObject);
procedure SelectTool(Sender: TObject);
procedure DrawBoxMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure DrawBoxMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure SpeedButton6Click(Sender: TObject);
procedure SpeedButton7Click(Sender: TObject);
procedure SpeedButton5Click(Sender: TObject);
procedure CheckBox3Click(Sender: TObject);
procedure CheckBox2Click(Sender: TObject);
procedure ScrollBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure CanvasHolderMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure PaintBox7Paint(Sender: TObject);
procedure CheckBox1Click(Sender: TObject);
procedure SpeedButton3Click(Sender: TObject);
procedure SpeedButton4Click(Sender: TObject);
procedure CButton2Click(Sender: TObject);
procedure CButton3Click(Sender: TObject);
procedure SaveActionExecute(Sender: TObject);
procedure Action2Execute(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure InitiateResize(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FinishResize(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure SizePreviewTimer(Sender: TObject);
procedure FormKeyPress(Sender: TObject; var Key: Char);
procedure Font_ListDrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
procedure InvisibleEditChange(Sender: TObject);
procedure Font_SizeExit(Sender: TObject);
procedure Font_SizeChange(Sender: TObject);
procedure Font_BoldClick(Sender: TObject);
procedure InvisibleEditKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure InvisibleEditKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure CanvasUpdaterTimer(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure SpeedButton15Click(Sender: TObject);
procedure Action3Execute(Sender: TObject);
procedure Action4Execute(Sender: TObject);
procedure ColorSelect(Sender: TObject);
procedure SpeedButton63Click(Sender: TObject);
procedure SpeedButton66Click(Sender: TObject);
procedure SpeedButton29Click(Sender: TObject);
procedure SpeedButton31Click(Sender: TObject);
procedure SpeedButton32Click(Sender: TObject);
procedure CButton1Click(Sender: TObject);
procedure CheckBox4Click(Sender: TObject);
procedure ShapeSelect(Sender: TObject);
procedure ButtonPressRepaint(Sender: TObject);
procedure SpeedButton26Click(Sender: TObject);
procedure Z(Sender: TObject);
procedure PaintBox9Paint(Sender: TObject);
procedure CopyCut(Sender: TObject);
procedure ActionCopyExecute(Sender: TObject);
procedure ActionCutExecute(Sender: TObject);
procedure ActionSelectAllExecute(Sender: TObject);
procedure ActionPasteClipboardExecute(Sender: TObject);
procedure SpeedButton9Click(Sender: TObject);
procedure ActionClipboardFileExecute(Sender: TObject);
procedure SpeedButton84Click(Sender: TObject);
procedure SpeedButton85Click(Sender: TObject);
procedure HideMiniPanel(Sender: TObject);
procedure SpeedButton11Click(Sender: TObject);
procedure SpeedButton88Click(Sender: TObject);
procedure SpeedButton89Click(Sender: TObject);
procedure SpeedButton87Click(Sender: TObject);
procedure SpeedButton86Click(Sender: TObject);
procedure SpeedButton14Click(Sender: TObject);
procedure SpeedButton16Click(Sender: TObject);
procedure SpeedButton90Click(Sender: TObject);
procedure MoveOnDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure SpeedButton22Click(Sender: TObject);
procedure SelectBrush(Sender: TObject);
procedure BrushTickTimer(Sender: TObject);
procedure ActionPrintExecute(Sender: TObject);
procedure PrinterPrint(Sender: TObject);
procedure SpeedButton103Click(Sender: TObject);
procedure SpeedButton17Click(Sender: TObject);
procedure InvertColor1Click(Sender: TObject);
procedure PopupMenu1Popup(Sender: TObject);
procedure RotateRight1Click(Sender: TObject);
procedure Rotateright901Click(Sender: TObject);
procedure Rotate1801Click(Sender: TObject);
procedure FlipVertical1Click(Sender: TObject);
procedure FlipHorizonta1Click(Sender: TObject);
procedure TrackBar1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure AnimateKeysTimer(Sender: TObject);
procedure ScrollBox1Click(Sender: TObject);
procedure CanvasHolderClick(Sender: TObject);
procedure Action5Execute(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
procedure SelectPanel(Index: integer);
protected
{ Protected declarations }
procedure WMDropFiles(var Msg: TWMDropFiles); message WM_DROPFILES;
public
{ Public declarations }
procedure SaveFile;
procedure LoadFile;
procedure UpdateFileSize;
function SaveFileOptional(SaveAs: boolean = false): boolean; // returns if SUCCEEDED
procedure LoadFileOptional;
// Painting
function GetSizeRect(ID: integer; Inflate: integer = 0): TRect;
procedure DrawShapeCanvas(Canvas: TCanvas; ARect: TRect; Index: integer; Finale: boolean = false);
procedure PastePicture(Picture: TBitMap; Location: TPoint);
procedure DrawStolen(Canvas: TCanvas; ARect: TRect);
// Scale
function ScaleToCanvas(P: TPoint): TPoint;
// File
procedure NewDocument;
// UI
procedure ClearAllSelect(Exception: TSpeedButton);
procedure LoadColorIcons(Search: TPanel);
function GetColorTag(Tag: integer): TColor;
procedure AddColorHistory(AColor: TColor);
procedure HideMiniPanels;
// Data
function GetUnit: string;
function ConvertUnit(Value: integer): string;
// Tool
procedure ChangeTool(ATool: TToolType);
procedure ToggleTextPage(Enabled: boolean);
// Cornet
function GetCorner(ARect: TRect; APoint: TPoint): TCornerPos;
function GetPoint(ARect: TRect; Corner: TCornerPos): TPoint;
// Font
procedure ApplyFontStyling(Font: TFont);
// Scale
function ReverseScale: real;
function IsZoomExtend: boolean;
// History
procedure CacheNew;
procedure ResetHistory;
procedure DoUndo;
procedure DoRedo;
procedure LoadHistory(Position: integer);
// Selection
function MouseOverSelection: boolean;
function SelectionSupportsMoving: boolean;
procedure FinishSelection(CloseMode: TCloseMode = TCloseMode.Succeed);
procedure StealSelectionZone;
procedure FillSelectionZone;
procedure CalculateFreeForm;
procedure FinaliseFreeForm;
procedure TranslateScale;
procedure FlipSelectionSize;
procedure ApplyTransparent;
function GetTopmostPoint: TPoint;
// Printing
procedure BeginPrint;
procedure TogglePrintPreview(Enter: boolean);
// Settings
procedure UserSettings(Load: boolean);
// Update
procedure UpdateCanvasDrawn;
procedure UpdateRectSize;
procedure UpdateColorIcons;
procedure UpdateSizing;
procedure UpdateCanvas;
procedure UpdateRulers;
end;
// Dialogs
function CheckSavedCanProceed: boolean;
// Utils
function GetCanvasDPI(Canvas: TCanvas): Integer;
procedure RotateBitmap90Degrees(var Bitmap: TBitmap);
procedure RotateBitmapNegative90Degrees(var Bitmap: TBitmap);
const
LINE_SPACING = 10;
MAX_UNDO = 50;
DEFAULT_WIDTH = 1030;
DEFAULT_HEIGHT = 552;
TRANSPARENT_COLOR = $002A414A;
var
MsPaint: TMsPaint;
DEFAULT_COLORS: array[1..20] of CRGB = (
(R:0; G:0; B:0),
(R:127; G:127; B:127),
(R:136; G:0; B:21),
(R:255; G:0; B:0),
(R:255; G:127; B:39),
(R:255; G:242; B:0),
(R:34; G:177; B:76),
(R:0; G:162; B:232),
(R:63; G:72; B:204),
(R:163; G:73; B:164),
(R:255; G:255; B:255),
(R:195; G:195; B:195),
(R:185; G:122; B:87),
(R:255; G:174; B:201),
(R:255; G:201; B:14),
(R:239; G:228; B:176),
(R:181; G:230; B:29),
(R:153; G:217; B:234),
(R:112; G:146; B:190),
(R:200; G:191; B:231)
);
// System
AppData: string;
RecentFiles: TStringList;
// Buttons
SelectedTop: integer = 1;
MenuOutline: TColor = clAppWorkSpace;
// File
FileName: string;
FileDisplayName: string = 'Untitled';
FileSaved: boolean;
ChangesUnsaved: boolean;
// Sizes
PenSize: integer = 1;
EraserSize: integer = 5;
ShapePen: integer = 4;
BrushSize: integer = 4;
FillShape: boolean;
EnableOutline: boolean;
Units: TUnit = TUnit.Pixel;
// Colors
PrimaryColor: TColor = clBlack;
SecondaryColor: TColor = clWhite;
ColorHistory: array[1..10] of TColor;
DrawColor: TColor;
// Image
Image: TBitMap;
ADPI: integer;
// History
History: TArray<TBitMap>;
DoPos: integer;
// Move
StolenZone: TBitMap;
TransparentSelection: boolean;
// Zoom
ZoomRect: TRect;
// Tools
Tool: TToolType = TToolType.Select;
// Move
KeyOffset: TPoint;
// Selection
SelectMode: TSelectionMode;
SelectionCanvas: TRect;
SelectionImage: TRect;
SelectionType: TSelectionType;
// FreeFormRect: TRect; uses SelectionCanvas and SelectionImage
FreeFormBorder: TArray<TArray<boolean>>;
FreeFormSelection: TArray<TArray<boolean>>;
FreeFormLines: TArray<TRect>;
FreeFormPoints: integer;
MoveOffsetCanvas: TPoint;
MoveOffsetImage: TPoint;
CornerStart: TCornerPos;
CornerEnd: TCornerPos;
DrawingPoints: TPoints;
PointIndex: integer = -1;
StartedMoving: boolean;
SizePoint: integer = -1;
ShapeID: integer;
// Brush
BrushID: integer = 0;
// Text Editor
DrawText: string;
// Canvas settings
Scale: real = 1;
MouseOnCanvas: boolean;
CanvasMouseDown: boolean;
DownButton: TMouseButton;
MouseOverSelectionWhenDown: boolean;
DownCanvas: TPoint;
DownImage: TPoint;
LastDownCanvas: TPoint;
LastDownImage: TPoint;
PositionCanvas: TPoint;
PositionImage: TPoint;
LastValidPointImage: TPoint;
implementation
{$R *.dfm}
function CheckSavedCanProceed: boolean;
begin
Result := true;
// No changes
if not ChangesUnsaved then
Exit;
Save := TSave.Create(Application);
try
Save.PrepareDialog(FileName);
case Save.ShowModal of
mrYes: if not MsPaint.SaveFileOptional() then // save
Result := false;
mrCancel: Result := false;
end;
finally
Save.Free;
end;
end;
function GetCanvasDPI(Canvas: TCanvas): Integer;
var
DC: HDC;
begin
DC := Canvas.Handle;
Result := GetDeviceCaps(DC, LOGPIXELSX); // or LOGPIXELSY, both axes have the same DPI
end;
procedure TMsPaint.FinishSelection(CloseMode: TCloseMode);
var
ADone: boolean;
begin
// No Selection
if SelectMode <> TSelectionMode.Exists then
Exit;
// Status
SelectMode := TSelectionMode.None;
ToggleTextPage(False);
Label8.Caption := '';
StartedMoving := false;
// Finish selection / text / shape, if there is one
case Tool of
TToolType.Select: begin
ADone := false;
case CloseMode of
TCloseMode.Succeed: ADone := true;
TCloseMode.Escape: begin
if false then
else
ADone := true;
end;
end;
// Done
if ADone then
DrawStolen(Image.Canvas, SelectionImage);
// Free
StolenZone.Free;
// Update Changed
UpdateCanvasDrawn;
end;
TToolType.Text: begin
InvisibleEdit.Width := 0;
if CloseMode = TCloseMode.Succeed then
with Image.Canvas do
begin
Brush.Color := SecondaryColor;
if SpeedButton67.Down then
Brush.Style := bsClear
else
Brush.Style := bsSolid;
ApplyFontStyling(Font);
TextRect(SelectionImage, DrawText, [tfWordBreak]);
// Update Changed
UpdateCanvasDrawn;
end;
end;
TToolType.Shape: begin
if CloseMode = TCloseMode.Succeed then
begin
Image.Canvas.Pen.Width := ShapePen;
DrawShapeCanvas(Image.Canvas, SelectionImage, ShapeID, true);
// Update Changed
UpdateCanvasDrawn;
end;
// Reset Values
DrawingPoints := [];
PointIndex := -1;
end;
end;
// Paint
UpdateCanvas;
end;
procedure TMsPaint.FlipHorizonta1Click(Sender: TObject);
begin
StolenZone.Canvas.StretchDraw(Rect(0, StolenZone.Height, StolenZone.Width, 0), StolenZone);
UpdateCanvas;
end;
procedure TMsPaint.FlipSelectionSize;
var
Previous: integer;
begin
// Selection
Previous := SelectionCanvas.Width;
SelectionCanvas.Width := SelectionCanvas.Height;
SelectionCanvas.Height := Previous;
// Image
Previous := SelectionImage.Width;
SelectionImage.Width := SelectionImage.Height;
SelectionImage.Height := Previous;
end;
procedure TMsPaint.FlipVertical1Click(Sender: TObject);
begin
StolenZone.Canvas.StretchDraw(Rect(StolenZone.Width, 0, 0, StolenZone.Height), StolenZone);
UpdateCanvas;
end;
procedure TMsPaint.FillSelectionZone;
var
I: Integer;
begin
with Image.Canvas do
if SelectionType = TSelectionType.Rectangular then
begin
Brush.Style := bsSolid;
Brush.Color := SecondaryColor;
FillRect(SelectionImage);
end
else
begin
Brush.Style := bsSolid;
Brush.Color := SecondaryColor;
for I := 0 to High(FreeFormLines) do
FillRect( FreeFormLines[I] );
end;
end;
procedure TMsPaint.FinaliseFreeForm;
var
DistX, DistY, ACount: integer;
APoint: TPoint;
I: Integer;
begin
if SelectionType = TSelectionType.FreeForm then
begin
// Finish shape
DistX := DownImage.X - LastValidPointImage.X;
DistY := DownImage.Y - LastValidPointImage.Y;
// Count
if abs(DistX) > abs(DistY) then
ACount := abs(DistX)
else
ACount := abs(DistY);
// Set pixels
if ACount > 0 then
for I := 0 to ACount do
begin
APoint.X := LastValidPointImage.X + trunc(I / ACount * DistX);
APoint.Y := LastValidPointImage.Y + trunc(I / ACount * DistY);
FreeFormBorder[APoint.X, APoint.Y] := true;
end;
end;
end;
procedure TMsPaint.FinishResize(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
AWidth, AHeight: integer;
PrevWidth, PrevHeight: integer;
ARect: TRect;
begin
// UI
CornerSize.Show;
LeftSize.Show;
TopSize.Show;
DotsSize.Hide;
// Canceled
if SizePreview.Enabled then
begin
// Finalise
SizePreview.Enabled := false;
PrevWidth := Image.Width;
PrevHeight := Image.Height;
AWidth := round((DotsSize.Width - 4) * ReverseScale);
AHeight := round((DotsSize.Height - 4) * ReverseScale);
if (AWidth > 0) and (AHeight > 0) then
begin
Image.SetSize(AWidth, AHeight);
// Fill Extended Zones
with Image.Canvas do
begin
Pen.Style := psClear;
Brush.Style := bsSolid;
Brush.Color := SecondaryColor;
ARect := Rect(PrevWidth, 0, AWidth, AHeight);
FillRect(ARect);
ARect := Rect(0, PrevHeight, AWidth, AHeight);
FillRect(ARect);
end;
end;
end;
// Update
UpdateSizing;
end;
procedure TMsPaint.Font_BoldClick(Sender: TObject);
begin
UpdateCanvas;
end;
procedure TMsPaint.Font_ListDrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var
AText: string;
begin
// Draw
with TComboBox(Control).Canvas do
begin
Brush.Color := TComboBox(Control).Color;
FillRect(Rect);
AText := TComboBox(Control).Items[Index];
Font.Color := clBlack;
Font.Name := AText;
Font.Size := 11;
DrawTextRect(TComboBox(Control).Canvas, Rect, AText, [TTextFlag.VerticalCenter]);
end;
end;
procedure TMsPaint.Font_SizeChange(Sender: TObject);
begin
UpdateCanvas;
end;
procedure TMsPaint.Font_SizeExit(Sender: TObject);
begin
try
strtoint(Font_Size.Text);
except
Font_Size.Text := DrawBox.Font.Size.ToString;
end;
end;
procedure TMsPaint.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
if ChangesUnsaved then
if not CheckSavedCanProceed then begin
CanClose := false;
Exit;
end;
// Settings
UserSettings(false);
// Position
FormPositionSettings(Self, AppData + 'Configuration.ini', false);
end;
procedure TMsPaint.FormCreate(Sender: TObject);
var
I: Integer;
S: string;
begin
// UI
SelectPanel(1);
// Prepare
NewDocument;
// Recent
RecentFiles := TStringList.Create;
// Reset History
ResetHistory;
AppData := GetPathInAppData('Paint', TAppDataType.Roaming, true);
// Update
UpdateSizing;