ozone: add collapsing sidebar in playlists

This commit is contained in:
natinusala 2019-02-27 13:34:42 +01:00
parent fb6a403220
commit be47416f84
4 changed files with 135 additions and 28 deletions

View File

@ -156,6 +156,9 @@ static void *ozone_init(void **userdata, bool video_is_threaded)
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->sidebar_collapsed = false;
ozone->animations.sidebar_text_alpha = 1.0f;
ozone->system_tab_end = 0;
ozone->tabs[ozone->system_tab_end] = OZONE_SYSTEM_TAB_MAIN;
if (settings->bools.menu_content_show_settings && !settings->bools.kiosk_mode_enable)
@ -383,7 +386,6 @@ static void ozone_context_reset(void *data, bool is_threaded)
ozone->dimensions.entry_icon_size = ENTRY_ICON_SIZE * scale;
ozone->dimensions.entry_icon_padding = ENTRY_ICON_PADDING * scale;
ozone->dimensions.sidebar_width = SIDEBAR_WIDTH * scale;
ozone->dimensions.sidebar_entry_height = SIDEBAR_ENTRY_HEIGHT * scale;
ozone->dimensions.sidebar_padding_horizontal = SIDEBAR_X_PADDING * scale;
ozone->dimensions.sidebar_padding_vertical = SIDEBAR_Y_PADDING * scale;
@ -391,6 +393,14 @@ static void ozone_context_reset(void *data, bool is_threaded)
ozone->dimensions.sidebar_entry_icon_size = SIDEBAR_ENTRY_ICON_SIZE * scale;
ozone->dimensions.sidebar_entry_icon_padding = SIDEBAR_ENTRY_ICON_PADDING * scale;
ozone->dimensions.sidebar_width_normal = SIDEBAR_WIDTH * scale;
ozone->dimensions.sidebar_width_collapsed = ozone->dimensions.sidebar_entry_icon_size
+ ozone->dimensions.sidebar_entry_icon_padding * 2
+ ozone->dimensions.sidebar_padding_horizontal * 2;
ozone->dimensions.sidebar_width = (float) ozone->dimensions.sidebar_width_normal;
ozone->dimensions.cursor_size = CURSOR_SIZE * scale;
/* Naive font size */
@ -1133,7 +1143,7 @@ static void ozone_frame(void *data, video_frame_info_t *video_info)
ozone_draw_sidebar(ozone, video_info);
/* Menu entries */
menu_display_scissor_begin(video_info, ozone->sidebar_offset + ozone->dimensions.sidebar_width, ozone->dimensions.header_height, video_info->width - ozone->dimensions.sidebar_width + (-ozone->sidebar_offset), video_info->height - ozone->dimensions.header_height - ozone->dimensions.footer_height);
menu_display_scissor_begin(video_info, ozone->sidebar_offset + (unsigned) ozone->dimensions.sidebar_width, ozone->dimensions.header_height, video_info->width - (unsigned) ozone->dimensions.sidebar_width + (-ozone->sidebar_offset), video_info->height - ozone->dimensions.header_height - ozone->dimensions.footer_height);
/* Current list */
ozone_draw_entries(ozone,
@ -1498,6 +1508,8 @@ static void ozone_toggle(void *userdata, bool menu_on)
{
ozone->draw_sidebar = true;
ozone->sidebar_offset = 0.0f;
ozone_sidebar_update_collapse(ozone, false);
}
}

View File

@ -122,6 +122,8 @@ struct ozone_handle
float list_alpha;
float messagebox_alpha;
float sidebar_text_alpha;
} animations;
bool fade_direction; /* false = left to right, true = right to left */
@ -186,14 +188,17 @@ struct ozone_handle
int footer_height;
int entry_padding_horizontal_half;
int entry_padding_horizontal_full; /* TODO: when sidebar is not visible */
int entry_padding_horizontal_full;
int entry_padding_vertical;
int entry_height;
int entry_spacing;
int entry_icon_size;
int entry_icon_padding;
int sidebar_width;
int sidebar_width_normal;
int sidebar_width_collapsed;
float sidebar_width;
int sidebar_padding_horizontal;
int sidebar_padding_vertical;
int sidebar_entry_padding_vertical;
@ -209,6 +214,8 @@ struct ozone_handle
int16_t cursor_x_old;
int16_t cursor_y_old;
bool sidebar_collapsed;
};
/* If you change this struct, also
@ -268,4 +275,6 @@ void ozone_compute_entries_position(ozone_handle_t *ozone);
void ozone_update_scroll(ozone_handle_t *ozone, bool allow_animation, ozone_node_t *node);
void ozone_sidebar_update_collapse(ozone_handle_t *ozone, bool allow_animation);
#endif

View File

@ -250,7 +250,7 @@ void ozone_compute_entries_position(ozone_handle_t *ozone)
{
char *sublabel_str = menu_entry_get_sublabel(&entry);
int sublabel_max_width = video_info_width - ozone->dimensions.sidebar_width -
int sublabel_max_width = video_info_width - (unsigned) ozone->dimensions.sidebar_width -
entry_padding * 2 - ozone->dimensions.entry_icon_padding * 2;
word_wrap(sublabel_str, sublabel_str, sublabel_max_width / ozone->sublabel_font_glyph_width, false);
@ -310,7 +310,7 @@ void ozone_draw_entries(ozone_handle_t *ozone, video_frame_info_t *video_info,
entries_end = file_list_get_size(selection_buf);
y = ozone->dimensions.header_height + 1 + ozone->dimensions.entry_padding_vertical;
sidebar_offset = ozone->sidebar_offset;
entry_width = video_info->width - ozone->dimensions.sidebar_width - ozone->sidebar_offset - entry_padding * 2;
entry_width = video_info->width - (unsigned) ozone->dimensions.sidebar_width - ozone->sidebar_offset - entry_padding * 2;
button_height = ozone->dimensions.entry_height; /* height of the button (entry minus sublabel) */
video_driver_get_size(&video_info_width, &video_info_height);
@ -359,7 +359,7 @@ void ozone_draw_entries(ozone_handle_t *ozone, video_frame_info_t *video_info,
else if (y + scroll_y - node->height - 20 > bottom_boundary)
goto border_iterate;
border_start_x = ozone->dimensions.sidebar_width + x_offset + entry_padding;
border_start_x = (unsigned) ozone->dimensions.sidebar_width + x_offset + entry_padding;
border_start_y = y + scroll_y;
menu_display_set_alpha(ozone->theme_dynamic.entries_border, alpha);
@ -389,12 +389,12 @@ border_iterate:
/* Cursor(s) layer - current */
if (!ozone->cursor_in_sidebar)
ozone_draw_cursor(ozone, video_info, ozone->dimensions.sidebar_width + x_offset + entry_padding + 3,
ozone_draw_cursor(ozone, video_info, (unsigned) ozone->dimensions.sidebar_width + x_offset + entry_padding + 3,
entry_width - 5, button_height + 2, selection_y + scroll_y + 1, ozone->animations.cursor_alpha * alpha);
/* Old*/
if (!ozone->cursor_in_sidebar_old)
ozone_draw_cursor(ozone, video_info, ozone->dimensions.sidebar_width + x_offset + entry_padding + 3,
ozone_draw_cursor(ozone, video_info, (unsigned) ozone->dimensions.sidebar_width + x_offset + entry_padding + 3,
entry_width - 5, button_height + 2, old_selection_y + scroll_y + 1, (1-ozone->animations.cursor_alpha) * alpha);
/* Icons + text */
@ -453,7 +453,7 @@ border_iterate:
if (ozone->empty_playlist)
{
unsigned text_width = font_driver_get_message_width(ozone->fonts.entries_label, rich_label, (unsigned)strlen(rich_label), 1);
x_offset = (video_info_width - ozone->dimensions.sidebar_width - entry_padding * 2) / 2 - text_width / 2 - 60;
x_offset = (video_info_width - (unsigned) ozone->dimensions.sidebar_width - entry_padding * 2) / 2 - text_width / 2 - 60;
y = video_info_height / 2 - 60;
}
@ -461,7 +461,7 @@ border_iterate:
if (node->wrap && sublabel_str)
{
int sublable_max_width = video_info_width - ozone->dimensions.sidebar_width -
int sublable_max_width = video_info_width - (unsigned) ozone->dimensions.sidebar_width -
entry_padding * 2 - ozone->dimensions.entry_icon_padding * 2;
word_wrap(sublabel_str, sublabel_str, sublable_max_width / ozone->sublabel_font_glyph_width, false);
}
@ -500,7 +500,7 @@ border_iterate:
menu_display_blend_begin(video_info);
ozone_draw_icon(video_info, ozone->dimensions.entry_icon_size, ozone->dimensions.entry_icon_size, texture,
ozone->dimensions.sidebar_width + x_offset + entry_padding + ozone->dimensions.entry_icon_padding,
(unsigned) ozone->dimensions.sidebar_width + x_offset + entry_padding + ozone->dimensions.entry_icon_padding,
y + scroll_y + ozone->dimensions.entry_height / 2 - ozone->dimensions.entry_icon_size / 2, video_info->width, video_info->height, 0, 1, icon_color);
menu_display_blend_end(video_info);
@ -511,10 +511,10 @@ border_iterate:
}
/* Draw text */
ozone_draw_text(video_info, ozone, rich_label, text_offset + ozone->dimensions.sidebar_width + x_offset + entry_padding + ozone->dimensions.entry_icon_size + ozone->dimensions.entry_icon_padding * 2,
ozone_draw_text(video_info, ozone, rich_label, text_offset + (unsigned) ozone->dimensions.sidebar_width + x_offset + entry_padding + ozone->dimensions.entry_icon_size + ozone->dimensions.entry_icon_padding * 2,
y + ozone->dimensions.entry_height / 2 + FONT_SIZE_ENTRIES_LABEL * 3/8 + scroll_y, TEXT_ALIGN_LEFT, video_info->width, video_info->height, ozone->fonts.entries_label, COLOR_TEXT_ALPHA(ozone->theme->text_rgba, alpha_uint32), false);
if (sublabel_str)
ozone_draw_text(video_info, ozone, sublabel_str, ozone->dimensions.sidebar_width + x_offset + entry_padding + ozone->dimensions.entry_icon_padding,
ozone_draw_text(video_info, ozone, sublabel_str, (unsigned) ozone->dimensions.sidebar_width + x_offset + entry_padding + ozone->dimensions.entry_icon_padding,
y + ozone->dimensions.entry_height + 1 + 5 + FONT_SIZE_ENTRIES_SUBLABEL + scroll_y, TEXT_ALIGN_LEFT, video_info->width, video_info->height, ozone->fonts.entries_sublabel, COLOR_TEXT_ALPHA(ozone->theme->text_sublabel_rgba, alpha_uint32), false);
/* Value */
@ -527,7 +527,7 @@ border_iterate:
menu_animation_ticker(&ticker);
ozone_draw_entry_value(ozone, video_info, entry_value_ticker, ozone->dimensions.sidebar_width + entry_padding + x_offset + entry_width - ozone->dimensions.entry_icon_padding,
ozone_draw_entry_value(ozone, video_info, entry_value_ticker, (unsigned) ozone->dimensions.sidebar_width + entry_padding + x_offset + entry_width - ozone->dimensions.entry_icon_padding,
y + ozone->dimensions.entry_height / 2 + FONT_SIZE_ENTRIES_LABEL * 3/8 + scroll_y, alpha_uint32, &entry);
free(entry_rich_label);

View File

@ -31,6 +31,8 @@
#include "../../../configuration.h"
/* TODO Add an always collapsed sidebar setting */
enum msg_hash_enums ozone_system_tabs_value[OZONE_SYSTEM_TAB_LAST] = {
MENU_ENUM_LABEL_VALUE_MAIN_MENU,
MENU_ENUM_LABEL_VALUE_SETTINGS_TAB,
@ -113,6 +115,8 @@ void ozone_draw_sidebar(ozone_handle_t *ozone, video_frame_info_t *video_info)
static const char* const ticker_spacer = OZONE_TICKER_SPACER;
settings_t *settings = config_get_ptr();
uint32_t text_alpha = ozone->animations.sidebar_text_alpha * 255.0f;
/* Initial ticker configuration */
ticker.type_enum = (enum menu_animation_ticker_type)settings->uints.menu_ticker_type;
ticker.spacer = ticker_spacer;
@ -129,16 +133,16 @@ void ozone_draw_sidebar(ozone_handle_t *ozone, video_frame_info_t *video_info)
if (ozone->horizontal_list)
horizontal_list_size = ozone->horizontal_list->size;
menu_display_scissor_begin(video_info, 0, ozone->dimensions.header_height, ozone->dimensions.sidebar_width, video_info->height - ozone->dimensions.header_height - ozone->dimensions.footer_height);
menu_display_scissor_begin(video_info, 0, ozone->dimensions.header_height, (unsigned) ozone->dimensions.sidebar_width, video_info->height - ozone->dimensions.header_height - ozone->dimensions.footer_height);
/* Background */
sidebar_height = video_info->height - ozone->dimensions.header_height - 55 - ozone->dimensions.footer_height;
if (!video_info->libretro_running)
{
menu_display_draw_quad(video_info, ozone->sidebar_offset, ozone->dimensions.header_height + 1, ozone->dimensions.sidebar_width, 55/2, video_info->width, video_info->height, ozone->theme->sidebar_top_gradient);
menu_display_draw_quad(video_info, ozone->sidebar_offset, ozone->dimensions.header_height + 1 + 55/2, ozone->dimensions.sidebar_width, sidebar_height, video_info->width, video_info->height, ozone->theme->sidebar_background);
menu_display_draw_quad(video_info, ozone->sidebar_offset, video_info->height - ozone->dimensions.footer_height - 55/2 - 1, ozone->dimensions.sidebar_width, 55/2 + 1, video_info->width, video_info->height, ozone->theme->sidebar_bottom_gradient);
menu_display_draw_quad(video_info, ozone->sidebar_offset, ozone->dimensions.header_height + 1, (unsigned) ozone->dimensions.sidebar_width, 55/2, video_info->width, video_info->height, ozone->theme->sidebar_top_gradient);
menu_display_draw_quad(video_info, ozone->sidebar_offset, ozone->dimensions.header_height + 1 + 55/2, (unsigned) ozone->dimensions.sidebar_width, sidebar_height, video_info->width, video_info->height, ozone->theme->sidebar_background);
menu_display_draw_quad(video_info, ozone->sidebar_offset, video_info->height - ozone->dimensions.footer_height - 55/2 - 1, (unsigned) ozone->dimensions.sidebar_width, 55/2 + 1, video_info->width, video_info->height, ozone->theme->sidebar_bottom_gradient);
}
/* Tabs */
@ -163,7 +167,7 @@ void ozone_draw_sidebar(ozone_handle_t *ozone, video_frame_info_t *video_info)
y += ozone->dimensions.sidebar_entry_height + ozone->dimensions.sidebar_entry_padding_vertical;
}
entry_width = ozone->dimensions.sidebar_width - ozone->dimensions.sidebar_padding_horizontal * 2;
entry_width = (unsigned) ozone->dimensions.sidebar_width - ozone->dimensions.sidebar_padding_horizontal * 2;
/* Cursor */
if (ozone->cursor_in_sidebar)
@ -181,9 +185,11 @@ void ozone_draw_sidebar(ozone_handle_t *ozone, video_frame_info_t *video_info)
for (i = 0; i < (unsigned)(ozone->system_tab_end+1); i++)
{
enum msg_hash_enums value_idx;
const char *title = NULL;
bool selected = (ozone->categories_selection_ptr == i);
unsigned icon = ozone_system_tabs_icons[ozone->tabs[i]];
const char *title = NULL;
bool selected = (ozone->categories_selection_ptr == i);
unsigned icon = ozone_system_tabs_icons[ozone->tabs[i]];
uint32_t text_color = COLOR_TEXT_ALPHA((selected ? ozone->theme->text_selected_rgba : ozone->theme->text_rgba), text_alpha);
/* Icon */
ozone_draw_icon(video_info, ozone->dimensions.sidebar_entry_icon_size, ozone->dimensions.sidebar_entry_icon_size,
@ -194,8 +200,9 @@ void ozone_draw_sidebar(ozone_handle_t *ozone, video_frame_info_t *video_info)
title = msg_hash_to_str(value_idx);
/* Text */
ozone_draw_text(video_info, ozone, title, ozone->sidebar_offset + ozone->dimensions.sidebar_padding_horizontal + ozone->dimensions.sidebar_entry_icon_padding * 2 + ozone->dimensions.sidebar_entry_icon_size,
y + ozone->dimensions.sidebar_entry_height / 2 + FONT_SIZE_SIDEBAR * 3/8 + ozone->animations.scroll_y_sidebar, TEXT_ALIGN_LEFT, video_info->width, video_info->height, ozone->fonts.sidebar, (selected ? ozone->theme->text_selected_rgba : ozone->theme->text_rgba), true);
if (!ozone->sidebar_collapsed)
ozone_draw_text(video_info, ozone, title, ozone->sidebar_offset + ozone->dimensions.sidebar_padding_horizontal + ozone->dimensions.sidebar_entry_icon_padding * 2 + ozone->dimensions.sidebar_entry_icon_size,
y + ozone->dimensions.sidebar_entry_height / 2 + FONT_SIZE_SIDEBAR * 3/8 + ozone->animations.scroll_y_sidebar, TEXT_ALIGN_LEFT, video_info->width, video_info->height, ozone->fonts.sidebar, text_color, true);
y += ozone->dimensions.sidebar_entry_height + ozone->dimensions.sidebar_entry_padding_vertical;
}
@ -215,6 +222,8 @@ void ozone_draw_sidebar(ozone_handle_t *ozone, video_frame_info_t *video_info)
{
bool selected = (ozone->categories_selection_ptr == ozone->system_tab_end + 1 + i);
uint32_t text_color = COLOR_TEXT_ALPHA((selected ? ozone->theme->text_selected_rgba : ozone->theme->text_rgba), text_alpha);
ozone_node_t *node = (ozone_node_t*) file_list_get_userdata_at_offset(ozone->horizontal_list, i);
if (!node)
@ -225,8 +234,10 @@ void ozone_draw_sidebar(ozone_handle_t *ozone, video_frame_info_t *video_info)
node->icon, ozone->sidebar_offset + ozone->dimensions.sidebar_padding_horizontal + ozone->dimensions.sidebar_entry_icon_padding,
y + ozone->dimensions.sidebar_entry_height / 2 - ozone->dimensions.sidebar_entry_icon_size / 2 + ozone->animations.scroll_y_sidebar, video_info->width, video_info->height, 0, 1, (selected ? ozone->theme->text_selected : ozone->theme->entries_icon));
/* Text */
if (ozone->sidebar_collapsed)
goto console_iterate;
ticker.idx = menu_animation_get_ticker_idx();
ticker.len = (entry_width - ozone->dimensions.sidebar_entry_icon_size - 35) / ozone->sidebar_font_glyph_width;
ticker.s = console_title;
@ -236,8 +247,8 @@ void ozone_draw_sidebar(ozone_handle_t *ozone, video_frame_info_t *video_info)
menu_animation_ticker(&ticker);
ozone_draw_text(video_info, ozone, console_title, ozone->sidebar_offset + ozone->dimensions.sidebar_padding_horizontal + ozone->dimensions.sidebar_entry_icon_padding * 2 + ozone->dimensions.sidebar_entry_icon_size,
y + ozone->dimensions.sidebar_entry_height / 2 + FONT_SIZE_SIDEBAR * 3/8 + ozone->animations.scroll_y_sidebar, TEXT_ALIGN_LEFT,
video_info->width, video_info->height, ozone->fonts.sidebar, (selected ? ozone->theme->text_selected_rgba : ozone->theme->text_rgba), true);
y + ozone->dimensions.sidebar_entry_height / 2 + FONT_SIZE_SIDEBAR * 3/8 + ozone->animations.scroll_y_sidebar, TEXT_ALIGN_LEFT,
video_info->width, video_info->height, ozone->fonts.sidebar, text_color, true);
console_iterate:
y += ozone->dimensions.sidebar_entry_height + ozone->dimensions.sidebar_entry_padding_vertical;
@ -313,6 +324,79 @@ unsigned ozone_get_sidebar_height(ozone_handle_t *ozone)
(ozone->horizontal_list && ozone->horizontal_list->size > 0 ? ozone->dimensions.sidebar_entry_padding_vertical + 1 : 0);
}
static void ozone_sidebar_collapse_end(void *userdata)
{
ozone_handle_t *ozone = (ozone_handle_t*) userdata;
ozone->sidebar_collapsed = true;
}
void ozone_sidebar_update_collapse(ozone_handle_t *ozone, bool allow_animation)
{
/* Collapse sidebar if needed */
bool is_playlist = ozone_is_playlist(ozone, false);
menu_animation_ctx_tag tag = (uintptr_t)NULL;
struct menu_animation_ctx_entry entry;
entry.easing_enum = EASING_OUT_QUAD;
entry.tag = tag;
entry.userdata = ozone;
entry.duration = ANIMATION_CURSOR_DURATION;
if (is_playlist && !ozone->sidebar_collapsed)
{
if (allow_animation)
{
entry.cb = ozone_sidebar_collapse_end;
//Text alpha
entry.subject = &ozone->animations.sidebar_text_alpha;
entry.target_value = 0.0f;
menu_animation_push(&entry);
//Collapse
entry.subject = &ozone->dimensions.sidebar_width;
entry.target_value = ozone->dimensions.sidebar_width_collapsed;
menu_animation_push(&entry);
}
else
{
ozone->animations.sidebar_text_alpha = 0.0f;
ozone->dimensions.sidebar_width = ozone->dimensions.sidebar_width_collapsed;
ozone_sidebar_collapse_end(ozone);
}
}
else if (!is_playlist && ozone->sidebar_collapsed)
{
if (allow_animation)
{
ozone->sidebar_collapsed = false;
entry.cb = NULL;
//Text alpha
entry.subject = &ozone->animations.sidebar_text_alpha;
entry.target_value = 1.0f;
menu_animation_push(&entry);
//Collapse
entry.subject = &ozone->dimensions.sidebar_width;
entry.target_value = ozone->dimensions.sidebar_width_normal;
menu_animation_push(&entry);
}
else
{
ozone->animations.sidebar_text_alpha = 1.0f;
ozone->dimensions.sidebar_width = ozone->dimensions.sidebar_width_normal;
}
}
}
void ozone_sidebar_goto(ozone_handle_t *ozone, unsigned new_selection)
{
unsigned video_info_height;
@ -390,6 +474,8 @@ void ozone_sidebar_goto(ozone_handle_t *ozone, unsigned new_selection)
{
ozone_change_tab(ozone, ozone_system_tabs_idx[ozone->tabs[new_selection]], ozone_system_tabs_type[ozone->tabs[new_selection]]);
}
ozone_sidebar_update_collapse(ozone, true);
}
void ozone_change_tab(ozone_handle_t *ozone,