-
Notifications
You must be signed in to change notification settings - Fork 5
/
fxcontainer.pas
176 lines (150 loc) Β· 3.78 KB
/
fxcontainer.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
unit FXContainer;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs,
OpenGLContext, LMessages, LCLType, BGRABitmap, BGRABitmapTypes, BGRAOpenGL;
const
SFXDrawable = '{46c3b16f-a846-4b27-a3d3-2313cc9be63e}';
type
IFXDrawable = interface
[SFXDrawable]
procedure FXDraw;
procedure FXPreview(aCanvas: TCanvas);
end;
{ TCustomFXContainer }
TCustomFXContainer = class(TCustomOpenGLControl)
private
FCanvas: TCanvas;
FLockReceivePaint: boolean;
protected
procedure WMPaint(var Message: TLMPaint); message LM_PAINT;
procedure DrawChilds;
public
procedure DoOnPaint; override;
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
end;
TFXContainer = class(TCustomFXContainer)
published
property Align;
property Anchors;
property AutoResizeViewport;
property BorderSpacing;
property ChildSizing;
property Color;
property Enabled;
{$IFDEF HasRGBBits}
property RedBits;
property GreenBits;
property BlueBits;
{$ENDIF}
property OpenGLMajorVersion;
property OpenGLMinorVersion;
property MultiSampling;
property AlphaBits;
property DepthBits;
property StencilBits;
property AUXBuffers;
property OnChangeBounds;
property OnClick;
property OnConstrainedResize;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMakeCurrent;
property OnMouseDown;
property OnMouseEnter;
property OnMouseLeave;
property OnMouseMove;
property OnMouseUp;
property OnMouseWheel;
property OnMouseWheelDown;
property OnMouseWheelUp;
property OnPaint;
property OnResize;
property OnShowHint;
property PopupMenu;
property ShowHint;
property Visible;
end;
procedure Register;
implementation
procedure Register;
begin
{$I icons\fxcontainer_icon.lrs}
RegisterComponents('BGRA Controls FX', [TFXContainer]);
end;
{ TCustomFXContainer }
procedure TCustomFXContainer.WMPaint(var Message: TLMPaint);
var
i: integer;
IFX: IFXDrawable;
begin
Include(FControlState, csCustomPaint);
inherited WMPaint(Message);
if (csDesigning in ComponentState) and (FCanvas <> nil) then
begin
if Message.DC <> 0 then
FCanvas.Handle := Message.DC;
FCanvas.Brush.Color := Color;
FCanvas.FillRect(0, 0, Width, Height);
for i := 0 to ControlCount - 1 do
if Controls[i].GetInterface(SFXDrawable, IFX) then
IFX.FXPreview(FCanvas);
if Message.DC <> 0 then
FCanvas.Handle := 0;
end
else
begin
Paint;
end;
Exclude(FControlState, csCustomPaint);
end;
procedure TCustomFXContainer.DrawChilds;
var
i: integer;
IFX: IFXDrawable;
begin
for i := 0 to ControlCount - 1 do
if Controls[i].GetInterface(SFXDrawable, IFX) then
IFX.FXDraw;
end;
procedure TCustomFXContainer.DoOnPaint;
begin
if (csDesigning in ComponentState) then
exit;
BGLViewPort(Width, Height, Color);
inherited DoOnPaint;
DrawChilds;
SwapBuffers;
end;
constructor TCustomFXContainer.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
FCompStyle := csPanel;
ControlStyle := ControlStyle + [csAcceptsControls, csCaptureMouse,
csClickEvents, csSetCaption, csDoubleClicks, csReplicatable,
csNoFocus, csAutoSize0x0] - [csOpaque];
AutoResizeViewport := True;
if (csDesigning in ComponentState) then
begin
FCanvas := TControlCanvas.Create;
TControlCanvas(FCanvas).Control := Self;
end
else
FCompStyle := csNonLCL;
Align := alClient;
Color := clWhite;
FLockReceivePaint := False;
end;
destructor TCustomFXContainer.Destroy;
begin
inherited Destroy;
end;
end.