Rate-limit volume meter updates

This commit is contained in:
Jean Pierre Cimalando 2021-05-11 19:43:44 +02:00
parent 2724a3490c
commit cbc7c912dd
2 changed files with 19 additions and 1 deletions

View file

@ -991,7 +991,23 @@ void SLevelMeter::setValue(float value)
return;
value_ = value;
invalid();
// instantiate the timer lazily
if (!timer_) {
const uint32_t interval = 10;
timer_ = makeOwned<CVSTGUITimer>(
[this](CVSTGUITimer* timer) {
timer->stop();
timerArmed_ = false;
invalid();
}, interval, false);
}
// defer the update, but do not rearm the timer
if (!timerArmed_) {
timerArmed_ = true;
timer_->start();
}
}
void SLevelMeter::draw(CDrawContext* dc)

View file

@ -402,6 +402,8 @@ private:
CColor dangerFillColor_;
CColor backColor_;
CCoord radius_ = 5.0;
SharedPointer<CVSTGUITimer> timer_;
bool timerArmed_ = false;
};
///