mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:47:47 +00:00
LibCore: Add CTimer::restart() and make set_interval() take effect soon.
This commit is contained in:
parent
a747a10eab
commit
d73ed74d1c
2 changed files with 23 additions and 1 deletions
|
@ -30,6 +30,13 @@ void CTimer::start(int interval)
|
||||||
m_active = true;
|
m_active = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CTimer::restart(int interval)
|
||||||
|
{
|
||||||
|
if (m_active)
|
||||||
|
stop();
|
||||||
|
start(interval);
|
||||||
|
}
|
||||||
|
|
||||||
void CTimer::stop()
|
void CTimer::stop()
|
||||||
{
|
{
|
||||||
if (!m_active)
|
if (!m_active)
|
||||||
|
@ -42,6 +49,13 @@ void CTimer::timer_event(CTimerEvent&)
|
||||||
{
|
{
|
||||||
if (m_single_shot)
|
if (m_single_shot)
|
||||||
stop();
|
stop();
|
||||||
|
else {
|
||||||
|
if (m_interval_dirty) {
|
||||||
|
stop();
|
||||||
|
start(m_interval);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (on_timeout)
|
if (on_timeout)
|
||||||
on_timeout();
|
on_timeout();
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,11 +11,18 @@ public:
|
||||||
|
|
||||||
void start();
|
void start();
|
||||||
void start(int interval);
|
void start(int interval);
|
||||||
|
void restart(int interval);
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
bool is_active() const { return m_active; }
|
bool is_active() const { return m_active; }
|
||||||
int interval() const { return m_interval; }
|
int interval() const { return m_interval; }
|
||||||
void set_interval(int interval) { m_interval = interval; }
|
void set_interval(int interval)
|
||||||
|
{
|
||||||
|
if (m_interval == interval)
|
||||||
|
return;
|
||||||
|
m_interval = interval;
|
||||||
|
m_interval_dirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
bool is_single_shot() const { return m_single_shot; }
|
bool is_single_shot() const { return m_single_shot; }
|
||||||
void set_single_shot(bool single_shot) { m_single_shot = single_shot; }
|
void set_single_shot(bool single_shot) { m_single_shot = single_shot; }
|
||||||
|
@ -29,5 +36,6 @@ private:
|
||||||
|
|
||||||
bool m_active { false };
|
bool m_active { false };
|
||||||
bool m_single_shot { false };
|
bool m_single_shot { false };
|
||||||
|
bool m_interval_dirty { false };
|
||||||
int m_interval { 0 };
|
int m_interval { 0 };
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue