mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-22 11:57:00 +00:00
Examples: SDL+GL3: Added Navigation keyboard mapping. (#787)
This commit is contained in:
parent
7e1496e994
commit
4b49f03a40
@ -4,6 +4,7 @@
|
||||
|
||||
// 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().
|
||||
@ -412,6 +413,29 @@ 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();
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
// 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().
|
||||
|
@ -34,7 +34,9 @@ int main(int, char**)
|
||||
gl3wInit();
|
||||
|
||||
// Setup ImGui binding
|
||||
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
||||
ImGui_ImplSdlGL3_Init(window);
|
||||
//io.NavFlags |= ImGuiNavFlags_EnableKeyboard;
|
||||
|
||||
// Setup style
|
||||
ImGui::StyleColorsDark();
|
||||
@ -47,7 +49,6 @@ int main(int, char**)
|
||||
// - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call.
|
||||
// - Read 'misc/fonts/README.txt' for more instructions and details.
|
||||
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
||||
//ImGuiIO& io = ImGui::GetIO();
|
||||
//io.Fonts->AddFontDefault();
|
||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f);
|
||||
|
Loading…
Reference in New Issue
Block a user