CtrlLib: ProgressInfo optimized (added time granularity to avoid too frequent updates)

git-svn-id: svn://ultimatepp.org/upp/trunk@11030 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2017-04-25 16:14:36 +00:00
parent 127bf245d1
commit cfad4caea2
2 changed files with 26 additions and 5 deletions

View file

@ -296,12 +296,30 @@ ProgressInfo& ProgressInfo::Set(int _pos, int _total)
{
pos = _pos;
total = _total;
Refresh();
if(info)
info->Sync();
dword t = GetTickCount();
if((int)(t - set_time) >= granularity) {
set_time = t;
Refresh();
if(info)
info->Sync();
}
return *this;
}
void ProgressInfo::Reset()
{
tabi = 0;
cx = 200;
total = 100;
pos = 0;
tw = 0;
info = NULL;
granularity = 50;
set_time = 0;
}
ProgressInfo::~ProgressInfo()
{
if(info)

View file

@ -97,9 +97,12 @@ class ProgressInfo {
int cx;
int total;
int pos;
int granularity;
dword set_time;
void Refresh();
void Reset() { tabi = 0; cx = 200; total = 100; pos = 0; tw = 0; info = NULL; }
void Reset();
public:
ProgressInfo& Text(const String& s) { text = s; Refresh(); return *this; }
@ -116,7 +119,7 @@ public:
int GetTotal() const { return total; }
void operator=(int p) { Set(p); }
void operator++() { pos++; Refresh(); }
void operator++() { Set(pos + 1, total); }
operator int() { return pos; }
ProgressInfo() { Reset(); }