Browse Source

Fixes for ocornut-imgui integration: keyboard keys, modifiers

ocornut 10 years ago
parent
commit
a3fd7b7132
1 changed files with 24 additions and 23 deletions
  1. 24 23
      examples/common/imgui/ocornut_imgui.cpp

+ 24 - 23
examples/common/imgui/ocornut_imgui.cpp

@@ -10,6 +10,7 @@
 #include "imgui.h"
 #include "ocornut_imgui.h"
 #include <stb/stb_image.c>
+#include "../entry/input.h"
 
 #include "vs_ocornut_imgui.bin.h"
 #include "fs_ocornut_imgui.bin.h"
@@ -111,10 +112,23 @@ struct OcornutImguiContext
 		io.IniFilename = NULL;
 		io.PixelCenterOffset = bgfx::RendererType::Direct3D9 == bgfx::getRendererType() ? 0.0f : 0.5f;
 
-		for (uint32_t ii = 0; ii < ImGuiKey_COUNT; ++ii)
-		{
-			io.KeyMap[ii] = ImGuiKey_(ii);
-		}
+        io.KeyMap[ImGuiKey_Tab]        = (int)entry::Key::Tab;
+        io.KeyMap[ImGuiKey_LeftArrow]  = (int)entry::Key::Left;
+        io.KeyMap[ImGuiKey_RightArrow] = (int)entry::Key::Right;
+        io.KeyMap[ImGuiKey_UpArrow]    = (int)entry::Key::Up;
+        io.KeyMap[ImGuiKey_DownArrow]  = (int)entry::Key::Down;
+        io.KeyMap[ImGuiKey_Home]       = (int)entry::Key::Home;
+        io.KeyMap[ImGuiKey_End]        = (int)entry::Key::End;
+        io.KeyMap[ImGuiKey_Delete]     = (int)entry::Key::Delete;
+        io.KeyMap[ImGuiKey_Backspace]  = (int)entry::Key::Backspace;
+        io.KeyMap[ImGuiKey_Enter]      = (int)entry::Key::Return;
+        io.KeyMap[ImGuiKey_Escape]     = (int)entry::Key::Esc;
+        io.KeyMap[ImGuiKey_A]          = (int)entry::Key::KeyA;
+        io.KeyMap[ImGuiKey_C]          = (int)entry::Key::KeyC;
+        io.KeyMap[ImGuiKey_V]          = (int)entry::Key::KeyV;
+        io.KeyMap[ImGuiKey_X]          = (int)entry::Key::KeyX;
+        io.KeyMap[ImGuiKey_Y]          = (int)entry::Key::KeyY;
+        io.KeyMap[ImGuiKey_Z]          = (int)entry::Key::KeyZ;
 
 		const bgfx::Memory* vsmem;
 		const bgfx::Memory* fsmem;
@@ -197,25 +211,12 @@ struct OcornutImguiContext
         io.MouseWheel = (float)(_scroll - m_lastScroll);
         m_lastScroll = _scroll;
 
-#if 0
-		io.KeysDown[ImGuiKey_Tab]        = inputGetKeyState(entry::Key::Tab);
-		io.KeysDown[ImGuiKey_LeftArrow]  = inputGetKeyState(entry::Key::Left);
-		io.KeysDown[ImGuiKey_RightArrow] = inputGetKeyState(entry::Key::Right);
-		io.KeysDown[ImGuiKey_UpArrow]    = inputGetKeyState(entry::Key::Up);
-		io.KeysDown[ImGuiKey_DownArrow]  = inputGetKeyState(entry::Key::Down);
-		io.KeysDown[ImGuiKey_Home]       = inputGetKeyState(entry::Key::Home);
-		io.KeysDown[ImGuiKey_End]        = inputGetKeyState(entry::Key::End);
-		io.KeysDown[ImGuiKey_Delete]     = inputGetKeyState(entry::Key::Delete);
-		io.KeysDown[ImGuiKey_Backspace]  = inputGetKeyState(entry::Key::Backspace);
-		io.KeysDown[ImGuiKey_Enter]      = inputGetKeyState(entry::Key::Return);
-		io.KeysDown[ImGuiKey_Escape]     = inputGetKeyState(entry::Key::Esc);
-		io.KeysDown[ImGuiKey_A]          = inputGetKeyState(entry::Key::KeyA);
-		io.KeysDown[ImGuiKey_C]          = inputGetKeyState(entry::Key::KeyC);
-		io.KeysDown[ImGuiKey_V]          = inputGetKeyState(entry::Key::KeyV);
-		io.KeysDown[ImGuiKey_X]          = inputGetKeyState(entry::Key::KeyX);
-		io.KeysDown[ImGuiKey_Y]          = inputGetKeyState(entry::Key::KeyY);
-		io.KeysDown[ImGuiKey_Z]          = inputGetKeyState(entry::Key::KeyZ);
-#endif // 0
+        uint8_t modifiers = inputGetModifiersState();
+        io.KeyShift = 0 != (modifiers & (entry::Modifier::LeftShift | entry::Modifier::RightShift) );
+        io.KeyCtrl  = 0 != (modifiers & (entry::Modifier::LeftCtrl  | entry::Modifier::RightCtrl ) );
+        io.KeyAlt   = 0 != (modifiers & (entry::Modifier::LeftAlt   | entry::Modifier::RightAlt  ) );
+        for (int32_t ii = 0; ii < (int32_t)entry::Key::Count; ++ii)
+            io.KeysDown[ii] = inputGetKeyState((entry::Key::Enum)ii);
 
 		ImGui::NewFrame();