1 | unit BGRAVirtualScreen;
|
---|
2 |
|
---|
3 | {$mode objfpc}{$H+}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs,
|
---|
9 | ExtCtrls, LMessages, BGRABitmap, BCTypes;
|
---|
10 |
|
---|
11 | type
|
---|
12 | { TCustomBGRAVirtualScreen }
|
---|
13 |
|
---|
14 | TCustomBGRAVirtualScreen = class(TCustomPanel)
|
---|
15 | private
|
---|
16 | { Private declarations }
|
---|
17 | FBGRA: TBGRABitmap;
|
---|
18 | FOnRedraw: TBGRARedrawEvent;
|
---|
19 | FBevelInner, FBevelOuter: TPanelBevel;
|
---|
20 | FBevelWidth: TBevelWidth;
|
---|
21 | FBorderWidth: TBorderWidth;
|
---|
22 | FAlignment: TAlignment;
|
---|
23 | procedure SetAlignment(const Value: TAlignment);
|
---|
24 | procedure SetBevelInner(const AValue: TPanelBevel);
|
---|
25 | procedure SetBevelOuter(const AValue: TPanelBevel);
|
---|
26 | procedure SetBevelWidth(const AValue: TBevelWidth);
|
---|
27 | procedure SetBorderWidth(const AValue: TBorderWidth);
|
---|
28 | protected
|
---|
29 | { Protected declarations }
|
---|
30 | procedure Paint; override;
|
---|
31 | procedure Resize; override;
|
---|
32 | procedure BGRASetSize(AWidth, AHeight: integer);
|
---|
33 | procedure RedrawBitmapContent; virtual;
|
---|
34 | procedure SetColor(Value: TColor); override;
|
---|
35 | procedure WMEraseBkgnd(var Message: TLMEraseBkgnd); message LM_ERASEBKGND;
|
---|
36 | procedure SetEnabled(Value: boolean); override;
|
---|
37 | public
|
---|
38 | { Public declarations }
|
---|
39 | constructor Create(TheOwner: TComponent); override;
|
---|
40 | procedure RedrawBitmap;
|
---|
41 | procedure DiscardBitmap;
|
---|
42 | destructor Destroy; override;
|
---|
43 | public
|
---|
44 | property OnRedraw: TBGRARedrawEvent Read FOnRedraw Write FOnRedraw;
|
---|
45 | property Bitmap: TBGRABitmap Read FBGRA;
|
---|
46 | property BorderWidth: TBorderWidth Read FBorderWidth Write SetBorderWidth default 0;
|
---|
47 | property BevelInner: TPanelBevel Read FBevelInner Write SetBevelInner default bvNone;
|
---|
48 | property BevelOuter: TPanelBevel Read FBevelOuter Write SetBevelOuter default bvNone;
|
---|
49 | property BevelWidth: TBevelWidth Read FBevelWidth Write SetBevelWidth default 1;
|
---|
50 | property Alignment: TAlignment Read FAlignment Write SetAlignment;
|
---|
51 | end;
|
---|
52 |
|
---|
53 | TBGRAVirtualScreen = class(TCustomBGRAVirtualScreen)
|
---|
54 | published
|
---|
55 | property OnRedraw;
|
---|
56 | property Bitmap;
|
---|
57 | // TPanel
|
---|
58 | property Align;
|
---|
59 | property Alignment;
|
---|
60 | property Anchors;
|
---|
61 | property AutoSize;
|
---|
62 | property BorderSpacing;
|
---|
63 | property BevelInner;
|
---|
64 | property BevelOuter;
|
---|
65 | property BevelWidth;
|
---|
66 | property BidiMode;
|
---|
67 | property BorderWidth;
|
---|
68 | property BorderStyle;
|
---|
69 | property Caption;
|
---|
70 | property ChildSizing;
|
---|
71 | property ClientHeight;
|
---|
72 | property ClientWidth;
|
---|
73 | property Color;
|
---|
74 | property Constraints;
|
---|
75 | property DockSite;
|
---|
76 | property DragCursor;
|
---|
77 | property DragKind;
|
---|
78 | property DragMode;
|
---|
79 | property Enabled;
|
---|
80 | property Font;
|
---|
81 | property FullRepaint;
|
---|
82 | property ParentBidiMode;
|
---|
83 | property ParentColor;
|
---|
84 | property ParentFont;
|
---|
85 | property ParentShowHint;
|
---|
86 | property PopupMenu;
|
---|
87 | property ShowHint;
|
---|
88 | property TabOrder;
|
---|
89 | property TabStop;
|
---|
90 | property UseDockManager default True;
|
---|
91 | property Visible;
|
---|
92 | property OnClick;
|
---|
93 | property OnContextPopup;
|
---|
94 | property OnDockDrop;
|
---|
95 | property OnDockOver;
|
---|
96 | property OnDblClick;
|
---|
97 | property OnDragDrop;
|
---|
98 | property OnDragOver;
|
---|
99 | property OnEndDock;
|
---|
100 | property OnEndDrag;
|
---|
101 | property OnEnter;
|
---|
102 | property OnExit;
|
---|
103 | property OnGetSiteInfo;
|
---|
104 | property OnGetDockCaption;
|
---|
105 | property OnMouseDown;
|
---|
106 | property OnMouseEnter;
|
---|
107 | property OnMouseLeave;
|
---|
108 | property OnMouseMove;
|
---|
109 | property OnMouseUp;
|
---|
110 | property OnResize;
|
---|
111 | property OnStartDock;
|
---|
112 | property OnStartDrag;
|
---|
113 | property OnUnDock;
|
---|
114 | end;
|
---|
115 |
|
---|
116 | procedure Register;
|
---|
117 |
|
---|
118 | implementation
|
---|
119 |
|
---|
120 | uses BGRABitmapTypes, Types;
|
---|
121 |
|
---|
122 | procedure Register;
|
---|
123 | begin
|
---|
124 | {$I bgravirtualscreen_icon.lrs}
|
---|
125 | RegisterComponents('BGRA Controls', [TBGRAVirtualScreen]);
|
---|
126 | end;
|
---|
127 |
|
---|
128 | { TCustomBGRAVirtualScreen }
|
---|
129 |
|
---|
130 | procedure TCustomBGRAVirtualScreen.SetAlignment(const Value: TAlignment);
|
---|
131 | begin
|
---|
132 | if FAlignment = Value then
|
---|
133 | exit;
|
---|
134 | FAlignment := Value;
|
---|
135 | DiscardBitmap;
|
---|
136 | end;
|
---|
137 |
|
---|
138 | procedure TCustomBGRAVirtualScreen.SetBevelInner(const AValue: TPanelBevel);
|
---|
139 | begin
|
---|
140 | if FBevelInner = AValue then
|
---|
141 | exit;
|
---|
142 | FBevelInner := AValue;
|
---|
143 | DiscardBitmap;
|
---|
144 | end;
|
---|
145 |
|
---|
146 | procedure TCustomBGRAVirtualScreen.SetBevelOuter(const AValue: TPanelBevel);
|
---|
147 | begin
|
---|
148 | if FBevelOuter = AValue then
|
---|
149 | exit;
|
---|
150 | FBevelOuter := AValue;
|
---|
151 | DiscardBitmap;
|
---|
152 | end;
|
---|
153 |
|
---|
154 | procedure TCustomBGRAVirtualScreen.SetBevelWidth(const AValue: TBevelWidth);
|
---|
155 | begin
|
---|
156 | if FBevelWidth = AValue then
|
---|
157 | exit;
|
---|
158 | FBevelWidth := AValue;
|
---|
159 | DiscardBitmap;
|
---|
160 | end;
|
---|
161 |
|
---|
162 | procedure TCustomBGRAVirtualScreen.SetBorderWidth(const AValue: TBorderWidth);
|
---|
163 | begin
|
---|
164 | if FBorderWidth = AValue then
|
---|
165 | exit;
|
---|
166 | FBorderWidth := AValue;
|
---|
167 | DiscardBitmap;
|
---|
168 | end;
|
---|
169 |
|
---|
170 | procedure TCustomBGRAVirtualScreen.Paint;
|
---|
171 | begin
|
---|
172 | {$IFDEF WINDOWS}
|
---|
173 | // to avoid flickering in Windows running without themes (classic style)
|
---|
174 | DoubleBuffered := ControlCount <> 0;
|
---|
175 | {$ENDIF}
|
---|
176 | BGRASetSize(Width, Height);
|
---|
177 | FBGRA.Draw(Canvas, 0, 0);
|
---|
178 | end;
|
---|
179 |
|
---|
180 | procedure TCustomBGRAVirtualScreen.Resize;
|
---|
181 | begin
|
---|
182 | inherited Resize;
|
---|
183 | DiscardBitmap;
|
---|
184 | end;
|
---|
185 |
|
---|
186 | procedure TCustomBGRAVirtualScreen.BGRASetSize(AWidth, AHeight: integer);
|
---|
187 | begin
|
---|
188 | if (FBGRA <> nil) and (AWidth <> FBGRA.Width) and (AHeight <> FBGRA.Height) then
|
---|
189 | begin
|
---|
190 | FBGRA.SetSize(AWidth, AHeight);
|
---|
191 | RedrawBitmapContent;
|
---|
192 | end;
|
---|
193 | end;
|
---|
194 |
|
---|
195 | procedure TCustomBGRAVirtualScreen.RedrawBitmapContent;
|
---|
196 | var
|
---|
197 | ARect: TRect;
|
---|
198 | TS: TTextStyle;
|
---|
199 | begin
|
---|
200 | if (FBGRA <> nil) and (FBGRA.NbPixels <> 0) then
|
---|
201 | begin
|
---|
202 | FBGRA.Fill(ColorToRGB(Color));
|
---|
203 |
|
---|
204 | ARect := GetClientRect;
|
---|
205 |
|
---|
206 | // if BevelOuter is set then draw a frame with BevelWidth
|
---|
207 | if (BevelOuter <> bvNone) and (BevelWidth > 0) then
|
---|
208 | FBGRA.CanvasBGRA.Frame3d(ARect, BevelWidth, BevelOuter,
|
---|
209 | BGRA(255, 255, 255, 200), BGRA(0, 0, 0, 160)); // Note: Frame3D inflates ARect
|
---|
210 |
|
---|
211 | InflateRect(ARect, -BorderWidth, -BorderWidth);
|
---|
212 |
|
---|
213 | // if BevelInner is set then skip the BorderWidth and draw a frame with BevelWidth
|
---|
214 | if (BevelInner <> bvNone) and (BevelWidth > 0) then
|
---|
215 | FBGRA.CanvasBGRA.Frame3d(ARect, BevelWidth, BevelInner,
|
---|
216 | BGRA(255, 255, 255, 160), BGRA(0, 0, 0, 160)); // Note: Frame3D inflates ARect
|
---|
217 |
|
---|
218 | if Caption <> '' then
|
---|
219 | begin
|
---|
220 | FBGRA.CanvasBGRA.Font.Assign(Canvas.Font);
|
---|
221 | TS := Canvas.TextStyle;
|
---|
222 | TS.Alignment := Alignment;
|
---|
223 | TS.Layout := tlTop;
|
---|
224 | TS.Opaque := False;
|
---|
225 | TS.Clipping := False;
|
---|
226 | TS.SystemFont := Canvas.Font.IsDefault;
|
---|
227 |
|
---|
228 | FBGRA.CanvasBGRA.Font.Color := Color xor $FFFFFF;
|
---|
229 |
|
---|
230 | if not Enabled then
|
---|
231 | FBGRA.CanvasBGRA.Font.Style := [fsStrikeOut]
|
---|
232 | else
|
---|
233 | FBGRA.CanvasBGRA.Font.Style := [];
|
---|
234 |
|
---|
235 | FBGRA.CanvasBGRA.TextRect(ARect, ARect.Left, ARect.Top, Caption, TS);
|
---|
236 | end;
|
---|
237 |
|
---|
238 | if Assigned(FOnRedraw) then
|
---|
239 | FOnRedraw(self, FBGRA);
|
---|
240 | end;
|
---|
241 | end;
|
---|
242 |
|
---|
243 | procedure TCustomBGRAVirtualScreen.SetColor(Value: TColor);
|
---|
244 | begin
|
---|
245 | if Value <> Color then
|
---|
246 | DiscardBitmap;
|
---|
247 | inherited SetColor(Value);
|
---|
248 | end;
|
---|
249 |
|
---|
250 | {$hints off}
|
---|
251 | procedure TCustomBGRAVirtualScreen.WMEraseBkgnd(var Message: TLMEraseBkgnd);
|
---|
252 | begin
|
---|
253 | //do nothing
|
---|
254 | end;
|
---|
255 |
|
---|
256 | {$hints on}
|
---|
257 |
|
---|
258 | procedure TCustomBGRAVirtualScreen.SetEnabled(Value: boolean);
|
---|
259 | begin
|
---|
260 | if Value <> Enabled then
|
---|
261 | DiscardBitmap;
|
---|
262 | inherited SetEnabled(Value);
|
---|
263 | end;
|
---|
264 |
|
---|
265 | constructor TCustomBGRAVirtualScreen.Create(TheOwner: TComponent);
|
---|
266 | begin
|
---|
267 | inherited Create(TheOwner);
|
---|
268 | FBGRA := TBGRABitmap.Create;
|
---|
269 | FBevelWidth := 1;
|
---|
270 | FAlignment := taLeftJustify;
|
---|
271 | Color := clWhite;
|
---|
272 | end;
|
---|
273 |
|
---|
274 | procedure TCustomBGRAVirtualScreen.RedrawBitmap;
|
---|
275 | begin
|
---|
276 | RedrawBitmapContent;
|
---|
277 | Repaint;
|
---|
278 | end;
|
---|
279 |
|
---|
280 | procedure TCustomBGRAVirtualScreen.DiscardBitmap;
|
---|
281 | begin
|
---|
282 | if (FBGRA <> nil) and (FBGRA.NbPixels <> 0) then
|
---|
283 | begin
|
---|
284 | FBGRA.SetSize(0, 0);
|
---|
285 | Invalidate;
|
---|
286 | end;
|
---|
287 | end;
|
---|
288 |
|
---|
289 | destructor TCustomBGRAVirtualScreen.Destroy;
|
---|
290 | begin
|
---|
291 | FBGRA.Free;
|
---|
292 | inherited Destroy;
|
---|
293 | end;
|
---|
294 |
|
---|
295 | end.
|
---|