Merge pull request #1501 from heuripedes/master

Add menu font color hints
This commit is contained in:
Twinaphex 2015-03-14 23:50:03 +01:00
commit e645f44d5e
9 changed files with 198 additions and 24 deletions

View File

@ -452,6 +452,9 @@ static bool default_block_config_read = true;
static bool collapse_subgroups_enable = true;
static bool show_advanced_settings = false;
static const uint32_t menu_entry_normal_color = 0xffffffff;
static const uint32_t menu_entry_hover_color = 0xff64ff64;
static const uint32_t menu_title_color = 0xff64ff64;
#else
static bool default_block_config_read = false;
#endif

View File

@ -223,6 +223,10 @@ struct settings
} navigation;
bool collapse_subgroups_enable;
bool show_advanced_settings;
unsigned entry_normal_color;
unsigned entry_hover_color;
unsigned title_color;
} menu;
#endif

View File

@ -44,6 +44,12 @@
base.var = tmp; \
} while(0)
#define CONFIG_GET_HEX_BASE(conf, base, var, key) do { \
unsigned tmp = 0; \
if (config_get_hex(conf, key, &tmp)) \
base.var = tmp; \
} while(0)
#define CONFIG_GET_FLOAT_BASE(conf, base, var, key) do { \
float tmp = 0.0f; \
if (config_get_float(conf, key, &tmp)) \
@ -59,6 +65,7 @@
#define CONFIG_GET_BOOL(var, key) CONFIG_GET_BOOL_BASE(conf, g_settings, var, key)
#define CONFIG_GET_INT(var, key) CONFIG_GET_INT_BASE(conf, g_settings, var, key)
#define CONFIG_GET_UINT64(var, key) CONFIG_GET_UINT64_BASE(conf, g_settings, var, key)
#define CONFIG_GET_HEX(var, key) CONFIG_GET_HEX_BASE(conf, g_settings, var, key)
#define CONFIG_GET_FLOAT(var, key) CONFIG_GET_FLOAT_BASE(conf, g_settings, var, key)
#define CONFIG_GET_STRING(var, key) CONFIG_GET_STRING_BASE(conf, g_settings, var, key)
#define CONFIG_GET_PATH(var, key) CONFIG_GET_PATH_BASE(conf, g_settings, var, key)

View File

@ -68,7 +68,7 @@ static int glui_entry_iterate(unsigned action)
return -1;
}
static void glui_blit_line(gl_t *gl, float x, float y, const char *message, bool green)
static void glui_blit_line(gl_t *gl, float x, float y, const char *message, uint32_t color)
{
struct font_params params = {0};
@ -77,12 +77,9 @@ static void glui_blit_line(gl_t *gl, float x, float y, const char *message, bool
params.x = x / gl->win_width;
params.y = 1.0f - y / gl->win_height;
params.scale = 1.0;
params.color = FONT_COLOR_RGBA(255, 255, 255, 255);
params.color = color;
params.full_screen = true;
if (green)
params.color = FONT_COLOR_RGBA(100, 255, 100, 255);
if (!driver.video_data)
return;
if (!driver.video_poke)
@ -256,7 +253,7 @@ static void glui_render_messagebox(const char *message)
{
const char *msg = list->elems[i].data;
if (msg)
glui_blit_line(gl, x, y + i * glui->line_height, msg, false);
glui_blit_line(gl, x, y + i * glui->line_height, msg, g_settings.menu.entry_normal_color);
}
end:
@ -361,7 +358,7 @@ static void glui_frame(void)
menu_animation_ticker_line(title_buf, glui->term_width - 3,
g_runloop.frames.video.count / glui->margin, title, true);
glui_blit_line(gl, glui->margin * 2, glui->margin + glui->line_height,
title_buf, true);
title_buf, g_settings.menu.title_color);
core_name = g_extern.menu.info.library_name;
if (!core_name)
@ -383,7 +380,7 @@ static void glui_frame(void)
glui_blit_line(gl,
glui->margin * 2,
glui->margin + glui->term_height * glui->line_height
+ glui->line_height * 2, title_msg, true);
+ glui->line_height * 2, title_msg, g_settings.menu.entry_hover_color);
}
@ -393,7 +390,7 @@ static void glui_frame(void)
glui_blit_line(gl,
glui->margin * 14,
glui->margin + glui->term_height * glui->line_height
+ glui->line_height * 2, timedate, true);
+ glui->line_height * 2, timedate, g_settings.menu.entry_hover_color);
}
x = glui->margin;
@ -432,10 +429,10 @@ static void glui_frame(void)
strlcpy(message, entry_title_buf, sizeof(message));
glui_blit_line(gl, x, y, message, selected);
glui_blit_line(gl, x, y, message, selected ? g_settings.menu.entry_hover_color : g_settings.menu.entry_normal_color);
glui_blit_line(gl, gl->win_width - glui->glyph_width * w - glui->margin ,
y, type_str_buf, selected);
y, type_str_buf, selected ? g_settings.menu.entry_hover_color : g_settings.menu.entry_normal_color);
}
if (menu->keyboard.display)

View File

@ -34,6 +34,25 @@
#define RGUI_TERM_WIDTH (((menu->frame_buf.width - RGUI_TERM_START_X - RGUI_TERM_START_X) / (FONT_WIDTH_STRIDE)))
#define RGUI_TERM_HEIGHT (((menu->frame_buf.height - RGUI_TERM_START_Y - RGUI_TERM_START_X) / (FONT_HEIGHT_STRIDE)) - 1)
#if defined(GEKKO)|| defined(PSP)
#define HOVER_COLOR ((3 << 0) | (10 << 4) | (3 << 8) | (7 << 12))
#define NORMAL_COLOR 0x7FFF
#define TITLE_COLOR HOVER_COLOR
#else
#define HOVER_COLOR (argb32_to_argb4444(g_settings.menu.entry_hover_color))
#define NORMAL_COLOR (argb32_to_argb4444(g_settings.menu.entry_normal_color))
#define TITLE_COLOR (argb32_to_argb4444(g_settings.menu.title_color))
#endif
static inline uint16_t argb32_to_argb4444(uint32_t col)
{
unsigned r = (col & 0xff) >> 4;
unsigned g = ((col >> 8) & 0xff) >> 4;
unsigned b = ((col >> 16) & 0xff) >> 4;
unsigned a = ((col >> 24) & 0xff) >> 4;
return r | g << 4 | b << 8 | a << 12;
}
static int rgui_entry_iterate(unsigned action)
{
const char *label = NULL;
@ -149,7 +168,7 @@ static void color_rect(menu_handle_t *menu,
menu->frame_buf.data[j * (menu->frame_buf.pitch >> 1) + i] = color;
}
static void blit_line(menu_handle_t *menu, int x, int y, const char *message, bool green)
static void blit_line(menu_handle_t *menu, int x, int y, const char *message, uint16_t color)
{
unsigned i, j;
@ -168,12 +187,7 @@ static void blit_line(menu_handle_t *menu, int x, int y, const char *message, bo
continue;
menu->frame_buf.data[(y + j) *
(menu->frame_buf.pitch >> 1) + (x + i)] = green ?
#if defined(GEKKO)|| defined(PSP)
(3 << 0) | (10 << 4) | (3 << 8) | (7 << 12) : 0x7FFF;
#else
(15 << 0) | (7 << 4) | (15 << 8) | (7 << 12) : 0xFFFF;
#endif
(menu->frame_buf.pitch >> 1) + (x + i)] = color;
}
}
@ -303,12 +317,14 @@ static void rgui_render_messagebox(const char *message)
fill_rect(&menu->frame_buf, x + 5, y + height - 5, width - 5, 5, green_filler);
fill_rect(&menu->frame_buf, x, y + 5, 5, height - 5, green_filler);
uint16_t color = NORMAL_COLOR;
for (i = 0; i < list->size; i++)
{
const char *msg = list->elems[i].data;
int offset_x = FONT_WIDTH_STRIDE * (glyphs_width - strlen(msg)) / 2;
int offset_y = FONT_HEIGHT_STRIDE * i;
blit_line(menu, x + 8 + offset_x, y + 8 + offset_y, msg, false);
blit_line(menu, x + 8 + offset_x, y + 8 + offset_y, msg, color);
}
end:
@ -385,7 +401,11 @@ static void rgui_render(void)
menu_animation_ticker_line(title_buf, RGUI_TERM_WIDTH - 3,
g_runloop.frames.video.count / RGUI_TERM_START_X, title, true);
blit_line(menu, RGUI_TERM_START_X + RGUI_TERM_START_X, RGUI_TERM_START_X, title_buf, true);
uint16_t hover_color = HOVER_COLOR;
uint16_t normal_color = NORMAL_COLOR;
blit_line(menu, RGUI_TERM_START_X + RGUI_TERM_START_X, RGUI_TERM_START_X, title_buf, TITLE_COLOR);
core_name = g_extern.menu.info.library_name;
if (!core_name)
@ -407,7 +427,7 @@ static void rgui_render(void)
blit_line(menu,
RGUI_TERM_START_X + RGUI_TERM_START_X,
(RGUI_TERM_HEIGHT * FONT_HEIGHT_STRIDE) +
RGUI_TERM_START_Y + 2, title_msg, true);
RGUI_TERM_START_Y + 2, title_msg, hover_color);
}
if (g_settings.menu.timedate_enable)
@ -417,7 +437,7 @@ static void rgui_render(void)
blit_line(menu,
(RGUI_TERM_WIDTH * FONT_HEIGHT_STRIDE) + (60),
(RGUI_TERM_HEIGHT * FONT_HEIGHT_STRIDE) +
RGUI_TERM_START_Y + 2, timedate, true);
RGUI_TERM_START_Y + 2, timedate, hover_color);
}
@ -466,7 +486,7 @@ static void rgui_render(void)
w,
type_str_buf);
blit_line(menu, x, y, message, selected);
blit_line(menu, x, y, message, selected ? hover_color : normal_color);
}
#ifdef GEKKO

View File

@ -96,6 +96,27 @@ void menu_input_st_uint_callback(void *userdata, const char *str)
menu_input_key_end_line();
}
void menu_input_st_hex_callback(void *userdata, const char *str)
{
menu_handle_t *menu = menu_driver_resolve();
if (!menu)
return;
if (str && *str)
{
rarch_setting_t *current_setting = NULL;
if ((current_setting = (rarch_setting_t*)
setting_data_find_setting(
menu->list_settings, menu->keyboard.label_setting)))
if (str[0] == '#')
str++;
*current_setting->value.unsigned_integer = strtoul(str, NULL, 16);
}
menu_input_key_end_line();
}
void menu_input_st_string_callback(void *userdata, const char *str)
{

View File

@ -52,6 +52,7 @@ void menu_input_key_start_line(const char *label,
input_keyboard_line_complete_t cb);
void menu_input_st_uint_callback(void *userdata, const char *str);
void menu_input_st_hex_callback(void *userdata, const char *str);
void menu_input_st_string_callback(void *userdata, const char *str);

View File

@ -499,6 +499,9 @@ static void config_set_defaults(void)
g_settings.menu.navigation.browser.filter.supported_extensions_enable = true;
g_settings.menu.collapse_subgroups_enable = collapse_subgroups_enable;
g_settings.menu.show_advanced_settings = show_advanced_settings;
g_settings.menu.entry_normal_color = menu_entry_normal_color;
g_settings.menu.entry_hover_color = menu_entry_hover_color;
g_settings.menu.title_color = menu_title_color;
#endif
g_settings.ui.menubar_enable = true;
@ -1124,6 +1127,9 @@ static bool config_load_file(const char *path, bool set_defaults)
CONFIG_GET_BOOL(menu.navigation.browser.filter.supported_extensions_enable, "menu_navigation_browser_filter_supported_extensions_enable");
CONFIG_GET_BOOL(menu.collapse_subgroups_enable, "menu_collapse_subgroups_enable");
CONFIG_GET_BOOL(menu.show_advanced_settings, "menu_show_advanced_settings");
CONFIG_GET_HEX(menu.entry_normal_color, "menu_entry_normal_color");
CONFIG_GET_HEX(menu.entry_hover_color, "menu_entry_hover_color");
CONFIG_GET_HEX(menu.title_color, "menu_title_color");
CONFIG_GET_PATH(menu.wallpaper, "menu_wallpaper");
if (!strcmp(g_settings.menu.wallpaper, "default"))
*g_settings.menu.wallpaper = '\0';
@ -1997,6 +2003,12 @@ bool config_save_file(const char *path)
g_settings.menu.collapse_subgroups_enable);
config_set_bool(conf, "menu_show_advanced_settings",
g_settings.menu.show_advanced_settings);
config_set_hex(conf, "menu_entry_normal_color",
g_settings.menu.entry_normal_color);
config_set_hex(conf, "menu_entry_hover_color",
g_settings.menu.entry_hover_color);
config_set_hex(conf, "menu_title_color",
g_settings.menu.title_color);
#endif
config_set_path(conf, "game_history_path", g_settings.content_history_path);

View File

@ -1014,6 +1014,19 @@ static int setting_data_uint_action_ok_linefeed(void *data, unsigned action)
return 0;
}
static int setting_data_hex_action_ok_linefeed(void *data, unsigned action)
{
rarch_setting_t *setting = (rarch_setting_t*)data;
if (!setting)
return -1;
menu_input_key_start_line(setting->short_description,
setting->name, 0, 0, menu_input_st_hex_callback);
return 0;
}
static int setting_data_action_action_ok(void *data, unsigned action)
{
rarch_setting_t *setting = (rarch_setting_t*)data;
@ -1413,6 +1426,15 @@ static void setting_data_get_string_representation_uint(void *data,
*setting->value.unsigned_integer);
}
static void setting_data_get_string_representation_hex(void *data,
char *type_str, size_t type_str_size)
{
rarch_setting_t *setting = (rarch_setting_t*)data;
if (setting)
snprintf(type_str, type_str_size, "%08x",
*setting->value.unsigned_integer);
}
/**
******* LIST BUILDING HELPER FUNCTIONS *******
**/
@ -1693,6 +1715,51 @@ rarch_setting_t setting_data_uint_setting(const char* name,
return result;
}
/**
* setting_data_uint_setting:
* @name : name of setting.
* @short_description : Short description of setting.
* @target : Target of unsigned integer setting.
* @default_value : Default value (in unsigned integer format).
* @group : Group that the setting belongs to.
* @subgroup : Subgroup that the setting belongs to.
* @change_handler : Function callback for change handler function pointer.
* @read_handler : Function callback for read handler function pointer.
*
* Initializes a setting of type ST_HEX.
*
* Returns: setting of type ST_HEX.
**/
rarch_setting_t setting_data_hex_setting(const char* name,
const char* short_description, unsigned int* target,
unsigned int default_value, const char *group, const char *subgroup,
change_handler_t change_handler, change_handler_t read_handler)
{
rarch_setting_t result;
memset(&result, 0, sizeof(result));
result.type = ST_HEX;
result.name = name;
result.size = sizeof(unsigned int);
result.short_description = short_description;
result.group = group;
result.subgroup = subgroup;
result.change_handler = change_handler;
result.read_handler = read_handler;
result.value.unsigned_integer = target;
result.original_value.unsigned_integer = *target;
result.default_value.unsigned_integer = default_value;
result.action_start = setting_data_uint_action_start_default;
result.action_toggle = NULL;
result.action_ok = setting_data_uint_action_ok_default;
result.action_cancel = NULL;
result.get_string_representation = &setting_data_get_string_representation_hex;
return result;
}
/**
* setting_data_bind_setting:
* @name : name of setting.
@ -3108,7 +3175,10 @@ static void general_write_handler(void *data)
if (!(settings_list_append(list, list_info, setting_data_string_setting_options(ST_STRING, NAME, SHORT, TARGET, sizeof(TARGET), DEF, "", OPTS, group_info, subgroup_info, CHANGE_HANDLER, READ_HANDLER)))) return false; \
}
#define CONFIG_HEX(TARGET, NAME, SHORT, group_info, subgroup_info)
#define CONFIG_HEX(TARGET, NAME, SHORT, DEF, group_info, subgroup_info, CHANGE_HANDLER, READ_HANDLER) \
{ \
if (!(settings_list_append(list, list_info, setting_data_hex_setting(NAME, SHORT, &TARGET, DEF, group_info, subgroup_info, CHANGE_HANDLER, READ_HANDLER)))) return false; \
}
#define CONFIG_BIND(TARGET, PLAYER, PLAYER_OFFSET, NAME, SHORT, DEF, group_info, subgroup_info) \
{ \
@ -3137,6 +3207,11 @@ static void setting_data_add_special_callbacks(
(*list)[idx].action_ok = setting_data_uint_action_ok_linefeed;
(*list)[idx].action_cancel = NULL;
break;
case ST_HEX:
(*list)[idx].action_start = setting_data_uint_action_start_linefeed;
(*list)[idx].action_ok = setting_data_hex_action_ok_linefeed;
(*list)[idx].action_cancel = NULL;
break;
case ST_STRING:
(*list)[idx].action_start = setting_data_string_action_start_allow_input;
(*list)[idx].action_ok = setting_data_string_action_ok_allow_input;
@ -5175,6 +5250,40 @@ static bool setting_data_append_list_menu_options(
general_write_handler,
general_read_handler);
/* These colors are hints. The menu driver is not required to use them. */
CONFIG_HEX(
g_settings.menu.entry_normal_color,
"menu_entry_normal_color",
"Menu entry normal color",
menu_entry_hover_color,
group_info.name,
subgroup_info.name,
general_write_handler,
general_read_handler);
settings_data_list_current_add_flags(list, list_info, SD_FLAG_ALLOW_INPUT);
CONFIG_HEX(
g_settings.menu.entry_hover_color,
"menu_entry_hover_color",
"Menu entry hover color",
menu_entry_hover_color,
group_info.name,
subgroup_info.name,
general_write_handler,
general_read_handler);
settings_data_list_current_add_flags(list, list_info, SD_FLAG_ALLOW_INPUT);
CONFIG_HEX(
g_settings.menu.title_color,
"menu_title_color",
"Menu title color",
menu_title_color,
group_info.name,
subgroup_info.name,
general_write_handler,
general_read_handler);
settings_data_list_current_add_flags(list, list_info, SD_FLAG_ALLOW_INPUT);
END_SUB_GROUP(list, list_info);
START_SUB_GROUP(list, list_info, "Browser", group_info.name, subgroup_info);