forked from radiasoft/rshellweg
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSmartProgressBar.cpp
More file actions
96 lines (84 loc) · 2.35 KB
/
SmartProgressBar.cpp
File metadata and controls
96 lines (84 loc) · 2.35 KB
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
//---------------------------------------------------------------------------
#pragma hdrstop
#include "SmartProgressBar.h"
//---------------------------------------------------------------------------
void TSmartProgress::Initialize(TWinControl *ParentWindow)
{
TextPanel=new TPanel(ParentWindow);
TextPanel->Parent=ParentWindow;
TextPanel->Height=25;
TextPanel->Align=alBottom;
Parent=ParentWindow;
Align=alClient;
ProgressLabel=new TLabel(TextPanel);
ProgressLabel->Parent=static_cast <TWinControl *> (TextPanel);
ProgressLabel->Align=alLeft;
SetPercent(0);
TimeLabel=new TLabel(TextPanel);
TimeLabel->Parent=static_cast <TWinControl *> (TextPanel);
TimeLabel->Align=alRight;
SetTime(0);
Max=100;
Min=0;
Position=0;
}
//---------------------------------------------------------------------------
void TSmartProgress::SetPercent(double p)
{
ProgressLabel->Caption=" Done: "+s.FormatFloat("#0",p)+"%";
}
//---------------------------------------------------------------------------
void TSmartProgress::SetTime(int m)
{
int h=0,M=0,sec=0;
h=m/(60*60*1000);
M=m/(60*1000)-60*h;
sec=ceil(m/1000.0)-60*M-3600*h;
TimeLabel->Caption="Time Left: "+s.FormatFloat("00 h",h)+" : "+s.FormatFloat("00 m",M)+" : "+s.FormatFloat("00 s ",sec);
}
//---------------------------------------------------------------------------
void TSmartProgress::Set()
{
float percent=0;
finish = clock();
if (Position>0 && finish-last>250){
SetTime((Max-Position)*(finish-start)/Position);
last=finish;
percent=100.0*Position/Max;
SetPercent(percent);
}
}
//---------------------------------------------------------------------------
void TSmartProgress::Reset()
{
Position=0;
start = clock();
last=start;
Set();
}
//---------------------------------------------------------------------------
void TSmartProgress::Reset(int M)
{
Max=M;
Reset();
}
//---------------------------------------------------------------------------
void TSmartProgress::operator =(int x)
{
Position=x;
Set();
}
//---------------------------------------------------------------------------
void TSmartProgress::operator +=(int x)
{
Position+=x;
Set();
}
//---------------------------------------------------------------------------
void TSmartProgress::operator ++()
{
Position++;
Set();
}
//---------------------------------------------------------------------------
#pragma package(smart_init)