forked from bgrabitmap/bgragames
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbgpanel.pas
More file actions
143 lines (118 loc) · 2.74 KB
/
bgpanel.pas
File metadata and controls
143 lines (118 loc) · 2.74 KB
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
unit bgPanel;
{$mode objfpc}{$H+}
interface
uses
Classes, Controls, ExtCtrls, LResources, LMessages,
BGRABitmap;
type
TBGRedrawEvent = procedure(Sender: TObject; Bitmap: TBGRABitmap) of object;
{ TBGPanel }
{ TCustomBGPanel }
TCustomBGPanel = class(TCustomPanel)
private
FBGRA: TBGRABitmap;
FOnRedraw: TBGRedrawEvent;
protected
procedure Paint; override;
procedure Resize; override;
procedure BGRASetSize(AWidth, AHeight: integer);
procedure RedrawBitmapContent; virtual;
procedure WMEraseBkgnd(var Message: TLMEraseBkgnd); message LM_ERASEBKGND;
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
public
procedure RedrawBitmap;
procedure DiscardBitmap;
public
property OnRedraw: TBGRedrawEvent read FOnRedraw write FOnRedraw;
property Bitmap: TBGRABitmap read FBGRA;
end;
TBGPanel = class(TCustomBGPanel)
published
property OnRedraw;
property Bitmap;
property Align;
property Anchors;
property Constraints;
property OnClick;
property OnDblClick;
property OnEnter;
property OnExit;
property OnMouseDown;
property OnMouseEnter;
property OnMouseLeave;
property OnMouseMove;
property OnMouseUp;
property OnResize;
property OnMouseWheel;
property OnMouseWheelDown;
property OnMouseWheelUp;
end;
procedure Register;
implementation
procedure Register;
begin
//{$I icons\bgpanel_icon.lrs}
RegisterComponents('BGRA Games', [TBGPanel]);
end;
{ TBGPanel }
procedure TCustomBGPanel.Paint;
begin
inherited Paint;
BGRASetSize(Width, Height);
FBGRA.Draw(Canvas, 0, 0);
end;
procedure TCustomBGPanel.Resize;
begin
inherited Resize;
DiscardBitmap;
end;
procedure TCustomBGPanel.BGRASetSize(AWidth, AHeight: integer);
begin
if (FBGRA <> nil) and (AWidth <> FBGRA.Width) and (AHeight <> FBGRA.Height) then
begin
FBGRA.SetSize(AWidth, AHeight);
RedrawBitmapContent;
end;
end;
procedure TCustomBGPanel.RedrawBitmapContent;
begin
if (FBGRA <> nil) and (FBGRA.NbPixels <> 0) then
begin
if Assigned(FOnRedraw) then
FOnRedraw(Self, FBGRA);
end;
end;
{$hints off}
procedure TCustomBGPanel.WMEraseBkgnd(var Message: TLMEraseBkgnd);
begin
end;
{$hints on}
constructor TCustomBGPanel.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
FBGRA := TBGRABitmap.Create;
{$IFDEF WINDOWS}
DoubleBuffered := True;
{$ENDIF}
end;
destructor TCustomBGPanel.Destroy;
begin
FBGRA.Free;
inherited Destroy;
end;
procedure TCustomBGPanel.RedrawBitmap;
begin
RedrawBitmapContent;
Repaint;
end;
procedure TCustomBGPanel.DiscardBitmap;
begin
if (FBGRA <> nil) and (FBGRA.NbPixels <> 0) then
begin
FBGRA.SetSize(0, 0);
Invalidate;
end;
end;
end.