-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgBar.pas
130 lines (115 loc) · 3.36 KB
/
ProgBar.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
//******************************************************************************
// Little Big Architect - editing grid, brick and layout files containing
// rooms in Little Big Adventure 1 & 2
//
// ProgBar unit (used in both Builder and Factory).
// Contains progress bar displaying routines.
//
// Copyright (C) Zink
// e-mail: zink@poczta.onet.pl
// See the GNU General Public License (License.txt) for details.
//******************************************************************************
unit ProgBar;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Math;
type
TProgBarForm = class(TForm)
Bevel1: TBevel;
Bevel2: TBevel;
Image1: TImage;
btStop: TButton;
procedure FormCreate(Sender: TObject);
procedure btStopClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
procedure ShowSpecial(Caption: String; CursorChange: Boolean;
StopBtn: Boolean; Min, Max: Integer);
procedure UpdateBar(Val: Integer);
procedure UpdateLabel(NewText: String);
end;
var
ProgBarForm: TProgBarForm;
AMin: Integer = 0;
AMax: Integer = 100;
Pos: Integer = 0;
PixPos: Integer = 0;
AText: PChar;
TextL: Integer; // length of the text
TextPL: Integer; // pixel length
TextR: TRect; // text rect
IntReq: Boolean = False;
implementation
{$R *.dfm}
uses LBAPackEd1;
procedure TProgBarForm.ShowSpecial(Caption: String; CursorChange: Boolean;
StopBtn: Boolean; Min, Max: Integer);
begin
If CursorChange then Screen.Cursor:=crHourGlass;
Image1.Canvas.Brush.Color:=clBtnFace;
Image1.Canvas.FillRect(Rect(0,0,Image1.Width,Image1.Height));
Image1.Canvas.Brush.Style:=bsClear;
AMin:=Min;
AMax:=Max;
Pos:=0;
PixPos:=0;
AText:=PChar(Caption);
TextPL:=ProgBarForm.Image1.Canvas.TextWidth(Caption);
TextL:=Length(Caption);
TextR:=Rect((Image1.Width-TextPL) div 2,1,TextPL,Image1.Canvas.TextHeight(Caption)+1);
Image1.Canvas.Font.Color:=clBlack;
Image1.Canvas.TextOut(TextR.Left,1,Caption);
Image1.Canvas.Font.Color:=clWhite;
btStop.Visible:=StopBtn;
If StopBtn then Bevel1.Height:=90 else Bevel1.Height:=57;
Form1.Enabled:=False;
IntReq:=False;
Show;
Application.ProcessMessages;
end;
procedure TProgBarForm.UpdateBar(Val: Integer);
var NewPix, a: Integer;
begin
If Pos=Val then Exit;
NewPix:=IfThen(AMax-AMin>0,Round(((Val-AMin)*317)/(AMax-AMin)));
If NewPix=PixPos then Exit;
for a:=0 to 17 do begin
Image1.Canvas.Pen.Color:=$ff9090-a*$070707;
Image1.Canvas.MoveTo(PixPos,a);
Image1.Canvas.LineTo(NewPix,a);
end;
If NewPix>=TextR.Left then begin
If TextR.Right-TextR.Left<TextPL then TextR.Right:=NewPix;
DrawText(Image1.Canvas.Handle,AText,TextL,TextR,DT_NOPREFIX);
end;
Pos:=Val;
PixPos:=NewPix;
Application.ProcessMessages;
end;
procedure TProgBarForm.UpdateLabel(NewText: String);
var temp: Integer;
begin
if AText=PChar(NewText) then Exit;
temp:=Pos;
ShowSpecial(NewText,False,btStop.Visible,AMin,AMax);
UpdateBar(temp);
end;
procedure TProgBarForm.FormCreate(Sender: TObject);
begin
DoubleBuffered:=True;
end;
procedure TProgBarForm.btStopClick(Sender: TObject);
begin
IntReq:=True;
end;
procedure TProgBarForm.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
Screen.Cursor:=crDefault;
Form1.Enabled:=True;
end;
end.