more elaborate keyboard input handling, and debug gui improvements
[laserbrain_demo] / src / dbg_gui.cc
index c0c7984..a968b29 100644 (file)
@@ -1,3 +1,4 @@
+#include <ctype.h>
 #include "dbg_gui.h"
 #include "imgui/imgui.h"
 #include "app.h"
 #include "dbg_gui.h"
 #include "imgui/imgui.h"
 #include "app.h"
@@ -16,6 +17,26 @@ bool init_debug_gui()
        io->DisplaySize.y = win_height;
        io->RenderDrawListsFn = render_func;
 
        io->DisplaySize.y = win_height;
        io->RenderDrawListsFn = render_func;
 
+       io->KeyMap[ImGuiKey_Tab] = '\t';
+       io->KeyMap[ImGuiKey_LeftArrow] = KEY_LEFT;
+       io->KeyMap[ImGuiKey_RightArrow] = KEY_RIGHT;
+       io->KeyMap[ImGuiKey_UpArrow] = KEY_UP;
+       io->KeyMap[ImGuiKey_DownArrow] = KEY_DOWN;
+       io->KeyMap[ImGuiKey_PageUp] = KEY_PGUP;
+       io->KeyMap[ImGuiKey_PageDown] = KEY_PGDOWN;
+       io->KeyMap[ImGuiKey_Home] = KEY_HOME;
+       io->KeyMap[ImGuiKey_End] = KEY_END;
+       io->KeyMap[ImGuiKey_Delete] = KEY_DEL;
+       io->KeyMap[ImGuiKey_Backspace] = '\b';
+       io->KeyMap[ImGuiKey_Enter] = '\n';
+       io->KeyMap[ImGuiKey_Escape] = 27;
+       io->KeyMap[ImGuiKey_A] = 'a';
+       io->KeyMap[ImGuiKey_C] = 'c';
+       io->KeyMap[ImGuiKey_V] = 'v';
+       io->KeyMap[ImGuiKey_X] = 'x';
+       io->KeyMap[ImGuiKey_Y] = 'y';
+       io->KeyMap[ImGuiKey_Z] = 'z';
+
        unsigned char *pixels;
        int width, height;
        io->Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
        unsigned char *pixels;
        int width, height;
        io->Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
@@ -42,32 +63,37 @@ void debug_gui_reshape(int x, int y)
        io->DisplaySize.y = y;
 }
 
        io->DisplaySize.y = y;
 }
 
-bool debug_gui_key(int key, bool press, unsigned int modstate)
+void debug_gui_key(int key, bool press, unsigned int modstate)
 {
 {
-       io->KeysDown[key] = press;
+       if(key < 512) {
+               io->KeysDown[key] = press;
+       }
        io->KeyShift = (modstate & MOD_SHIFT) != 0;
        io->KeyCtrl = (modstate & MOD_CTRL) != 0;
        io->KeyAlt = (modstate & MOD_ALT) != 0;
        io->KeySuper = false;
 
        io->KeyShift = (modstate & MOD_SHIFT) != 0;
        io->KeyCtrl = (modstate & MOD_CTRL) != 0;
        io->KeyAlt = (modstate & MOD_ALT) != 0;
        io->KeySuper = false;
 
-       return true;    // TODO
+       if(press && key < 256 && isprint(key)) {
+               io->AddInputCharacter(key);
+       }
 }
 
 }
 
-bool debug_gui_mbutton(int bn, bool press, int x, int y)
+void debug_gui_mbutton(int bn, bool press, int x, int y)
 {
        io->MouseDown[bn] = press;
        io->MousePos.x = x;
        io->MousePos.y = y;
 {
        io->MouseDown[bn] = press;
        io->MousePos.x = x;
        io->MousePos.y = y;
-
-       return true;    // TODO
 }
 
 }
 
-bool debug_gui_mmotion(int x, int y)
+void debug_gui_mmotion(int x, int y)
 {
        io->MousePos.x = x;
        io->MousePos.y = y;
 {
        io->MousePos.x = x;
        io->MousePos.y = y;
+}
 
 
-       return true;    // TODO
+void debug_gui_wheel(int dir)
+{
+       io->MouseWheel = dir;
 }
 
 static void render_func(ImDrawData *ddat)
 }
 
 static void render_func(ImDrawData *ddat)