From 4ccfc1af02fa9b112fa3bbe685a139e3aa5c1e0e Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 17 Jan 2015 04:50:46 +0100 Subject: [PATCH] Add date/time in menu --- general.h | 2 ++ menu/drivers_display/glui.c | 10 ++++++++++ menu/drivers_display/lakka.c | 12 ++++++++++++ menu/drivers_display/rgui.c | 9 +++++++++ menu/drivers_display/shared.h | 25 +++++++++++++++++++++++++ menu/drivers_display/xmb.c | 13 +++++++++++-- retroarch.cfg | 3 +++ settings.c | 3 +++ settings_data.c | 12 ++++++++++++ 9 files changed, 87 insertions(+), 2 deletions(-) diff --git a/general.h b/general.h index 51ed03ce1d..19b2e6009c 100644 --- a/general.h +++ b/general.h @@ -190,6 +190,8 @@ struct settings char driver[32]; bool pause_libretro; bool mouse_enable; + bool timedate_enable; + struct { struct diff --git a/menu/drivers_display/glui.c b/menu/drivers_display/glui.c index dbe3ce887f..5fddc16a38 100644 --- a/menu/drivers_display/glui.c +++ b/menu/drivers_display/glui.c @@ -263,6 +263,7 @@ static void glui_frame(void) size_t i; char title[PATH_MAX_LENGTH], title_buf[PATH_MAX_LENGTH], title_msg[PATH_MAX_LENGTH]; + char timedate[PATH_MAX_LENGTH]; const char *dir = NULL; const char *label = NULL; unsigned menu_type = 0; @@ -337,11 +338,20 @@ static void glui_frame(void) snprintf(title_msg, sizeof(title_msg), "%s - %s %s", PACKAGE_VERSION, core_name, core_version); + + disp_timedate_set_label(timedate, sizeof(timedate), 0); + glui_blit_line( glui->margin * 2, glui->margin + glui->term_height * glui->line_height + glui->line_height * 2, title_msg, true); + if (g_settings.menu.timedate_enable) + glui_blit_line( + glui->margin * 14, + glui->margin + glui->term_height * glui->line_height + + glui->line_height * 2, timedate, true); + x = glui->margin; y = glui->margin + glui->line_height * 2; diff --git a/menu/drivers_display/lakka.c b/menu/drivers_display/lakka.c index 575915cdda..9268e57f9d 100644 --- a/menu/drivers_display/lakka.c +++ b/menu/drivers_display/lakka.c @@ -29,6 +29,7 @@ #include "../../gfx/gl_common.h" #include "../../gfx/video_thread_wrapper.h" #include +#include "shared.h" #include "../../settings_data.h" @@ -558,6 +559,7 @@ static void lakka_draw_fbo(lakka_handle_t *lakka) static void lakka_frame(void) { + char timedate[PATH_MAX_LENGTH]; menu_item_t *active_item = NULL; menu_category_t *active_category = NULL; lakka_handle_t *lakka = NULL; @@ -602,6 +604,8 @@ static void lakka_frame(void) lakka_draw_arrow(lakka); #endif + disp_timedate_set_label(timedate, sizeof(timedate), 0); + if (lakka->depth == 0) lakka_draw_text(lakka, active_category->name, lakka->title_margin_left, lakka->title_margin_top, 1, 1.0); @@ -609,6 +613,11 @@ static void lakka_frame(void) lakka_draw_text(lakka, active_item->name, lakka->title_margin_left, lakka->title_margin_top, 1, 1.0); + if (g_settings.menu.timedate_enable) + lakka_draw_text(lakka, timedate, + (lakka->title_margin_left * 25) - lakka->title_margin_left, + lakka->title_margin_top, 1, 1.0); + gl_set_viewport(gl, gl->win_width, gl->win_height, false, false); glDisable(GL_BLEND); @@ -1311,6 +1320,9 @@ static bool lakka_init_lists(void *data) info->display_name); } + (void)get_title; + (void)disp_set_label; + return true; } diff --git a/menu/drivers_display/rgui.c b/menu/drivers_display/rgui.c index 64044c00df..470d3aa68f 100644 --- a/menu/drivers_display/rgui.c +++ b/menu/drivers_display/rgui.c @@ -330,6 +330,7 @@ static void rgui_render(void) { size_t i, end; char title[256], title_buf[256], title_msg[64]; + char timedate[PATH_MAX_LENGTH]; unsigned x, y, menu_type = 0; const char *dir = NULL; const char *label = NULL; @@ -392,6 +393,8 @@ static void rgui_render(void) if (!core_version) core_version = ""; + disp_timedate_set_label(timedate, sizeof(timedate), 3); + snprintf(title_msg, sizeof(title_msg), "%s - %s %s", PACKAGE_VERSION, core_name, core_version); blit_line( @@ -399,6 +402,12 @@ static void rgui_render(void) (RGUI_TERM_HEIGHT * FONT_HEIGHT_STRIDE) + RGUI_TERM_START_Y + 2, title_msg, true); + if (g_settings.menu.timedate_enable) + blit_line( + (RGUI_TERM_WIDTH * FONT_HEIGHT_STRIDE) + (60), + (RGUI_TERM_HEIGHT * FONT_HEIGHT_STRIDE) + + RGUI_TERM_START_Y + 2, timedate, true); + x = RGUI_TERM_START_X; y = RGUI_TERM_START_Y; diff --git a/menu/drivers_display/shared.h b/menu/drivers_display/shared.h index 63cc5e36ce..b5d030be83 100644 --- a/menu/drivers_display/shared.h +++ b/menu/drivers_display/shared.h @@ -17,6 +17,7 @@ #define _DISP_SHARED_H #include "../../settings_data.h" +#include static void get_title(const char *label, const char *dir, unsigned menu_type, char *title, size_t sizeof_title) @@ -162,6 +163,30 @@ static void get_title(const char *label, const char *dir, } } +static void disp_timedate_set_label(char *label, size_t label_size, + unsigned time_mode) +{ + char datetime[PATH_MAX_LENGTH]; + time_t time_; + time(&time_); + + switch (time_mode) + { + case 0: /* Date and time */ + strftime(label, label_size, "%Y-%m-%d %H:%M:%S", localtime(&time_)); + break; + case 1: /* Date */ + strftime(label, label_size, "%Y-%m-%d", localtime(&time_)); + break; + case 2: /* Time */ + strftime(label, label_size, "%H:%M:%S", localtime(&time_)); + break; + case 3: /* Time (hours-minutes) */ + strftime(label, label_size, "%H:%M", localtime(&time_)); + break; + } +} + static void disp_set_label(file_list_t* list, unsigned *w, unsigned type, unsigned i, const char *label, diff --git a/menu/drivers_display/xmb.c b/menu/drivers_display/xmb.c index 904d7419bd..5f555c79b1 100644 --- a/menu/drivers_display/xmb.c +++ b/menu/drivers_display/xmb.c @@ -674,7 +674,7 @@ static void xmb_list_switch_new(file_list_t *list, int dir, size_t current) } } -static void xmb_set_title() +static void xmb_set_title(void) { xmb_handle_t *xmb = (xmb_handle_t*)driver.menu->userdata; @@ -818,6 +818,7 @@ static void xmb_draw_items(file_list_t *list, file_list_t *stack, entry_label, path, path_buf, sizeof(path_buf)); + GLuint icon = 0; switch(type) { @@ -927,7 +928,7 @@ static void xmb_draw_items(file_list_t *list, file_list_t *stack, static void xmb_frame(void) { int i, depth; - char title_msg[64]; + char title_msg[PATH_MAX_LENGTH], timedate[PATH_MAX_LENGTH]; const char *core_name = NULL; const char *core_version = NULL; xmb_handle_t *xmb = (xmb_handle_t*)driver.menu->userdata; @@ -953,6 +954,13 @@ static void xmb_frame(void) xmb_draw_text( xmb->title, xmb->title_margin_left, xmb->title_margin_top, 1, 1); + disp_timedate_set_label(timedate, sizeof(timedate), 0); + + if (g_settings.menu.timedate_enable) + xmb_draw_text( + timedate, (xmb->title_margin_left * 25) - xmb->title_margin_left, + xmb->title_margin_top, 1, 1); + core_version = g_extern.menu.info.library_version; if (!core_version) @@ -965,6 +973,7 @@ static void xmb_frame(void) xmb_draw_text(title_msg, xmb->title_margin_left, gl->win_height - xmb->title_margin_bottom, 1, 1); + xmb_draw_icon(xmb->textures[XMB_TEXTURE_ARROW].id, xmb->x + xmb->margin_left + xmb->hspacing - xmb->icon_size/2.0 + xmb->icon_size, xmb->margin_top + xmb->icon_size/2.0 + xmb->vspacing * xmb->active_item_factor, diff --git a/retroarch.cfg b/retroarch.cfg index 97af99a03c..d22cfede3d 100644 --- a/retroarch.cfg +++ b/retroarch.cfg @@ -570,6 +570,9 @@ # Enable mouse input inside the menu. # menu_mouse_enable = false +# Shows current date and/or time inside menu. +# menu_timedate_enable = true + # Wrap-around toe beginning and/or end if boundary of list reached horizontally # menu_navigation_wraparound_horizontal_enable = false diff --git a/settings.c b/settings.c index ec1d9ffe26..0392d16440 100644 --- a/settings.c +++ b/settings.c @@ -509,6 +509,7 @@ static void config_set_defaults(void) g_settings.menu_show_start_screen = menu_show_start_screen; g_settings.menu.pause_libretro = true; g_settings.menu.mouse_enable = false; + g_settings.menu.timedate_enable = true; g_settings.menu.navigation.wraparound.horizontal_enable = true; g_settings.menu.navigation.wraparound.vertical_enable = true; g_settings.menu.navigation.browser.filter.supported_extensions_enable = true; @@ -1100,6 +1101,7 @@ static bool config_load_file(const char *path, bool set_defaults) #ifdef HAVE_MENU CONFIG_GET_BOOL(menu.pause_libretro, "menu_pause_libretro"); CONFIG_GET_BOOL(menu.mouse_enable, "menu_mouse_enable"); + CONFIG_GET_BOOL(menu.timedate_enable, "menu_timedate_enable"); CONFIG_GET_BOOL(menu.navigation.wraparound.horizontal_enable, "menu_navigation_wraparound_horizontal_enable"); CONFIG_GET_BOOL(menu.navigation.wraparound.vertical_enable, "menu_navigation_wraparound_vertical_enable"); CONFIG_GET_BOOL(menu.navigation.browser.filter.supported_extensions_enable, "menu_navigation_browser_filter_supported_extensions_enable"); @@ -1816,6 +1818,7 @@ bool config_save_file(const char *path) config_set_string(conf,"menu_driver", g_settings.menu.driver); config_set_bool(conf,"menu_pause_libretro", g_settings.menu.pause_libretro); config_set_bool(conf,"menu_mouse_enable", g_settings.menu.mouse_enable); + config_set_bool(conf,"menu_timedate_enable", g_settings.menu.timedate_enable); #endif config_set_bool(conf, "video_vsync", g_settings.video.vsync); config_set_bool(conf, "video_hard_sync", g_settings.video.hard_sync); diff --git a/settings_data.c b/settings_data.c index 0ce9c22b90..9533b07056 100644 --- a/settings_data.c +++ b/settings_data.c @@ -5305,6 +5305,18 @@ static bool setting_data_append_list_menu_options( general_write_handler, general_read_handler); + CONFIG_BOOL( + g_settings.menu.timedate_enable, + "menu_timedate_enable", + "Time / date enable", + true, + "OFF", + "ON", + group_info.name, + subgroup_info.name, + general_write_handler, + general_read_handler); + END_SUB_GROUP(list, list_info); END_GROUP(list, list_info);