forked from dim-s/soulengine
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathNewSizeControl.pas
More file actions
3988 lines (3600 loc) · 108 KB
/
NewSizeControl.pas
File metadata and controls
3988 lines (3600 loc) · 108 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 SizeControl;
{$DEFINE SOULENGINE}
{$IFDEF FPC}
{$MODE Delphi}
{$warnings off}
{$DEFINE VER3U}
{$DEFINE VER3UP}
{$ENDIF}
(*
---------------------------------------------------------------------------
Component Name: TSizeCtrl
Module: SizeControl
Description: Enables both moving and resizing of controls at runtime.
Version: 8.2
Date: 03-JUN-2019
Author: Leu Zenin, kashaket@protonmail.com
Angus Johnson, angusj@myrealbox.com
Copyright: © 2019 Leu Zenin
{near 94.45% code is refactored}
--------------------------------------------------------------------------- *)
interface
{$R SIZECONTROL}
{$IFNDEF FPC}
{$WARN HIDDEN_VIRTUAL OFF}
{$IFDEF VER80}
{$DEFINE VER3D}
{$ENDIF}
{$IFDEF VER90}
{$DEFINE VER3D}
{$ENDIF}
{$IFDEF VER100}
{$DEFINE VER3D}
{$ENDIF}
{$IFNDEF VER80} {$IFNDEF VER90} {$DEFINE VER3U} {$ENDIF} {$ENDIF}
{$IFDEF VER3U} {$IFNDEF VER100} {$DEFINE VER3UP} {$ENDIF} {$ENDIF}
{$IFNDEF VER3UP} {$MESSAGE WARN 'AlphaTransparency is not supported under Delphi < 5'} {$ENDIF}
{$ENDIF}
uses
{$IFDEF FPC}LCLIntf, LCLType, LMessages,
{$ELSE} Windows, Messages,{$ENDIF} SysUtils, Classes,
Controls, Graphics,
Dialogs,
Menus, //To hook the TSizeCtrl.PopupMenu
ComCtrls, //To check the TTabSheet, TPageControl
{$IFDEF VER3U} TypInfo, {$ENDIF} //To hook the OnClick event
{$IFDEF VER3UP} Math, {$IFNDEF FPC}System.UITypes,{$ENDIF} {$ENDIF}
//To calculate TSizeBtn shape region//TO expand the GetColor function for our needs
Forms;
(* [TSizeBtn reqs]
To make transparent and topmost at the same time...
Another way is to use TGraphicControl, but, it doesn't gives ability
to use the Alpha-Blending :)
*)
function getAbsoluteX(cntrl: TControl; LastControl: TControl): integer;
function getAbsoluteY(cntrl: TControl; LastControl: TControl): integer;
{$IFNDEF VER3UP}
function Floor(const X: Extended): Integer;
function Ceil(const X: Extended): Integer;
function min(const X, Y: Integer): Integer;
function max(const X, Y: Integer): Integer;
{$ENDIF}
{$IFDEF FPC}
const
WM_SYSCOMMAND = LM_SYSCOMMAND;
WM_NCLBUTTONDBLCLK = LM_NCLBUTTONDBLCLK;
WM_NCLBUTTONDOWN = LM_NCLBUTTONDOWN;
WM_LBUTTONDOWN = LM_LBUTTONDOWN;
WM_NCLBUTTONUP = LM_NCLBUTTONUP;
WM_NCRBUTTONDOWN = LM_CONTEXTMENU;
WM_NCMOUSEMOVE = LM_NCMOUSEMOVE;
WM_LBUTTONUP = LM_LBUTTONUP;
WM_MOUSEMOVE = LM_MOUSEMOVE;
WM_MOUSEFIRST = LM_MOUSEFIRST;
WM_RBUTTONDOWN = LM_RBUTTONDOWN;
WM_MOUSELAST = LM_MOUSELAST;
WM_CREATE = LM_CREATE;
WM_DESTROY = LM_DESTROY;
WM_PARENTNOTIFY = LM_PARENTNOTIFY;
WM_SETCURSOR = LM_SETCURSOR;
WM_GETDLGCODE = LM_GETDLGCODE;
WM_KEYDOWN = LM_KEYDOWN;
WM_KEYUP = LM_KEYUP;
WM_CHAR = LM_CHAR;
WM_CANCELMODE = LM_CANCELMODE;
type
TMessage = TLMessage;
TWMMouse = TLMMouse;
TWMParentNotify = TLMCommand;
TWMSysCommand = TLMSysCommand;
TWMNCHitMessage = TLMNCHITTEST;
{$ELSE}
type
{$ENDIF}
TSizeCtrl = class;
TTargetObj = class;
TBtnPos = (bpNone, bpLeft, bpTop, bpRight, bpBottom, bpTopLeft, bpTopRight,
bpBottomRight, bpBottomLeft);
TBtnPosSet = set of TBtnPos;
TSizeCtrlBtnCount = (szctrl4btns, szctrl8btns);
TRecursionVector = (trecChild, trecParent, trecBoth);
TSCState = (scsReady, scsMoving, scsSizing);
TStartEndEvent = procedure(Sender: TObject; State: TSCState) of object;
TDuringEvent = procedure(Sender: TObject; dx, dy: integer; State: TSCState) of object;
TMouseDownEvent = procedure(Sender: TObject; Target: TControl;
TargetPt: TPoint; var handled: boolean) of object;
TSetCursorEvent = procedure(Sender: TObject; Target: TControl;
TargetPt: TPoint; var handled: boolean) of object;
TContextPopupEvent = procedure(Sender: TObject; MousePos: TPoint;
var Handled: boolean) of object;
TReSizeFrameType = (tszfNone, tszfButtons, tzfRButtons, tszfRButton);
TReSizeHideType = (tszhNone, tszhMove, tszhHide);
TSizeBtnShapeType = (tszbSquare, tszbTriangle, tszbCircle,
tszbRoundRect, tszbRhombus, tszbMockTube);
//TSizeBtn is used internally by TSizeCtrl.
//There are 8 TSizeBtns for each target which are the target's resize handles.
{$IFDEF FPC}
TSizeBtn = class(TForm)
{$ELSE}
TSizeBtn = class(TCustomForm)
{$ENDIF}
private
fTargetObj: TTargetObj;
fPos: TBtnPos;
fHoverDown, fHover: boolean;
fLeft, fTop: integer;
fColor, fPen: TColor;
fImage: TPicture;
protected
procedure DrawTriangle({$IFDEF FPC} b: Graphics.TBitmap;{$ENDIF}l, t:integer);
procedure PaintAs(l,t:integer);
procedure doPaint(Sender:TObject);
procedure mEnter(Sender:TObject);
procedure mLeave(Sender:TObject);
procedure UpdateBtnCursorAndColor;
{$IFDEF FPC}
procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
{%H-}X, {%H-}Y: integer); override;
{$ELSE}
procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: integer); override;
{$ENDIF}
procedure dMouseUp;
function GetTop: integer;
function GetLeft: integer;
procedure setLeft(value: integer);
procedure SetTop(value: integer);
public
procedure Reset;
property Left: integer read GetLeft write SetLeft;
property Top: integer read GetTop write SetTop;
constructor Create(TargetObj: TTargetObj; BtnPos: TBtnPos);
{$IFNDEF VER3U} reintroduce; {$ENDIF}
end;
{$IFNDEF FPC}
TMovePanel = class(TCustomForm)
private
fSizeCtrl: TSizeCtrl;
procedure setfcanvas(fCanvas: TCanvas);
protected
procedure SetBoundsRect(Sender: TObject);
procedure DoPaint(Sender: TObject);
public
constructor Create(AOwner: TComponent;AsizeCtrl:TSizeCtrl);
{$IFNDEF VER3U} reintroduce; {$ENDIF}
end;
{$ENDIF}
//TRegisteredObj is used internally by TSizeCtrl. Each TRegisteredObj
//contains info about a possible target control.
TRegisteredObj = class
protected
fSizeCtrl: TSizeCtrl; //the owner of TRegisteredObj
fControl: TControl;
fHooked: boolean;
fOldWindowProc: TWndMethod;
fOldClickMethod: TMethod;
procedure Hook;
procedure UnHook;
procedure NewWindowProc(var Msg: TMessage);
procedure NewWindowProcB(var Msg: TMessage);
public
constructor Create(aSizeCtrl: TSizeCtrl; aControl: TControl);
{$IFNDEF VER3U} reintroduce; {$ENDIF}
destructor Destroy; override;
end;
//TTargetObj is the container for each current target, and contains the 8
//TSizeBtn objects. Any number of TTargetObj's can be contained by TSizeCtrl.
TTargetObj = class
private
fSizeCtrl: TSizeCtrl; //the owner of TTargetObj
fTarget: TControl;
{$IFDEF FPC}
p: TPen;
br: TBRuSH;
frw:TCustomControl;
fDrawRect: boolean;
{$ELSE}
fPanels: TList;
fPanelsNames: TStrings;
{$ENDIF}
fBtns: array [TBtnPos] of TSizeBtn;
fFocusRect: TRect;
fLastRect: TRect;
fStartRec: TRect;
procedure Update;
procedure DragMoveUpdate(const Rectange: TRect;const t: byte);
procedure StartFocus();
function MoveFocus(dx, dy: integer): boolean;
function SizeFocus(dx, dy: integer; BtnPos: TBtnPos): boolean;
procedure EndFocus;
procedure DrawRect(obj: TControl);
public
constructor Create(aSizeCtrl: TSizeCtrl; aTarget: TControl);
{$IFNDEF VER3U} reintroduce; {$ENDIF}
destructor Destroy; override;
procedure ReconfButtons;
end;
TSizeCtrlTags = record
//ChangeTopLeft: integer read fnTopLeft write fnTopLeft;
DenySelect: int64;
AllowMove: int64;
DenyMove: int64;
AllowMultiMove: int64;
DenyMultiMove: int64;
AllowChange: int64;
DenyChange: int64;
AllowMultiChange: int64;
DenyMultiChange: int64;
ChangeTop: int64;
ChangeLeft: int64;
ChangeWidth: int64;
ChangeHeight: int64;
ChangeTopHeight: int64;
ChangeTopWidth: int64;
ChangeLeftHeight: int64;
ChangeLeftWidth: int64;
ChangeTopLeftWidth: int64;
ChangeTopLeftHeight: int64;
ChangeTopLeftWidthHeight: int64;
// ChangeHeightWidth: int64 read fnHeightWidth write fnHeightWidth;
AllowResize: int64;
DenyResize: int64;
AllowMultiResize: int64;
DenyMultiResize: int64;
end;
{$IFDEF FPC}
TSizeCtrl = class(TForm)
{$ELSE}
TSizeCtrl = class(TComponent)
{$ENDIF}
private
fLastBtn: TBtnPos;
fTargetList: TList; //list of TTargetObj (current targets)
fRegList: TList; //list of TRegisteredObj (possible targets)
fState: TSCState;
fMoveOnly: boolean;
fBtnAlpha, fBtnSize: integer;
fClipRec: TRect;
fStartPt: TPoint;
fEnabledBtnColor: TColor;
fHoverBtnColor: TColor;
fDisabledBtnColor: TColor;
fValidBtns: TBtnPosSet;
fMultiResize: boolean;
fEnabled, fAlignToGrid: boolean;
fCapturedCtrl: TControl;
fCapturedBtnPos: TBtnPos;
fGridSize: integer;
{$IFDEF FPC}
fDefWindowProc,{$ENDIF}
fOldWindowProc: TWndMethod;
fEscCancelled: boolean;
fParentForm: TCustomForm;
{$IFNDEF FPC}
fHandle: THandle;
{$ENDIF}
fPopupMenu: TPopupMenu;
fOnContextPopup: TContextPopupEvent;
fLMouseDownPending: boolean;
fForm: TWinControl;
fTags: TSizeCtrlTags;
fGridWhite: TColor;
fGridBlack: TColor;
fBtnFrameColor: TColor;
fHoverBtnFrameColor: TColor;
fDisabledBtnFrameColor: TColor;
fBtnShape: TSizeBtnShapeType;
fReSizeType: TReSizeFrameType;
fReIgnBtn: TReSizeHideType;
fShowFrame, fApplySizes: boolean;
fBtnCount: TSizeCtrlBtnCount;
FSelKey,
fSelActionSPKey,
fSelToggleKey,
fMoveLeftKey, fMoveTopKey,
fMoveRightKey, fMoveBottomKey,
FDGKey: integer;
fStartEvent: TStartEndEvent;
fDuringEvent: TDuringEvent;
fEndEvent: TStartEndEvent;
fTargetChangeEvent, fOnBh, fOnBtnUh: TNotifyEvent;
fOnMouseDown: TMouseDownEvent;
fOnMouseEnter: TMouseDownEvent;
fOnSetCursor: TSetCursorEvent;
fOnKeyDown: TKeyEvent;
FShowGrid: boolean;
fCanv: TCanvas;
fMovePanelAlpha: integer;
fPanelImage: TPicture;
fBtnImage: TPicture;
fHoverBtnImage: TPicture;
fEditParent: boolean;
fDisabledBtnImage: TPicture;
fStretchBtnImage, fStretchPanelImage: boolean;
function GetTargets(index: integer): TControl;
function GetTargetCount: integer;
procedure SetEnabled(Value: boolean);
procedure WinProc(var iMsg: TMessage);
procedure FormWindowProc(var Msg: TMessage);
procedure DoWindowProc(DefaultProc: TWndMethod; var Msg: TMessage);
procedure DrawRect;
procedure SetMoveOnly(Value: boolean);
function IsValidSizeBtn(BtnPos: TBtnPos): boolean;
function IsValidMove: boolean;
procedure SetMultiResize(Value: boolean);
procedure SetPopupMenu(Value: TPopupMenu);
procedure DoPopupMenuStuff;
procedure setGridSize(Value: integer);
procedure setGridWhite(Value: TColor);
procedure setGridBlack(Value: TColor);
procedure SetBtnCount(Value: TSizeCtrlBtnCount);
procedure setBtnSize(Value: integer);
procedure setBtnAlphaBlend(Value: integer);
procedure setMovePanelAlphaBlend(Value: integer);
procedure setPanelImage(Value: TPicture);
procedure setBtnImage(Value: TPicture);
procedure setHoverBtnImage(Value: TPicture);
procedure setDisabledBtnImage(Value: TPicture);
procedure setStretchBtnImage(Value: boolean);
procedure SetEnabledBtnColor(aColor: TColor);
procedure SetHoverBtnColor(aColor: TColor);
procedure SetDisabledBtnColor(aColor: TColor);
procedure SetBtnShape(v: TSizeBtnShapeType);
procedure SetBtnFrameColor(aColor: TColor);
procedure SetHoverBtnFrameColor(aColor: TColor);
procedure SetDisabledBtnFrameColor(aColor: TColor);
{$IFDEF FPC}
procedure DoMouseDown(Sender: TObject; {%H-}Button: TMouseButton; Shift: TShiftState);
procedure DoMouseUp(Sender: TObject; {%H-}Button: TMouseButton; {%H-}Shift: TShiftState);
procedure DoMouseMove(Sender: TObject; {%H-}Shift: TShiftState);
{$ELSE}
procedure DoMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState);
procedure DoMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState);
procedure DoMouseMove(Sender: TObject; Shift: TShiftState);
{$ENDIF}
procedure SetShowGrid(const Value: boolean);
protected
{$IFNDEF FPC}
fGrid: TBitmap; // сетка
{$ENDIF}
fGridForm: TForm;
lastW: integer;
lastH: integer; // последнЯЯ ширина и высота формы
lastColor: TColor; // последний цвет формы
FConstraints: TSizeConstraints;
procedure CreateGrid;
procedure Hide;
procedure Show;
procedure UpdateGrid;
procedure HardReset(sizes:boolean=false);
procedure UpdateBtnCursors;
procedure MoveTargets(dx, dy: integer);
procedure SizeTargets(dx, dy: integer);
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
{$IFDEF FPC}
function DoKeyDown(var Message: TLMKey): boolean;
{$ELSE}
function DoKeyDown(var Message: TWMKey): boolean;
{$ENDIF}
procedure formPaint(Sender: TObject);
function PerformRecursively
(
Control: TControl;
Func: byte;
FullRecursion: boolean;
Include:boolean;
AddType:TRecursionVector
): boolean;
function XYweckPositive(x,y:integer;c:byte;t:int64): boolean;
function XyWeckTag(c: TBtnPos;t:int64):boolean;
function XYweck(x,y:integer;c:byte;t:int64): boolean;
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
function isTarget(tcrl: TControl): boolean;
function FixSize(input, wh: integer): integer;
function KeysToShiftState(Keys: Word): TShiftState;
function KeyDataToShiftState(): TShiftState;
property LastBtn: TBtnPos read fLastBtn;
property TagOptions: TSizeCtrlTags read fTags write fTags;
//Targets: used to access individual targets (read-only)
property Targets[index: integer]: TControl read GetTargets;
published
function RegisteredCtrlFromPt(screenPt: TPoint;
ParentX: TWinControl = nil): TControl;
//Update: it is the responsibility of the component user to call Update
//if the target(s) are moved or resized independently of this control
//(eg if the form is resized and targets are aligned with it.)
procedure Update;
procedure UpdateBtns;
procedure toFront(CNTR: TControl);
procedure toBack(CNTR: TControl);
//RegisterControl: Register potential target controls with TSizeCtrl
function RegisterControl(Control: TControl): integer;
function RegisterControlR
(
Control: TControl;
AddType: TRecursionVector=TRecursionVector.trecChild;
FullRecursion: boolean=True
): boolean;
function UnRegisterControl(Control: TControl): integer;
function UnRegisterControlR
(
Control: TControl;
AddType: TRecursionVector=TRecursionVector.trecChild;
FullRecursion: boolean=True
): boolean;
procedure UnRegisterAll;
function RegisteredIndex(Control: TControl): integer;
function getRegObj(C: TComponent): TRegisteredObj;
function getSelected(): TList;
//AddTarget: Add any number of targets to TSizeCtrl so they can be
//resized or moved together.
//(nb: The programmer doesn't normally need to call this method directly
//since TSizeCtrl will call it whenever a target is clicked.)
function AddTarget(Control: TControl): integer;
function AddTargetR
(
Control: TControl;
AddType: TRecursionVector=TRecursionVector.trecChild;
FullRecursion: boolean=True
): boolean;
function DeleteTarget(Control: TControl): integer;
function DeleteTargetR
(
Control: TControl;
AddType: TRecursionVector=TRecursionVector.trecChild;
FullRecursion: boolean=True
): boolean;
procedure ClearTargets;
function TargetIndex(Control: TControl): integer;
function TargetCtrlFromPt(screenPt: TPoint): TControl;
//Enabled: This key property should be self-explanatory.
property Enabled: boolean read fEnabled write SetEnabled;
//<summary>
//Used for getting targets count
//</summary>
property TargetCount: integer read GetTargetCount;
property EditParent: boolean read fEditParent write fEditParent;
property Parent:TWinControl read FForm;
//MinWidth: minimal target (resizing) width
//MinHeight: minimal target (resizing) height
//MaxWidth: maximal target (resizing) width
//MaxHeight: maximal target (resizing) height
property Constraints: TSizeConstraints read FConstraints write FConstraints;
//MoveOnly: ie prevents resizing
property MoveOnly: boolean read fMoveOnly write SetMoveOnly;
//BtnCount: Count of the grab buttons
property BtnCount: TSizeCtrlBtnCount read fBtnCount write setBtnCount;
//BtnSize: Size of a grab-handle buttons
property BtnSize: integer read FBtnSize write setBtnSize;
//BtnAlphaBlend: Alpha-blend semitransparent multiplier for grab btns
property BtnAlphaBlend: integer read fBtnAlpha write setBtnAlphaBlend;
//BtnColor: Color of grab-handle buttons
property BtnColor: TColor read fEnabledBtnColor write SetEnabledBtnColor;
//BtnColor: Color of grab-handle buttons
property HoverBtnColor: TColor read fHoverBtnColor write SetHoverBtnColor;
//BtnColorDisabled: eg grab buttons along aligned edges of target controls
property DisabledBtnColor: TColor read fDisabledBtnColor write SetDisabledBtnColor;
property BtnShape: TSizeBtnShapeType read fBtnShape write setBtnShape;
property BtnFrameColor: TColor read fBtnFrameColor write setBtnFrameColor;
property HoverBtnFrameColor: TColor read fHoverBtnFrameColor write setHoverBtnFrameColor;
property DisabledBtnFrameColor: TColor read fDisabledBtnFrameColor write setDisabledBtnFrameColor;
//BtnImage eg grab buttons along 8 edges of target controls
property BtnImage: TPicture read fBtnImage write setBtnImage;
//Hover-state button(s)
property HoverBtnImage: TPicture read fHoverBtnImage write setHoverBtnImage;
//DisabledBtnImage - you will understand
property DisabledBtnImage: TPicture read fDisabledBtnImage write setDisabledBtnImage;
//BtnImage eg grab buttons along 8 edges of target controls
property StretchBtnImage: Boolean read fStretchBtnImage write setStretchBtnImage;
//Custom keymaps
property SelectionKey: integer read FSelKey write FSelKey;
property SelectionSelectParentKey:
integer read fSelActionSPKey write fSelActionSPKey;
property SelectionTabKey:
integer read fSelToggleKey write fSelToggleKey;
property MoveLeftKey: integer read fMoveLeftKey write fMoveLeftKey;
property MoveRightKey:integer read fMoveRightKey write fMoveRightKey;
property MoveUpKey:integer read fMoveTopKey write fMoveTopKey;
property MoveDownKey:integer read fMoveBottomKey write fMoveBottomKey;
property DisableGridAlignKey: integer read FDGKey write FDGKey;
property ShowGrid: boolean read FShowGrid write SetShowGrid;
//GridSize: aligns mouse moved/resized controls to nearest grid dimensions
property GridSize: integer read fGridSize write setGridSize;
property AlignToGrid: boolean read fAlignToGrid write fAlignToGrid;
property GridColor: TColor read fGridBlack write setGridBlack;
property GridColorContrast: TColor read fGridWhite write setGridWhite;
//MultiTargetResize: Resizing of multiple targets is allowed by default
//as long as this isn't impeded by specific Target control alignments
property MultiTargetResize: boolean read fMultiResize write SetMultiResize;
//The TMovePanel canvases (applicable to all descedants)
property MovePanelCanvas: TCanvas read fCanv;
property MovePanelImage: TPicture read fPanelImage write setPanelImage;
property StretchMovePanelImage: boolean read fStretchPanelImage write fStretchPanelImage;
//The TMovePanel alphachannel (applicable to all descedants)
property MovePanelAlphaBlend: Integer read fMovePanelAlpha write setMovePanelAlphaBlend;
//Apply sizes when moving
property ApplySizes: boolean read fApplySizes write fApplySizes default false;
//Show selection frame
property ShowFrame: boolean read fShowFrame write fShowFrame default true;
//Resize showing type
property ResizeFrameType: TReSizeFrameType read fReSizeType write fReSizeType;
//Ignoring method for unwanted btns
property ResizeIgnoreMethod: TReSizeHideType read fReIgnBtn write fReIgnBtn;
property PopupMenu: TPopupMenu read fPopupMenu write SetPopupMenu;
//Self-explanatory Events ...
property OnStartSizeMove: TStartEndEvent read fStartEvent write fStartEvent;
property OnDuringSizeMove: TDuringEvent read fDuringEvent write fDuringEvent;
property OnEndSizeMove: TStartEndEvent read fEndEvent write fEndEvent;
property OnTargetChange: TNotifyEvent read fTargetChangeEvent
write fTargetChangeEvent;
property onButtonHover: TNotifyEvent read fOnBH write fOnBH;
property onButtonUnhover: TNotifyEvent read fOnBtnUh write fOnBtnUh;
property OnKeyDown: TKeyEvent read fOnKeyDown write fOnKeyDown;
property OnMouseDown: TMouseDownEvent read fOnMouseDown write fOnMouseDown;
property OnMouseEnter: TMouseDownEvent read fOnMouseEnter write fOnMouseEnter;
property OnSetCursor: TSetCursorEvent read fOnSetCursor write fOnSetCursor;
property OnContextPopup: TContextPopupEvent
read fOnContextPopup write fOnContextPopup;
end;
const
CM_LMOUSEDOWN = WM_USER + $1;
CM_RMOUSEDOWN = WM_USER + $2;
procedure Register;
implementation
uses Types;
type
THackedControl = class(TControl){$IFNDEF FPC};{$ELSE}
public
procedure SendCancelMode(Sender: TControl);
end;
{$ENDIF}
THackedWinControl = {$IFNDEF FPC}class(TWinControl);{$ELSE}
class(TCustomForm)
public
procedure SendCancelMode(Sender: TControl);
end;
{$ENDIF}
procedure Register;
begin
RegisterComponents('Samples', [TSizeCtrl]);
end;
{$IFDEF VER3D} type
TAlignSet = set of TAlign; {$ENDIF}
//turn warnings off concerning unsafe typecasts since we know they're safe...
{$WARNINGS OFF}
//------------------------------------------------------------------------------
// Miscellaneous functions
//------------------------------------------------------------------------------
{$IFNDEF VER3UP}
function Floor(const X: Extended): integer;
begin
Result := Integer(Trunc(X));
if Frac(X) < 0 then
Dec(Result);
end;
function Ceil(const X: Extended): Integer;
begin
Result := Integer(Trunc(X));
if Frac(X) > 0 then
Inc(Result);
end;
function Min(const X, Y: Integer): Integer;
begin
if X < Y then
Result := X
else
Result := Y;
end;
function Max(const X, Y: Integer): Integer;
begin
if X > Y then
Result := X
else
Result := Y;
end;
{$ENDIF}
{$IFDEF FPC}
procedure THackedControl.SendCancelMode(Sender: TControl);
procedure SendWMMode(F:TCustomForm;Sender: TControl);
begin
F.ActiveControl.Perform(CM_CANCELMODE, 0, LPARAM(Sender));
if (F.FormStyle = fsMDIForm) and (F.ActiveMDIChild <> nil) then
SendWMMode(F.ActiveMDIChild, Sender);
end;
var
Control: TControl;
begin
Control := Self;
while Control <> nil do
begin
if Control is TCustomForm then
SendWMMode( TCustomForm(Control), Sender);
Control := Control.Parent;
end;
end;
procedure THackedWinControl.SendCancelMode(Sender: TControl);
procedure SendWMMode(F:TCustomForm;Sender: TControl);
begin
F.ActiveControl.Perform(CM_CANCELMODE, 0, LPARAM(Sender));
if (F.FormStyle = fsMDIForm) and (F.ActiveMDIChild <> nil) then
SendWMMode(F.ActiveMDIChild, Sender);
end;
var
Control: TControl;
begin
Control := Self;
while Control <> nil do
begin
if Control is TCustomForm then
SendWMMode( TCustomForm(Control), Sender);
Control := Control.Parent;
end;
end;
{$ENDIF}
function getAbsoluteX(cntrl: TControl; LastControl: TControl): integer;
begin
Result := cntrl.Left;
if integer(cntrl.Parent) <> integer(LastControl) then
Result := Result + getAbsoluteX(cntrl.Parent, LastControl);
end;
function getAbsoluteY(cntrl: TControl; LastControl: TControl): integer;
begin
Result := cntrl.top;
if integer(cntrl.Parent) <> integer(LastControl) then
Result := Result + getAbsoluteY(cntrl.Parent, LastControl);
end;
//------------------------------------------------------------------------------
function IsVisible(Control: TControl): boolean;
begin
Result := True;
while assigned(Control) do
if Control is TCustomForm then
exit
else if not Control.Visible then
break
else
Control := Control.Parent;
Result := False;
end;
//------------------------------------------------------------------------------
function GetBoundsAsScreenRect(Control: TControl): TRect;
begin
//GetBoundsAsScreenRect() assumes 'Control' is both assigned and has a parent.
//Not all TControls have handles (ie only TWinControls) so ...
with Control do
begin
Result.TopLeft := parent.ClientToScreen(BoundsRect.TopLeft);
Result.Right := Result.Left + Width;
Result.Bottom := Result.Top + Height;
end;
end;
//------------------------------------------------------------------------------
function PointIsInControl(screenPt: TPoint; Control: TControl): boolean;
begin
//PointIsInControl() assumes 'Control' is both assigned and has a parent.
Result := PtInRect(GetBoundsAsScreenRect(Control), screenPt);
end;
//------------------------------------------------------------------------------
function KeyIsPressed(key: integer): boolean;
begin
if key = -1 then
Result := true
else
if key = 0 then
Result := false
Else
Result := GetKeyState(key) < 0;
end;
//------------------------------------------------------------------------------
{
function inSizeTag(key: integer;arr: array of integer): boolean;
var i: integer;
begin
Result := False;
for i in arr do
if i = key then
begin
Result := true;
Exit;
end;
end;
//P.s Delphi compiler is kind of a shit
}
//------------------------------------------------------------------------------
function TSizeCtrl.XyWeck(x,y:integer;c:byte;t:int64): boolean;
begin
Result :=
(
(fTargetList.Count > 1) and
(
(fTags.DenyMultiChange = t) or
((c=1)and(fTags.DenyMultiResize = t)) or
((c=0)and(fTags.DenyMultiMove = t))
)
)
or
(fTags.DenyChange = t)
or
(fTags.DenySelect = t)//Should never happen,but...
or
(
(c = 0)
and
(fTags.DenyMove = t)
or
((x<>0)
and
(
(fTags.ChangeTop=t)
or
(fTags.ChangeTopHeight=t)
or
(fTags.ChangeTopWidth=t)
or
(fTags.ChangeWidth=t)
or
(fTags.ChangeHeight=t)
)
)
or
((y<>0)
and
(
(FTags.ChangeWidth=t)
or
(fTags.ChangeHeight=t)
or
(fTags.ChangeLeftHeight=t)
or
(fTags.ChangeLeft=t)
or
(fTags.ChangeLeftWidth=t)
)
)
)
or
(
(c = 1)
and
(fTags.DenyResize = t)
or
((x<>0)
and
(
(fTags.ChangeTop=t)
or
(fTags.ChangeTopHeight=t)
or
(fTags.ChangeLeft=t)
or
(fTags.ChangeLeftHeight=t)
or
(fTags.ChangeHeight=t)
)
)
or
((y<>0)
and
(
(FTags.ChangeWidth=t)
or
(fTags.ChangeTopWidth=1)
or
(fTags.ChangeTopHeight=t)
or
(fTags.ChangeLeft=t)
or
(fTags.ChangeLeftWidth=t)
)
)
)
;
end;
//------------------------------------------------------------------------------
function TSizeCtrl.XyWeckPositive(x,y:integer;c:byte;t:int64): boolean;
begin
Result :=
(
(fTargetList.Count > 1) and
(
(fTags.AllowMultiChange = t) or
((c=1)and(fTags.AllowMultiResize = t)) or
((c=0)and(fTags.AllowMultiMove = t))
)
)
or
(fTags.AllowChange = t)
or
(
(c = 0)
and
(fTags.AllowMove = t)
or
((x<>0)
and
not (
(fTags.ChangeTop=t)
or
(fTags.ChangeTopHeight=t)
or
(fTags.ChangeTopWidth=t)
or
(fTags.ChangeWidth=t)
or
(fTags.ChangeHeight=t)
)
)
or
((y<>0)
and
not (
(FTags.ChangeWidth=t)
or
(fTags.ChangeHeight=t)
or
(fTags.ChangeLeftHeight=t)
or
(fTags.ChangeLeft=t)
or
(fTags.ChangeLeftWidth=t)
)
)
)
or
(
(c = 1)
and
(fTags.AllowResize = t)
or
((x<>0)
and
not (
(fTags.ChangeTop=t)
or
(fTags.ChangeTopHeight=t)
or
(fTags.ChangeLeft=t)
or
(fTags.ChangeLeftHeight=t)
or
(fTags.ChangeHeight=t)
)
)
or
((y<>0)
and
not (
(FTags.ChangeWidth=t)
or
(fTags.ChangeTopWidth=1)
or
(fTags.ChangeTopHeight=t)
or
(fTags.ChangeLeft=t)
or
(fTags.ChangeLeftWidth=t)
)
)
)
;
end;
//-----------------------------------------------------------------------------
function TSizeCtrl.XyWeckTag(c: TBtnPos;t:int64):boolean;
begin
case c of
bpLeft:
Result :=
XyWeckPositive(1,0,0,t) and XyWeckPositive(1,0,1,t);
bpTop:
Result :=
XyWeckPositive(0,1,0,t) and XyWeckPositive(0,1,1,t);
bpRight:
Result :=
XyWeckPositive(1,0,1,t);
bpBottom:
Result :=
XyWeckPositive(0,1,1,t);
bpTopLeft:
Result :=
XyWeckPositive(1,0,0,t) and XyWeckPositive(1,0,1,t) AND XyWeckPositive(0,1,0,t) and XyWeckPositive(0,1,1,t);
bpTopRight:
Result :=
XyWeckPositive(1,0,1,t) AND XyWeckPositive(0,1,0,t) and XyWeckPositive(0,1,1,t);
bpBottomRight:
Result :=
XyWeckPositive(1,0,1,t) AND XyWeckPositive(0,1,1,t);
bpBottomLeft:
Result :=
XyWeckPositive(1,0,0,t) and XyWeckPositive(1,0,1,t) AND XyWeckPositive(0,1,1,t);
end;
end;
//------------------------------------------------------------------------------
function checkTag(tag: integer; _pi: TBtnPos; ts: TSizeCtrlTags;tCount:integer):boolean;
begin
If Tag = 0 then
Result := False
Else
Result :=
(Tag = ts.DenyChange)
or
(Tag = ts.DenyResize)
or
((Tag = ts.DenyMultiResize) and (tCount > 1))
or
((Tag = ts.DenyMultiChange) and (tCount > 1))
or
((Tag = ts.ChangeTop) and (_pi <> bpTop))
or
((Tag = ts.ChangeLeft) and (_pi <> bpLeft))
or
((Tag = ts.ChangeHeight) and (_pi <> bpBottom))
or
((Tag = ts.ChangeWidth) and (_pi <> bpRight))
or
((Tag = ts.ChangeTopHeight) and
(_pi <> bpTop) and (_pi <> bpBottom))
or
((Tag = ts.ChangeTopWidth) and
(_pi <> bpTop) and (_pi <> bpRight))
or
((Tag = ts.ChangeLeftHeight) and
(_pi <> bpLeft) and (_pi <> bpBottom))