source: trunk/Packages/bgracontrols/bgravirtualscreen.pas

Last change on this file was 2, checked in by chronos, 5 years ago
File size: 7.7 KB
Line 
1unit BGRAVirtualScreen;
2
3{$mode objfpc}{$H+}
4
5interface
6
7uses
8 Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs,
9 ExtCtrls, LMessages, BGRABitmap, BCTypes;
10
11type
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
116procedure Register;
117
118implementation
119
120uses BGRABitmapTypes, Types;
121
122procedure Register;
123begin
124 {$I bgravirtualscreen_icon.lrs}
125 RegisterComponents('BGRA Controls', [TBGRAVirtualScreen]);
126end;
127
128{ TCustomBGRAVirtualScreen }
129
130procedure TCustomBGRAVirtualScreen.SetAlignment(const Value: TAlignment);
131begin
132 if FAlignment = Value then
133 exit;
134 FAlignment := Value;
135 DiscardBitmap;
136end;
137
138procedure TCustomBGRAVirtualScreen.SetBevelInner(const AValue: TPanelBevel);
139begin
140 if FBevelInner = AValue then
141 exit;
142 FBevelInner := AValue;
143 DiscardBitmap;
144end;
145
146procedure TCustomBGRAVirtualScreen.SetBevelOuter(const AValue: TPanelBevel);
147begin
148 if FBevelOuter = AValue then
149 exit;
150 FBevelOuter := AValue;
151 DiscardBitmap;
152end;
153
154procedure TCustomBGRAVirtualScreen.SetBevelWidth(const AValue: TBevelWidth);
155begin
156 if FBevelWidth = AValue then
157 exit;
158 FBevelWidth := AValue;
159 DiscardBitmap;
160end;
161
162procedure TCustomBGRAVirtualScreen.SetBorderWidth(const AValue: TBorderWidth);
163begin
164 if FBorderWidth = AValue then
165 exit;
166 FBorderWidth := AValue;
167 DiscardBitmap;
168end;
169
170procedure TCustomBGRAVirtualScreen.Paint;
171begin
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);
178end;
179
180procedure TCustomBGRAVirtualScreen.Resize;
181begin
182 inherited Resize;
183 DiscardBitmap;
184end;
185
186procedure TCustomBGRAVirtualScreen.BGRASetSize(AWidth, AHeight: integer);
187begin
188 if (FBGRA <> nil) and (AWidth <> FBGRA.Width) and (AHeight <> FBGRA.Height) then
189 begin
190 FBGRA.SetSize(AWidth, AHeight);
191 RedrawBitmapContent;
192 end;
193end;
194
195procedure TCustomBGRAVirtualScreen.RedrawBitmapContent;
196var
197 ARect: TRect;
198 TS: TTextStyle;
199begin
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;
241end;
242
243procedure TCustomBGRAVirtualScreen.SetColor(Value: TColor);
244begin
245 if Value <> Color then
246 DiscardBitmap;
247 inherited SetColor(Value);
248end;
249
250{$hints off}
251procedure TCustomBGRAVirtualScreen.WMEraseBkgnd(var Message: TLMEraseBkgnd);
252begin
253 //do nothing
254end;
255
256{$hints on}
257
258procedure TCustomBGRAVirtualScreen.SetEnabled(Value: boolean);
259begin
260 if Value <> Enabled then
261 DiscardBitmap;
262 inherited SetEnabled(Value);
263end;
264
265constructor TCustomBGRAVirtualScreen.Create(TheOwner: TComponent);
266begin
267 inherited Create(TheOwner);
268 FBGRA := TBGRABitmap.Create;
269 FBevelWidth := 1;
270 FAlignment := taLeftJustify;
271 Color := clWhite;
272end;
273
274procedure TCustomBGRAVirtualScreen.RedrawBitmap;
275begin
276 RedrawBitmapContent;
277 Repaint;
278end;
279
280procedure TCustomBGRAVirtualScreen.DiscardBitmap;
281begin
282 if (FBGRA <> nil) and (FBGRA.NbPixels <> 0) then
283 begin
284 FBGRA.SetSize(0, 0);
285 Invalidate;
286 end;
287end;
288
289destructor TCustomBGRAVirtualScreen.Destroy;
290begin
291 FBGRA.Free;
292 inherited Destroy;
293end;
294
295end.
Note: See TracBrowser for help on using the repository browser.