Add "time_format" parameter; update time string every "fps_sampling_period" interval

See std::put_time docs for supported formatting
pull/58/head
jackun 4 years ago
parent 9a4c9033fa
commit 6bf37f8510
No known key found for this signature in database
GPG Key ID: 119DB3F1D05A9ED3

@ -211,6 +211,7 @@ struct swapchain_data {
double frametimeDisplay;
const char* cpuString;
const char* gpuString;
std::string time;
enum overlay_param_enabled stat_selector;
double time_dividor;
@ -999,6 +1000,12 @@ static void snapshot_swapchain_frame(struct swapchain_data *data)
data->frametimeDisplay = data->frametime;
data->fps = fps;
std::time_t t = std::time(nullptr);
std::stringstream time;
time << std::put_time(std::localtime(&t), instance_data->params.time_format.c_str());
data->time = time.str();
if (instance_data->capture_started) {
if (!instance_data->first_line_printed) {
bool first_column = true;
@ -1114,12 +1121,7 @@ static void compute_swapchain_display(struct swapchain_data *data)
if (!instance_data->params.no_display){
ImGui::Begin("Main", &open, ImGuiWindowFlags_NoDecoration);
if (instance_data->params.enabled[OVERLAY_PARAM_ENABLED_time]){
std::time_t t = std::time(nullptr);
std::stringstream time;
time << std::put_time(std::localtime(&t), "%T");
ImGui::PushFont(data->font1);
ImGui::TextColored(ImVec4(1.0f, 1.0f, 1.0f, 1.00f), "%s", time.str().c_str());
ImGui::PopFont();
ImGui::TextColored(ImVec4(1.0f, 1.0f, 1.0f, 1.00f), "%s", data->time.c_str());
}
if (device_data->gpu_stats && instance_data->params.enabled[OVERLAY_PARAM_ENABLED_gpu_stats]){
ImGui::TextColored(ImVec4(0.180, 0.592, 0.384, 1.00f), "GPU");

@ -136,11 +136,18 @@ parse_unsigned(const char *str)
return strtol(str, NULL, 0);
}
static const char *
parse_str(const char *str)
{
return str;
}
#define parse_width(s) parse_unsigned(s)
#define parse_height(s) parse_unsigned(s)
#define parse_vsync(s) parse_unsigned(s)
#define parse_offset_x(s) parse_unsigned(s)
#define parse_offset_y(s) parse_unsigned(s)
#define parse_time_format(s) parse_str(s)
#define parse_crosshair_color(s) parse_color(s)
@ -259,7 +266,7 @@ parse_overlay_config(struct overlay_params *params,
const char *env)
{
memset(params, 0, sizeof(*params));
*params = {};
/* Visible by default */
params->enabled[OVERLAY_PARAM_ENABLED_fps] = true;
@ -285,6 +292,7 @@ parse_overlay_config(struct overlay_params *params,
params->offset_x = 0;
params->offset_y = 0;
params->background_alpha = 0.5;
params->time_format = "%T";
// first pass with env var
if (env)

@ -24,6 +24,8 @@
#ifndef OVERLAY_PARAMS_H
#define OVERLAY_PARAMS_H
#include <string>
#ifdef __cplusplus
extern "C" {
#endif
@ -68,6 +70,7 @@ extern "C" {
OVERLAY_PARAM_CUSTOM(offset_y) \
OVERLAY_PARAM_CUSTOM(crosshair_color) \
OVERLAY_PARAM_CUSTOM(background_alpha) \
OVERLAY_PARAM_CUSTOM(time_format) \
OVERLAY_PARAM_CUSTOM(help)
enum overlay_param_position {
@ -108,6 +111,7 @@ struct overlay_params {
KeySym toggle_hud;
KeySym toggle_logging;
KeySym refresh_config;
std::string time_format;
};
const extern char *overlay_param_names[];

Loading…
Cancel
Save