From cfad4caea2e38930b88fbc1789cab9ea2ae49e54 Mon Sep 17 00:00:00 2001 From: cxl Date: Tue, 25 Apr 2017 16:14:36 +0000 Subject: [PATCH] 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 --- uppsrc/CtrlLib/StatusBar.cpp | 24 +++++++++++++++++++++--- uppsrc/CtrlLib/StatusBar.h | 7 +++++-- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/uppsrc/CtrlLib/StatusBar.cpp b/uppsrc/CtrlLib/StatusBar.cpp index 1255a5501..98e3e75df 100644 --- a/uppsrc/CtrlLib/StatusBar.cpp +++ b/uppsrc/CtrlLib/StatusBar.cpp @@ -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) diff --git a/uppsrc/CtrlLib/StatusBar.h b/uppsrc/CtrlLib/StatusBar.h index 331a6f894..10c882d31 100644 --- a/uppsrc/CtrlLib/StatusBar.h +++ b/uppsrc/CtrlLib/StatusBar.h @@ -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(); }