载入中...
搜索中...
未找到
EventSink.cpp
浏览该文件的文档.
1// Lets ImGui see platform events before anything else claims them.
2//
3// The SDL event pump used to call UI::processEvent directly, which was one of
4// the eight modules it had to know about. The UI module binds itself as owner
5// at construction so the hot path never looks up ModuleManager.
6
7#include "common/Capability.h"
9#include "ui/EventSinkOwner.h"
10#include "ui/UI.h"
11
12#include <SDL2/SDL_events.h>
13
14namespace eve::ui {
15namespace {
16
17UI* g_owner = nullptr;
18
19class UIEventSink : public eve::platform_event::IPlatformEventSink {
20public:
21 bool shouldConsumePlatformEvent(const void *nativeEvent) override {
22 if (g_owner) g_owner->processEvent(static_cast<const SDL_Event*>(nativeEvent));
23 // ImGui records the event for its own state but does not claim it; the
24 // game still receives the matching message.
25 return false;
26 }
27};
28
29struct Register {
30 Register() {
31 static UIEventSink sink;
32 eve::cap::addListener<eve::platform_event::IPlatformEventSink>(
34 }
35} g_register;
36
37} // namespace
38
39void bindUIEventSinkOwner(UI* owner) noexcept { g_owner = owner; }
40
41} // namespace eve::ui
EVENGINE_API_FOUNDATION public API.
Declarative UI module (eve.UI).
Definition UI.h:41
void bindUIEventSinkOwner(UI *owner) noexcept
Bind the live UI module into the platform event sink. @ownership Borrowed; cleared when the UI module...
Definition EventSink.cpp:39