-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrounded_panel.pas
More file actions
325 lines (305 loc) · 7.77 KB
/
rounded_panel.pas
File metadata and controls
325 lines (305 loc) · 7.77 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
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
unit rounded_panel;
{$mode objfpc}{$H+}
interface
uses //
{rtl}
Classes, Controls, Graphics, StdCtrls,
{3d party units}
BGRABitmap, BGRABitmapTypes, BGRACanvas2D;
type
PLabel =^TLabel;
PBGRABitmap =^TBGRABitmap;
TPtPos =record
X,Y: integer;
end;
TPtPos3 =array[0..2] of TPtPos;
TGeom2DType =(g2DtRectangle,
g2DtFilledRectangle,
g2DtCircle,
g2DtFilledCircle,
g2DtVertLine,
g2DtHorizLine,
g2DtArrowLeftRight,
g2DtCapArc,
g2DtStar,
g2DtImage);
TGeom2DObj =record
BGRABmpPtr: PBGRABitmap;
Pt3 : TPtPos3;
RctDst : TRect;
Radius1 : Integer;
Radius2 : Integer;
Angle1 : Single;
Angle2 : Single;
Scale : Single;
Thikness : Integer;
Color : TColor;
Alpha : Word;
Geom2DType: TGeom2DType;
DrawMode : TDrawMode;
IsChecked : Boolean;
end;
TBGRARoundedPanel=class(TCustomControl)
public
FBmp : TBGRABitmap;
BkgndColor : TColor;
geom_2D_arr: array of TGeom2DObj;
label_ind : Integer;
constructor Create (AOwner :TComponent); override;
procedure Paint; override;
procedure Resize; override;
procedure Geom2DAdd (Geom2DType_:TGeom2DType);
procedure Geom2DDraw(Geom2DObj_ :TGeom2DObj);
published
property OnMouseEnter;
property OnMouseLeave;
property OnMouseMove;
property OnMouseDown;
property OnMouseUp;
property OnClick;
end;
implementation
uses
main;
function ColorWithAlpha (const Color:TColor; const Alpha:Byte):TBGRAPixel; inline;
var
C: TBGRAPixel;
begin
Result :=ColorToBGRA(Color);
Result.Alpha:=Alpha;
end;
procedure DrawEmptyRect (Bmp:TBGRABitmap; R:TRect; Rx,Ry:Single; Thickness:Single; Color:TBGRAPixel);
begin
with bmp.Canvas2D do
begin
StrokeStyle(Color);
LineWidth:=Thickness;
BeginPath;
RoundRect
(
R.Left,
R.Top,
R.Width,
R.Height,
Rx,
Ry
);
Stroke;
end;
end;
procedure DrawStar (Bmp:TBGRABitmap; Cx,Cy:Single; Rad1_,Rad2_:Single; Color:TBGRAPixel);
var
I: Integer;
A: Single;
begin
with bmp.Canvas2D do
begin
FillStyle(Color);
BeginPath;
for I:=0 to 9 do
begin
A:=Pi/2+I*Pi/5;
if (I and 1)=0 then
LineTo(Cx+Cos(A)*Rad1_,
Cy+Sin(A)*Rad1_)
else
LineTo(
Cx+Cos(A)*Rad2_,
Cy+Sin(A)*Rad2_);
end;
ClosePath;
Fill;
end;
end;
constructor TBGRARoundedPanel.Create (AOwner:TComponent);
begin
inherited Create(AOwner);
DoubleBuffered:=True;
FBmp :=TBGRABitmap.Create;
end;
procedure TBGRARoundedPanel.Paint;
var
I: Integer;
begin
FBmp.SetSize(Width,Height);
FBmp.Fill (BkgndColor);
for I:=0 to Length(geom_2D_arr)-1 do
Geom2DDraw(geom_2D_arr[I]);
FBmp.Draw(Canvas,0,0,True);
inherited Paint;
end;
procedure TBGRARoundedPanel.Resize;
begin
inherited Resize;
FBmp.SetSize(Width,Height);
end;
procedure TBGRARoundedPanel.Geom2DAdd (Geom2DType_:TGeom2DType);
begin
SetLength(geom_2D_arr,Length(geom_2D_arr)+1);
geom_2D_arr[Length(geom_2D_arr)-1].Geom2DType:=Geom2DType_;
if (Geom2DType_=g2DtImage) then
geom_2D_arr[Length(geom_2D_arr)-1].Scale:=1;
end;
procedure TBGRARoundedPanel.Geom2DDraw(Geom2DObj_:TGeom2DObj);
begin
with Geom2DObj_ do
case Geom2DType of
g2DtRectangle:
with FBmp do
begin
DrawEmptyRect
(
FBmp,
RctDst,
Radius1,
Radius2,
Thikness,
ColorToBGRA(Color)
);
end;
g2DtFilledRectangle:
with FBmp do
begin
FillRoundRectAntialias
(
RctDst.Left +1,
RctDst.Top +1,
RctDst.Width -2,
RctDst.Height-2,
Radius1,
Radius2,
ColorToBGRA(Color)
);
end;
g2DtCircle:
with FBmp do
begin
EllipseAntialias
(
RctDst.Left,
RctDst.Top,
Radius1,
Radius2,
ColorToBGRA(Color),
Thikness
);
end;
g2DtFilledCircle:
with FBmp do
begin
FillEllipseAntialias
(
RctDst.Left,
RctDst.Top,
Radius1,
Radius2,
ColorWithAlpha(Color,Alpha)
);
end;
g2DtVertLine:
with FBmp,Canvas2D do
begin
StrokeStyle(Color);
LineWidth:=Thikness;
LineCap :='round';
BeginPath;
MoveTo(Pt3[0].X,Pt3[0].Y);
LineTo(Pt3[0].X,Pt3[1].Y);
Stroke;
end;
g2DtHorizLine:
with FBmp do
begin
HorizLine
(
Pt3[0].X,
Pt3[0].Y,
Pt3[1].X,
Color,
DrawMode,
Alpha
);
end;
g2DtArrowLeftRight:
with FBmp do
begin
DrawLineAntialias
(
Pt3[0].X,
Pt3[0].Y,
Pt3[1].X,
Pt3[1].Y,
Color,
Thikness
);
DrawLineAntialias
(
Pt3[0].X,
Pt3[0].Y,
Pt3[1].X,
Pt3[0].Y*2-Pt3[1].Y,
Color,
Thikness
);
end;
g2DtCapArc:
with FBmp,Canvas2D do
begin
StrokeStyle(Color);
LineWidth:=Thikness;
LineCap :='round';
BeginPath;
Arc
(
RctDst.Left,
RctDst.Top,
Radius1,
Angle1,
Angle2,
False
);
Stroke;
end;
g2DtStar:
with FBmp do
begin
DrawStar
(
FBmp,
RctDst.Left,
RctDst.Top,
Radius1,
Radius2,
Color
);
end;
g2DtImage:
with FBmp do
begin
{if (Scale=1) then
PutImage
(
RctDst.Left-BGRABmpPtr^.Width >>1,
RctDst.Top -BGRABmpPtr^.Height>>1,
BGRABmpPtr^,
dmDrawWithTransparency,
255
)
else}
StretchPutImage
(
Rect
(
Trunc( +RctDst.Left-Scale*BGRABmpPtr^.Width /2),
Trunc( +RctDst.Top -Scale*BGRABmpPtr^.Height/2),
Trunc(Scale*BGRABmpPtr^.Width +RctDst.Left-Scale*BGRABmpPtr^.Width /2),
Trunc(Scale*BGRABmpPtr^.Height+RctDst.Top -Scale*BGRABmpPtr^.Height/2)
),
BGRABmpPtr^,
dmDrawWithTransparency
);
end;
end;
end;
end.
end.