diff options
| author | iamcheeseman <[email protected]> | 2026-05-11 14:30:48 -0400 |
|---|---|---|
| committer | iamcheeseman <[email protected]> | 2026-05-11 14:30:48 -0400 |
| commit | f4017a52d90567c2df482c5d553076dc706ac59b (patch) | |
| tree | 6cce9684cee03370188e6c46e745fabb64007a46 /platform/gl | |
| parent | da2585ddc49abb80e7457ccc2805fff884eb2021 (diff) | |
Allow user input
Diffstat (limited to 'platform/gl')
| -rw-r--r-- | platform/gl/gl.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/platform/gl/gl.c b/platform/gl/gl.c index 060a19d..acfa0c5 100644 --- a/platform/gl/gl.c +++ b/platform/gl/gl.c @@ -215,3 +215,37 @@ double ty_platform_get_time(void) { return glfwGetTime(); } + +struct ty_vec2i ty_platform_get_mouse(void) +{ + double x, y; + glfwGetCursorPos(p.win, &x, &y); + return ty_vec2i(x, y); +} + +static +int button_to_glfw_key(enum ty_button btn) +{ + switch (btn) { + case TY_BTN_LEFT_UP: return GLFW_KEY_W; + case TY_BTN_LEFT_DOWN: return GLFW_KEY_S; + case TY_BTN_LEFT_LEFT: return GLFW_KEY_A; + case TY_BTN_LEFT_RIGHT: return GLFW_KEY_D; + case TY_BTN_RIGHT_UP: return GLFW_KEY_I; + case TY_BTN_RIGHT_DOWN: return GLFW_KEY_K; + case TY_BTN_RIGHT_LEFT: return GLFW_KEY_J; + case TY_BTN_RIGHT_RIGHT: return GLFW_KEY_L; + case TY_BTN_ACTION_1: return GLFW_KEY_Q; + case TY_BTN_ACTION_2: return GLFW_KEY_E; + case TY_BTN_ACTION_3: return GLFW_KEY_U; + case TY_BTN_ACTION_4: return GLFW_KEY_O; + case TY_BTN_DB_CTRL: return GLFW_KEY_LEFT_CONTROL; + case TY_BTN_DB_SHIFT: return GLFW_KEY_LEFT_SHIFT; + } + return 0; +} + +bool ty_platform_is_button_down(enum ty_button btn) +{ + return glfwGetKey(p.win, button_to_glfw_key(btn)) == GLFW_PRESS; +} |
