source: trunk/Packages/bgracontrols/custombgraimagebutton.pas

Last change on this file was 2, checked in by chronos, 5 years ago
File size: 7.4 KB
Line 
1unit CustomBGRAImageButton;
2
3{$mode objfpc}{$H+}
4
5interface
6
7uses
8 Classes, Controls, Graphics{, Buttons}, Forms, LMessages, BGRABitmap, BGRABitmapTypes,
9 BGRATextFXTypes, types, ExtCtrls;
10
11{off $DEFINE DEBUG}
12
13type
14
15 TButtonState =
16 (
17 bsUp, // button is up
18 bsDisabled, // button disabled (grayed)
19 bsDown, // button is down
20 bsExclusive,// button is the only down in his group
21 bsHot // button is under mouse
22 );
23
24 TCustomBGRAImageButtonRedraw = procedure(Sender: TObject;
25 const ABGRA: TBGRABitmap; AState: TButtonState) of object;
26
27 TCustomBGRAImageButtonPlaySound = procedure(Sender: TObject;
28 const AFileName: string; AState: TButtonState) of object;
29
30 { TCustomResizeBitmap }
31
32 TCustomResizeBitmap = class(TPersistent)
33 protected
34 FOwner: TControl;
35 FBorderWidth: integer;
36 FBorderHeight: integer;
37 FDrawMode: TDrawMode;
38 FResampleMode: TResampleMode;
39 FResampleFilter: TResampleFilter;
40 FEnable: boolean deprecated;
41 FFillLeft: boolean;
42 FFillTop: boolean;
43 FFillRight: boolean;
44 FFillBottom: boolean;
45 FFillCenter: boolean;
46 procedure SetFBorderHeight(AValue: integer);
47 procedure SetFBorderWidth(AValue: integer);
48 procedure SetFDrawMode(AValue: TDrawMode);
49 procedure SetFEnable(AValue: boolean);
50 procedure SetFFillBottom(AValue: boolean);
51 procedure SetFFillCenter(AValue: boolean);
52 procedure SetFFillLeft(AValue: boolean);
53 procedure SetFFillRight(AValue: boolean);
54 procedure SetFFillTop(AValue: boolean);
55 procedure SetFResampleFilter(AValue: TResampleFilter);
56 procedure SetFResampleMode(AValue: TResampleMode);
57 public
58 constructor Create(AOwner: TControl);
59 destructor Destroy; override;
60 published
61 property BorderWidth: integer read FBorderWidth write SetFBorderWidth;
62 property BorderHeight: integer read FBorderHeight write SetFBorderHeight;
63 property DrawMode: TDrawMode read FDrawMode write SetFDrawMode;
64 property ResampleMode: TResampleMode read FResampleMode write SetFResampleMode;
65 property ResampleFilter: TResampleFilter read FResampleFilter
66 write SetFResampleFilter;
67 property Enable: boolean read FEnable write SetFEnable;
68 property FillLeft: boolean read FFillLeft write SetFFillLeft;
69 property FillTop: boolean read FFillTop write SetFFillTop;
70 property FillRight: boolean read FFillRight write SetFFillRight;
71 property FillBottom: boolean read FFillBottom write SetFFillBottom;
72 property FillCenter: boolean read FFillCenter write SetFFillCenter;
73 end;
74
75 { TCustomBGRAImageButton }
76
77 TCustomBGRAImageButton = class(TGraphicControl)
78 protected
79 FAnimation: boolean;
80 FAutoSizeExtraX: integer;
81 FAutoSizeExtraY: integer;
82 FBGRA: TBGRABitmap;
83 FBGRADisabled: TBGRABitmap;
84 FBGRADown: TBGRABitmap;
85 FBGRAHot: TBGRABitmap;
86 FBGRAText: TBGRABitmap;
87 FBGRAUp: TBGRABitmap;
88 FBitmapFile: string;
89 FBitmapOptions: TCustomResizeBitmap;
90 FBmp: TBitmap;
91 FBmpState: TButtonState;
92 FChecked: boolean;
93 FCheckedState: TButtonState;
94 FModalResult: TModalResult;
95 FOnPlaySound: TCustomBGRAImageButtonPlaySound;
96 FOnRedraw: TCustomBGRAImageButtonRedraw;
97 FShadow: TBGRATextEffectShadow;
98 FSound: boolean;
99 FSoundEnter, FSoundClick: string;
100 FTextVisible: boolean;
101 FTimer: TTimer;
102 FTimerIncreasing: boolean;
103 FTimerStep: integer;
104 FToggle: boolean;
105 {$IFDEF DEBUG}
106 FInvalidateCount, FUpdateCount, FUpdateCountTxt: integer;
107 {$ENDIF}
108 protected
109 procedure SetFAnimation(AValue: boolean); virtual;
110 procedure SetFAutoSizeExtraX(AValue: integer); virtual;
111 procedure SetFAutoSizeExtraY(AValue: integer); virtual;
112 procedure SetFBitmapFile(AValue: string); virtual;
113 procedure SetFBitmapOptions(AValue: TCustomResizeBitmap); virtual;
114 procedure SetFBmp(const AValue: TBitmap); virtual;
115 procedure SetFChecked(AValue: boolean); virtual;
116 procedure SetFTextVisible(AValue: boolean); virtual;
117 protected
118 procedure DoButtonDown; virtual;
119 procedure DoButtonEnter; virtual;
120 procedure DoButtonLeave; virtual;
121 procedure DoButtonUp; virtual;
122 protected
123 procedure Click; override;
124 procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
125 X, Y: integer); override;
126 procedure MouseEnter; override;
127 procedure MouseLeave; override;
128 procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: integer); override;
129 protected
130 procedure CalculatePreferredSize(var PreferredWidth, PreferredHeight: integer;
131 WithThemeSpace: boolean); override;
132 protected
133 procedure Animate(Sender: TObject); virtual;
134 procedure CMChanged(var Message: TLMessage); message CM_CHANGED; virtual;
135 procedure CMFontChanged(var Message: TLMessage); message CM_FONTCHANGED; virtual;
136 procedure DoPlaySound(AFileName: string); virtual;
137 procedure Paint; override;
138 procedure RealSetText(const Value: TCaption); override;
139 procedure UpdateBmp(Sender: TObject); virtual;
140 procedure UpdateTxt; virtual;
141 protected
142 property ABGRA: TBGRABitmap read FBGRA write FBGRA;
143 property ABGRADisabled: TBGRABitmap read FBGRADisabled write FBGRADisabled;
144 property ABGRADown: TBGRABitmap read FBGRADown write FBGRADown;
145 property ABGRAHot: TBGRABitmap read FBGRAHot write FBGRAHot;
146 property ABGRAText: TBGRABitmap read FBGRAText write FBGRA;
147 property ABGRAUp: TBGRABitmap read FBGRAUp write FBGRAUp;
148 property ABmpState: TButtonState read FBmpState write FBmpState;
149 property ACheckedState: TButtonState read FCheckedState write FCheckedState;
150 property ATimer: TTimer read FTimer write FTimer;
151 property ATimerIncreasing: boolean read FTimerIncreasing write FTimerIncreasing;
152 property ATimerStep: integer read FTimerStep write FTimerStep;
153 public
154 constructor Create(AOwner: TComponent); override;
155 destructor Destroy; override;
156 function BitmapLoadFromFile(AFileName: string): boolean; virtual;
157 function LoadFromFile(AFileName: string): boolean; virtual;
158 function SaveToFile(AFileName: string): boolean; virtual;
159 procedure Assign(Source: TPersistent); override;
160 public
161 property Animation: boolean read FAnimation write SetFAnimation default False;
162 property AutoSizeExtraHorizontal: integer
163 read FAutoSizeExtraX write SetFAutoSizeExtraX default 24;
164 property AutoSizeExtraVertical: integer read FAutoSizeExtraY
165 write SetFAutoSizeExtraY default 8;
166 property Bitmap: TBitmap read FBmp write SetFBmp;
167 property BitmapFile: string read FBitmapFile write SetFBitmapFile;
168 property BitmapOptions: TCustomResizeBitmap
169 read FBitmapOptions write SetFBitmapOptions;
170 property Checked: boolean read FChecked write SetFChecked default False;
171 property ModalResult: TModalResult
172 read FModalResult write FModalResult default mrNone;
173 property OnPlaySound: TCustomBGRAImageButtonPlaySound
174 read FOnPlaySound write FOnPlaySound;
175 property OnRedraw: TCustomBGRAImageButtonRedraw read FOnRedraw write FOnRedraw;
176 property Shadow: TBGRATextEffectShadow read FShadow write FShadow;
177 property Sound: boolean read FSound write FSound default False;
178 property SoundClick: string read FSoundClick write FSoundClick;
179 property SoundEnter: string read FSoundEnter write FSoundEnter;
180 property TextVisible: boolean read FTextVisible write SetFTextVisible default True;
181 property Toggle: boolean read FToggle write FToggle default False;
182 end;
183
184implementation
185
186{$I custombgraimagebutton.inc}
187
188end.
189
Note: See TracBrowser for help on using the repository browser.