1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 16:18:12 +00:00

Start working on a Widgets library.

This commit is contained in:
Andreas Kling 2018-10-10 15:12:38 +02:00
parent a181a8f6e7
commit 8c84f9749e
18 changed files with 594 additions and 0 deletions

52
Widgets/EventLoop.cpp Normal file
View file

@ -0,0 +1,52 @@
#include "EventLoop.h"
#include "Event.h"
#include "Object.h"
static EventLoop* s_mainEventLoop;
EventLoop::EventLoop()
{
if (!s_mainEventLoop)
s_mainEventLoop = this;
}
EventLoop::~EventLoop()
{
}
EventLoop& EventLoop::main()
{
ASSERT(s_mainEventLoop);
return *s_mainEventLoop;
}
int EventLoop::exec()
{
for (;;) {
if (m_queuedEvents.isEmpty())
waitForEvent();
auto events = std::move(m_queuedEvents);
for (auto& queuedEvent : events) {
auto* receiver = queuedEvent.receiver;
auto& event = *queuedEvent.event;
printf("EventLoop: Object{%p} event %u (%s)\n", receiver, (unsigned)event.type(), event.name());
if (!receiver) {
switch (event.type()) {
case Event::Quit:
return 0;
default:
printf("event type %u with no receiver :(\n", event.type());
return 1;
}
} else {
receiver->event(event);
}
}
}
}
void EventLoop::postEvent(Object* receiver, OwnPtr<Event>&& event)
{
m_queuedEvents.append({ receiver, std::move(event) });
}