mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 00:27:43 +00:00
Add a clock widget.
This commit is contained in:
parent
6637dec958
commit
73895ce043
12 changed files with 143 additions and 15 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue