This repository has been archived by the owner on Aug 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathprogress_form.pas
158 lines (124 loc) · 3.81 KB
/
progress_form.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
{ This file is a part of Map editor for VCMI project
Copyright (C) 2017 Alexander Shishkin [email protected]
This source is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later
version.
This code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
A copy of the GNU General Public License is available on the World Wide Web at
<http://www.gnu.org/copyleft/gpl.html>. You can also obtain it by writing to the Free Software Foundation, Inc., 59
Temple Place - Suite 330, Boston, MA 02111-1307, USA.
}
unit progress_form;
{$I compilersetup.inc}
interface
uses
Classes, SysUtils, FileUtil, LazLoggerBase, Forms, Controls, Graphics, Dialogs, ComCtrls,
StdCtrls, ActnList, editor_classes;
type
{ TProgressForm }
TProgressForm = class(TForm,IProgressCallback)
act: TActionList;
actClose: TAction;
CloseButton: TButton;
lbDetail: TLabel;
Errors: TMemo;
pbDetail: TProgressBar;
procedure actCloseExecute(Sender: TObject);
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
procedure FormCreate(Sender: TObject);
private
FCompleted: Boolean;
FHasErrors: boolean;
FMax: Integer;
FCurrent: integer;
procedure SetCompleted(AValue: Boolean);
{ private declarations }
public
property HasErrors: boolean read FHasErrors;
property Completed: Boolean read FCompleted write SetCompleted;
procedure Reset;
public
//IProgressCallback
function GetMax: Integer;
procedure SetMax(AValue: Integer);
procedure Advance(ADelta: integer);
procedure NextStage(const AStageLabel:string);
procedure AddError(const ADescription: string);
procedure AddMessage(const ADescription: string);
end;
implementation
{$R *.lfm}
{ TProgressForm }
procedure TProgressForm.Advance(ADelta: integer);
var
FOld, FOldNormalized, FCurrentNormalized: Integer;
begin
FOld := FCurrent;
inc(FCurrent, ADelta);
FOldNormalized := FOld * pbDetail.Max div FMax;
FCurrentNormalized := FCurrent * pbDetail.Max div FMax;
if FOldNormalized < FCurrentNormalized then
begin
pbDetail.StepBy(FCurrentNormalized - FOldNormalized);
Application.ProcessMessages;
end;
end;
procedure TProgressForm.FormCreate(Sender: TObject);
begin
Reset;
Height:=75;
Errors.Visible:=false;
end;
procedure TProgressForm.SetCompleted(AValue: Boolean);
begin
FCompleted:=AValue;
CloseButton.Enabled := FCompleted;
end;
procedure TProgressForm.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
CloseAction := caHide; //may be reused, owned by root_manager
end;
procedure TProgressForm.actCloseExecute(Sender: TObject);
begin
Close;
end;
function TProgressForm.GetMax: Integer;
begin
Result := FMax;
end;
procedure TProgressForm.NextStage(const AStageLabel: string);
begin
pbDetail.Position := pbDetail.Min;
lbDetail.Caption := AStageLabel;
Application.ProcessMessages;
end;
procedure TProgressForm.AddError(const ADescription: string);
begin
Height:=320;
Errors.Visible := true;
Errors.Append(ADescription);
DebugLn(ADescription);
FHasErrors:=True;
end;
procedure TProgressForm.AddMessage(const ADescription: string);
begin
//todo: use different format
AddError(ADescription);
end;
procedure TProgressForm.Reset;
begin
pbDetail.Position := pbDetail.Min;
FCurrent:=0;
lbDetail.Caption := '';
FCompleted:=false;
end;
procedure TProgressForm.SetMax(AValue: Integer);
begin
FMax := AValue;
FCurrent:=0;
pbDetail.Position := pbDetail.Min;
Application.ProcessMessages;
end;
end.