-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathksProgressIndicator.pas
More file actions
290 lines (244 loc) · 8.36 KB
/
Copy pathksProgressIndicator.pas
File metadata and controls
290 lines (244 loc) · 8.36 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
{ *******************************************************************************
* *
* TksProgressIndicator *
* *
* https://bitbucket.org/gmurt/kscomponents *
* *
* Copyright 2017 Graham Murt *
* *
* email: graham@kernow-software.co.uk *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License forthe specific language governing permissions and *
* limitations under the License. *
* *
*******************************************************************************}
unit ksProgressIndicator;
interface
{$I ksComponents.inc}
uses FMX.Controls, Classes, FMX.StdCtrls, FMX.Graphics, FMX.Types, FMX.Objects, ksTypes,
System.UIConsts, System.UITypes;
type
TksProgressIndicator = class;
TksProgressIndicatorSteps = class(TPersistent)
private
[weak]FOwner: TksProgressIndicator;
FMaxSteps: integer;
FCurrentStep: integer;
FSize: integer;
FVisible: Boolean;
procedure SetCurrentStep(const Value: integer);
procedure SetMaxSteps(const Value: integer);
procedure SetVisible(const Value: Boolean);
procedure Changed;
procedure SetSize(const Value: integer);
public
constructor Create(AOwner: TksProgressIndicator);
published
property MaxSteps: integer read FMaxSteps write SetMaxSteps default 5;
property CurrentStep: integer read FCurrentStep write SetCurrentStep default 1;
property Size: integer read FSize write SetSize default 12;
property Visible: Boolean read FVisible write SetVisible default True;
end;
[ComponentPlatformsAttribute(
pidWin32 or
pidWin64 or
{$IFDEF XE8_OR_NEWER} pidiOSDevice32 or pidiOSDevice64 {$ELSE} pidiOSDevice {$ENDIF} or
{$IFDEF XE10_3_OR_NEWER} pidiOSSimulator32 or pidiOSSimulator64 {$ELSE} pidiOSSimulator {$ENDIF} or
{$IFDEF XE10_3_OR_NEWER} pidAndroid32Arm or pidAndroid64Arm {$ELSE} pidAndroid {$ENDIF}
)]
TksProgressIndicator = class(TksControl)
private
FSteps: TksProgressIndicatorSteps;
FActiveColor: TAlphaColor;
FInActiveColor: TAlphaColor;
FBitmap: TBitmap;
FOutlineColor: TAlphaColor;
FKeepHighlighted: Boolean;
procedure SetActiveColor(const Value: TAlphaColor);
procedure SetInActiveColor(const Value: TAlphaColor);
procedure Redraw;
procedure Changed;
protected
procedure Paint; override;
procedure Resize; override;
procedure SetOutlineColor(const Value: TAlphaColor);
procedure SetKeepHighlighted(const Value: Boolean);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property ActiveColor: TAlphaColor read FActiveColor write SetActiveColor default claDodgerblue;
property InactiveColor: TAlphaColor read FInActiveColor write SetInActiveColor default claSilver;
property KeepHighlighted: Boolean read FKeepHighlighted write SetKeepHighlighted default False;
property Align;
property Position;
property Width;
property Height;
property Steps: TksProgressIndicatorSteps read FSteps write FSteps;
property OutlineColor: TAlphaColor read FOutlineColor write SetOutlineColor default claNull;
end;
procedure Register;
implementation
uses Types, SysUtils, ksCommon;
procedure Register;
begin
RegisterComponents('Kernow Software FMX', [TksProgressIndicator]);
end;
{ TksProgressIndicatorSteps }
procedure TksProgressIndicatorSteps.Changed;
begin
FOwner.Changed;
end;
constructor TksProgressIndicatorSteps.Create(AOwner: TksProgressIndicator);
begin
inherited Create;
FOwner := AOwner;
FMaxSteps := 5;
FCurrentStep := 1;
FSize := 12;
FVisible := True;
end;
procedure TksProgressIndicatorSteps.SetCurrentStep(const Value: integer);
begin
FCurrentStep := Value;
Changed;
end;
procedure TksProgressIndicatorSteps.SetMaxSteps(const Value: integer);
begin
FMaxSteps := Value;
Changed;
end;
procedure TksProgressIndicatorSteps.SetSize(const Value: integer);
begin
if FSize <> Value then
begin
FSize := Value;
Changed;
end;
end;
procedure TksProgressIndicatorSteps.SetVisible(const Value: Boolean);
begin
if FVisible <> Value then
begin
FVisible := Value;
Changed;
end;
end;
{ TksProgressIndicator }
procedure TksProgressIndicator.Changed;
begin
Redraw;
InvalidateRect(ClipRect);
end;
constructor TksProgressIndicator.Create(AOwner: TComponent);
begin
inherited;
FSteps := TksProgressIndicatorSteps.Create(Self);
FBitmap := TBitmap.Create;
Size.Width := 200;
Size.Height := 40;
FActiveColor := claDodgerblue;
FInActiveColor := claSilver;
FKeepHighlighted := False;
Redraw;
end;
destructor TksProgressIndicator.Destroy;
begin
FreeAndNil(FSteps);
FreeAndNil(FBitmap);
inherited;
end;
procedure TksProgressIndicator.Paint;
begin
inherited;
Canvas.BeginScene;
Canvas.DrawBitmap(FBitmap,
RectF(0, 0, FBitmap.Width, FBitmap.Height),
ClipRect,
1,
False);
Canvas.EndScene;
end;
procedure TksProgressIndicator.Redraw;
var
ARect: TRectF;
AXPos: single;
ASize: single;
ICount: integer;
AColor: TAlphaColor;
begin
if FBitmap = nil then
Exit;
FBitmap.Resize(Round(Size.Width * (GetScreenScale*2)), Round(Size.Height * (GetScreenScale*2)));
FBitmap.Clear(claNull);
ASize := FSteps.Size * (GetScreenScale*2);
if FSteps.Visible = False then
Exit;
ARect := RectF(0, 0, (FSteps.MaxSteps + (FSteps.MaxSteps-1)) * ASize, ASize);
OffsetRect(ARect, ((Width * (GetScreenScale*2)) - ARect.Width) / 2, ((Height * (GetScreenScale*2)) - ARect.Height) / 2);
AXpos := ARect.Left;
FBitmap.Canvas.BeginScene;
try
for ICount := 0 to FSteps.MaxSteps-1 do
begin
AColor := FInactiveColor;
if ((ICount+1) = FSteps.CurrentStep) then
AColor := FActiveColor;
if ((ICount+1) < FSteps.CurrentStep) and (FKeepHighlighted) then
AColor := FActiveColor;
FBitmap.Canvas.Stroke.Color := FOutlineColor;
FBitmap.Canvas.Stroke.Thickness := GetScreenScale * 2;
FBitmap.Canvas.Stroke.Kind := TBrushKind.Solid;
FBitmap.Canvas.Fill.Color := AColor;
FBitmap.Canvas.Fill.Kind := TBrushKind.Solid;
FBitmap.Canvas.FillEllipse(RectF(AXPos, ARect.Top, AXpos+ASize, ARect.Top+ASize), 1);
FBitmap.Canvas.DrawEllipse(RectF(AXPos, ARect.Top, AXpos+ASize, ARect.Top+ASize), 1);
AXPos := AXPos + (ASize*2);
end;
finally
FBitmap.Canvas.EndScene;
end;
end;
procedure TksProgressIndicator.Resize;
begin
inherited;
Changed;
end;
procedure TksProgressIndicator.SetActiveColor(const Value: TAlphaColor);
begin
if FActiveColor <> Value then
begin
FActiveColor := Value;
Repaint;
end;
end;
procedure TksProgressIndicator.SetInActiveColor(const Value: TAlphaColor);
begin
if FInActiveColor <> Value then
begin
FInActiveColor := Value;
Redraw;
end;
end;
procedure TksProgressIndicator.SetKeepHighlighted(const Value: Boolean);
begin
FKeepHighlighted := Value;
Redraw;
end;
procedure TksProgressIndicator.SetOutlineColor(const Value: TAlphaColor);
begin
FOutlineColor := Value;
Redraw;
end;
initialization
Classes.RegisterClass(TksProgressIndicator);
end.