diff --git a/doomsday/libs/core/include/de/core/coreevent.h b/doomsday/libs/core/include/de/core/coreevent.h index cc4bbfe365..e008fa5c00 100644 --- a/doomsday/libs/core/include/de/core/coreevent.h +++ b/doomsday/libs/core/include/de/core/coreevent.h @@ -34,6 +34,7 @@ class DE_PUBLIC CoreEvent : public Event CoreEvent(int type); CoreEvent(int type, const Value &value); CoreEvent(int type, const std::function &callback); + CoreEvent(const std::function &callback); const Value &value() const; inline int valuei() const { return value().asInt(); } diff --git a/doomsday/libs/core/include/de/core/eventloop.h b/doomsday/libs/core/include/de/core/eventloop.h index fb71e241f5..83870b8369 100644 --- a/doomsday/libs/core/include/de/core/eventloop.h +++ b/doomsday/libs/core/include/de/core/eventloop.h @@ -78,6 +78,9 @@ class DE_PUBLIC EventLoop virtual void processEvent(const Event &event); +public: + static void post(Event *event); + private: DE_PRIVATE(d) }; diff --git a/doomsday/libs/core/src/core/coreevent.cpp b/doomsday/libs/core/src/core/coreevent.cpp index ecb782e735..7f8ff754ae 100644 --- a/doomsday/libs/core/src/core/coreevent.cpp +++ b/doomsday/libs/core/src/core/coreevent.cpp @@ -35,6 +35,11 @@ CoreEvent::CoreEvent(int type, const std::function &callback) , _callback(callback) {} +CoreEvent::CoreEvent(const std::function &callback) + : Event(Callback) + , _callback(callback) +{} + const Value &CoreEvent::value() const { if (!_value) diff --git a/doomsday/libs/core/src/core/eventloop.cpp b/doomsday/libs/core/src/core/eventloop.cpp index 934aad266c..389130c442 100644 --- a/doomsday/libs/core/src/core/eventloop.cpp +++ b/doomsday/libs/core/src/core/eventloop.cpp @@ -157,6 +157,19 @@ void EventLoop::processEvent(const Event &event) } } +void EventLoop::post(Event *event) +{ + if (auto *evloop = get()) + { + evloop->postEvent(event); + } + else + { + delete event; + warning("[EventLoop] Posted event was discarded because no event loop is running"); + } +} + EventLoop *EventLoop::get() { using namespace internal;