From f538123210381975a8aded31f53ffff92d95a806 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sun, 27 Oct 2019 00:08:01 +1000 Subject: [PATCH] Frontend: Use imgui functions for handling SDL events --- src/duckstation/sdl_interface.cpp | 70 +++---------------------------- src/duckstation/sdl_interface.h | 1 - 2 files changed, 6 insertions(+), 65 deletions(-) diff --git a/src/duckstation/sdl_interface.cpp b/src/duckstation/sdl_interface.cpp index d1223353f..dfd1e5532 100644 --- a/src/duckstation/sdl_interface.cpp +++ b/src/duckstation/sdl_interface.cpp @@ -468,8 +468,7 @@ static void HandleSDLControllerButtonEventForController(const SDL_Event* ev, Dig void SDLInterface::HandleSDLEvent(const SDL_Event* event) { - if (PassEventToImGui(event)) - return; + ImGui_ImplSDL2_ProcessEvent(event); switch (event->type) { @@ -489,8 +488,11 @@ void SDLInterface::HandleSDLEvent(const SDL_Event* event) case SDL_KEYDOWN: case SDL_KEYUP: - HandleSDLKeyEvent(event); - break; + { + if (!ImGui::GetIO().WantCaptureKeyboard) + HandleSDLKeyEvent(event); + } + break; case SDL_CONTROLLERDEVICEADDED: { @@ -573,66 +575,6 @@ void SDLInterface::HandleSDLKeyEvent(const SDL_Event* event) } } -bool SDLInterface::PassEventToImGui(const SDL_Event* event) -{ - ImGuiIO& io = ImGui::GetIO(); - switch (event->type) - { - case SDL_MOUSEWHEEL: - { - if (event->wheel.x > 0) - io.MouseWheelH += 1; - if (event->wheel.x < 0) - io.MouseWheelH -= 1; - if (event->wheel.y > 0) - io.MouseWheel += 1; - if (event->wheel.y < 0) - io.MouseWheel -= 1; - return io.WantCaptureMouse; - } - - case SDL_MOUSEBUTTONDOWN: - case SDL_MOUSEBUTTONUP: - { - bool down = event->type == SDL_MOUSEBUTTONDOWN; - if (event->button.button == SDL_BUTTON_LEFT) - io.MouseDown[0] = down; - if (event->button.button == SDL_BUTTON_RIGHT) - io.MouseDown[1] = down; - if (event->button.button == SDL_BUTTON_MIDDLE) - io.MouseDown[2] = down; - return io.WantCaptureMouse; - } - - case SDL_MOUSEMOTION: - { - io.MousePos.x = float(event->motion.x); - io.MousePos.y = float(event->motion.y); - return io.WantCaptureMouse; - } - - case SDL_TEXTINPUT: - { - io.AddInputCharactersUTF8(event->text.text); - return io.WantCaptureKeyboard; - } - - case SDL_KEYDOWN: - case SDL_KEYUP: - { - int key = event->key.keysym.scancode; - IM_ASSERT(key >= 0 && key < IM_ARRAYSIZE(io.KeysDown)); - io.KeysDown[key] = (event->type == SDL_KEYDOWN); - io.KeyShift = ((SDL_GetModState() & KMOD_SHIFT) != 0); - io.KeyCtrl = ((SDL_GetModState() & KMOD_CTRL) != 0); - io.KeyAlt = ((SDL_GetModState() & KMOD_ALT) != 0); - io.KeySuper = ((SDL_GetModState() & KMOD_GUI) != 0); - return io.WantCaptureKeyboard; - } - } - return false; -} - void SDLInterface::Render() { DrawImGui(); diff --git a/src/duckstation/sdl_interface.h b/src/duckstation/sdl_interface.h index 96448ab09..af49350e1 100644 --- a/src/duckstation/sdl_interface.h +++ b/src/duckstation/sdl_interface.h @@ -75,7 +75,6 @@ private: void HandleSDLEvent(const SDL_Event* event); void HandleSDLKeyEvent(const SDL_Event* event); - bool PassEventToImGui(const SDL_Event* event); void Render(); void RenderDisplay(); void DrawMainMenuBar();