Respect io.WantCaptureKeyboard & io.WantCaptureMouse

* Fixes issues with the game cursor appearing during gameplay.

Original commit sources:
 - 1601a6f269
 - bb0d98b95d

Signed-off-by: aixxe <me@aixxe.net>
This commit is contained in:
LuK1337 2016-12-20 16:20:10 +00:00 committed by aixxe
parent 13f8d44aa7
commit 7d0497e049
1 changed files with 28 additions and 13 deletions

View File

@ -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,6 +229,8 @@ 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;
if (io.WantCaptureMouse)
{
int mx, my;
Uint32 mouseMask = SDL_GetMouseState(&mx, &my);
@ -234,6 +248,7 @@ void ImGui_ImplSdl_NewFrame(SDL_Window *window) {
g_MouseWheel = 0.0f;
SDL_ShowCursor(io.MouseDrawCursor ? 0: 1);
}
ImGui::NewFrame();
}