diff options
Diffstat (limited to 'Widgets/Object.cpp')
-rw-r--r-- | Widgets/Object.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Widgets/Object.cpp b/Widgets/Object.cpp index 57216928a2..a46657a6d0 100644 --- a/Widgets/Object.cpp +++ b/Widgets/Object.cpp @@ -1,7 +1,12 @@ #include "Object.h" #include "Event.h" +#include "EventLoop.h" #include <AK/Assertions.h> +#ifdef USE_SDL +#include <SDL.h> +#endif + Object::Object(Object* parent) : m_parent(parent) { @@ -21,6 +26,8 @@ Object::~Object() void Object::event(Event& event) { switch (event.type()) { + case Event::Timer: + return onTimer(static_cast<TimerEvent&>(event)); case Event::Invalid: ASSERT_NOT_REACHED(); break; @@ -44,3 +51,35 @@ void Object::removeChild(Object& object) } m_children = std::move(newList); } + +void Object::onTimer(TimerEvent&) +{ +} + +#ifdef USE_SDL +static dword sdlTimerCallback(dword interval, void* param) +{ + EventLoop::main().postEvent(static_cast<Object*>(param), make<TimerEvent>()); + return interval; +} +#endif + +void Object::startTimer(int ms) +{ + if (m_timerID) { + printf("Object{%p} already has a timer!\n", this); + ASSERT_NOT_REACHED(); + } +#if USE_SDL + m_timerID = SDL_AddTimer(ms, sdlTimerCallback, this); +#endif +} + +void Object::stopTimer() +{ + if (!m_timerID) + return; + SDL_RemoveTimer(m_timerID); + m_timerID = 0; +} + |