mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 13:27:35 +00:00
LibCore: Move LibGUI/GTimer to LibCore/CTimer.
This commit is contained in:
parent
667e678aa6
commit
47a2982119
5 changed files with 14 additions and 14 deletions
39
LibCore/CTimer.cpp
Normal file
39
LibCore/CTimer.cpp
Normal file
|
@ -0,0 +1,39 @@
|
|||
#include <LibCore/CTimer.h>
|
||||
|
||||
CTimer::CTimer(CObject* parent)
|
||||
: CObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
CTimer::~CTimer()
|
||||
{
|
||||
}
|
||||
|
||||
void CTimer::start()
|
||||
{
|
||||
start(m_interval);
|
||||
}
|
||||
|
||||
void CTimer::start(int interval)
|
||||
{
|
||||
if (m_active)
|
||||
return;
|
||||
start_timer(interval);
|
||||
m_active = true;
|
||||
}
|
||||
|
||||
void CTimer::stop()
|
||||
{
|
||||
if (!m_active)
|
||||
return;
|
||||
stop_timer();
|
||||
m_active = false;
|
||||
}
|
||||
|
||||
void CTimer::timer_event(CTimerEvent&)
|
||||
{
|
||||
if (m_single_shot)
|
||||
stop();
|
||||
if (on_timeout)
|
||||
on_timeout();
|
||||
}
|
32
LibCore/CTimer.h
Normal file
32
LibCore/CTimer.h
Normal file
|
@ -0,0 +1,32 @@
|
|||
#pragma once
|
||||
|
||||
#include <LibCore/CObject.h>
|
||||
#include <AK/Function.h>
|
||||
|
||||
class CTimer final : public CObject {
|
||||
public:
|
||||
explicit CTimer(CObject* parent = nullptr);
|
||||
virtual ~CTimer() override;
|
||||
|
||||
void start();
|
||||
void start(int interval);
|
||||
void stop();
|
||||
|
||||
bool is_active() const { return m_active; }
|
||||
int interval() const { return m_interval; }
|
||||
void set_interval(int interval) { m_interval = interval; }
|
||||
|
||||
bool is_single_shot() const { return m_single_shot; }
|
||||
void set_single_shot(bool single_shot) { m_single_shot = single_shot; }
|
||||
|
||||
Function<void()> on_timeout;
|
||||
|
||||
virtual const char* class_name() const override { return "CTimer"; }
|
||||
|
||||
private:
|
||||
virtual void timer_event(CTimerEvent&) override;
|
||||
|
||||
bool m_active { false };
|
||||
bool m_single_shot { false };
|
||||
int m_interval { 0 };
|
||||
};
|
|
@ -11,6 +11,7 @@ OBJS = \
|
|||
CNetworkJob.o \
|
||||
CNetworkResponse.o \
|
||||
CObject.o \
|
||||
CTimer.o \
|
||||
CEventLoop.o \
|
||||
CEvent.o
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue