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