diff --git a/menu/drivers/zarch.c b/menu/drivers/zarch.c index fff14e1a99..6db2c19d04 100644 --- a/menu/drivers/zarch.c +++ b/menu/drivers/zarch.c @@ -266,10 +266,15 @@ static int16_t zarch_zui_input_state(zui_t *zui, enum zarch_zui_input_state stat static bool zarch_zui_check_button_down(zui_t *zui, unsigned id, int x1, int y1, int x2, int y2) { + menu_input_ctx_hitbox_t hitbox; bool result = false; - bool inside = menu_input_mouse_check_hitbox(x1, y1, x2, y2); - if (inside) + hitbox.x1 = x1; + hitbox.x2 = x2; + hitbox.y1 = y1; + hitbox.y2 = y2; + + if (menu_input_ctl(MENU_INPUT_CTL_CHECK_INSIDE_HITBOX, &hitbox)) zui->item.hot = id; if ( zui->item.hot == id @@ -285,10 +290,15 @@ static bool zarch_zui_check_button_down(zui_t *zui, static bool zarch_zui_check_button_up(zui_t *zui, unsigned id, int x1, int y1, int x2, int y2) { + menu_input_ctx_hitbox_t hitbox; bool result = false; - bool inside = menu_input_mouse_check_hitbox(x1, y1, x2, y2); - if (inside) + hitbox.x1 = x1; + hitbox.x2 = x2; + hitbox.y1 = y1; + hitbox.y2 = y2; + + if (menu_input_ctl(MENU_INPUT_CTL_CHECK_INSIDE_HITBOX, &hitbox)) zui->item.hot = id; if ( zui->item.active == id diff --git a/menu/menu_input.c b/menu/menu_input.c index d5599e0997..fe0092b96e 100644 --- a/menu/menu_input.c +++ b/menu/menu_input.c @@ -196,6 +196,22 @@ bool menu_input_ctl(enum menu_input_ctl_state state, void *data) switch (state) { + case MENU_INPUT_CTL_CHECK_INSIDE_HITBOX: + { + menu_input_ctx_hitbox_t *hitbox = (menu_input_ctx_hitbox_t*)data; + int16_t mouse_x = menu_input_mouse_state(MENU_MOUSE_X_AXIS); + int16_t mouse_y = menu_input_mouse_state(MENU_MOUSE_Y_AXIS); + bool inside_hitbox = + (mouse_x >= hitbox->x1) + && (mouse_x <= hitbox->x2) + && (mouse_y >= hitbox->y1) + && (mouse_y <= hitbox->y2) + ; + + if (!inside_hitbox) + return false; + } + break; case MENU_INPUT_CTL_DEINIT: memset(menu_input, 0, sizeof(menu_input_t)); break; @@ -1023,19 +1039,6 @@ int16_t menu_input_pointer_state(enum menu_input_pointer_state state) return 0; } -bool menu_input_mouse_check_hitbox(int x1, int y1, int x2, int y2) -{ - int16_t mouse_x = menu_input_mouse_state(MENU_MOUSE_X_AXIS); - int16_t mouse_y = menu_input_mouse_state(MENU_MOUSE_Y_AXIS); - - return ( - (mouse_x >= x1) - && (mouse_x <= x2) - && (mouse_y >= y1) - && (mouse_y <= y2) - ); -} - int16_t menu_input_mouse_state(enum menu_input_mouse_state state) { menu_input_t *menu = menu_input_get_ptr(); diff --git a/menu/menu_input.h b/menu/menu_input.h index 3340feb225..875b95de3c 100644 --- a/menu/menu_input.h +++ b/menu/menu_input.h @@ -88,7 +88,8 @@ enum menu_input_ctl_state MENU_INPUT_CTL_SET_KEYBOARD_LABEL_SETTING, MENU_INPUT_CTL_UNSET_KEYBOARD_LABEL_SETTING, MENU_INPUT_CTL_SEARCH_START, - MENU_INPUT_CTL_DEINIT + MENU_INPUT_CTL_DEINIT, + MENU_INPUT_CTL_CHECK_INSIDE_HITBOX }; enum menu_input_bind_mode @@ -98,6 +99,14 @@ enum menu_input_bind_mode MENU_INPUT_BIND_ALL }; +typedef struct menu_input_ctx_hitbox +{ + int32_t x1; + int32_t x2; + int32_t y1; + int32_t y2; +} menu_input_ctx_hitbox_t; + void menu_input_key_start_line(const char *label, const char *label_setting, unsigned type, unsigned idx, input_keyboard_line_complete_t cb); @@ -123,8 +132,6 @@ int16_t menu_input_pointer_state(enum menu_input_pointer_state state); int16_t menu_input_mouse_state(enum menu_input_mouse_state state); -bool menu_input_mouse_check_hitbox(int x1, int y1, int x2, int y2); - bool menu_input_ctl(enum menu_input_ctl_state state, void *data); #ifdef __cplusplus