-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTPROGRES.INC
160 lines (144 loc) · 4.07 KB
/
TPROGRES.INC
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
{ Copyright 2015 Jerome Shidel }
(*
This project and related files are subject to either the terms
specified in the included LICENSE.TXT file or the GNU GPLv2.0.
*)
{ ---TProgressBar --- }
{$IFDEF INTERFACE}
const
class_TProgressBar = 'TProgressBar';
type
TProgressBarElements = record
Filled, Partial, Empty : Char;
end;
PProgressBar = ^TProgressBar;
TProgressBar = object(TControl)
private
FProgress : integer;
FChars : TProgressBarElements;
FPercent : String;
FTextWidth : integer;
public { protected }
function ObjectClass ( AName : String ) : String; virtual;
public
constructor Create(AParent : PControl; AName : String);
procedure SetProgress(AValue : integer); virtual;
function GetProgress : integer; virtual;
procedure Draw; virtual;
procedure ApplyLanguage( AConfig : PConfigFile ); virtual;
procedure ApplyTheme( AConfig : PConfigFile ); virtual;
function GetPercentText : string; virtual;
procedure SetPercentText (AValue : String); virtual;
end;
{$ENDIF}
{$IFDEF IMPLEMENTATION}
function TProgressBar.ObjectClass(AName : String) : String;
begin
if (AName = '') or (AName = class_TProgressBar) then
ObjectClass := class_TProgressBar
else
ObjectClass := inherited ObjectClass(AName);
end;
constructor TProgressBar.Create;
begin
inherited Create(AParent, AName);
FProgress := 0;
FChars.Empty := #$B0;
FChars.Partial := #$B0;
FChars.Filled := #$B1;
FTextWidth := 0;
FPercent := '';
SetPercentText('0;%0%%');
FTextAlign := True;
end;
procedure TProgressBar.SetProgress(AValue : integer);
begin
if AValue < 0 then AValue := 0;
if AValue > 100 then AValue := 100;
if AValue = FProgress then exit;
FProgress := AValue;
Refresh;;
end;
function TProgressBar.GetProgress : integer;
begin
GetProgress := FProgress;
end;
procedure TProgressBar.Draw;
var
TW, I, A : integer;
S : String;
D : TFormatData;
begin
TW := Width;
D.ID := fmtInteger;
D.IntegerValue := FProgress;
S := FormatStr(FPercent, D, 1);
if (S <> '') and (FHAlign <> AlignCenter) then begin
TW := TW - FTextWidth;
end;
if FHAlign = AlignLeft then begin
if FProgress < 100 then
TextAttr := FAttr.Disabled
else
TextAttr := FAttr.Normal;
FWrite(RSpace(S, FTextWidth));
end;
TextAttr := FAttr.Normal;
FWrite(ChrStr(FChars.Filled, Trunc(TW * FProgress / 100 )));
if FProgress < 100 then begin
if Trunc(TW * FProgress / 100 ) < Round(TW * FProgress / 100 ) then begin
FWriteChar(FChars.Partial);
TextAttr := FAttr.Disabled;
FWrite(ChrStr(FChars.Empty, TW - Trunc(TW * FProgress / 100 ) - 1));
end else begin
TextAttr := FAttr.Disabled;
FWrite(ChrStr(FChars.Empty, TW - Trunc(TW * FProgress / 100 ) ));
end;
TextAttr := FAttr.Disabled;
end;
{ TextAttr := FAttr.Normal; }
if FHAlign = AlignCenter then begin
for I := 1 to Length(S) do begin
GotoXY(Width div 2 - Length(S) div 2 + I, 1);
TextAttr := FReadAttr;
GotoXY(Width div 2 - Length(S) div 2 + I, 1);
FWriteChar(S[I]);
end;
end else if FHAlign = AlignRight then begin
FWrite(LSpace(S, FTextWidth));
end;
end;
procedure TProgressBar.ApplyLanguage( AConfig : PConfigFile );
begin
inherited ApplyLanguage(AConfig);
SetPercentText(AConfig^.GetValue(GetPathID, GetPercentText));
end;
procedure TProgressBar.ApplyTheme( AConfig : PConfigFile );
var
Temp : Array[0..2] of integer;
begin
inherited ApplyTheme(AConfig);
Temp[0] := byte(FChars.Empty);
Temp[1] := byte(FChars.Partial);
Temp[2] := byte(FChars.Filled);
AConfig^.GetInts('DISPLAY', Temp, SizeOf(Temp) div SizeOf(Integer));
FChars.Empty := Chr(Temp[0]);
FChars.Partial := Chr(Temp[1]);
FChars.Filled := Chr(Temp[2]);
end;
function TProgressBar.GetPercentText : string;
begin
GetPercentText := FPercent;
end;
procedure TProgressBar.SetPercentText (AValue : String);
var
D : TFormatData;
begin
if AValue = FPercent then exit;
FPercent := AValue;
D.ID := 0;
D.IntegerValue := 100;
FTextWidth := Length(FormatStr(FPercent, D, 1)) + 1;
Refresh;
end;
{$ENDIF}