-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
bcimagebutton.pas
1454 lines (1277 loc) · 40 KB
/
bcimagebutton.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
// SPDX-License-Identifier: LGPL-3.0-linking-exception
{
Created by BGRA Controls Team
Dibo, Circular, lainz (007) and contributors.
For detailed information see readme.txt
Site: https://sourceforge.net/p/bgra-controls/
Wiki: http://wiki.lazarus.freepascal.org/BGRAControls
Forum: http://forum.lazarus.freepascal.org/index.php/board,46.0.html
}
{******************************* CONTRIBUTOR(S) ******************************
- Edivando S. Santos Brasil | [email protected]
(Compatibility with delphi VCL 11/2018)
***************************** END CONTRIBUTOR(S) *****************************}
unit BCImageButton;
{$I bgracontrols.inc}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics,
{$IFDEF FPC}{$ifdef Windows}Windows,{$endif}LCLType, LResources, LMessages,{$ENDIF} ExtCtrls,
Types,
{$IFNDEF FPC}Windows, Messages, BGRAGraphics, GraphType, FPImage, {$ENDIF}
{ BGRAControls }
BCBaseCtrls, BCEffect,
{ BGRABitmap }
BGRABitmap, BGRABitmapTypes, BGRASliceScaling;
{off $DEFINE DEBUG}
function CalculateAspectRatioH(W1, H1, W2: integer): integer; //result H2
function CalculateAspectRatioW(W1, H1, H2: integer): integer; //result W2
function CalculateDestRect(ImageW, ImageH, DestW, DestH: integer;
Stretch, Proportional, Center: boolean): TRect;
procedure AssignFontToBGRA(Source: TFont; Dest: TBGRABitmap);
type
TBCGraphicButtonState = (gbsNormal, gbsHover, gbsActive, gbsDisabled);
TOnRenderControl = procedure(Sender: TObject; Bitmap: TBGRABitmap;
State: TBCGraphicButtonState) of object;
type
{ TBCGraphicButton }
TBCGraphicButton = class(TBCGraphicControl)
protected
FState: TBCGraphicButtonState;
FModalResult: TModalResult;
protected
procedure DoClick; virtual;
procedure DoMouseDown; virtual;
procedure DoMouseUp; virtual;
procedure DoMouseEnter; virtual;
procedure DoMouseLeave; virtual;
procedure DoMouseMove({%H-}x, {%H-}y: integer); virtual;
protected
procedure Click; override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: integer); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: integer); override;
procedure MouseEnter; override;
procedure MouseLeave; override;
procedure MouseMove(Shift: TShiftState; X,Y: Integer); override;
public
property ModalResult: TModalResult
read FModalResult write FModalResult default mrNone;
end;
{ TBCXButton }
TBCXButton = class(TBCGraphicButton)
protected
FOnRenderControl: TOnRenderControl;
FBGRANormal, FBGRAHover, FBGRAActive, FBGRADisabled: TBGRABitmap;
protected
class function GetControlClassDefaultSize: TSize; override;
procedure DrawControl; override;
procedure RenderControl; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property OnRenderControl: TOnRenderControl
read FOnRenderControl write FOnRenderControl;
published
property Action;
property Align;
property Anchors;
property AutoSize;
property BidiMode;
property BorderSpacing;
property Caption;
property Color;
property Constraints;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property Font;
property ParentBidiMode;
property ModalResult;
{$IFDEF FPC}
property OnChangeBounds;
{$ENDIF}
property OnClick;
property OnContextPopup;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnMouseDown;
property OnMouseEnter;
property OnMouseLeave;
property OnMouseMove;
property OnMouseUp;
property OnMouseWheel;
property OnMouseWheelDown;
property OnMouseWheelUp;
property OnResize;
property OnStartDrag;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property Visible;
end;
{ TBCSliceScalingOptions }
TBCCustomSliceScalingOptions = class(TPersistent)
protected
FOwner: TControl;
FBitmap: TBGRABitmap;
FAutoDetectRepeat, FRepeatTop, FRepeatLeft, FRepeatMiddleHorizontal,
FRepeatMiddleVertical, FRepeatRight, FRepeatBottom: boolean;
FMarginTop, FMarginRight, FMarginBottom, FMarginLeft, FNumberOfItems: integer;
FDirection: TSliceScalingDirection;
FDrawMode: TDrawMode;
FResampleMode: TResampleMode;
FResampleFilter: TResampleFilter;
private
procedure SetFBitmap(AValue: TBGRABitmap);
procedure SetFMarginBottom(AValue: integer);
procedure SetFMarginLeft(AValue: integer);
procedure SetFMarginRight(AValue: integer);
procedure SetFMarginTop(AValue: integer);
procedure SetFAutoDetectRepeat(AValue: boolean);
procedure SetFDirection(AValue: TSliceScalingDirection);
procedure SetFDrawMode(AValue: TDrawMode);
procedure SetFNumberOfItems(AValue: integer);
procedure SetFRepeatBottom(AValue: boolean);
procedure SetFRepeatLeft(AValue: boolean);
procedure SetFRepeatMiddleHorizontal(AValue: boolean);
procedure SetFRepeatMiddleVertical(AValue: boolean);
procedure SetFRepeatRight(AValue: boolean);
procedure SetFRepeatTop(AValue: boolean);
procedure SetFResampleFilter(AValue: TResampleFilter);
procedure SetFResampleMode(AValue: TResampleMode);
public
constructor Create(AOwner: TControl);
destructor Destroy; override;
published
property Bitmap: TBGRABitmap read FBitmap write SetFBitmap;
property AutoDetectRepeat: boolean read FAutoDetectRepeat
write SetFAutoDetectRepeat default False;
property RepeatTop: boolean read FRepeatTop write SetFRepeatTop default False;
property RepeatLeft: boolean read FRepeatLeft write SetFRepeatLeft default False;
property RepeatMiddleHorizontal: boolean
read FRepeatMiddleHorizontal write SetFRepeatMiddleHorizontal default False;
property RepeatMiddleVertical: boolean read FRepeatMiddleVertical
write SetFRepeatMiddleVertical default False;
property RepeatRight: boolean read FRepeatRight write SetFRepeatRight default False;
property RepeatBottom: boolean
read FRepeatBottom write SetFRepeatBottom default False;
property MarginTop: integer read FMarginTop write SetFMarginTop default 0;
property MarginRight: integer read FMarginRight write SetFMarginRight default 0;
property MarginBottom: integer read FMarginBottom write SetFMarginBottom default 0;
property MarginLeft: integer read FMarginLeft write SetFMarginLeft default 0;
property NumberOfItems: integer
read FNumberOfItems write SetFNumberOfItems default 1;
property Direction: TSliceScalingDirection read FDirection write SetFDirection;
property DrawMode: TDrawMode read FDrawMode write SetFDrawMode default
dmDrawWithTransparency;
property ResampleMode: TResampleMode read FResampleMode
write SetFResampleMode default rmFineResample;
property ResampleFilter: TResampleFilter read FResampleFilter
write SetFResampleFilter default rfBestQuality;
end;
{ TBCImageButtonSliceScalingOptions }
TBCImageButtonSliceScalingOptions = class(TBCCustomSliceScalingOptions)
private
procedure SetFCenter(AValue: boolean);
procedure SetFProportional(AValue: boolean);
procedure SetFStretch(AValue: boolean);
protected
FCenter, FStretch, FProportional: boolean;
published
property NumberOfItems: integer read FNumberOfItems default 4;
property Center: boolean read FCenter write SetFCenter default True;
property Stretch: boolean read FStretch write SetFStretch default True;
property Proportional: boolean
read FProportional write SetFProportional default False;
public
constructor Create(AOwner: TControl);
procedure Assign(Source: TPersistent); override;
end;
{ TBCCustomImageButton }
TBCCustomImageButton = class(TBCGraphicButton)
private
{ Private declarations }
FAlphaTest: boolean;
FAlphaTestValue: byte;
{$IFDEF INDEBUG}
FDrawCount: integer;
FRenderCount: integer;
{$ENDIF}
FBitmapOptions: TBCImageButtonSliceScalingOptions;
FBGRAMultiSliceScaling: TBGRAMultiSliceScaling;
FBGRANormal, FBGRAHover, FBGRAActive, FBGRADisabled: TBGRABitmap;
FDestRect: TRect;
FPressed: boolean;
FTimer: TTimer;
FFade: TFading;
FAnimation: boolean;
FBitmapFile: string;
FTextVisible: boolean;
FToggle: boolean;
FMouse: TPoint;
procedure SetFAlphaTest(AValue: boolean);
procedure SetFAlphaTestValue(AValue: byte);
procedure SetFAnimation(AValue: boolean);
procedure SetFBitmapFile(AValue: string);
procedure SetFBitmapOptions(AValue: TBCImageButtonSliceScalingOptions);
procedure Fade({%H-}Sender: TObject);
procedure SetFPressed(AValue: boolean);
procedure SetFTextVisible(AValue: boolean);
procedure SetFToggle(AValue: boolean);
protected
{ Protected declarations }
procedure DrawControl; override;
procedure RenderControl; override;
procedure TextChanged; override;
procedure FontChanged(Sender: TObject); override;
procedure CMChanged(var {%H-}Message: {$IFDEF FPC}TLMessage{$ELSE}TMessage{$ENDIF}); message CM_CHANGED; {$IFDEF FPC}virtual;{$ENDIF}
{$IFDEF INDEBUG}
{$IFDEF FPC}
function GetDebugText: string;
{$ENDIF}
{$ENDIF}
procedure DoMouseDown; override;
procedure DoMouseUp; override;
procedure DoMouseEnter; override;
procedure DoMouseLeave; override;
procedure DoMouseMove(x, y: integer); override;
procedure Click; override;
public
{ Public declarations }
property AlphaTest: boolean read FAlphaTest write SetFAlphaTest default True;
property AlphaTestValue: byte
read FAlphaTestValue write SetFAlphaTestValue default 255;
property Toggle: boolean read FToggle write SetFToggle default False;
property Pressed: boolean read FPressed write SetFPressed default False;
//property State: TBCGraphicButtonState read FState;
property BitmapOptions: TBCImageButtonSliceScalingOptions
read FBitmapOptions write SetFBitmapOptions;
property Animation: boolean read FAnimation write SetFAnimation default True;
property BitmapFile: string read FBitmapFile write SetFBitmapFile;
property TextVisible: boolean read FTextVisible write SetFTextVisible default True;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
{ It loads the 'BitmapFile' }
procedure LoadFromBitmapResource(const Resource: string; ResourceType: PChar); overload;
procedure LoadFromBitmapResource(const Resource: string); overload;
procedure LoadFromBitmapFile;
procedure Assign(Source: TPersistent); override;
{ Streaming }
{$IFDEF FPC}
procedure SaveToFile(AFileName: string); override;
procedure LoadFromFile(AFileName: string); override;
procedure AssignFromFile(AFileName: string); override;
{$ENDIF}
procedure OnFindClass({%H-}Reader: TReader; const AClassName: string;
var ComponentClass: TComponentClass);
published
{ Published declarations }
end;
TBCImageButton = class(TBCCustomImageButton)
published
property AlphaTest;
property AlphaTestValue;
property Action;
property Align;
property Anchors;
property Animation;
property AutoSize;
//property AutoSizeExtraHorizontal;
//property AutoSizeExtraVertical;
property BidiMode;
//property Bitmap;
property BitmapFile;
property BitmapOptions;
property BorderSpacing;
property Caption;
//property Checked;
property Color;
property Constraints;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property Font;
property ModalResult;
{$IFDEF FPC}
property OnChangeBounds;
{$ENDIF}
property OnClick;
property OnContextPopup;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnMouseEnter;
property OnMouseLeave;
property OnMouseWheel;
property OnMouseWheelDown;
property OnMouseWheelUp;
//property OnPlaySound;
//property OnRedraw;
property OnResize;
property OnStartDrag;
property ParentBidiMode;
property ParentFont;
property ParentShowHint;
property PopupMenu;
//property Shadow;
property ShowHint;
//property Sound;
//property SoundClick;
//property SoundEnter;
property TextVisible;
property Toggle;
property Pressed;
property Visible;
end;
{$IFDEF FPC}procedure Register;{$ENDIF}
implementation
{$IFDEF FPC}procedure Register;
begin
RegisterComponents('BGRA Button Controls', [TBCImageButton]);
RegisterComponents('BGRA Button Controls', [TBCXButton]);
end;
{$ENDIF}
function CalculateAspectRatioH(W1, H1, W2: integer): integer;
begin
Result := Round(H1 / W1 * W2);
end;
function CalculateAspectRatioW(W1, H1, H2: integer): integer;
begin
Result := Round(W1 / H1 * H2);
end;
function CalculateDestRect(ImageW, ImageH, DestW, DestH: integer;
Stretch, Proportional, Center: boolean): TRect;
var
w: integer;
h: integer;
begin
// Stretch or Proportional when Image (Width or Height) is bigger than Destination
if Stretch or (Proportional and ((ImageW > DestW) or (ImageH > DestH))) then
begin
// Proportional when Image (Width or Height) is bigger than 0
if Proportional and (ImageW > 0) and (ImageH > 0) then
begin
w := DestW;
h := CalculateAspectRatioH(ImageW, ImageH, DestW);
if h > DestH then
begin
h := DestH;
w := CalculateAspectRatioW(ImageW, ImageH, DestH);
end;
ImageW := w;
ImageH := h;
end
// Stretch not Proportional or when Image (Width or Height) is 0
else
begin
ImageW := DestW;
ImageH := DestH;
end;
end;
Result := Rect(0, 0, ImageW, ImageH);
// Center: Destination (Width or Height) - Image divided by 2
if Center then
begin
Result.Left := Round((DestW - ImageW) div 2);
Result.Top := Round((DestH - ImageH) div 2);
end;
end;
procedure AssignFontToBGRA(Source: TFont; Dest: TBGRABitmap);
begin
Dest.FontAntialias := True;
Dest.FontName := Source.Name;
Dest.FontStyle := Source.Style;
Dest.FontOrientation := Source.Orientation;
case Source.Quality of
fqNonAntialiased: Dest.FontQuality := fqSystem;
fqAntialiased: Dest.FontQuality := fqFineAntialiasing;
fqProof: Dest.FontQuality := fqFineClearTypeRGB;
fqDefault, fqDraft, fqCleartype, fqCleartypeNatural: Dest.FontQuality :=
fqSystemClearType;
end;
Dest.FontHeight := -Source.Height;
end;
{ TBCXButton }
class function TBCXButton.GetControlClassDefaultSize: TSize;
begin
Result := inherited GetControlClassDefaultSize;
end;
procedure TBCXButton.DrawControl;
begin
if Enabled then
case FState of
gbsNormal: FBGRANormal.Draw(Canvas, 0, 0, False);
gbsHover: FBGRAHover.Draw(Canvas, 0, 0, False);
gbsActive: FBGRAActive.Draw(Canvas, 0, 0, False);
end
else
FBGRADisabled.Draw(Canvas, 0, 0, False);
end;
procedure TBCXButton.RenderControl;
begin
{ Free cache bitmaps }
if FBGRANormal <> nil then
FreeAndNil(FBGRANormal);
if FBGRAHover <> nil then
FreeAndNil(FBGRAHover);
if FBGRAActive <> nil then
FreeAndNil(FBGRAActive);
if FBGRADisabled <> nil then
FreeAndNil(FBGRADisabled);
{ Create cache bitmaps }
FBGRANormal := TBGRABitmap.Create(Width, Height);
FBGRAHover := TBGRABitmap.Create(Width, Height);
FBGRAActive := TBGRABitmap.Create(Width, Height);
FBGRADisabled := TBGRABitmap.Create(Width, Height);
if Assigned(FOnRenderControl) then
begin
FOnRenderControl(Self, FBGRANormal, gbsNormal);
FOnRenderControl(Self, FBGRAHover, gbsHover);
FOnRenderControl(Self, FBGRAActive, gbsActive);
FOnRenderControl(Self, FBGRADisabled, gbsDisabled);
end;
end;
constructor TBCXButton.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
with GetControlClassDefaultSize do
SetInitialBounds(0, 0, CX, CY);
end;
destructor TBCXButton.Destroy;
begin
if FBGRANormal <> nil then
FreeAndNil(FBGRANormal);
if FBGRAHover <> nil then
FreeAndNil(FBGRAHover);
if FBGRAActive <> nil then
FreeAndNil(FBGRAActive);
if FBGRADisabled <> nil then
FreeAndNil(FBGRADisabled);
inherited Destroy;
end;
{ TBCImageButtonSliceScalingOptions }
procedure TBCImageButtonSliceScalingOptions.SetFCenter(AValue: boolean);
begin
if FCenter = AValue then
Exit;
FCenter := AValue;
FOwner.Perform(CM_CHANGED, 0, 0);
FOwner.Invalidate;
end;
procedure TBCImageButtonSliceScalingOptions.SetFProportional(AValue: boolean);
begin
if FProportional = AValue then
Exit;
FProportional := AValue;
FOwner.Perform(CM_CHANGED, 0, 0);
FOwner.Invalidate;
end;
procedure TBCImageButtonSliceScalingOptions.SetFStretch(AValue: boolean);
begin
if FStretch = AValue then
Exit;
FStretch := AValue;
FOwner.Perform(CM_CHANGED, 0, 0);
FOwner.Invalidate;
end;
constructor TBCImageButtonSliceScalingOptions.Create(AOwner: TControl);
begin
inherited Create(AOwner);
FNumberOfItems := 4;
FCenter := True;
FProportional := False;
FStretch := True;
end;
procedure TBCImageButtonSliceScalingOptions.Assign(Source: TPersistent);
begin
if Source is TBCImageButtonSliceScalingOptions then
begin
FAutoDetectRepeat := TBCImageButtonSliceScalingOptions(Source).AutoDetectRepeat;
FCenter := TBCImageButtonSliceScalingOptions(Source).Center;
FRepeatTop := TBCImageButtonSliceScalingOptions(Source).RepeatTop;
FRepeatLeft := TBCImageButtonSliceScalingOptions(Source).RepeatLeft;
FRepeatMiddleHorizontal :=
TBCImageButtonSliceScalingOptions(Source).RepeatMiddleHorizontal;
FRepeatMiddleVertical := TBCImageButtonSliceScalingOptions(
Source).RepeatMiddleVertical;
FRepeatRight := TBCImageButtonSliceScalingOptions(Source).RepeatRight;
FRepeatBottom := TBCImageButtonSliceScalingOptions(Source).RepeatBottom;
FMarginTop := TBCImageButtonSliceScalingOptions(Source).MarginTop;
FMarginRight := TBCImageButtonSliceScalingOptions(Source).MarginRight;
FMarginBottom := TBCImageButtonSliceScalingOptions(Source).MarginBottom;
FMarginLeft := TBCImageButtonSliceScalingOptions(Source).MarginLeft;
FDirection := TBCImageButtonSliceScalingOptions(Source).Direction;
FDrawMode := TBCImageButtonSliceScalingOptions(Source).DrawMode;
FResampleMode := TBCImageButtonSliceScalingOptions(Source).ResampleMode;
FResampleFilter := TBCImageButtonSliceScalingOptions(Source).ResampleFilter;
FStretch := TBCImageButtonSliceScalingOptions(Source).Stretch;
FProportional := TBCImageButtonSliceScalingOptions(Source).Proportional;
end
else
inherited Assign(Source);
end;
{ TBCCustomSliceScalingOptions }
procedure TBCCustomSliceScalingOptions.SetFBitmap(AValue: TBGRABitmap);
begin
if FBitmap = AValue then
Exit;
FBitmap := AValue;
FOwner.Perform(CM_CHANGED, 0, 0);
FOwner.Invalidate;
end;
procedure TBCCustomSliceScalingOptions.SetFMarginBottom(AValue: integer);
begin
if FMarginBottom = AValue then
Exit;
FMarginBottom := AValue;
FOwner.Perform(CM_CHANGED, 0, 0);
FOwner.Invalidate;
end;
procedure TBCCustomSliceScalingOptions.SetFMarginLeft(AValue: integer);
begin
if FMarginLeft = AValue then
Exit;
FMarginLeft := AValue;
FOwner.Perform(CM_CHANGED, 0, 0);
FOwner.Invalidate;
end;
procedure TBCCustomSliceScalingOptions.SetFMarginRight(AValue: integer);
begin
if FMarginRight = AValue then
Exit;
FMarginRight := AValue;
FOwner.Perform(CM_CHANGED, 0, 0);
FOwner.Invalidate;
end;
procedure TBCCustomSliceScalingOptions.SetFMarginTop(AValue: integer);
begin
if FMarginTop = AValue then
Exit;
FMarginTop := AValue;
FOwner.Perform(CM_CHANGED, 0, 0);
FOwner.Invalidate;
end;
procedure TBCCustomSliceScalingOptions.SetFAutoDetectRepeat(AValue: boolean);
begin
if FAutoDetectRepeat = AValue then
Exit;
FAutoDetectRepeat := AValue;
FOwner.Perform(CM_CHANGED, 0, 0);
FOwner.Invalidate;
end;
procedure TBCCustomSliceScalingOptions.SetFDirection(AValue: TSliceScalingDirection);
begin
if FDirection = AValue then
Exit;
FDirection := AValue;
FOwner.Perform(CM_CHANGED, 0, 0);
FOwner.Invalidate;
end;
procedure TBCCustomSliceScalingOptions.SetFDrawMode(AValue: TDrawMode);
begin
if FDrawMode = AValue then
Exit;
FDrawMode := AValue;
FOwner.Perform(CM_CHANGED, 0, 0);
FOwner.Invalidate;
end;
procedure TBCCustomSliceScalingOptions.SetFNumberOfItems(AValue: integer);
begin
if FNumberOfItems = AValue then
Exit;
FNumberOfItems := AValue;
end;
procedure TBCCustomSliceScalingOptions.SetFRepeatBottom(AValue: boolean);
begin
if FRepeatBottom = AValue then
Exit;
FRepeatBottom := AValue;
FOwner.Perform(CM_CHANGED, 0, 0);
FOwner.Invalidate;
end;
procedure TBCCustomSliceScalingOptions.SetFRepeatLeft(AValue: boolean);
begin
if FRepeatLeft = AValue then
Exit;
FRepeatLeft := AValue;
FOwner.Perform(CM_CHANGED, 0, 0);
FOwner.Invalidate;
end;
procedure TBCCustomSliceScalingOptions.SetFRepeatMiddleHorizontal(AValue: boolean);
begin
if FRepeatMiddleHorizontal = AValue then
Exit;
FRepeatMiddleHorizontal := AValue;
FOwner.Perform(CM_CHANGED, 0, 0);
FOwner.Invalidate;
end;
procedure TBCCustomSliceScalingOptions.SetFRepeatMiddleVertical(AValue: boolean);
begin
if FRepeatMiddleVertical = AValue then
Exit;
FRepeatMiddleVertical := AValue;
FOwner.Perform(CM_CHANGED, 0, 0);
FOwner.Invalidate;
end;
procedure TBCCustomSliceScalingOptions.SetFRepeatRight(AValue: boolean);
begin
if FRepeatRight = AValue then
Exit;
FRepeatRight := AValue;
FOwner.Perform(CM_CHANGED, 0, 0);
FOwner.Invalidate;
end;
procedure TBCCustomSliceScalingOptions.SetFRepeatTop(AValue: boolean);
begin
if FRepeatTop = AValue then
Exit;
FRepeatTop := AValue;
FOwner.Perform(CM_CHANGED, 0, 0);
FOwner.Invalidate;
end;
procedure TBCCustomSliceScalingOptions.SetFResampleFilter(AValue: TResampleFilter);
begin
if FResampleFilter = AValue then
Exit;
FResampleFilter := AValue;
FOwner.Perform(CM_CHANGED, 0, 0);
FOwner.Invalidate;
end;
procedure TBCCustomSliceScalingOptions.SetFResampleMode(AValue: TResampleMode);
begin
if FResampleMode = AValue then
Exit;
FResampleMode := AValue;
FOwner.Perform(CM_CHANGED, 0, 0);
FOwner.Invalidate;
end;
constructor TBCCustomSliceScalingOptions.Create(AOwner: TControl);
begin
FOwner := AOwner;
FBitmap := nil;
FAutoDetectRepeat := False;
FRepeatTop := False;
FRepeatLeft := False;
FRepeatMiddleHorizontal := False;
FRepeatMiddleVertical := False;
FRepeatRight := False;
FRepeatBottom := False;
FMarginTop := 0;
FMarginRight := 0;
FMarginBottom := 0;
FMarginLeft := 0;
FNumberOfItems := 1;
FDirection := sdVertical;
FDrawMode := dmDrawWithTransparency;
FResampleMode := rmFineResample;
FResampleFilter := rfBestQuality;
inherited Create;
end;
destructor TBCCustomSliceScalingOptions.Destroy;
begin
if FBitmap <> nil then
FreeAndNil(FBitmap);
inherited Destroy;
end;
{ TBCGraphicButton }
procedure TBCGraphicButton.DoClick;
var
Form: TCustomForm;
begin
if ModalResult <> mrNone then
begin
Form := GetParentForm(Self);
if Form <> nil then
Form.ModalResult := ModalResult;
end;
end;
procedure TBCGraphicButton.DoMouseDown;
var
NewState: TBCGraphicButtonState;
begin
NewState := gbsActive;
if NewState <> FState then
begin
FState := NewState;
Invalidate;
end;
end;
procedure TBCGraphicButton.DoMouseUp;
var
NewState: TBCGraphicButtonState;
p: TPoint;
begin
p := ScreenToClient(Mouse.CursorPos);
if (p.x >= 0) and (p.x <= Width) and (p.y >= 0) and (p.y <= Height) then
NewState := gbsHover
else
NewState := gbsNormal;
if NewState <> FState then
begin
FState := NewState;
Invalidate;
end;
end;
procedure TBCGraphicButton.DoMouseEnter;
var
NewState: TBCGraphicButtonState;
begin
if Enabled then
NewState := gbsHover
else
begin
FState := gbsNormal;
NewState := FState;
end;
if NewState <> FState then
begin
FState := NewState;
Invalidate;
end;
end;
procedure TBCGraphicButton.DoMouseLeave;
var
NewState: TBCGraphicButtonState;
begin
if Enabled then
NewState := gbsNormal
else
begin
FState := gbsNormal;
NewState := FState;
end;
if NewState <> FState then
begin
FState := NewState;
Invalidate;
end;
end;
procedure TBCGraphicButton.DoMouseMove(x, y: integer);
begin
inherited;
end;
procedure TBCGraphicButton.Click;
begin
DoClick;
inherited Click;
end;
procedure TBCGraphicButton.MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: integer);
begin
inherited MouseDown(Button, Shift, X, Y);
if Button = mbLeft then
DoMouseDown;
end;
procedure TBCGraphicButton.MouseUp(Button: TMouseButton; Shift: TShiftState;
X, Y: integer);
begin
inherited MouseUp(Button, Shift, X, Y);
DoMouseUp;
end;
procedure TBCGraphicButton.MouseEnter;
begin
inherited MouseEnter;
DoMouseEnter;
end;
procedure TBCGraphicButton.MouseLeave;
begin
inherited MouseLeave;
DoMouseLeave;
end;
procedure TBCGraphicButton.MouseMove(Shift: TShiftState; X, Y: Integer);
begin
inherited MouseMove(Shift, X, Y);
DoMouseMove(X, Y);
end;
{ TBCCustomImageButton }
procedure TBCCustomImageButton.Fade(Sender: TObject);
begin
if FFade.Mode <> fmSuspended then
Invalidate;
if csDesigning in ComponentState then
Exit;
FTimer.Enabled := FAnimation;
end;
procedure TBCCustomImageButton.SetFPressed(AValue: boolean);
begin
if FPressed = AValue then
Exit;
FPressed := AValue;
RenderControl;
end;
procedure TBCCustomImageButton.SetFTextVisible(AValue: boolean);
begin
if FTextVisible = AValue then
Exit;
FTextVisible := AValue;
RenderControl;
end;
procedure TBCCustomImageButton.SetFToggle(AValue: boolean);
begin
if FToggle = AValue then
Exit;
FToggle := AValue;
end;
procedure TBCCustomImageButton.SetFBitmapOptions(AValue:
TBCImageButtonSliceScalingOptions);
begin
if FBitmapOptions = AValue then
Exit;
FBitmapOptions := AValue;
end;
procedure TBCCustomImageButton.SetFAlphaTest(AValue: boolean);
begin
if FAlphaTest = AValue then
Exit;
FAlphaTest := AValue;
end;
procedure TBCCustomImageButton.SetFAlphaTestValue(AValue: byte);
begin
if FAlphaTestValue = AValue then
Exit;
FAlphaTestValue := AValue;
end;
procedure TBCCustomImageButton.SetFAnimation(AValue: boolean);
begin
if FAnimation = AValue then
Exit;
FAnimation := AValue;
if csDesigning in ComponentState then Exit;
FTimer.Enabled := FAnimation;
end;
procedure TBCCustomImageButton.SetFBitmapFile(AValue: string);
begin
if FBitmapFile = AValue then
Exit;
FBitmapFile := AValue;
end;
procedure TBCCustomImageButton.DrawControl;
var
temp: TBGRABitmap;
begin
{$IFNDEF FPC}//# //@ IN DELPHI RenderControl NEDD. IF NO RenderControl BE BLACK AFTER INVALIDATE.
RenderControl;
{$ENDIF}
if Color <> clDefault then
begin
Canvas.Brush.Color := Color;
Canvas.FillRect(Rect(0, 0, Width, Height));
end;
if Enabled then
begin
if (Toggle) then
begin
if (Pressed) then
FBGRAActive.Draw(Canvas, FDestRect.Left, FDestRect.Top, False)
else
case FState of
gbsHover: FBGRAHover.Draw(Canvas, FDestRect.Left,
FDestRect.Top, False);
else
FBGRANormal.Draw(Canvas, FDestRect.Left,