From 7d0497e049a45a4d3113840344fc50ca0d07ead8 Mon Sep 17 00:00:00 2001 From: LuK1337 Date: Tue, 20 Dec 2016 16:20:10 +0000 Subject: [PATCH] Respect io.WantCaptureKeyboard & io.WantCaptureMouse * Fixes issues with the game cursor appearing during gameplay. Original commit sources: - https://github.com/McSwaggens/AimTux/commit/1601a6f26900c6191ca1de457ecce5da0ca07b83 - https://github.com/McSwaggens/AimTux/commit/bb0d98b95d9bab927f7e9766baf3b29ff2204a96 Signed-off-by: aixxe --- include/imgui/imgui_impl_sdl.cpp | 41 ++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/include/imgui/imgui_impl_sdl.cpp b/include/imgui/imgui_impl_sdl.cpp index 9e9cb73..f3d45b7 100644 --- a/include/imgui/imgui_impl_sdl.cpp +++ b/include/imgui/imgui_impl_sdl.cpp @@ -96,6 +96,9 @@ bool ImGui_ImplSdl_ProcessEvent(SDL_Event* event) { switch (event->type) { case SDL_MOUSEWHEEL: { + if (!io.WantCaptureMouse) + return false; + if (event->wheel.y > 0) g_MouseWheel = 1; if (event->wheel.y < 0) @@ -104,6 +107,9 @@ bool ImGui_ImplSdl_ProcessEvent(SDL_Event* event) { } case SDL_MOUSEBUTTONDOWN: { + if (!io.WantCaptureMouse) + return false; + if (event->button.button == SDL_BUTTON_LEFT) g_MousePressed[0] = true; if (event->button.button == SDL_BUTTON_RIGHT) g_MousePressed[1] = true; if (event->button.button == SDL_BUTTON_MIDDLE) g_MousePressed[2] = true; @@ -111,12 +117,18 @@ bool ImGui_ImplSdl_ProcessEvent(SDL_Event* event) { } case SDL_TEXTINPUT: { + if (!io.WantCaptureKeyboard) + return false; + io.AddInputCharactersUTF8(event->text.text); return true; } case SDL_KEYDOWN: case SDL_KEYUP: { + if (!io.WantCaptureKeyboard) + return false; + int key = event->key.keysym.sym & ~SDLK_SCANCODE_MASK; io.KeysDown[key] = (event->type == SDL_KEYDOWN); io.KeyShift = ((SDL_GetModState() & KMOD_SHIFT) != 0); @@ -217,23 +229,26 @@ void ImGui_ImplSdl_NewFrame(SDL_Window *window) { io.DeltaTime = g_Time > 0.0 ? (float)(current_time - g_Time) : (float)(1.0f / 60.0f); g_Time = current_time; - int mx, my; - Uint32 mouseMask = SDL_GetMouseState(&mx, &my); + if (io.WantCaptureMouse) + { + int mx, my; + Uint32 mouseMask = SDL_GetMouseState(&mx, &my); - if (SDL_GetWindowFlags(window) & SDL_WINDOW_MOUSE_FOCUS) - io.MousePos = ImVec2((float)mx, (float)my); - else - io.MousePos = ImVec2(-1, -1); + if (SDL_GetWindowFlags(window) & SDL_WINDOW_MOUSE_FOCUS) + io.MousePos = ImVec2((float)mx, (float)my); + else + io.MousePos = ImVec2(-1, -1); - io.MouseDown[0] = g_MousePressed[0] || (mouseMask & SDL_BUTTON(SDL_BUTTON_LEFT)) != 0; - io.MouseDown[1] = g_MousePressed[1] || (mouseMask & SDL_BUTTON(SDL_BUTTON_RIGHT)) != 0; - io.MouseDown[2] = g_MousePressed[2] || (mouseMask & SDL_BUTTON(SDL_BUTTON_MIDDLE)) != 0; - g_MousePressed[0] = g_MousePressed[1] = g_MousePressed[2] = false; + io.MouseDown[0] = g_MousePressed[0] || (mouseMask & SDL_BUTTON(SDL_BUTTON_LEFT)) != 0; + io.MouseDown[1] = g_MousePressed[1] || (mouseMask & SDL_BUTTON(SDL_BUTTON_RIGHT)) != 0; + io.MouseDown[2] = g_MousePressed[2] || (mouseMask & SDL_BUTTON(SDL_BUTTON_MIDDLE)) != 0; + g_MousePressed[0] = g_MousePressed[1] = g_MousePressed[2] = false; - io.MouseWheel = g_MouseWheel; - g_MouseWheel = 0.0f; + io.MouseWheel = g_MouseWheel; + g_MouseWheel = 0.0f; - SDL_ShowCursor(io.MouseDrawCursor ? 0: 1); + SDL_ShowCursor(io.MouseDrawCursor ? 0: 1); + } ImGui::NewFrame(); } \ No newline at end of file