-
Notifications
You must be signed in to change notification settings - Fork 6
/
untERDProgressBar.pas
235 lines (193 loc) · 5.36 KB
/
untERDProgressBar.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
{
untERDProgressBar v1.0.0 - a progressbar used in the ERDPlayerDisplay
for Delphi 2010 - 10.4 by Ernst Reidinga
https://erdesigns.eu
This unit is part of the ERDesigns Audio Toolkit Components Pack.
(c) Copyright 2020 Ernst Reidinga <ernst@erdesigns.eu>
Bugfixes / Updates:
- Initial Release 1.0.0
If you use this unit, please give credits to the original author;
Ernst Reidinga.
}
unit untERDProgressBar;
interface
uses
System.SysUtils, System.Classes, Winapi.Windows, Vcl.Controls, Vcl.Graphics,
Winapi.Messages, System.Types, Vcl.ExtCtrls, GDIPlus;
type
TERDProgressBar = class(TGraphicControl)
private
{ Private declarations }
FBuffer : TBitmap;
FRedraw : Boolean;
FBorderColor : TColor;
FProgressColor : TColor;
FPosition : Integer;
FMax : Integer;
procedure SetProgressColor(const C: TColor);
procedure SetPosition(const I: Integer);
procedure SetMax(const I: Integer);
protected
{ Protected declarations }
procedure Paint; override;
procedure Resize; override;
procedure WndProc(var Message: TMessage); override;
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
property Redraw: Boolean read FRedraw write FRedraw;
published
{ Published declarations }
property ProgressColor: TColor read FProgressColor write SetProgressColor default $00EAA900;
property Position: Integer read FPosition write SetPosition default 0;
property Max: Integer read FMax write SetMax default 100;
property Align;
property Anchors;
property Color;
property ParentColor;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property Touch;
property Visible;
property OnClick;
property OnGesture;
property OnMouseActivate;
property OnMouseDown;
property OnMouseEnter;
property OnMouseLeave;
property OnMouseMove;
property OnMouseUp;
property OnResize;
end;
implementation
uses System.Math, System.StrUtils, untERDMidiCommon;
(******************************************************************************)
(*
(* ERD Progress Bar (TERDProgressBar)
(*
(******************************************************************************)
constructor TERDProgressBar.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
{ Transparent background }
ControlStyle := ControlStyle + [csOpaque];
{ Create Buffers }
FBuffer := TBitmap.Create;
FBuffer.PixelFormat := pf32bit;
{ Defaults }
FProgressColor := $00EAA900;
FPosition := 0;
FMax := 100;
{ Set default width and height }
Width := 184;
Height := 20;
{ Initial Drawing }
Redraw := True;
end;
destructor TERDProgressBar.Destroy;
begin
FBuffer.Free;
inherited Destroy;
end;
procedure TERDProgressBar.SetProgressColor(const C: TColor);
begin
if ProgressColor <> C then
begin
FProgressColor := C;
Redraw := True;
Invalidate;
end;
end;
procedure TERDProgressBar.SetPosition(const I: Integer);
begin
if (Position <> I) and (I >= 0) and (I <= 100) then
begin
FPosition := I;
Redraw := True;
Invalidate;
end;
end;
procedure TERDProgressBar.SetMax(const I: Integer);
begin
if (Max <> I) and (I >= 0) then
begin
FMax := I;
Redraw := True;
Invalidate;
end;
end;
procedure TERDProgressBar.Paint;
var
WorkRect : TRect;
procedure DrawBackground;
begin
with FBuffer.Canvas do
begin
Brush.Color := Brighten(Color, 10);
FillRect(WorkRect);
end;
end;
procedure DrawProgress(var FGraphics : IGPGraphics);
var
FInnerBrush : IGPLinearGradientBrush;
W : Integer;
begin
FInnerBrush := TGPLinearGradientBrush.Create(
TGPRect.Create(WorkRect),
TGPColor.CreateFromColorRef(Brighten(ProgressColor, 25)),
TGPColor.CreateFromColorRef(Darken(ProgressColor, 20)),
90);
W := Round((WorkRect.Width / Max) * Position);
WorkRect.Right := WorkRect.Left + W;
FGraphics.FillRectangle(FInnerBrush, TGPRect.Create(WorkRect));
end;
var
FGraphics : IGPGraphics;
begin
if Redraw then
begin
Redraw := False;
{ Create Work rect }
WorkRect := ClientRect;
{ Set Buffer size }
FBuffer.SetSize(ClientWidth, ClientHeight);
{ Create GDI+ Graphic }
FGraphics := TGPGraphics.Create(FBuffer.Canvas.Handle);
FGraphics.SmoothingMode := SmoothingModeAntiAlias;
FGraphics.InterpolationMode := InterpolationModeHighQualityBicubic;
{ Draw to buffer }
DrawBackground;
DrawProgress(FGraphics);
end;
{ Draw the whole buffer to the surface }
BitBlt(Canvas.Handle, 0, 0, ClientWidth, ClientHeight, FBuffer.Canvas.Handle, 0, 0, SRCCOPY);
inherited;
end;
procedure TERDProgressBar.Resize;
begin
Redraw := True;
Invalidate;
inherited;
end;
procedure TERDProgressBar.WndProc(var Message: TMessage);
begin
inherited;
case Message.Msg of
{ The color changed }
CM_COLORCHANGED:
begin
Redraw := True;
Invalidate
end;
{ Font changed }
CM_FONTCHANGED:
begin
{ }
Redraw := True;
Invalidate
end;
end;
end;
end.