1 //////////////////////////////////////////////////////////////////////
3 // TRarProgressBar version 1.0 //
4 // Description: TRarProgressBar is a component which //
5 // displays dual progress bar like a WinRAR //
8 //////////////////////////////////////////////////////////////////////
14 uses Windows
, Messages
, SysUtils
, Classes
, Graphics
, Controls
, Forms
,
15 ComCtrls
, ExtCtrls
, Mirror
;
18 Boolean2Str
: array [Boolean] of string = ('False','True');
21 TRarProgressBar
= class(TKOLControl
)
23 { Private declarations }
28 FPercent1
,FPercent2
: integer;
31 FLightColor1
,FDarkColor
,FLightColor2
,FFrameColor1
,FFrameColor2
,
32 FFillColor1
,FFillColor2
,FBackFrameColor1
,FBackFrameColor2
,
33 FBackFillColor
,FShadowColor
: TColor
;
35 TopX
,TopY
,SizeX
,SizeY
: integer;
37 function AdditionalUnits
: string; override;
38 procedure SetupFirst(SL
: TStringList
; const AName
,AParent
,Prefix
: string); override;
39 procedure SetPos1(P
: integer);
40 procedure SetPos2(P
: integer);
41 procedure SetMin(M
: integer);
42 procedure SetMax(M
: integer);
43 procedure SetDouble(D
: boolean);
45 procedure SetLightColor1(C
: TColor
);
46 procedure SetLightColor2(C
: TColor
);
47 procedure SetDarkColor(C
: TColor
);
48 procedure SetFrameColor1(C
: TColor
);
49 procedure SetFrameColor2(C
: TColor
);
50 procedure SetFillColor1(C
: TColor
);
51 procedure SetFillColor2(C
: TColor
);
52 procedure SetBackFrameColor1(C
: TColor
);
53 procedure SetBackFrameColor2(C
: TColor
);
54 procedure SetBackFillColor(C
: TColor
);
55 procedure SetShadowColor(C
: TColor
);
57 { Protected declarations }
59 procedure WMPaint(var Msg
: TMessage
); message WM_PAINT
;
60 procedure WMSize(var Msg
: TMessage
); message WM_SIZE
;
61 procedure WMActiv(var Msg
: TMessage
); message WM_SHOWWINDOW
;
63 { Public declarations }
64 constructor Create(Owner
: TComponent
); override;
66 { Published declarations }
67 property Position1
: integer read FPosition1 write SetPos1
;
68 property Position2
: integer read FPosition2 write SetPos2
;
69 property Percent1
: integer read FPercent1
;
70 property Percent2
: integer read FPercent2
;
71 property Max
: integer read FMax write SetMax
;
72 property Min
: integer read FMin write SetMin
;
73 property Double: boolean read FDouble write SetDouble
;
75 property LightColor1
: TColor read FLightColor1 write SetLightColor1
;
76 property LightColor2
: TColor read FLightColor2 write SetLightColor2
;
77 property DarkColor
: TColor read FDarkColor write SetDarkColor
;
78 property FrameColor1
: TColor read FFrameColor1 write SetFrameColor1
;
79 property FrameColor2
: TColor read FFrameColor2 write SetFrameColor2
;
80 property FillColor1
: TColor read FFillColor1 write SetFillColor1
;
81 property FillColor2
: TColor read FFillColor2 write SetFillColor2
;
82 property BackFrameColor1
: TColor read FBackFrameColor1 write SetBackFrameColor1
;
83 property BackFrameColor2
: TColor read FBackFrameColor2 write SetBackFrameColor2
;
84 property BackFillColor
: TColor read FBackFillColor write SetBackFillColor
;
85 property ShadowColor
: TColor read FShadowColor write SetShadowColor
;
87 procedure Add1(D
: integer);
88 procedure Add2(D
: integer);
95 {$R mckRarProgBar.dcr}
99 RegisterComponents('KOL', [TRarProgressBar
]);
102 constructor TRarProgressBar
.Create
;
114 FLightColor1
:=clWhite
;
116 FLightColor2
:=$C0FFFF;
117 FFrameColor1
:=$EEE8E8;
118 FFrameColor2
:=$B4D4E4;
119 FFillColor1
:=$DCD6D6;
120 FFillColor2
:=$A0C0D0;
121 FBackFrameColor1
:=$9494B4;
122 FBackFrameColor2
:=$80809E;
123 FBackFillColor
:=$6E6E94;
124 FShadowColor
:=$464040;
127 procedure TRarProgressBar
.WMPaint
;
133 procedure TRarProgressBar
.WMSize
;
139 procedure TRarProgressBar
.WMActiv
;
145 function TRarProgressBar
.AdditionalUnits
;
147 Result
:=', KOLRarProgBar';
150 procedure TRarProgressBar
.SetupFirst
;
153 SL
.Add(Prefix
+AName
+'.Position1 := '+IntToStr(FPosition1
)+';');
154 SL
.Add(Prefix
+AName
+'.Position2 := '+IntToStr(FPosition2
)+';');
155 SL
.Add(Prefix
+AName
+'.Min := '+IntToStr(FMin
)+';');
156 SL
.Add(Prefix
+AName
+'.Max := '+IntToStr(FMax
)+';');
157 SL
.Add(Prefix
+AName
+'.Double := '+Boolean2Str
[FDouble
]+';');
158 SL
.Add(Prefix
+AName
+'.LightColor1 := '+Color2Str(FLightColor1
)+';');
159 SL
.Add(Prefix
+AName
+'.LightColor2 := '+Color2Str(FLightColor2
)+';');
160 SL
.Add(Prefix
+AName
+'.DarkColor := '+Color2Str(FDarkColor
)+';');
161 SL
.Add(Prefix
+AName
+'.FrameColor1 := '+Color2Str(FFrameColor1
)+';');
162 SL
.Add(Prefix
+AName
+'.FrameColor2 := '+Color2Str(FFrameColor2
)+';');
163 SL
.Add(Prefix
+AName
+'.FillColor1 := '+Color2Str(FFillColor1
)+';');
164 SL
.Add(Prefix
+AName
+'.FillColor2 := '+Color2Str(FFillColor2
)+';');
165 SL
.Add(Prefix
+AName
+'.BackFrameColor1 := '+Color2Str(FBackFrameColor1
)+';');
166 SL
.Add(Prefix
+AName
+'.BackFrameColor2 := '+Color2Str(FBackFrameColor2
)+';');
167 SL
.Add(Prefix
+AName
+'.BackFillColor := '+Color2Str(FBackFillColor
)+';');
168 SL
.Add(Prefix
+AName
+'.ShadowColor := '+Color2Str(FShadowColor
)+';');
171 procedure TRarProgressBar
.SetPos1
;
173 if FDouble
then if P
<FPosition2
then P
:=FPosition2
;
174 if P
>FMax
then P
:=FMax
;
179 procedure TRarProgressBar
.SetPos2
;
181 if FDouble
then if P
>FPosition1
then P
:=FPosition1
;
186 procedure TRarProgressBar
.SetMin
;
188 if M
>FMax
then M
:=FMax
;
193 procedure TRarProgressBar
.SetMax
;
195 if M
<FMin
then M
:=FMin
;
200 procedure TRarProgressBar
.SetDouble
;
206 procedure TRarProgressBar
.SetLightColor1
;
212 procedure TRarProgressBar
.SetLightColor2
;
218 procedure TRarProgressBar
.SetDarkColor
;
224 procedure TRarProgressBar
.SetFrameColor1
;
230 procedure TRarProgressBar
.SetFrameColor2
;
236 procedure TRarProgressBar
.SetFillColor1
;
242 procedure TRarProgressBar
.SetFillColor2
;
248 procedure TRarProgressBar
.SetBackFrameColor1
;
254 procedure TRarProgressBar
.SetBackFrameColor2
;
260 procedure TRarProgressBar
.SetBackFillColor
;
266 procedure TRarProgressBar
.SetShadowColor
;
272 procedure TRarProgressBar
.Paint
;
279 SizeY
:=Height
-TopY
-4;
280 if (SizeX
=0) or (SizeY
=0) or (FMax
-FMin
=0) then Exit
;
282 ///////////////////////////////////////////////////////////////////////////////
284 ///////////////////////////////////////////////////////////////////////////////
286 Canvas
.Brush
.Style
:=bsSolid
;
287 Canvas
.Brush
.Color
:=Color
;
288 Canvas
.FillRect(Bounds(0,0,Width
,Height
));
289 Canvas
.Brush
.Color
:=FShadowColor
;
290 Canvas
.FillRect(Bounds(TopX
+1,TopY
+2,SizeX
,SizeY
));
291 Canvas
.Brush
.Color
:=FBackFillColor
;
292 Canvas
.FillRect(Bounds(TopX
,TopY
,SizeX
,SizeY
+1));
293 Canvas
.Brush
.Color
:=FDarkColor
;
294 Canvas
.FrameRect(Bounds(TopX
,TopY
,SizeX
,SizeY
+1));
295 Canvas
.Brush
.Color
:=FBackFrameColor1
;
296 Canvas
.FrameRect(Bounds(TopX
,TopY
,SizeX
,SizeY
));
297 Canvas
.Brush
.Color
:=FBackFrameColor2
;
298 Canvas
.FrameRect(Bounds(TopX
+1,TopY
+1,SizeX
-2,SizeY
-2));
300 ///////////////////////////////////////////////////////////////////////////////
302 ///////////////////////////////////////////////////////////////////////////////
304 R
:=(FPosition1
-FMin
)/((FMax
-FMin
)/SizeX
);
306 FPercent1
:=Byte(Round(R
/(SizeX
/100)));
309 Canvas
.Brush
.Color
:=FLightColor1
;
310 Canvas
.FillRect(Bounds(TopX
,TopY
,TopX
+Prog
-2,TopY
+SizeY
-2));
313 Canvas
.Brush
.Color
:=FFillColor1
;
314 Canvas
.FillRect(Bounds(TopX
+1,TopY
+1,TopX
+Prog
-3,TopY
+SizeY
-3));
315 Canvas
.Brush
.Color
:=FFrameColor1
;
316 Canvas
.FrameRect(Bounds(TopX
+1,TopY
+1,TopX
+Prog
-3,TopY
+SizeY
-3));
318 Canvas
.Brush
.Color
:=FDarkColor
;
319 Canvas
.FillRect(Bounds(TopX
+Prog
,TopY
,1,TopY
+SizeY
-1));
322 Canvas
.Brush
.Color
:=FBackFillColor
;
323 Canvas
.FillRect(Bounds(TopX
+Prog
+1,TopY
,SizeX
-Prog
-1,SizeY
));
324 Canvas
.Brush
.Color
:=FBackFrameColor1
;
325 Canvas
.FrameRect(Bounds(TopX
+Prog
+1,TopY
,SizeX
-Prog
-1,SizeY
));
326 Canvas
.Brush
.Color
:=FBackFrameColor2
;
327 Canvas
.FrameRect(Bounds(TopX
+Prog
+1,TopY
+1,SizeX
-Prog
-2,SizeY
-2));
331 ///////////////////////////////////////////////////////////////////////////////
332 // Drawing second bar
333 ///////////////////////////////////////////////////////////////////////////////
337 R
:=(FPosition2
-FMin
)/((FMax
-FMin
)/SizeX
);
339 FPercent2
:=Byte(Round(R
/(SizeX
/100)));
342 Canvas
.Brush
.Color
:=FLightColor2
;
343 Canvas
.FillRect(Bounds(TopX
,TopY
,TopX
+Prog
-2,TopY
+SizeY
-2));
346 Canvas
.Brush
.Color
:=FFillColor2
;
347 Canvas
.FillRect(Bounds(TopX
+1,TopY
+1,TopX
+Prog
-3,TopY
+SizeY
-3));
348 Canvas
.Brush
.Color
:=FFrameColor2
;
349 Canvas
.FrameRect(Bounds(TopX
+1,TopY
+1,TopX
+Prog
-3,TopY
+SizeY
-3));
355 procedure TRarProgressBar
.Add1
;
361 procedure TRarProgressBar
.Add2
;