Skip to content

Commit 5a22582

Browse files
authored
Add On-Screen Time option (#19021)
1 parent c39cf47 commit 5a22582

14 files changed

Lines changed: 149 additions & 14 deletions

config.def.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,6 +1287,9 @@
12871287
/* Includes displaying the current memory usage/total with FPS/Frames. */
12881288
#define DEFAULT_MEMORY_SHOW false
12891289

1290+
/* Displays the current time in the preferred format. */
1291+
#define DEFAULT_TIME_SHOW TIME_SHOW_OFF
1292+
12901293
/* Enables displaying various timing statistics. */
12911294
#define DEFAULT_STATISTICS_SHOW false
12921295

configuration.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2458,6 +2458,7 @@ static struct config_uint_setting *populate_settings_uint(
24582458
SETTING_UINT("libretro_log_level", &settings->uints.libretro_log_level, true, DEFAULT_LIBRETRO_LOG_LEVEL, false);
24592459
SETTING_UINT("fps_update_interval", &settings->uints.fps_update_interval, true, DEFAULT_FPS_UPDATE_INTERVAL, false);
24602460
SETTING_UINT("memory_update_interval", &settings->uints.memory_update_interval, true, DEFAULT_MEMORY_UPDATE_INTERVAL, false);
2461+
SETTING_UINT("time_show", &settings->uints.video_time_show, true, DEFAULT_TIME_SHOW, false);
24612462
SETTING_UINT("core_updater_auto_backup_history_size", &settings->uints.core_updater_auto_backup_history_size, true, DEFAULT_CORE_UPDATER_AUTO_BACKUP_HISTORY_SIZE, false);
24622463
SETTING_UINT("autosave_interval", &settings->uints.autosave_interval, true, DEFAULT_AUTOSAVE_INTERVAL, false);
24632464
SETTING_UINT("rewind_granularity", &settings->uints.rewind_granularity, true, DEFAULT_REWIND_GRANULARITY, false);

configuration.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ typedef struct settings
200200

201201
unsigned fps_update_interval;
202202
unsigned memory_update_interval;
203+
unsigned video_time_show;
203204

204205
unsigned input_block_timeout;
205206

gfx/gfx_widgets.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,6 +1598,7 @@ bool gfx_widgets_visible(void *data)
15981598
bool framecount_show = video_info->framecount_show;
15991599
bool memory_show = video_info->memory_show;
16001600
bool core_status_msg_show = video_info->core_status_msg_show;
1601+
bool time_show = video_info->time_show;
16011602
uint32_t video_flags = video_info->video_st_flags;
16021603
bool widgets_is_paused = (video_flags & VIDEO_FLAG_WIDGETS_PAUSED) != 0;
16031604
bool widgets_is_fastmotion = (video_flags & VIDEO_FLAG_WIDGETS_FASTMOTION) != 0;
@@ -1618,7 +1619,11 @@ bool gfx_widgets_visible(void *data)
16181619
return true;
16191620
#endif
16201621

1621-
if (fps_show || framecount_show || memory_show || core_status_msg_show)
1622+
if ( fps_show
1623+
|| framecount_show
1624+
|| memory_show
1625+
|| core_status_msg_show
1626+
|| time_show)
16221627
return true;
16231628

16241629
if ( widgets_is_paused
@@ -1652,6 +1657,8 @@ void gfx_widgets_frame(void *data)
16521657
bool framecount_show = video_info->framecount_show;
16531658
bool memory_show = video_info->memory_show;
16541659
bool core_status_msg_show = video_info->core_status_msg_show;
1660+
bool time_show = video_info->time_show;
1661+
bool onscreen_panels = fps_show || framecount_show || memory_show || core_status_msg_show || time_show;
16551662
void *userdata = video_info->userdata;
16561663
unsigned video_width = video_info->width;
16571664
unsigned video_height = video_info->height;
@@ -1829,12 +1836,8 @@ void gfx_widgets_frame(void *data)
18291836
}
18301837
#endif
18311838

1832-
/* Status Text (FPS, framecount, memory, core status message) */
1833-
if ( fps_show
1834-
|| framecount_show
1835-
|| memory_show
1836-
|| core_status_msg_show
1837-
)
1839+
/* On-Screen Panels (FPS, framecount, memory, core status message, time) */
1840+
if (onscreen_panels)
18381841
{
18391842
const char *txt = *p_dispwidget->gfx_widgets_status_text == '\0'
18401843
? msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE)
@@ -1892,9 +1895,7 @@ void gfx_widgets_frame(void *data)
18921895
video_height,
18931896
p_dispwidget->gfx_widgets_icons_textures[
18941897
MENU_WIDGETS_ICON_PAUSED],
1895-
(fps_show
1896-
? p_dispwidget->simple_widget_height
1897-
: 0),
1898+
(onscreen_panels ? p_dispwidget->simple_widget_height : 0),
18981899
top_right_x_advance,
18991900
MSG_PAUSED);
19001901

@@ -1908,7 +1909,7 @@ void gfx_widgets_frame(void *data)
19081909
video_height,
19091910
p_dispwidget->gfx_widgets_icons_textures[
19101911
MENU_WIDGETS_ICON_FAST_FORWARD],
1911-
(fps_show ? p_dispwidget->simple_widget_height : 0),
1912+
(onscreen_panels ? p_dispwidget->simple_widget_height : 0),
19121913
top_right_x_advance,
19131914
MSG_FAST_FORWARD);
19141915

@@ -1922,7 +1923,7 @@ void gfx_widgets_frame(void *data)
19221923
video_height,
19231924
p_dispwidget->gfx_widgets_icons_textures[
19241925
MENU_WIDGETS_ICON_REWIND],
1925-
(fps_show ? p_dispwidget->simple_widget_height : 0),
1926+
(onscreen_panels ? p_dispwidget->simple_widget_height : 0),
19261927
top_right_x_advance,
19271928
MSG_REWINDING);
19281929

@@ -1937,7 +1938,7 @@ void gfx_widgets_frame(void *data)
19371938
video_height,
19381939
p_dispwidget->gfx_widgets_icons_textures[
19391940
MENU_WIDGETS_ICON_SLOW_MOTION],
1940-
(fps_show ? p_dispwidget->simple_widget_height : 0),
1941+
(onscreen_panels ? p_dispwidget->simple_widget_height : 0),
19411942
top_right_x_advance,
19421943
MSG_SLOW_MOTION);
19431944
(void)top_right_x_advance;

gfx/video_defines.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,16 @@ enum autoswitch_refresh_rate
111111
AUTOSWITCH_REFRESH_RATE_LAST
112112
};
113113

114+
enum time_show_type
115+
{
116+
TIME_SHOW_OFF = 0,
117+
TIME_SHOW_HM,
118+
TIME_SHOW_HMS,
119+
TIME_SHOW_HM_AMPM,
120+
TIME_SHOW_HMS_AMPM,
121+
TIME_SHOW_LAST
122+
};
123+
114124
enum rarch_display_type
115125
{
116126
/* Non-bindable types like consoles, KMS, VideoCore, etc. */

gfx/video_driver.c

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <string/stdstring.h>
2222
#include <retro_math.h>
2323
#include <retro_timers.h>
24+
#include <time/rtime.h>
2425

2526
#ifdef HAVE_CONFIG_H
2627
#include "../config.h"
@@ -3299,6 +3300,7 @@ void video_driver_build_info(video_frame_info_t *video_info)
32993300
video_info->memory_show = settings->bools.video_memory_show;
33003301
video_info->statistics_show = settings->bools.video_statistics_show;
33013302
video_info->framecount_show = settings->bools.video_framecount_show;
3303+
video_info->time_show = settings->uints.video_time_show;
33023304
video_info->core_status_msg_show = runloop_st->core_status_msg.set;
33033305
video_info->aspect_ratio_idx = settings->uints.video_aspect_ratio_idx;
33043306
video_info->post_filter_record = settings->bools.video_post_filter_record;
@@ -4130,7 +4132,7 @@ bool video_driver_init_internal(bool *video_is_threaded, bool verbosity_enabled)
41304132
void video_driver_frame(const void *data, unsigned width,
41314133
unsigned height, size_t pitch)
41324134
{
4133-
char status_text[128];
4135+
char status_text[256];
41344136
static char video_driver_msg[256];
41354137
static retro_time_t last_time;
41364138
static retro_time_t curr_time;
@@ -4465,6 +4467,62 @@ void video_driver_frame(const void *data, unsigned width,
44654467
RUNLOOP_MSG_QUEUE_UNLOCK(runloop_st);
44664468
}
44674469

4470+
if (video_info.time_show)
4471+
{
4472+
static char time_text[64];
4473+
static retro_time_t next_time_update;
4474+
static unsigned time_show_last_format;
4475+
time_t time_;
4476+
4477+
_len = strlen(status_text);
4478+
4479+
if (_len > 0)
4480+
{
4481+
status_text[ _len] = ' ';
4482+
status_text[++_len] = '|';
4483+
status_text[++_len] = '|';
4484+
status_text[++_len] = ' ';
4485+
status_text[++_len] = '\0';
4486+
}
4487+
4488+
if ( !next_time_update
4489+
|| (new_time >= next_time_update)
4490+
|| video_info.time_show != time_show_last_format)
4491+
{
4492+
struct tm tm_;
4493+
retro_time_t time_update_interval = 0;
4494+
4495+
time(&time_);
4496+
4497+
time_show_last_format = video_info.time_show;
4498+
rtime_localtime(&time_, &tm_);
4499+
4500+
switch (video_info.time_show)
4501+
{
4502+
case TIME_SHOW_HM:
4503+
strftime(time_text, sizeof(time_text), "%H:%M", &tm_);
4504+
time_update_interval = (60 - tm_.tm_sec) * 1000000;
4505+
break;
4506+
case TIME_SHOW_HMS:
4507+
strftime(time_text, sizeof(time_text), "%H:%M:%S", &tm_);
4508+
time_update_interval = 500000;
4509+
break;
4510+
case TIME_SHOW_HM_AMPM:
4511+
strftime_am_pm(time_text, sizeof(time_text), "%I:%M %p", &tm_);
4512+
time_update_interval = (60 - tm_.tm_sec) * 1000000;
4513+
break;
4514+
case TIME_SHOW_HMS_AMPM:
4515+
strftime_am_pm(time_text, sizeof(time_text), "%I:%M:%S %p", &tm_);
4516+
time_update_interval = 500000;
4517+
break;
4518+
}
4519+
4520+
next_time_update = new_time + time_update_interval;
4521+
}
4522+
4523+
strlcpy(status_text + _len, time_text, sizeof(status_text) - _len);
4524+
}
4525+
44684526
/* Slightly messy code,
44694527
* but we really need to do processing before blocking on VSync
44704528
* for best possible scheduling.
@@ -4751,6 +4809,7 @@ void video_driver_frame(const void *data, unsigned width,
47514809
|| video_info.framecount_show
47524810
|| video_info.memory_show
47534811
|| video_info.core_status_msg_show
4812+
|| video_info.time_show
47544813
)
47554814
#if HAVE_MENU
47564815
&& !((video_info.menu_st_flags & MENU_ST_FLAG_SCREENSAVER_ACTIVE))

gfx/video_driver.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ typedef struct video_frame_info
388388
unsigned current_subframe;
389389
unsigned fps_update_interval;
390390
unsigned memory_update_interval;
391+
unsigned time_show;
391392
unsigned msg_queue_delay;
392393

393394
float menu_wallpaper_opacity;

intl/msg_hash_us.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5858,6 +5858,14 @@ MSG_HASH(
58585858
MENU_ENUM_SUBLABEL_MEMORY_UPDATE_INTERVAL,
58595859
"Memory usage display will be updated at the set interval in frames."
58605860
)
5861+
MSG_HASH(
5862+
MENU_ENUM_LABEL_VALUE_TIME_SHOW,
5863+
"Display Time"
5864+
)
5865+
MSG_HASH(
5866+
MENU_ENUM_SUBLABEL_TIME_SHOW,
5867+
"Display the current time in the preferred format."
5868+
)
58615869
MSG_HASH(
58625870
MENU_ENUM_LABEL_VALUE_NETPLAY_PING_SHOW,
58635871
"Display Netplay Ping"

menu/cbs/menu_cbs_sublabel.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_fps_update_interval, MENU_
414414
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_framecount_show, MENU_ENUM_SUBLABEL_FRAMECOUNT_SHOW)
415415
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_memory_show, MENU_ENUM_SUBLABEL_MEMORY_SHOW)
416416
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_memory_update_interval, MENU_ENUM_SUBLABEL_MEMORY_UPDATE_INTERVAL)
417+
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_time_show, MENU_ENUM_SUBLABEL_TIME_SHOW)
417418
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_statistics_show, MENU_ENUM_SUBLABEL_STATISTICS_SHOW)
418419
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_netplay_ping_show, MENU_ENUM_SUBLABEL_NETPLAY_PING_SHOW)
419420
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_netplay_settings, MENU_ENUM_SUBLABEL_NETPLAY)
@@ -5119,6 +5120,9 @@ int menu_cbs_init_bind_sublabel(menu_file_list_cbs_t *cbs,
51195120
case MENU_ENUM_LABEL_MEMORY_UPDATE_INTERVAL:
51205121
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_memory_update_interval);
51215122
break;
5123+
case MENU_ENUM_LABEL_TIME_SHOW:
5124+
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_time_show);
5125+
break;
51225126
case MENU_ENUM_LABEL_MENU_VIEWS_SETTINGS:
51235127
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_menu_views_settings_list);
51245128
break;

menu/menu_displaylist.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11063,6 +11063,7 @@ unsigned menu_displaylist_build_list(
1106311063
{MENU_ENUM_LABEL_STATISTICS_SHOW, PARSE_ONLY_BOOL, false },
1106411064
{MENU_ENUM_LABEL_MEMORY_SHOW, PARSE_ONLY_BOOL, false },
1106511065
{MENU_ENUM_LABEL_MEMORY_UPDATE_INTERVAL, PARSE_ONLY_UINT, false },
11066+
{MENU_ENUM_LABEL_TIME_SHOW, PARSE_ONLY_UINT, false },
1106611067
{MENU_ENUM_LABEL_MENU_SHOW_LOAD_CONTENT_ANIMATION, PARSE_ONLY_BOOL, false },
1106711068
{MENU_ENUM_LABEL_NOTIFICATION_SHOW_WHEN_MENU_IS_ALIVE, PARSE_ONLY_BOOL, false },
1106811069
{MENU_ENUM_LABEL_NOTIFICATION_SHOW_AUTOCONFIG, PARSE_ONLY_BOOL, false },

0 commit comments

Comments
 (0)