{
unsigned int mod = app_get_modifiers();
- if(!debug_gui_key(key, pressed, mod)) {
- // the debug gui indicated that we should ignore the event
- return;
+ if(show_debug_gui && !(pressed && (key == '`' || key == 27))) {
+ debug_gui_key(key, pressed, mod);
+ return; // ignore all keystrokes when GUI is visible
}
if(pressed) {
}
break;
- case '\t':
+ case '`':
show_debug_gui = !show_debug_gui;
show_message("debug gui %s", show_debug_gui ? "enabled" : "disabled");
break;
- case '`':
+ case 'm':
app_toggle_grab_mouse();
show_message("mouse %s", app_is_mouse_grabbed() ? "grabbed" : "released");
break;
void app_mouse_button(int bn, bool pressed, int x, int y)
{
- if(!debug_gui_mbutton(bn, pressed, x, y)) {
- // the debug GUI indicated we should ignore the event
- return;
+ if(show_debug_gui) {
+ debug_gui_mbutton(bn, pressed, x, y);
+ return; // ignore mouse events while GUI is visible
}
prev_mx = x;
void app_mouse_motion(int x, int y)
{
- if(!debug_gui_mmotion(x, y)) {
- // the debug GUI indicated we should ignore the event
- return;
+ if(show_debug_gui) {
+ debug_gui_mmotion(x, y);
+ return; // ignore mouse events while GUI is visible
}
int dx = x - prev_mx;
}
}
+void app_mouse_wheel(int dir)
+{
+ if(show_debug_gui) {
+ debug_gui_wheel(dir);
+ }
+}
+
void app_gamepad_axis(int axis, float val)
{
switch(axis) {
MOD_CTRL = 4
};
+/* special keys */
+enum {
+ KEY_DEL = 127,
+ KEY_LEFT,
+ KEY_RIGHT,
+ KEY_UP,
+ KEY_DOWN,
+ KEY_PGUP,
+ KEY_PGDOWN,
+ KEY_HOME,
+ KEY_END,
+ KEY_F1,
+ KEY_F2,
+ KEY_F3,
+ KEY_F4,
+ KEY_F5,
+ KEY_F6,
+ KEY_F7,
+ KEY_F8,
+ KEY_F9,
+ KEY_F10,
+ KEY_F11,
+ KEY_F12
+};
+
/* XXX make sure these match with SDL_GameControllerButton */
enum {
GPAD_A,
void app_mouse_button(int bn, bool pressed, int x, int y);
void app_mouse_motion(int x, int y);
void app_mouse_delta(int dx, int dy);
+void app_mouse_wheel(int dir);
void app_gamepad_axis(int axis, float val);
void app_gamepad_button(int bn, bool pressed);
+#include <ctype.h>
#include "dbg_gui.h"
#include "imgui/imgui.h"
#include "app.h"
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);
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;
- 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;
-
- 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;
+}
- return true; // TODO
+void debug_gui_wheel(int dir)
+{
+ io->MouseWheel = dir;
}
static void render_func(ImDrawData *ddat)
void cleanup_debug_gui();
void debug_gui_reshape(int x, int y);
-bool debug_gui_key(int key, bool press, unsigned int modstate);
-bool debug_gui_mbutton(int bn, bool press, int x, int y);
-bool debug_gui_mmotion(int x, int y);
+void debug_gui_key(int key, bool press, unsigned int modstate);
+void debug_gui_mbutton(int bn, bool press, int x, int y);
+void debug_gui_mmotion(int x, int y);
+void debug_gui_wheel(int dir);
#endif // DBG_GUI_H_
static bool init(int argc, char **argv);
static void process_event(SDL_Event *ev);
static void proc_modkeys();
+static int translate_keysym(SDL_Keycode sym);
static SDL_Window *win;
static SDL_GLContext ctx;
static void process_event(SDL_Event *ev)
{
+ int key;
+
switch(ev->type) {
case SDL_QUIT:
quit = true;
case SDL_KEYDOWN:
case SDL_KEYUP:
proc_modkeys();
- app_keyboard(ev->key.keysym.sym, ev->key.state == SDL_PRESSED);
+ if((key = translate_keysym(ev->key.keysym.sym)) != -1) {
+ app_keyboard(key, ev->key.state == SDL_PRESSED);
+ }
break;
case SDL_MOUSEBUTTONDOWN:
}
break;
+ case SDL_MOUSEWHEEL:
+ app_mouse_wheel(ev->wheel.y);
+ break;
+
case SDL_WINDOWEVENT:
if(ev->window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
SDL_GL_GetDrawableSize(win, &win_width, &win_height);
modkeys |= MOD_CTRL;
}
}
+
+static int translate_keysym(SDL_Keycode sym)
+{
+ switch(sym) {
+ case SDLK_RETURN:
+ return '\n';
+ case SDLK_DELETE:
+ return KEY_DEL;
+ case SDLK_LEFT:
+ return KEY_LEFT;
+ case SDLK_RIGHT:
+ return KEY_RIGHT;
+ case SDLK_UP:
+ return KEY_UP;
+ case SDLK_DOWN:
+ return KEY_DOWN;
+ case SDLK_PAGEUP:
+ return KEY_PGUP;
+ case SDLK_PAGEDOWN:
+ return KEY_PGDOWN;
+ case SDLK_HOME:
+ return KEY_HOME;
+ case SDLK_END:
+ return KEY_END;
+ default:
+ break;
+ }
+
+ if(sym < 127) {
+ return sym;
+ }
+ if(sym >= SDLK_F1 && sym <= SDLK_F12) {
+ return KEY_F1 + sym - SDLK_F1;
+ }
+ return -1;
+}