-
Notifications
You must be signed in to change notification settings - Fork 5
/
fxradialprogressbar.pas
239 lines (207 loc) Β· 6.43 KB
/
fxradialprogressbar.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
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
unit FXRadialProgressBar;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, FXGraphicControl,
BGRABitmap, BGRABitmapTypes, BGRATextFX;
type
{ TFXRadialProgressBar }
TFXRadialProgressBar = class(TFXGraphicControl)
private
{ Private declarations }
FMaxValue: integer;
FMinValue: integer;
FValue: integer;
FLineColor: TColor;
FLineBkgColor: TColor;
FFontShadowColor: TColor;
FFontShadowOffsetX: integer;
FFontShadowOffsetY: integer;
FFontShadowRadius: integer;
procedure SetFFontShadowColor(AValue: TColor);
procedure SetFFontShadowOffsetX(AValue: integer);
procedure SetFFontShadowOffsetY(AValue: integer);
procedure SetFFontShadowRadius(AValue: integer);
procedure SetFLineBkgColor(AValue: TColor);
procedure SetFLineColor(AValue: TColor);
procedure SetMaxValue(AValue: integer);
procedure SetMinValue(AValue: integer);
procedure SetValue(AValue: integer);
protected
{ Protected declarations }
procedure CalculatePreferredSize(var PreferredWidth, PreferredHeight: integer;
{%H-}WithThemeSpace: boolean); override;
procedure Draw; override;
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
published
{ Published declarations }
property Align;
property Anchors;
property MinValue: integer read FMinValue write SetMinValue default 0;
property MaxValue: integer read FMaxValue write SetMaxValue default 100;
property Value: integer read FValue write SetValue default 0;
property OnClick;
property OnMouseDown;
property OnMouseEnter;
property OnMouseLeave;
property OnMouseMove;
property OnMouseUp;
property OnMouseWheel;
property OnMouseWheelUp;
property OnMouseWheelDown;
property Color default clWhite;
property LineColor: TColor read FLineColor write SetFLineColor default clBlack;
property LineBkgColor: TColor read FLineBkgColor write SetFLineBkgColor default
clSilver;
property FontShadowColor: TColor read FFontShadowColor
write SetFFontShadowColor default clBlack;
property FontShadowOffsetX: integer read FFontShadowOffsetX
write SetFFontShadowOffsetX default 2;
property FontShadowOffsetY: integer read FFontShadowOffsetY
write SetFFontShadowOffsetY default 2;
property FontShadowRadius: integer read FFontSHadowRadius
write SetFFontShadowRadius default 4;
property Font;
end;
procedure Register;
implementation
procedure Register;
begin
{$I icons\fxradialprogressbar_icon.lrs}
RegisterComponents('BGRA Controls FX', [TFXRadialProgressBar]);
end;
{ TFXRadialProgressBar }
procedure TFXRadialProgressBar.SetMaxValue(AValue: integer);
begin
if FMaxValue = AValue then
exit;
FMaxValue := AValue;
if FValue > FMaxValue then
FValue := FMaxValue;
if FMinValue > FMaxValue then
FMinValue := FMaxValue;
Invalidate;
end;
procedure TFXRadialProgressBar.SetFLineBkgColor(AValue: TColor);
begin
if FLineBkgColor = AValue then
Exit;
FLineBkgColor := AValue;
Invalidate;
end;
procedure TFXRadialProgressBar.SetFFontShadowColor(AValue: TColor);
begin
if FFontShadowColor = AValue then
Exit;
FFontShadowColor := AValue;
Invalidate;
end;
procedure TFXRadialProgressBar.SetFFontShadowOffsetX(AValue: integer);
begin
if FFontShadowOffsetX = AValue then
Exit;
FFontShadowOffsetX := AValue;
Invalidate;
end;
procedure TFXRadialProgressBar.SetFFontShadowOffsetY(AValue: integer);
begin
if FFontShadowOffsetY = AValue then
Exit;
FFontShadowOffsetY := AValue;
Invalidate;
end;
procedure TFXRadialProgressBar.SetFFontShadowRadius(AValue: integer);
begin
if FFontSHadowRadius = AValue then
Exit;
FFontSHadowRadius := AValue;
Invalidate;
end;
procedure TFXRadialProgressBar.SetFLineColor(AValue: TColor);
begin
if FLineColor = AValue then
Exit;
FLineColor := AValue;
Invalidate;
end;
procedure TFXRadialProgressBar.SetMinValue(AValue: integer);
begin
if FMinValue = AValue then
exit;
FMinValue := AValue;
if FValue < FMinValue then
FValue := FMinValue;
if FMaxValue < FMinValue then
FMaxValue := FMinValue;
Invalidate;
end;
procedure TFXRadialProgressBar.SetValue(AValue: integer);
begin
if FValue = AValue then
exit;
FValue := AValue;
if FValue < FMinValue then
FValue := FMinValue;
if FValue > FMaxValue then
FValue := FMaxValue;
Invalidate;
end;
procedure TFXRadialProgressBar.CalculatePreferredSize(
var PreferredWidth, PreferredHeight: integer; WithThemeSpace: boolean);
begin
PreferredWidth := 200;
PreferredHeight := 200;
end;
procedure TFXRadialProgressBar.Draw;
var
textBmp: TBGRABitmap;
textStr: string;
begin
if (FXLayers[0].BGRA.Width <> Width) or (FXLayers[0].BGRA.Height <> Height) then
FXLayers[0].BGRA.SetSize(Width, Height);
FXLayers[0].BGRA.FillTransparent;
FXLayers[0].BGRA.Canvas2D.beginPath;
FXLayers[0].BGRA.Canvas2D.arc(Width / 2, Height / 2, Height / 2.5, 0, pi * 2, False);
FXLayers[0].BGRA.Canvas2D.fillStyle(Color);
FXLayers[0].BGRA.Canvas2D.fill;
FXLayers[0].BGRA.Canvas2D.lineWidth := Height / 50;
FXLayers[0].BGRA.Canvas2D.strokeStyle(LineBkgColor);
FXLayers[0].BGRA.Canvas2D.stroke;
FXLayers[0].BGRA.Canvas2D.beginPath;
if Value <> MinValue then
FXLayers[0].BGRA.Canvas2D.arc(Width / 2, Height / 2, Height / 2.5, pi * 1.5,
(pi * 1.5) + ((pi * 2) * Value / MaxValue), False);
FXLayers[0].BGRA.Canvas2D.fillStyle(BGRAPixelTransparent);
FXLayers[0].BGRA.Canvas2D.fill;
FXLayers[0].BGRA.Canvas2D.lineWidth := Height / 50;
FXLayers[0].BGRA.Canvas2D.strokeStyle(LineColor);
FXLayers[0].BGRA.Canvas2D.stroke;
textStr := FloatToStr((Value / MaxValue) * 100) + '%';
textBmp := TextShadow(Width, Height, textStr, Font.Height,
Font.Color, FontShadowColor, FontShadowOFfsetX,
FontShadowOffsetY, FontSHadowRadius, Font.Style, Font.Name) as TBGRABitmap;
FXLayers[0].BGRA.PutImage(0, 0, textBmp, dmDrawWithTransparency);
textBmp.Free;
FXLayers[0].Texture := nil;
end;
constructor TFXRadialProgressBar.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
with GetControlClassDefaultSize do
SetInitialBounds(0, 0, 200, 200);
FMaxValue := 100;
FMinValue := 0;
FValue := 0;
FLineColor := clBlack;
FLineBkgColor := clSilver;
FFontShadowColor := clBlack;
FFontShadowOffsetX := 2;
FFontShadowOffsetY := 2;
FFontShadowRadius := 4;
Font.Color := clBlack;
Font.Height := 20;
Color := clWhite;
end;
end.