ozone: full mouse support on entries (no sidebar yet)

This commit is contained in:
natinusala 2019-02-13 10:32:07 +01:00
parent cb9d227db5
commit 492590a0ae
4 changed files with 80 additions and 66 deletions

View File

@ -151,6 +151,10 @@ static void *ozone_init(void **userdata, bool video_is_threaded)
ozone->pending_message = NULL; ozone->pending_message = NULL;
ozone->show_cursor = false; ozone->show_cursor = false;
ozone->cursor_mode = false;
ozone->cursor_x_old = menu_input_mouse_state(MENU_MOUSE_X_AXIS);
ozone->cursor_y_old = menu_input_mouse_state(MENU_MOUSE_Y_AXIS);
ozone->system_tab_end = 0; ozone->system_tab_end = 0;
ozone->tabs[ozone->system_tab_end] = OZONE_SYSTEM_TAB_MAIN; ozone->tabs[ozone->system_tab_end] = OZONE_SYSTEM_TAB_MAIN;
if (settings->bools.menu_content_show_settings && !settings->bools.kiosk_mode_enable) if (settings->bools.menu_content_show_settings && !settings->bools.kiosk_mode_enable)
@ -1226,7 +1230,6 @@ static void ozone_frame(void *data, video_frame_info_t *video_info)
font_driver_flush(video_info->width, video_info->height, ozone->fonts.entries_label, video_info); font_driver_flush(video_info->width, video_info->height, ozone->fonts.entries_label, video_info);
/* Cursor */ /* Cursor */
#if OZONE_ENABLE_MOUSE
if (ozone->show_cursor) if (ozone->show_cursor)
{ {
menu_display_set_alpha(ozone_pure_white, 1.0f); menu_display_set_alpha(ozone_pure_white, 1.0f);
@ -1241,7 +1244,6 @@ static void ozone_frame(void *data, video_frame_info_t *video_info)
video_info->height video_info->height
); );
} }
#endif
menu_display_unset_viewport(video_info->width, video_info->height); menu_display_unset_viewport(video_info->width, video_info->height);
} }
@ -1265,6 +1267,7 @@ static void ozone_animation_end(void *userdata)
{ {
ozone_handle_t *ozone = (ozone_handle_t*) userdata; ozone_handle_t *ozone = (ozone_handle_t*) userdata;
ozone->draw_old_list = false; ozone->draw_old_list = false;
ozone->animations.cursor_alpha = 1.0f;
} }
static void ozone_list_open(ozone_handle_t *ozone) static void ozone_list_open(ozone_handle_t *ozone)
@ -1379,6 +1382,7 @@ static int ozone_menu_iterate(menu_handle_t *menu, void *userdata, enum menu_act
switch (action) switch (action)
{ {
case MENU_ACTION_DOWN: case MENU_ACTION_DOWN:
ozone->cursor_mode = false;
if (!ozone->cursor_in_sidebar) if (!ozone->cursor_in_sidebar)
break; break;
@ -1394,6 +1398,7 @@ static int ozone_menu_iterate(menu_handle_t *menu, void *userdata, enum menu_act
new_action = MENU_ACTION_NOOP; new_action = MENU_ACTION_NOOP;
break; break;
case MENU_ACTION_UP: case MENU_ACTION_UP:
ozone->cursor_mode = false;
if (!ozone->cursor_in_sidebar) if (!ozone->cursor_in_sidebar)
break; break;
@ -1409,6 +1414,7 @@ static int ozone_menu_iterate(menu_handle_t *menu, void *userdata, enum menu_act
new_action = MENU_ACTION_NOOP; new_action = MENU_ACTION_NOOP;
break; break;
case MENU_ACTION_LEFT: case MENU_ACTION_LEFT:
ozone->cursor_mode = false;
if (ozone->cursor_in_sidebar) if (ozone->cursor_in_sidebar)
{ {
new_action = MENU_ACTION_NOOP; new_action = MENU_ACTION_NOOP;
@ -1422,6 +1428,7 @@ static int ozone_menu_iterate(menu_handle_t *menu, void *userdata, enum menu_act
new_action = MENU_ACTION_NOOP; new_action = MENU_ACTION_NOOP;
break; break;
case MENU_ACTION_RIGHT: case MENU_ACTION_RIGHT:
ozone->cursor_mode = false;
if (!ozone->cursor_in_sidebar) if (!ozone->cursor_in_sidebar)
{ {
if (ozone->depth == 1) if (ozone->depth == 1)
@ -1434,6 +1441,7 @@ static int ozone_menu_iterate(menu_handle_t *menu, void *userdata, enum menu_act
new_action = MENU_ACTION_NOOP; new_action = MENU_ACTION_NOOP;
break; break;
case MENU_ACTION_OK: case MENU_ACTION_OK:
ozone->cursor_mode = false;
if (ozone->cursor_in_sidebar) if (ozone->cursor_in_sidebar)
{ {
ozone_leave_sidebar(ozone, tag); ozone_leave_sidebar(ozone, tag);
@ -1442,6 +1450,7 @@ static int ozone_menu_iterate(menu_handle_t *menu, void *userdata, enum menu_act
} }
break; break;
case MENU_ACTION_CANCEL: case MENU_ACTION_CANCEL:
ozone->cursor_mode = false;
if (ozone->cursor_in_sidebar) if (ozone->cursor_in_sidebar)
{ {
/* Go back to main menu tab */ /* Go back to main menu tab */
@ -1771,7 +1780,6 @@ static bool ozone_get_load_content_animation_data(void *userdata, menu_texture_i
} }
#endif #endif
#if OZONE_ENABLE_MOUSE
static int ozone_pointer_tap(void *userdata, static int ozone_pointer_tap(void *userdata,
unsigned x, unsigned y, unsigned ptr, unsigned x, unsigned y, unsigned ptr,
menu_file_list_cbs_t *cbs, menu_file_list_cbs_t *cbs,
@ -1788,7 +1796,6 @@ static int ozone_pointer_tap(void *userdata,
return 0; return 0;
} }
#endif
menu_ctx_driver_t menu_ctx_ozone = { menu_ctx_driver_t menu_ctx_ozone = {
NULL, /* set_texture */ NULL, /* set_texture */
@ -1824,11 +1831,7 @@ menu_ctx_driver_t menu_ctx_ozone = {
NULL, /* load_image */ NULL, /* load_image */
"ozone", "ozone",
ozone_environ_cb, ozone_environ_cb,
#if OZONE_ENABLE_MOUSE
ozone_pointer_tap, ozone_pointer_tap,
#else
NULL,
#endif
NULL, /* update_thumbnail_path */ NULL, /* update_thumbnail_path */
NULL, /* update_thumbnail_image */ NULL, /* update_thumbnail_image */
NULL, /* set_thumbnail_system */ NULL, /* set_thumbnail_system */

View File

@ -27,8 +27,6 @@ typedef struct ozone_handle ozone_handle_t;
#include "../../menu_driver.h" #include "../../menu_driver.h"
#include "../../../retroarch.h" #include "../../../retroarch.h"
#define OZONE_ENABLE_MOUSE 0 /* TODO: remove this define once it works */
#define ANIMATION_PUSH_ENTRY_DURATION 10 #define ANIMATION_PUSH_ENTRY_DURATION 10
#define ANIMATION_CURSOR_DURATION 8 #define ANIMATION_CURSOR_DURATION 8
#define ANIMATION_CURSOR_PULSE 30 #define ANIMATION_CURSOR_PULSE 30
@ -200,6 +198,10 @@ struct ozone_handle
} dimensions; } dimensions;
bool show_cursor; bool show_cursor;
bool cursor_mode;
int16_t cursor_x_old;
int16_t cursor_y_old;
}; };
/* If you change this struct, also /* If you change this struct, also

View File

@ -287,13 +287,20 @@ void ozone_draw_entries(ozone_handle_t *ozone, video_frame_info_t *video_info,
bool old_list = selection_buf == ozone->selection_buf_old; bool old_list = selection_buf == ozone->selection_buf_old;
int x_offset = 0; int x_offset = 0;
size_t selection_y = 0; size_t selection_y = 0; /* 0 means no selection (we assume that no entry has y = 0) */
size_t old_selection_y = 0; size_t old_selection_y = 0;
int entry_padding = ozone_get_entries_padding(ozone, old_list); int entry_padding = ozone_get_entries_padding(ozone, old_list);
int16_t mouse_x = menu_input_mouse_state(MENU_MOUSE_X_AXIS); int16_t cursor_x = menu_input_mouse_state(MENU_MOUSE_X_AXIS);
int16_t cursor_y = menu_input_mouse_state(MENU_MOUSE_Y_AXIS);
int16_t mouse_y = menu_input_mouse_state(MENU_MOUSE_Y_AXIS); if (!ozone->cursor_mode && (cursor_x != ozone->cursor_x_old || cursor_y != ozone->cursor_y_old))
{
ozone->cursor_mode = true;
}
ozone->cursor_x_old = cursor_x;
ozone->cursor_y_old = cursor_y;
menu_entries_ctl(MENU_ENTRIES_CTL_START_GET, &i); menu_entries_ctl(MENU_ENTRIES_CTL_START_GET, &i);
@ -333,10 +340,10 @@ void ozone_draw_entries(ozone_handle_t *ozone, video_frame_info_t *video_info,
ozone_node_t *node = NULL; ozone_node_t *node = NULL;
if (entry_selected) if (entry_selected && selection_y == 0)
selection_y = y; selection_y = y;
if (entry_old_selected) if (entry_old_selected && old_selection_y == 0)
old_selection_y = y; old_selection_y = y;
node = (ozone_node_t*) file_list_get_userdata_at_offset(selection_buf, i); node = (ozone_node_t*) file_list_get_userdata_at_offset(selection_buf, i);
@ -361,15 +368,17 @@ void ozone_draw_entries(ozone_handle_t *ozone, video_frame_info_t *video_info,
menu_display_draw_quad(video_info, border_start_x, menu_display_draw_quad(video_info, border_start_x,
border_start_y + button_height, entry_width, 1, video_info->width, video_info->height, ozone->theme_dynamic.entries_border); border_start_y + button_height, entry_width, 1, video_info->width, video_info->height, ozone->theme_dynamic.entries_border);
/* Mouse click */ /* Cursor */
#if OZONE_ENABLE_MOUSE if (!old_list && ozone->cursor_mode)
if (mouse_x >= border_start_x && mouse_x <= border_start_x + entry_width {
&& mouse_y >= border_start_y && mouse_y <= border_start_y + button_height) if ( cursor_x >= border_start_x && cursor_x <= border_start_x + entry_width &&
cursor_y >= border_start_y && cursor_y <= border_start_y + button_height)
{ {
selection_y = y; selection_y = y;
menu_navigation_set_selection(i);
menu_input_ctl(MENU_INPUT_CTL_MOUSE_PTR, &i); menu_input_ctl(MENU_INPUT_CTL_MOUSE_PTR, &i);
} }
#endif }
border_iterate: border_iterate:
y += node->height; y += node->height;
@ -429,7 +438,7 @@ border_iterate:
ticker.s = rich_label; ticker.s = rich_label;
ticker.str = entry_rich_label; ticker.str = entry_rich_label;
ticker.selected = entry_selected && !ozone->cursor_in_sidebar; ticker.selected = entry_selected && !ozone->cursor_in_sidebar;
ticker.len = (entry_width - 60 - text_offset) / ozone->entry_font_glyph_width; ticker.len = (entry_width - entry_padding - text_offset) / ozone->entry_font_glyph_width;
menu_animation_ticker(&ticker); menu_animation_ticker(&ticker);