diff options
author | omnisci3nce <omniscient.oce@gmail.com> | 2024-07-19 16:47:15 +1000 |
---|---|---|
committer | omnisci3nce <omniscient.oce@gmail.com> | 2024-07-19 16:47:15 +1000 |
commit | 0a984656f5fec68c90acc612b01f897918c0070b (patch) | |
tree | 59fffbcf00ac1507c7c1b281806ae5231c97ed4b | |
parent | 3ccedcee719f5f1663a3be0210761495fab74856 (diff) |
handle right btn as well
-rw-r--r-- | src/core/camera.c | 2 | ||||
-rw-r--r-- | src/systems/input.c | 16 | ||||
-rw-r--r-- | src/systems/input.h | 12 |
3 files changed, 18 insertions, 12 deletions
diff --git a/src/core/camera.c b/src/core/camera.c index c0228ba..7f04207 100644 --- a/src/core/camera.c +++ b/src/core/camera.c @@ -47,7 +47,7 @@ void Camera_Update(Camera *camera) { } // Mouse - if (MouseBtn_Held()) { + if (MouseBtn_Held(MOUSEBTN_LEFT)) { mouse_state mouse = Input_GetMouseState(); // printf("Delta x: %d Delta y %d\n",mouse.x_delta, mouse.y_delta ); diff --git a/src/systems/input.c b/src/systems/input.c index 87a0678..1122576 100644 --- a/src/systems/input.c +++ b/src/systems/input.c @@ -75,14 +75,13 @@ void Input_Update(Input_State *input) { // buttons int left_state = glfwGetMouseButton(input->window, GLFW_MOUSE_BUTTON_LEFT); - // int right_state = glfwGetMouseButton(input->window, GLFW_MOUSE_BUTTON_RIGHT); + int right_state = glfwGetMouseButton(input->window, GLFW_MOUSE_BUTTON_RIGHT); - new_mouse_state.prev_left_btn_pressed = input->mouse.left_btn_pressed; - if (left_state == GLFW_PRESS) { - new_mouse_state.left_btn_pressed = true; - } else { - new_mouse_state.left_btn_pressed = false; + for (int i = 0; i < 3; i++) { + new_mouse_state.prev_pressed_states[i] = input->mouse.cur_pressed_states[i]; } + new_mouse_state.cur_pressed_states[MOUSEBTN_LEFT] = left_state == GLFW_PRESS; + new_mouse_state.cur_pressed_states[MOUSEBTN_RIGHT] = right_state == GLFW_PRESS; // this was dumb! need to also check button state changes lol // if (new_mouse_state.x != input->mouse.x || new_mouse_state.y != input->mouse.y) @@ -97,8 +96,9 @@ bool key_just_pressed(keycode key) { return g_input->just_pressed_keys[key]; } bool key_just_released(keycode key) { return g_input->just_released_keys[key]; } -bool MouseBtn_Held() { - return g_input->mouse.prev_left_btn_pressed && g_input->mouse.left_btn_pressed; +bool MouseBtn_Held(MouseBtn btn) { + assert(btn < 3); + return g_input->mouse.prev_pressed_states[btn] && g_input->mouse.cur_pressed_states[btn]; } mouse_state Input_GetMouseState() { return g_input->mouse; }
\ No newline at end of file diff --git a/src/systems/input.h b/src/systems/input.h index ce6e190..bf80a84 100644 --- a/src/systems/input.h +++ b/src/systems/input.h @@ -8,13 +8,19 @@ struct GLFWWindow; +typedef enum MouseBtn { + MOUSEBTN_LEFT = 0, + MOUSEBTN_RIGHT = 1, + MOUSEBTN_MIDDLE = 2, +} MouseBtn; + typedef struct mouse_state { i32 x; i32 y; i32 x_delta; i32 y_delta; - bool prev_left_btn_pressed; - bool left_btn_pressed; + bool prev_pressed_states[3]; + bool cur_pressed_states[3]; } mouse_state; typedef struct Input_State { @@ -35,7 +41,7 @@ bool key_just_pressed(keycode key); bool key_just_released(keycode key); // TODO: right btn as well -bool MouseBtn_Held(); +bool MouseBtn_Held(MouseBtn btn); // --- Lifecycle |