mirror of
https://github.com/libretro/RetroArch
synced 2025-02-28 03:39:59 +00:00
Create MENU_INPUT_CTL_CHECK_INSIDE_HITBOX
This commit is contained in:
parent
6b0e0adf27
commit
b1a3d5bb25
@ -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
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user