diff --git a/src/imgui/imgui_layer.h b/src/imgui/imgui_layer.h index a6c7e2a4a..a2ec7fd24 100644 --- a/src/imgui/imgui_layer.h +++ b/src/imgui/imgui_layer.h @@ -12,6 +12,10 @@ public: static void RemoveLayer(Layer* layer); virtual void Draw() = 0; + + virtual bool ShouldGrabGamepad() { + return false; + } }; } // namespace ImGui \ No newline at end of file diff --git a/src/imgui/renderer/imgui_core.cpp b/src/imgui/renderer/imgui_core.cpp index 41b7add99..0b8f12e3a 100644 --- a/src/imgui/renderer/imgui_core.cpp +++ b/src/imgui/renderer/imgui_core.cpp @@ -71,10 +71,7 @@ void Shutdown(const vk::Device& device) { } bool ProcessEvent(SDL_Event* event) { - const bool used = Sdl::ProcessEvent(event); - if (!used) { - return false; - } + Sdl::ProcessEvent(event); switch (event->type) { case SDL_EVENT_MOUSE_MOTION: case SDL_EVENT_MOUSE_WHEEL: @@ -85,6 +82,15 @@ bool ProcessEvent(SDL_Event* event) { case SDL_EVENT_KEY_DOWN: case SDL_EVENT_KEY_UP: return GetIO().WantCaptureKeyboard; + case SDL_EVENT_GAMEPAD_BUTTON_DOWN: + case SDL_EVENT_GAMEPAD_BUTTON_UP: + case SDL_EVENT_GAMEPAD_AXIS_MOTION: + case SDL_EVENT_GAMEPAD_ADDED: + case SDL_EVENT_GAMEPAD_REMOVED: + case SDL_EVENT_GAMEPAD_TOUCHPAD_DOWN: + case SDL_EVENT_GAMEPAD_TOUCHPAD_UP: + case SDL_EVENT_GAMEPAD_TOUCHPAD_MOTION: + return (GetIO().BackendFlags & ImGuiBackendFlags_HasGamepad) != 0; default: return false; } @@ -109,8 +115,17 @@ void NewFrame() { Sdl::NewFrame(); ImGui::NewFrame(); + bool capture_gamepad = false; for (auto* layer : layers) { layer->Draw(); + if (layer->ShouldGrabGamepad()) { + capture_gamepad = true; + } + } + if (capture_gamepad) { + GetIO().BackendFlags |= ImGuiBackendFlags_HasGamepad; + } else { + GetIO().BackendFlags &= ~ImGuiBackendFlags_HasGamepad; } }