Dropdown lists: Add a checked bool to menu_entry_t

This commit is contained in:
natinusala 2018-11-05 17:30:50 +01:00
parent d34f96866e
commit 07068e5035
6 changed files with 116 additions and 12 deletions

View File

@ -72,6 +72,7 @@ enum OZONE_THEME_TEXTURES {
OZONE_THEME_TEXTURE_BUTTON_A = 0,
OZONE_THEME_TEXTURE_BUTTON_B,
OZONE_THEME_TEXTURE_SWITCH,
OZONE_THEME_TEXTURE_CHECK,
OZONE_THEME_TEXTURE_LAST
};
@ -79,7 +80,8 @@ enum OZONE_THEME_TEXTURES {
static char* OZONE_THEME_TEXTURES_FILES[OZONE_THEME_TEXTURE_LAST] = {
"button_a",
"button_b",
"switch"
"switch",
"check"
};
enum OZONE_TAB_TEXTURES {
@ -533,6 +535,7 @@ typedef struct ozone_handle
float selection[16];
float entries_border[16];
float entries_icon[16];
float entries_checkmark[16];
} theme_dynamic;
bool need_compute;
@ -1353,6 +1356,7 @@ static void ozone_set_color_theme(ozone_handle_t *ozone, unsigned color_theme)
memcpy(ozone->theme_dynamic.selection, ozone->theme->selection, sizeof(ozone->theme_dynamic.selection));
memcpy(ozone->theme_dynamic.entries_border, ozone->theme->entries_border, sizeof(ozone->theme_dynamic.entries_border));
memcpy(ozone->theme_dynamic.entries_icon, ozone->theme->entries_icon, sizeof(ozone->theme_dynamic.entries_icon));
memcpy(ozone->theme_dynamic.entries_checkmark, ozone_pure_white, sizeof(ozone->theme_dynamic.entries_checkmark));
last_color_theme = color_theme;
}
@ -2058,14 +2062,10 @@ static void ozone_compute_entries_position(ozone_handle_t *ozone)
{
/* Entry */
menu_entry_t entry;
char entry_value[255];
ozone_node_t *node = NULL;
entry_value[0] = '\0';
menu_entry_init(&entry);
menu_entry_get(&entry, 0, (unsigned)i, NULL, true);
menu_entry_get_value(&entry, entry_value, sizeof(entry_value));
/* Cache node */
node = (ozone_node_t*)file_list_get_userdata_at_offset(selection_buf, i);
@ -2359,18 +2359,32 @@ static void ozone_draw_sidebar(ozone_handle_t *ozone, video_frame_info_t *video_
menu_display_scissor_end(video_info);
}
static void ozone_draw_entry_value(ozone_handle_t *ozone, video_frame_info_t *video_info, char *value, unsigned x, unsigned y, uint32_t alpha_uint32)
static void ozone_draw_entry_value(ozone_handle_t *ozone,
video_frame_info_t *video_info,
char *value,
unsigned x, unsigned y,
uint32_t alpha_uint32,
bool checked)
{
enum msg_file_type hash_type;
bool switch_is_on = true;
bool do_draw_text = false;
if (string_is_empty(value))
if (!checked && string_is_empty(value))
return;
hash_type = msg_hash_to_file_type(msg_hash_calculate(value));
/* set switch_is_on */
/* check icon */
if (checked)
{
menu_display_blend_begin(video_info);
ozone_draw_icon(video_info, 35, 35, ozone->theme->textures[OZONE_THEME_TEXTURE_CHECK], x - 25, y - 25, video_info->width, video_info->height, 0, 1, ozone->theme_dynamic.entries_checkmark);
menu_display_blend_end(video_info);
return;
}
/* text value */
if (string_is_equal(value, msg_hash_to_str(MENU_ENUM_LABEL_DISABLED)) ||
(string_is_equal(value, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_OFF))))
{
@ -2482,6 +2496,7 @@ static void ozone_draw_entries(ozone_handle_t *ozone, video_frame_info_t *video_
goto text_iterate;
ozone_color_alpha(ozone->theme_dynamic.entries_border, alpha);
ozone_color_alpha(ozone->theme_dynamic.entries_checkmark, alpha);
/* Borders */
menu_display_draw_quad(video_info, x_offset + 456-3, y - 3 + scroll_y, entry_width + 10 - 3 -1, 1, video_info->width, video_info->height, ozone->theme_dynamic.entries_border);
@ -2537,10 +2552,8 @@ text_iterate:
ozone_draw_icon(video_info, 46, 46, ozone->icons_textures[icon], x_offset + 451+5+10, y + scroll_y, video_info->width, video_info->height, 0, 1, ozone->theme_dynamic.entries_icon);
menu_display_blend_end(video_info);
entry_rich_label = menu_entry_get_rich_label(&entry);
ticker.idx = ozone->frame_count / 20;
ticker.s = rich_label;
ticker.str = entry_rich_label;
@ -2562,7 +2575,7 @@ text_iterate:
ticker.len = (entry_width - 60 - ((int)utf8len(entry_rich_label) * ozone->entry_font_glyph_width)) / ozone->entry_font_glyph_width;
menu_animation_ticker(&ticker);
ozone_draw_entry_value(ozone, video_info, entry_value_ticker, x_offset + 426 + entry_width, y + FONT_SIZE_ENTRIES_LABEL + 8 - 1 + scroll_y,alpha_uint32);
ozone_draw_entry_value(ozone, video_info, entry_value_ticker, x_offset + 426 + entry_width, y + FONT_SIZE_ENTRIES_LABEL + 8 - 1 + scroll_y,alpha_uint32, entry.checked);
free(entry_rich_label);

View File

@ -8012,6 +8012,9 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, menu_displaylist
unsigned size = (unsigned)tmp_str_list->size;
unsigned i = atoi(tmp_str_list->elems[size-1].data);
struct core_option *option = NULL;
bool checked_found = false;
unsigned checked = 0;
const char *val = core_option_manager_get_val(coreopts, i-1);
i--;
@ -8033,9 +8036,19 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, menu_displaylist
val_d,
MENU_ENUM_LABEL_NO_ITEMS,
MENU_SETTING_DROPDOWN_SETTING_CORE_OPTIONS_ITEM, k, 0);
if (!checked_found && string_is_equal(str, val))
{
checked = k;
checked_found = true;
}
count++;
}
}
if (checked_found)
menu_entries_set_checked(info->list, checked, true);
}
}
}
@ -8057,7 +8070,9 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, menu_displaylist
if (tmp_str_list && tmp_str_list->size > 0)
{
unsigned i;
unsigned size = (unsigned)tmp_str_list->size;
unsigned size = (unsigned)tmp_str_list->size;
bool checked_found = false;
unsigned checked = 0;
for (i = 0; i < size; i++)
{
@ -8068,7 +8083,16 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, menu_displaylist
val_d,
MENU_ENUM_LABEL_NO_ITEMS,
MENU_SETTING_DROPDOWN_SETTING_STRING_OPTIONS_ITEM, i, 0);
if (!checked_found && string_is_equal(tmp_str_list->elems[i].data, setting->value.target.string))
{
checked = i;
checked_found = true;
}
}
if (checked_found)
menu_entries_set_checked(info->list, checked, true);
}
}
break;
@ -8080,6 +8104,8 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, menu_displaylist
float step = setting->step;
double min = setting->enforce_minrange ? setting->min : 0.00;
double max = setting->enforce_maxrange ? setting->max : 999.00;
bool checked_found = false;
unsigned checked = 0;
if (setting->get_string_representation)
{
@ -8098,6 +8124,12 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, menu_displaylist
val_d,
MENU_ENUM_LABEL_NO_ITEMS,
setting_type, val, 0);
if (!checked_found && string_is_equal(val_s, setting->value.target.string))
{
checked = i;
checked_found = true;
}
}
*setting->value.target.integer = orig_value;
@ -8117,8 +8149,17 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, menu_displaylist
val_d,
MENU_ENUM_LABEL_NO_ITEMS,
setting_type, val, 0);
if (!checked_found && string_is_equal(val_s, setting->value.target.string))
{
checked = i;
checked_found = true;
}
}
}
if (checked_found)
menu_entries_set_checked(info->list, checked, true);
}
break;
case ST_FLOAT:
@ -8129,6 +8170,8 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, menu_displaylist
float step = setting->step;
double min = setting->enforce_minrange ? setting->min : 0.00;
double max = setting->enforce_maxrange ? setting->max : 999.00;
bool checked_found = false;
unsigned checked = 0;
if (setting->get_string_representation)
{
@ -8146,6 +8189,12 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, menu_displaylist
val_d,
MENU_ENUM_LABEL_NO_ITEMS,
setting_type, 0, 0);
if (!checked_found && string_is_equal(val_s, setting->value.target.string))
{
checked = i;
checked_found = true;
}
}
*setting->value.target.fraction = orig_value;
@ -8164,8 +8213,17 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, menu_displaylist
val_d,
MENU_ENUM_LABEL_NO_ITEMS,
setting_type, 0, 0);
if (!checked_found && string_is_equal(val_s, setting->value.target.string))
{
checked = i;
checked_found = true;
}
}
}
if (checked_found)
menu_entries_set_checked(info->list, checked, true);
}
break;
case ST_UINT:
@ -8176,6 +8234,8 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, menu_displaylist
float step = setting->step;
double min = setting->enforce_minrange ? setting->min : 0.00;
double max = setting->enforce_maxrange ? setting->max : 999.00;
bool checked_found = false;
unsigned checked = 0;
if (setting->get_string_representation)
{
@ -8194,6 +8254,12 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, menu_displaylist
val_d,
MENU_ENUM_LABEL_NO_ITEMS,
setting_type, val, 0);
if (!checked_found && string_is_equal(val_s, setting->value.target.string))
{
checked = i;
checked_found = true;
}
}
*setting->value.target.unsigned_integer = orig_value;
@ -8213,8 +8279,17 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, menu_displaylist
val_d,
MENU_ENUM_LABEL_NO_ITEMS,
setting_type, val, 0);
if (!checked_found && string_is_equal(val_s, setting->value.target.string))
{
checked = i;
checked_found = true;
}
}
}
if (checked_found)
menu_entries_set_checked(info->list, checked, true);
}
break;
default:

View File

@ -487,6 +487,15 @@ error:
return false;
}
void menu_entries_set_checked(file_list_t *list, size_t entry_idx,
bool checked)
{
menu_file_list_cbs_t *cbs = (menu_file_list_cbs_t*)file_list_get_actiondata_at_offset(list, entry_idx);
if (cbs)
cbs->checked = checked;
}
void menu_entries_append(file_list_t *list, const char *path, const char *label,
unsigned type, size_t directory_ptr, size_t entry_idx)
{

View File

@ -99,6 +99,8 @@ typedef struct menu_file_list_cbs
const char *action_down_ident;
const char *action_get_value_ident;
bool checked;
rarch_setting_t *setting;
int (*action_iterate)(const char *label, unsigned action);
@ -180,6 +182,9 @@ void menu_entries_append_enum(file_list_t *list, const char *path, const char *l
bool menu_entries_ctl(enum menu_entries_ctl_state state, void *data);
void menu_entries_set_checked(file_list_t *list, size_t entry_idx,
bool checked);
RETRO_END_DECLS
#endif

View File

@ -325,6 +325,7 @@ void menu_entry_get(menu_entry_t *entry, size_t stack_idx,
enum msg_hash_enums enum_idx = MSG_UNKNOWN;
entry->enum_idx = cbs->enum_idx;
entry->checked = cbs->checked;
menu_entries_get_last_stack(NULL, &label, NULL, &enum_idx, NULL);

View File

@ -56,6 +56,7 @@ typedef struct menu_entry
char *sublabel;
char *rich_label;
char *value;
bool checked;
} menu_entry_t;
enum menu_entry_type menu_entry_get_type(uint32_t i);