Nav: Keyboard is now automatically mapped based on io.KeyDown[]. (#787)

This commit is contained in:
omar
2018-02-06 19:54:30 +01:00
parent 9e3a807813
commit 3171f90a1a
8 changed files with 59 additions and 99 deletions

View File

@ -2,7 +2,6 @@
// Implemented features:
// [X] User texture binding. Use 'ID3D11ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp.
// [X] Keyboard navigation mapping. Enable with 'io.NavFlags |= ImGuiNavFlags_EnableKeyboard'.
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown().
@ -609,26 +608,6 @@ void ImGui_ImplDX11_NewFrame()
// io.MouseDown : filled by WM_*BUTTON* events
// io.MouseWheel : filled by WM_MOUSEWHEEL events
// Gamepad/keyboard navigation mapping [BETA]
memset(io.NavInputs, 0, sizeof(io.NavInputs));
if (io.NavFlags & ImGuiNavFlags_EnableKeyboard)
{
// Update keyboard
// FIXME-NAV: We are still using some of the ImGuiNavInput_PadXXX enums as keyboard support is incomplete.
#define MAP_KEY(NAV_NO, KEY_NO) { if (io.KeysDown[KEY_NO]) io.NavInputs[NAV_NO] = 1.0f; }
MAP_KEY(ImGuiNavInput_KeyLeft, VK_LEFT);
MAP_KEY(ImGuiNavInput_KeyRight, VK_RIGHT);
MAP_KEY(ImGuiNavInput_KeyUp, VK_UP);
MAP_KEY(ImGuiNavInput_KeyDown, VK_DOWN);
MAP_KEY(ImGuiNavInput_KeyMenu, VK_MENU);
MAP_KEY(ImGuiNavInput_PadActivate, VK_SPACE);
MAP_KEY(ImGuiNavInput_PadCancel, VK_ESCAPE);
MAP_KEY(ImGuiNavInput_PadInput, VK_RETURN);
MAP_KEY(ImGuiNavInput_PadTweakFast, VK_SHIFT);
MAP_KEY(ImGuiNavInput_PadTweakSlow, VK_CONTROL);
#undef MAP_KEY
}
// Set OS mouse position if requested last frame by io.WantMoveMouse flag (used when io.NavMovesTrue is enabled by user and using directional navigation)
if (io.WantMoveMouse)
{

View File

@ -2,7 +2,6 @@
// Implemented features:
// [X] User texture binding. Use 'ID3D11ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp.
// [X] Keyboard navigation mapping. Enable with 'io.NavFlags |= ImGuiNavFlags_EnableKeyboard'.
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown().

View File

@ -4,7 +4,6 @@
// Implemented features:
// [X] User texture binding. Cast 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID in imgui.cpp.
// [X] Keyboard navigation mapping. Enable with 'io.NavFlags |= ImGuiNavFlags_EnableKeyboard'.
// [X] Gamepad navigation mapping. Enable with 'io.NavFlags |= ImGuiNavFlags_EnableGamepad'.
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
@ -416,27 +415,8 @@ void ImGui_ImplGlfwGL3_NewFrame()
// Hide OS mouse cursor if ImGui is drawing it
glfwSetInputMode(g_Window, GLFW_CURSOR, io.MouseDrawCursor ? GLFW_CURSOR_HIDDEN : GLFW_CURSOR_NORMAL);
// Gamepad/keyboard navigation mapping [BETA]
// Gamepad navigation mapping [BETA]
memset(io.NavInputs, 0, sizeof(io.NavInputs));
if (io.NavFlags & ImGuiNavFlags_EnableKeyboard)
{
// Update keyboard
// FIXME-NAV: We are still using some of the ImGuiNavInput_PadXXX enums as keyboard support is incomplete.
#define MAP_KEY(NAV_NO, KEY_NO) { if (io.KeysDown[KEY_NO]) io.NavInputs[NAV_NO] = 1.0f; }
MAP_KEY(ImGuiNavInput_KeyLeft, GLFW_KEY_LEFT);
MAP_KEY(ImGuiNavInput_KeyRight, GLFW_KEY_RIGHT);
MAP_KEY(ImGuiNavInput_KeyUp, GLFW_KEY_UP);
MAP_KEY(ImGuiNavInput_KeyDown, GLFW_KEY_DOWN);
MAP_KEY(ImGuiNavInput_KeyMenu, GLFW_KEY_LEFT_ALT);
MAP_KEY(ImGuiNavInput_PadActivate, GLFW_KEY_SPACE);
MAP_KEY(ImGuiNavInput_PadCancel, GLFW_KEY_ESCAPE);
MAP_KEY(ImGuiNavInput_PadInput, GLFW_KEY_ENTER);
MAP_KEY(ImGuiNavInput_PadTweakSlow, GLFW_KEY_LEFT_ALT);
MAP_KEY(ImGuiNavInput_PadTweakSlow, GLFW_KEY_RIGHT_ALT);
MAP_KEY(ImGuiNavInput_PadTweakFast, GLFW_KEY_LEFT_SHIFT);
MAP_KEY(ImGuiNavInput_PadTweakFast, GLFW_KEY_RIGHT_SHIFT);
#undef MAP_KEY
}
if (io.NavFlags & ImGuiNavFlags_EnableGamepad)
{
// Update gamepad inputs
@ -453,10 +433,10 @@ void ImGui_ImplGlfwGL3_NewFrame()
MAP_BUTTON(ImGuiNavInput_DpadRight, 11); // D-Pad Right
MAP_BUTTON(ImGuiNavInput_DpadUp, 10); // D-Pad Up
MAP_BUTTON(ImGuiNavInput_DpadDown, 12); // D-Pad Down
MAP_BUTTON(ImGuiNavInput_FocusPrev, 4); // L Trigger
MAP_BUTTON(ImGuiNavInput_FocusNext, 5); // R Trigger
MAP_BUTTON(ImGuiNavInput_TweakSlow, 4); // L Trigger
MAP_BUTTON(ImGuiNavInput_TweakFast, 5); // R Trigger
MAP_BUTTON(ImGuiNavInput_FocusPrev, 4); // L1 / LB
MAP_BUTTON(ImGuiNavInput_FocusNext, 5); // R1 / RB
MAP_BUTTON(ImGuiNavInput_TweakSlow, 4); // L1 / LB
MAP_BUTTON(ImGuiNavInput_TweakFast, 5); // R1 / RB
MAP_ANALOG(ImGuiNavInput_LStickLeft, 0, -0.3f, -0.9f);
MAP_ANALOG(ImGuiNavInput_LStickRight,0, +0.3f, +0.9f);
MAP_ANALOG(ImGuiNavInput_LStickUp, 1, +0.3f, +0.9f);

View File

@ -4,7 +4,6 @@
// Implemented features:
// [X] User texture binding. Cast 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID in imgui.cpp.
// [X] Keyboard navigation mapping. Enable with 'io.NavFlags |= ImGuiNavFlags_EnableKeyboard'.
// [X] Gamepad navigation mapping. Enable with 'io.NavFlags |= ImGuiNavFlags_EnableGamepad'.
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.

View File

@ -4,7 +4,6 @@
// Implemented features:
// [X] User texture binding. Cast 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID in imgui.cpp.
// [X] Keyboard navigation mapping. Enable with 'io.NavFlags |= ImGuiNavFlags_EnableKeyboard'.
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown().
@ -414,29 +413,6 @@ void ImGui_ImplSdlGL3_NewFrame(SDL_Window* window)
// Hide OS mouse cursor if ImGui is drawing it
SDL_ShowCursor(io.MouseDrawCursor ? 0 : 1);
// Gamepad/keyboard navigation mapping [BETA]
memset(io.NavInputs, 0, sizeof(io.NavInputs));
if (io.NavFlags & ImGuiNavFlags_EnableKeyboard)
{
// Update keyboard
// FIXME-NAV: We are still using some of the ImGuiNavInput_PadXXX enums as keyboard support is incomplete.
#define MAP_KEY(NAV_NO, KEY_NO) { if (io.KeysDown[KEY_NO]) io.NavInputs[NAV_NO] = 1.0f; }
MAP_KEY(ImGuiNavInput_KeyLeft, SDL_SCANCODE_LEFT);
MAP_KEY(ImGuiNavInput_KeyRight, SDL_SCANCODE_RIGHT);
MAP_KEY(ImGuiNavInput_KeyUp, SDL_SCANCODE_UP);
MAP_KEY(ImGuiNavInput_KeyDown, SDL_SCANCODE_DOWN);
MAP_KEY(ImGuiNavInput_KeyMenu, SDL_SCANCODE_LALT);
MAP_KEY(ImGuiNavInput_KeyMenu, SDL_SCANCODE_RALT);
MAP_KEY(ImGuiNavInput_PadActivate, SDL_SCANCODE_SPACE);
MAP_KEY(ImGuiNavInput_PadCancel, SDL_SCANCODE_ESCAPE);
MAP_KEY(ImGuiNavInput_PadInput, SDL_SCANCODE_RETURN);
MAP_KEY(ImGuiNavInput_PadTweakSlow, SDL_SCANCODE_LALT);
MAP_KEY(ImGuiNavInput_PadTweakSlow, SDL_SCANCODE_LALT);
MAP_KEY(ImGuiNavInput_PadTweakFast, SDL_SCANCODE_LSHIFT);
MAP_KEY(ImGuiNavInput_PadTweakFast, SDL_SCANCODE_RSHIFT);
#undef MAP_KEY
}
// Start the frame. This call will update the io.WantCaptureMouse, io.WantCaptureKeyboard flag that you can use to dispatch inputs (or not) to your application.
ImGui::NewFrame();
}

View File

@ -4,7 +4,6 @@
// Implemented features:
// [X] User texture binding. Cast 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID in imgui.cpp.
// [X] Keyboard navigation mapping. Enable with 'io.NavFlags |= ImGuiNavFlags_EnableKeyboard'.
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown().