mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-08 12:19:37 +03:00
25f28a54a1
Added a GTimer class to help with this. It's just a simple GObject subclass that sets up an event loop timer and invokes a callback on timeout.
40 lines
503 B
C++
40 lines
503 B
C++
#include <LibGUI/GTimer.h>
|
|
|
|
GTimer::GTimer(GObject* parent)
|
|
: GObject(parent)
|
|
{
|
|
}
|
|
|
|
GTimer::~GTimer()
|
|
{
|
|
}
|
|
|
|
void GTimer::start()
|
|
{
|
|
start(m_interval);
|
|
}
|
|
|
|
void GTimer::start(int interval)
|
|
{
|
|
if (m_active)
|
|
return;
|
|
start_timer(interval);
|
|
m_active = true;
|
|
}
|
|
|
|
void GTimer::stop()
|
|
{
|
|
if (!m_active)
|
|
return;
|
|
stop_timer();
|
|
m_active = false;
|
|
}
|
|
|
|
void GTimer::timer_event(GTimerEvent&)
|
|
{
|
|
if (m_single_shot)
|
|
stop();
|
|
if (on_timeout)
|
|
on_timeout();
|
|
}
|