-
Notifications
You must be signed in to change notification settings - Fork 33
/
HGM.Button.pas
1245 lines (1138 loc) · 34.2 KB
/
HGM.Button.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 HGM.Button;
interface
uses
Winapi.Windows, Winapi.Messages, System.Classes, Vcl.Graphics, Vcl.Controls,
Vcl.StdCtrls, System.Generics.Collections, Vcl.ExtCtrls, System.UITypes,
System.Types, HGM.Controls.VirtualTable, Vcl.Direct2D, Winapi.D2D1, HGM.Common,
HGM.Common.Utils, Vcl.Menus, System.SysUtils;
type
TButtonFlatState = (bfsNormal, bfsOver, bfsPressed);
TButtonFlatGroupItem = (giNone, giLeft, giCenter, giRight);
TButtonFlat = class(TCustomControl)
private
FColors: array[TButtonFlatState] of TColor;
FShape: TShapeType;
FGettingTextWidth: Boolean;
FTextWidth: Integer;
FSubText: string;
FButtonState: TButtonFlatState;
FPrevState: TButtonFlatState;
FDowned: Boolean;
FMouseOver: Boolean;
FLabel: string;
FTextFormat: TTextFormat;
FEllipseRectVertical: Boolean;
FIgnorBounds: Boolean;
FNeedColor: TColor;
FAnimPerc: Integer;
FTimerProcing: Boolean;
FStyledColor: TColor;
FOnPaint: TNotifyEvent;
FRoundRectParam: Integer;
FOnMouseDown: TMouseEvent;
FOnMouseUp: TMouseEvent;
FOnMouseLeave: TNotifyEvent;
FOnMouseEnter: TNotifyEvent;
FFlat: Boolean;
FImages: TImageList;
FImageIndex: Integer;
FImageOver: Integer;
FImagePress: Integer;
FTimerAnimate: TTimer;
FImageIndentLeft: Integer;
FImageIndentRight: Integer;
FNotifyColor: TColor;
FNotifyVisible: Boolean;
FNotifyWidth: Integer;
FTimedText: string;
FTimerTT: TTimer;
FTimerAutoClick: TTimer;
FDrawTimedText: Boolean;
FGroupItemKind: TButtonFlatGroupItem;
FImagesOver: TImageList;
FImagesPress: TImageList;
FFontOver: TFont;
FFontDown: TFont;
FFromColor: TColor;
FTransparent: Boolean;
FShowFocusRect: Boolean;
FVisibleSubText: Boolean;
FDblClickTooClick: Boolean;
FAutoClick: Cardinal;
FPopup: TPopupMenu;
FBorderColor: TColor;
FEllipseAnimate: Boolean;
FSubTextColor: TColor;
FSubTextFont: TFont;
FBorderWidth: Integer;
FShowCaption: Boolean;
FSubTextColorBorder: TColor;
FSubTextColorBorderDepth: Integer;
FBackgroundColor: TColor;
procedure FOnDblClick(Sender: TObject);
function FGetTextWidth: Integer;
procedure SetLabel(const Value: string);
procedure SetStyledColor(const Value: TColor);
procedure SetTextFormat(const Value: TTextFormat);
procedure SetEllipseRectVertical(const Value: Boolean);
procedure SetRoundRectParam(const Value: Integer);
procedure SetIgnorBounds(const Value: Boolean);
procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
procedure DoMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure DoMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure SetButtonState(const Value: TButtonFlatState);
procedure OnTimerAnimateTime(Sender: TObject);
procedure OnTimerTTTime(Sender: TObject);
procedure OnTimerAutoClickTime(Sender: TObject);
procedure StopAnimate;
procedure SetNeedColor(const Value: TColor);
procedure SetShape(Value: TShapeType);
procedure SetColorNormal(const Value: TColor);
function GetColorNormal: TColor;
function GetColorOver: TColor;
function GetColorPressed: TColor;
procedure SetColorOver(const Value: TColor);
procedure SetColorPressed(const Value: TColor);
procedure SetImageIndentLeft(const Value: Integer);
procedure SetImageIndentRight(const Value: Integer);
procedure SetImageIndex(const Value: Integer);
procedure SetNotifyColor(const Value: TColor);
procedure SetNotifyVisible(const Value: Boolean);
procedure SetNotifyWidth(const Value: Integer);
procedure SetGroupItemKind(const Value: TButtonFlatGroupItem);
procedure SetImages(const Value: TImageList);
procedure SetImagesOver(const Value: TImageList);
procedure SetImagesPress(const Value: TImageList);
procedure SetFontDown(const Value: TFont);
procedure SetFontOver(const Value: TFont);
procedure SetFlat(const Value: Boolean);
procedure SetTransparent(const Value: Boolean);
procedure SetShowFocusRect(const Value: Boolean);
procedure SetSubText(const Value: string);
procedure SetVisibleSubText(const Value: Boolean);
procedure SetDblClickTooClick(const Value: Boolean);
procedure SetAutoClick(const Value: Cardinal);
procedure SetPopup(const Value: TPopupMenu);
procedure SetBorderColor(const Value: TColor);
procedure SetEllipseAnimate(const Value: Boolean);
procedure SetSubTextColor(const Value: TColor);
procedure SetSubTextFont(const Value: TFont);
procedure SetBorderWidth(const Value: Integer);
procedure SetShowCaption(const Value: Boolean);
procedure SetOnMouseEnter(const Value: TNotifyEvent);
procedure SetOnMouseLeave(const Value: TNotifyEvent);
procedure SetSubTextColorBorder(const Value: TColor);
procedure SetSubTextColorBorderDepth(const Value: Integer);
procedure SetBackgroundColor(const Value: TColor);
property ButtonState: TButtonFlatState read FButtonState write SetButtonState;
property StyledColor: TColor read FStyledColor write SetStyledColor;
property FromColor: TColor read FFromColor write FFromColor;
property NeedColor: TColor read FNeedColor write SetNeedColor;
protected
procedure Paint; override;
public
property Canvas;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure TimedText(Text: string; Delay: Cardinal);
procedure ShowPopup;
procedure Click; override;
property GetTextWidth: Integer read FGetTextWidth;
published
property Align;
property Anchors;
property Caption: string read FLabel write SetLabel;
property ColorNormal: TColor read GetColorNormal write SetColorNormal;
property ColorOver: TColor read GetColorOver write SetColorOver;
property ColorPressed: TColor read GetColorPressed write SetColorPressed;
property Constraints;
property Cursor default crHandPoint;
property DoubleBuffered;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property EllipseRectVertical: Boolean read FEllipseRectVertical write SetEllipseRectVertical default False;
property Font;
property Flat: Boolean read FFlat write SetFlat default True;
property BackgroundColor: TColor read FBackgroundColor write SetBackgroundColor default clNone;
property BorderColor: TColor read FBorderColor write SetBorderColor default clNone;
property BorderWidth: Integer read FBorderWidth write SetBorderWidth default 1;
property FontOver: TFont read FFontOver write SetFontOver;
property FontDown: TFont read FFontDown write SetFontDown;
property GroupItemKind: TButtonFlatGroupItem read FGroupItemKind write SetGroupItemKind default giNone;
property IgnorBounds: Boolean read FIgnorBounds write SetIgnorBounds default False;
property ImageIndentLeft: Integer read FImageIndentLeft write SetImageIndentLeft default 3;
property ImageIndentRight: Integer read FImageIndentRight write SetImageIndentRight default 0;
property ImageIndex: Integer read FImageIndex write SetImageIndex default -1;
property ImageOver: Integer read FImageOver write FImageOver default -1;
property ImagePress: Integer read FImagePress write FImagePress default -1;
property Images: TImageList read FImages write SetImages;
property ImagesOver: TImageList read FImagesOver write SetImagesOver;
property ImagesPress: TImageList read FImagesPress write SetImagesPress;
property NotifyColor: TColor read FNotifyColor write SetNotifyColor default $0042A4FF;
property NotifyVisible: Boolean read FNotifyVisible write SetNotifyVisible default False;
property NotifyWidth: Integer read FNotifyWidth write SetNotifyWidth default 8;
property Transparent: Boolean read FTransparent write SetTransparent default False;
property OnClick;
property OnContextPopup;
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
property OnGesture;
property OnMouseActivate;
property OnMouseDown: TMouseEvent read FOnMouseDown write FOnMouseDown;
property OnMouseEnter: TNotifyEvent read FOnMouseEnter write SetOnMouseEnter;
property OnMouseLeave: TNotifyEvent read FOnMouseLeave write SetOnMouseLeave;
property OnMouseMove;
property OnMouseUp: TMouseEvent read FOnMouseUp write FOnMouseUp;
property OnMouseWheelDown;
property OnMouseWheelUp;
property OnPaint: TNotifyEvent read FOnPaint write FOnPaint;
property OnStartDock;
property OnStartDrag;
property ParentShowHint;
property RoundRectParam: Integer read FRoundRectParam write SetRoundRectParam;
property Shape: TShapeType read FShape write SetShape default stRectangle;
property ShowHint;
property ShowFocusRect: Boolean read FShowFocusRect write SetShowFocusRect default True;
property TabOrder;
property TabStop;
property TextFormat: TTextFormat read FTextFormat write SetTextFormat;
property SubText: string read FSubText write SetSubText;
property SubTextFont: TFont read FSubTextFont write SetSubTextFont;
property SubTextColor: TColor read FSubTextColor write SetSubTextColor default clGrayText;
property SubTextColorBorder: TColor read FSubTextColorBorder write SetSubTextColorBorder default clNone;
property SubTextColorBorderDepth: Integer read FSubTextColorBorderDepth write SetSubTextColorBorderDepth default 1;
property VisibleSubText: Boolean read FVisibleSubText write SetVisibleSubText default False;
property Touch;
property Visible;
property AutoClick: Cardinal read FAutoClick write SetAutoClick default 0;
property DblClickTooClick: Boolean read FDblClickTooClick write SetDblClickTooClick default False;
property Popup: TPopupMenu read FPopup write SetPopup;
property EllipseAnimate: Boolean read FEllipseAnimate write SetEllipseAnimate default True;
property ShowCaption: Boolean read FShowCaption write SetShowCaption default True;
end;
TCheckBoxFlat = class(TButtonFlat)
private
FChecked: Boolean;
FImageCheck: Integer;
FImageUncheck: Integer;
procedure SetChecked(const Value: Boolean);
procedure UpdateChecked;
procedure SetImageCheck(const Value: Integer);
procedure SetImageUncheck(const Value: Integer);
public
property Canvas;
constructor Create(AOwner: TComponent); override;
procedure Click; override;
published
property Align;
property Anchors;
property Caption;
property ColorNormal;
property ColorOver;
property ColorPressed;
property Constraints;
property Cursor;
property DoubleBuffered;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property EllipseRectVertical;
property Font;
property Flat;
property BorderColor;
property FontOver;
property FontDown;
property GroupItemKind;
property IgnorBounds;
property ImageIndentLeft;
property ImageIndentRight;
property Images;
property NotifyColor;
property NotifyVisible;
property NotifyWidth;
property Transparent;
property OnClick;
property OnContextPopup;
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
property OnGesture;
property OnMouseActivate;
property OnMouseDown;
property OnMouseEnter;
property OnMouseLeave;
property OnMouseMove;
property OnMouseUp;
property OnPaint;
property OnStartDock;
property OnStartDrag;
property ParentShowHint;
property RoundRectParam;
property Shape;
property ShowHint;
property ShowFocusRect;
property TabOrder;
property TabStop;
property TextFormat;
property SubText;
property SubTextFont;
property SubTextColor;
property VisibleSubText;
property Touch;
property Visible;
property GetTextWidth;
property AutoClick;
property DblClickTooClick default True;
property Popup;
property EllipseAnimate;
property Checked: Boolean read FChecked write SetChecked default False;
property ImageCheck: Integer read FImageCheck write SetImageCheck default -1;
property ImageUncheck: Integer read FImageUncheck write SetImageUncheck default -1;
end;
TButtonItems = TList<TButtonFlat>;
TButtonRadioControl = class
private
FItems: TButtonItems;
FSelected: TButtonFlat;
FSelectedColor: TColor;
FUnselectedColor: TColor;
procedure SetItems(const Value: TButtonItems);
procedure SetSelected(const Value: TButtonFlat);
procedure SetSelect(Button: TButtonFlat);
public
constructor Create(Selected, Unselected: TColor);
destructor Destroy; override;
property Items: TButtonItems read FItems write SetItems;
property Selected: TButtonFlat read FSelected write SetSelected;
end;
procedure Register;
implementation
uses
Math;
procedure Register;
begin
RegisterComponents(PackageName, [TButtonFlat]);
RegisterComponents(PackageName, [TCheckBoxFlat]);
end;
function GrayColor(AColor: TColor): TColor;
var
Gr: Byte;
begin
AColor := ColorToRGB(AColor);
Gr := Trunc((GetBValue(AColor) + GetGValue(AColor) + GetRValue(AColor)) / 3);
Result := RGB(Gr, Gr, Gr);
end;
{ TLabelEx }
procedure TButtonFlat.TimedText(Text: string; Delay: Cardinal);
begin
Enabled := False;
FTimedText := Text;
FDrawTimedText := True;
FTimerTT.Interval := Delay;
FTimerTT.Enabled := True;
Repaint;
end;
procedure TButtonFlat.SetShape(Value: TShapeType);
begin
if FShape <> Value then
begin
FShape := Value;
Invalidate;
end;
end;
procedure TButtonFlat.SetShowCaption(const Value: Boolean);
begin
FShowCaption := Value;
Repaint;
end;
procedure TButtonFlat.SetShowFocusRect(const Value: Boolean);
begin
FShowFocusRect := Value;
Repaint;
end;
procedure TButtonFlat.Click;
begin
inherited;
end;
procedure TButtonFlat.CMMouseEnter(var Message: TMessage);
begin
if Assigned(FOnMouseEnter) then
FOnMouseEnter(Self);
FMouseOver := True;
ButtonState := bfsOver;
end;
procedure TButtonFlat.CMMouseLeave(var Message: TMessage);
begin
if Assigned(FOnMouseLeave) then
FOnMouseLeave(Self);
FMouseOver := False;
ButtonState := bfsNormal;
end;
constructor TButtonFlat.Create(AOwner: TComponent);
begin
{$IFNDEF FORXP}
//DOTO Íóæíà ïðîâåðêà íà âåðñèþ âèíäû. Åñëè XP, òî òðåáîâàòü âêëþ÷åíèÿ äèðåêòèâû FORXP. XP íå õî÷åò ðàáîòàòü ñ Direct2D
{$ENDIF}
inherited Create(AOwner);
inherited Cursor := crHandPoint;
ControlStyle := ControlStyle + [csReplicatable, csOpaque];
OnDblClick := FOnDblClick;
FDblClickTooClick := False;
FAutoClick := 0;
FBackgroundColor := clNone;
FTimerAnimate := TTimer.Create(nil);
FTimerAnimate.Interval := 10;
FTimerAnimate.Enabled := False;
FTimerAnimate.OnTimer := OnTimerAnimateTime;
FTimerTT := TTimer.Create(nil);
FTimerTT.Interval := 100;
FTimerTT.Enabled := False;
FTimerTT.OnTimer := OnTimerTTTime;
FTimerAutoClick := TTimer.Create(nil);
FTimerAutoClick.Interval := FAutoClick;
FTimerAutoClick.Enabled := False;
FTimerAutoClick.OnTimer := OnTimerAutoClickTime;
FDrawTimedText := False;
FSubTextColorBorderDepth := 1;
FSubTextColorBorder := clNone;
FAnimPerc := 0;
FShowCaption := True;
FGettingTextWidth := False;
FSubText := '';
FVisibleSubText := False;
FFlat := True;
FEllipseAnimate := True;
FTimedText := '';
FImageIndex := -1;
FImagePress := -1;
FImageOver := -1;
FImageIndentLeft := 3;
FImageIndentRight := 0;
FLabel := 'Êíîïêà';
FNotifyColor := $0042A4FF;
FNotifyWidth := 8;
FNotifyVisible := False;
FBorderColor := clNone;
FBorderWidth := 1;
ParentColor := False;
TabStop := True;
ParentBackground := False;
StyleElements := [];
FColors[bfsNormal] := $00DFD3C4;
FColors[bfsOver] := $00AD8D64;
FColors[bfsPressed] := $009F7949;
FDowned := False;
FMouseOver := False;
Font.Size := 10;
FFontOver := TFont.Create;
FFontOver.Color := Font.Color;
FFontOver.Size := Font.Size;
FFontDown := TFont.Create;
FFontDown.Color := Font.Color;
FFontDown.Size := Font.Size;
FSubTextFont := TFont.Create;
FSubTextFont.Color := clWhite;
FSubTextFont.Size := Font.Size;
FSubTextColor := clGrayText;
Width := 90;
Height := 30;
FRoundRectParam := 0;
FIgnorBounds := True;
FTextFormat := [tfCenter, tfVerticalCenter, tfSingleLine];
ButtonState := bfsNormal;
inherited OnMouseDown := DoMouseDown;
inherited OnMouseUp := DoMouseUp;
end;
destructor TButtonFlat.Destroy;
begin
FTimerAnimate.Free;
FTimerTT.Free;
FTimerAutoClick.Free;
FFontOver.Free;
FFontDown.Free;
FSubTextFont.Free;
inherited;
end;
procedure TButtonFlat.DoMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
SetFocus;
ButtonState := bfsPressed;
FDowned := True;
if FAutoClick > 0 then
begin
FTimerAutoClick.Interval := 1000;
FTimerAutoClick.Enabled := True;
end;
if Assigned(FOnMouseDown) then
FOnMouseDown(Sender, Button, Shift, X, Y);
end;
procedure TButtonFlat.DoMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if FMouseOver then
ButtonState := bfsOver
else
ButtonState := bfsNormal;
FDowned := False;
if Assigned(FOnMouseUp) then
FOnMouseUp(Sender, Button, Shift, X, Y);
end;
function TButtonFlat.FGetTextWidth: Integer;
begin
FGettingTextWidth := True;
Paint;
Result := FTextWidth;
end;
procedure TButtonFlat.FOnDblClick(Sender: TObject);
begin
if DblClickTooClick then
Click;
end;
function TButtonFlat.GetColorNormal: TColor;
begin
Result := FColors[bfsNormal];
end;
function TButtonFlat.GetColorOver: TColor;
begin
Result := FColors[bfsOver];
end;
function TButtonFlat.GetColorPressed: TColor;
begin
Result := FColors[bfsPressed];
end;
procedure TButtonFlat.OnTimerAnimateTime(Sender: TObject);
begin
//if csFreeNotification in ComponentState then Exit;
if FTimerProcing then
Exit;
FTimerProcing := True;
Inc(FAnimPerc, 8);
if FAnimPerc >= 100 then
begin
FAnimPerc := 100;
StopAnimate;
StyledColor := NeedColor;
end
else
StyledColor := MixColors(NeedColor, FromColor, FAnimPerc);
FTimerProcing := False;
end;
procedure TButtonFlat.OnTimerAutoClickTime(Sender: TObject);
begin
//if csFreeNotification in ComponentState then Exit;
if FDowned then
begin
FTimerAutoClick.Interval := FAutoClick;
Click;
end
else
FTimerAutoClick.Enabled := False;
end;
procedure TButtonFlat.OnTimerTTTime(Sender: TObject);
begin
//if csFreeNotification in ComponentState then Exit;
Enabled := True;
FDrawTimedText := False;
FTimerTT.Enabled := False;
Repaint;
end;
type
TColorControl = class(TControl)
public
property Color;
end;
function GetColor(Control: TControl): TColor;
begin
if Assigned(Control) and (Control is TControl) then
begin
if (Control.HasParent) and TColorControl(Control).ParentColor then
Result := GetColor(Control.Parent)
else
Result := TColorControl(Control).Color;
end
else
Result := clDefault;
end;
procedure TButtonFlat.Paint;
var
X, Y, W, H, S, Rx: Integer;
FRect, FSubRect: TRect;
d: Double;
FDrawImg: Integer;
PaintTag: tagPAINTSTRUCT;
FText: string;
{$IFDEF FORXP}
Target: TCanvas;
{$ELSE}
Target: TDirect2DCanvas;
{$ENDIF}
begin
BeginPaint(Handle, PaintTag);
try
if FDrawTimedText then
FText := FTimedText
else
FText := FLabel;
case FButtonState of
bfsOver:
Canvas.Font.Assign(FontOver);
bfsPressed:
Canvas.Font.Assign(FontDown);
bfsNormal:
Canvas.Font.Assign(Font);
end;
{$IFNDEF FORXP}
Target := TDirect2DCanvas.Create(Canvas, ClientRect);
{$ELSE}
Target := Canvas;
{$ENDIF}
with Target do
begin
{$IFNDEF FORXP}
BeginDraw;
{$ENDIF}
Brush.Style := bsSolid;
if Assigned(Parent) and (Parent is TControl) then
begin
//TColorControl(Parent).ParentColor
if FBackgroundColor = clNone then
Brush.Color := GetColor(Parent)
else
Brush.Color := FBackgroundColor;
end
else
begin
if FBackgroundColor = clNone then
Brush.Color := ColorNormal
else
Brush.Color := FBackgroundColor;
end;
FillRect(ClientRect);
if Enabled then
Brush.Color := StyledColor
else
Brush.Color := GrayColor(StyledColor);
// Ïëîñêèé ñòèëü
if Flat then
Pen.Color := Brush.Color
else
begin
if FBorderColor = clNone then
Pen.Color := ColorDarker(StyledColor)
else
Pen.Color := FBorderColor;
Pen.Width := FBorderWidth;
end;
// Ôèãóðà
X := Pen.Width div 2;
Y := X;
W := Width - Pen.Width + 1;
H := Height - Pen.Width + 1;
if Pen.Width = 0 then
begin
Dec(W);
Dec(H);
end;
if W < H then
S := W
else
S := H;
if Shape in [stSquare, stRoundSquare, stCircle] then
begin
if W < H then
S := W
else
S := H;
Inc(X, (W - S) div 2);
W := S;
Inc(Y, (H - S) div 2);
H := S;
end;
// Åñëè íå ïðîçðà÷íàÿ êíîïêà, òî ðèñóåì ôèãóðó
if not FTransparent then
begin
case Shape of
stRectangle, stSquare:
Rectangle(X, Y, X + W, Y + H);
stRoundRect, stRoundSquare:
begin
if FRoundRectParam = 0 then
Rx := S div 4
else
Rx := FRoundRectParam;
if GroupItemKind = giCenter then
RoundRect(X, Y, X + W, Y + H, 0, 0)
else
RoundRect(X, Y, X + W, Y + H, Rx, Rx);
case GroupItemKind of
giLeft:
begin
FRect := Rect(X, Y, X + W, Y + H);
FRect.Offset(FRect.Width div 2 + 1, 0);
FRect.Width := FRect.Width div 2;
Rectangle(FRect);
FRect.Inflate(-1, -1);
FRect.Left := FRect.Left - 1;
FillRect(FRect);
FRect.Inflate(1, 1);
FRect.Left := FRect.Left + 1;
end;
giRight:
begin
FRect := Rect(X, Y, X + W, Y + H);
FRect.Width := FRect.Width - (FRect.Width div 2);
Rectangle(FRect);
FRect.Inflate(0, -1);
FRect.Left := FRect.Right - 1;
FillRect(FRect);
FRect.Inflate(0, 1);
FRect.Left := FRect.Right + 1;
end;
end;
end;
stCircle, stEllipse:
begin
FSubRect := Rect(X, Y, X + W, Y + H);
if FEllipseAnimate then
begin
if (FButtonState <> bfsPressed) and (FPrevState <> bfsPressed) then
FSubRect.Inflate(-Round(W / 100 * FAnimPerc), -Round(H / 100 * FAnimPerc));
end;
Ellipse(FSubRect);
end;
end;
end;
// Óâåäîìëåíèå
if FNotifyVisible then
begin
FRect := Rect(0, 0, FNotifyWidth, FNotifyWidth);
if Assigned(Images) then
FRect.SetLocation(Min(ImageIndentLeft + Images.Width - 4, ClientWidth - FNotifyWidth - 2),
(Height div 2 - Images.Height div 2) - 4)
else
FRect.SetLocation(FNotifyWidth div 2, FNotifyWidth div 2);
//if FText <> '' then FRect.Offset(Canvas.TextWidth(FText), 0);
Brush.Style := bsSolid;
Pen.Style := psSolid;
Pen.Color := FNotifyColor;
Brush.Color := FNotifyColor;
Ellipse(FRect);
end;
//
//Äîï. òåêñò
if FVisibleSubText then
begin
FSubRect := ClientRect;
FSubRect.Inflate(0, -(FSubRect.Height - (Canvas.TextHeight(FSubText) + 4)) div 2);
FSubRect.Width := Max(FSubRect.Height, Canvas.TextWidth(FSubText) + 10);
FSubRect.Offset(ClientRect.Right - FSubRect.Width - 10, 0);
Brush.Color := FSubTextColor;
if FSubTextColorBorder = clNone then
Pen.Color := FSubTextColor
else
Pen.Color := FSubTextColorBorder;
Pen.Width := FSubTextColorBorderDepth;
RoundRect(FSubRect, FSubRect.Height, FSubRect.Height);
end;
//
{$IFNDEF FORXP}
EndDraw;
Free;
{$ENDIF}
end;
//Ïðÿìîóãîëüíèê äëÿ òåêñòà
if FIgnorBounds then
FRect := ClientRect
else
begin
d := 1.6; //6.8
if FEllipseRectVertical then
FRect := Rect(Round(X + W / (6.8 / d)), Round(Y + H / (6.8 * d)), Round(X + W - W / (6.8 / d)),
Round(Y + H - H / (6.8 * d)))
else
FRect := Rect(Round(X + W / (6.8 * d)), Round(Y + H / (6.8 / d)), Round(X + W - W / (6.8 * d)),
Round(Y + H - H / (6.8 / d)));
end;
//Èçîáðàæåíèå
FRect.Offset(FImageIndentLeft, 0);
FRect.Width := FRect.Width - FImageIndentLeft;
if Assigned(FImages) and (FImageIndex >= 0) then
begin
FRect.Offset(FImages.Width + FImageIndentRight, 0);
FRect.Width := FRect.Width - FImages.Width + FImageIndentRight;
case FButtonState of
bfsNormal:
begin
FDrawImg := FImageIndex;
if IndexInList(FDrawImg, FImages.Count) then
FImages.Draw(Canvas, FImageIndentLeft, Height div 2 - FImages.Height div 2, FDrawImg, True);
end;
bfsOver:
begin
FDrawImg := FImageOver;
if FDrawImg < 0 then
FDrawImg := FImageIndex;
if Assigned(FImagesOver) then
begin
if IndexInList(FDrawImg, FImagesOver.Count) then
FImagesOver.Draw(Canvas, FImageIndentLeft, Height div 2 - FImagesOver.Height div 2, FDrawImg, True);
end
else
begin
if IndexInList(FDrawImg, FImages.Count) then
FImages.Draw(Canvas, FImageIndentLeft, Height div 2 - FImages.Height div 2, FDrawImg, True);
end;
end;
bfsPressed:
begin
FDrawImg := FImagePress;
if FDrawImg < 0 then
FDrawImg := FImageIndex;
if Assigned(FImagesPress) then
begin
if IndexInList(FDrawImg, FImagesPress.Count) then
FImagesPress.Draw(Canvas, FImageIndentLeft, Height div 2 - FImagesPress.Height div 2, FDrawImg, True);
end
else
begin
if IndexInList(FDrawImg, FImages.Count) then
FImages.Draw(Canvas, FImageIndentLeft, Height div 2 - FImages.Height div 2, FDrawImg, True);
end;
end;
end;
end;
// Òåêñò
Canvas.Brush.Color := clWhite;
Canvas.Brush.Style := bsClear;
if FShowCaption then
begin
Canvas.TextRect(FRect, FText, FTextFormat);
if FGettingTextWidth then
begin
FGettingTextWidth := False;
FTextWidth := Canvas.TextWidth(FText);
if Assigned(FImages) and (FImageIndex >= 0) then
begin
FTextWidth := FTextWidth + FImages.Width + FImageIndentLeft + FImageIndentRight;
end;
end;
end;
//Óìåíüøèì ðàçìåð äëÿ äîï òåêñòà
if FVisibleSubText then
begin
Canvas.Font.Assign(FSubTextFont);
Canvas.Brush.Style := bsClear;
Canvas.Font.Color := clWhite;
FSubRect.Offset(0, -1);
Canvas.TextRect(FSubRect, FSubText, [tfSingleLine, tfCenter, tfVerticalCenter]);
FRect.Right := Min(FRect.Right, FSubRect.Left);
end;
if Assigned(FOnPaint) then
FOnPaint(Self);
if FShowFocusRect and Focused then
begin
DrawFocusRect(Canvas.Handle, ClientRect);
end;
except
//
end;
EndPaint(Handle, PaintTag);
end;
procedure TButtonFlat.ShowPopup;
var
MP: TPoint;
begin
if Assigned(FPopup) then
begin
MP := ClientToScreen(Point(0, 0));
FPopup.Popup(MP.X, MP.Y + Height);
end;
end;
procedure TButtonFlat.SetAutoClick(const Value: Cardinal);
begin
FAutoClick := Value;
FTimerAutoClick.Interval := FAutoClick;
end;
procedure TButtonFlat.SetBackgroundColor(const Value: TColor);
begin
FBackgroundColor := Value;
end;
procedure TButtonFlat.SetBorderColor(const Value: TColor);
begin
FBorderColor := Value;
Repaint;
end;
procedure TButtonFlat.SetBorderWidth(const Value: Integer);
begin
if Value < 1 then
raise Exception.Create('Çíà÷åíèå äîëæíî áûòü áîëüøå 1');
FBorderWidth := Value;
Repaint;
end;
procedure TButtonFlat.SetButtonState(const Value: TButtonFlatState);
begin
FPrevState := FButtonState;
FButtonState := Value;
NeedColor := FColors[FButtonState];
end;
procedure TButtonFlat.SetColorNormal(const Value: TColor);
begin
FColors[bfsNormal] := Value;
ButtonState := ButtonState;
end;
procedure TButtonFlat.SetColorOver(const Value: TColor);
begin
FColors[bfsOver] := Value;
ButtonState := ButtonState;
end;
procedure TButtonFlat.SetColorPressed(const Value: TColor);
begin
FColors[bfsPressed] := Value;
ButtonState := ButtonState;
end;
procedure TButtonFlat.SetDblClickTooClick(const Value: Boolean);
begin
FDblClickTooClick := Value;
end;
procedure TButtonFlat.SetEllipseAnimate(const Value: Boolean);
begin
FEllipseAnimate := Value;
end;
procedure TButtonFlat.SetEllipseRectVertical(const Value: Boolean);
begin
FEllipseRectVertical := Value;
Repaint;
end;
procedure TButtonFlat.SetFlat(const Value: Boolean);
begin
FFlat := Value;
Repaint;
end;
procedure TButtonFlat.SetFontDown(const Value: TFont);
begin
FFontDown := Value;
Repaint;
end;
procedure TButtonFlat.SetFontOver(const Value: TFont);
begin
FFontOver := Value;
Repaint;
end;
procedure TButtonFlat.SetGroupItemKind(const Value: TButtonFlatGroupItem);
begin
FGroupItemKind := Value;
Repaint;
end;
procedure TButtonFlat.SetIgnorBounds(const Value: Boolean);
begin