Merge pull request #358 from gort818/load_color

Change color depending on load
remotes/origin/pr/380
flightlessmango 4 years ago committed by GitHub
commit e3354433ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -57,7 +57,13 @@ struct swapchain_stats {
background,
text,
media_player,
wine;
wine,
gpu_load_high,
gpu_load_med,
gpu_load_low,
cpu_load_high,
cpu_load_med,
cpu_load_low;
} colors;
};

@ -152,6 +152,33 @@ parse_color(const char *str)
return strtol(str, NULL, 16);
}
static std::vector<unsigned>
parse_load_color(const char *str)
{
std::vector<unsigned> load_colors;
std::stringstream ss(str);
std::string token;
while (std::getline(ss, token, ',')) {
trim(token);
load_colors.push_back(std::stoi(token, NULL, 16));
}
return load_colors;
}
static std::vector<unsigned>
parse_load_value(const char *str)
{
std::vector<unsigned> load_value;
std::stringstream ss(str);
std::string token;
while (std::getline(ss, token, ',')) {
trim(token);
load_value.push_back(std::stoi(token));
}
return load_value;
}
static unsigned
parse_unsigned(const char *str)
{
@ -324,6 +351,10 @@ parse_font_glyph_ranges(const char *str)
#define parse_text_color(s) parse_color(s)
#define parse_media_player_color(s) parse_color(s)
#define parse_wine_color(s) parse_color(s)
#define parse_gpu_load_color(s) parse_load_color(s)
#define parse_cpu_load_color(s) parse_load_color(s)
#define parse_gpu_load_value(s) parse_load_value(s)
#define parse_cpu_load_value(s) parse_load_value(s)
static bool
parse_help(const char *str)
@ -415,6 +446,8 @@ parse_overlay_env(struct overlay_params *params,
#undef OVERLAY_PARAM_BOOL
#undef OVERLAY_PARAM_CUSTOM
params->enabled[OVERLAY_PARAM_ENABLED_histogram] = 0;
params->enabled[OVERLAY_PARAM_ENABLED_gpu_load_change] = 0;
params->enabled[OVERLAY_PARAM_ENABLED_cpu_load_change] = 0;
params->enabled[OVERLAY_PARAM_ENABLED_read_cfg] = read_cfg;
}
#define OVERLAY_PARAM_BOOL(name) \
@ -456,6 +489,8 @@ parse_overlay_config(struct overlay_params *params,
params->enabled[OVERLAY_PARAM_ENABLED_io_read] = false;
params->enabled[OVERLAY_PARAM_ENABLED_io_write] = false;
params->enabled[OVERLAY_PARAM_ENABLED_wine] = false;
params->enabled[OVERLAY_PARAM_ENABLED_gpu_load_change] = false;
params->enabled[OVERLAY_PARAM_ENABLED_cpu_load_change] = false;
params->fps_sampling_period = 500000; /* 500ms */
params->width = 0;
params->height = 140;
@ -481,12 +516,18 @@ parse_overlay_config(struct overlay_params *params,
params->media_player_name = "";
params->font_scale = 1.0f;
params->wine_color = 0xeb5b5b;
params->gpu_load_color = { 0xb22222, 0xfdfd09, 0x39f900 };
params->cpu_load_color = { 0xb22222, 0xfdfd09, 0x39f900 };
params->font_scale_media_player = 0.55f;
params->log_interval = 100;
params->media_player_order = { MP_ORDER_TITLE, MP_ORDER_ARTIST, MP_ORDER_ALBUM };
params->permit_upload = 0;
params->render_mango = 0;
params->benchmark_percentiles = { "97", "AVG", "1", "0.1" };
params->gpu_load_value = { 90, 60 };
params->cpu_load_value = { 90, 60 };
#ifdef HAVE_X11
params->toggle_hud = { XK_Shift_R, XK_F12 };
@ -562,7 +603,7 @@ parse_overlay_config(struct overlay_params *params,
params->font_scale_media_player = 0.55f;
// Convert from 0xRRGGBB to ImGui's format
std::array<unsigned *, 11> colors = {
std::array<unsigned *, 17> colors = {
&params->cpu_color,
&params->gpu_color,
&params->vram_color,
@ -574,6 +615,13 @@ parse_overlay_config(struct overlay_params *params,
&params->text_color,
&params->media_player_color,
&params->wine_color,
&params->gpu_load_color[0],
&params->gpu_load_color[1],
&params->gpu_load_color[2],
&params->cpu_load_color[0],
&params->cpu_load_color[1],
&params->cpu_load_color[2],
};
for (auto color : colors){

@ -50,6 +50,8 @@ typedef unsigned long KeySym;
OVERLAY_PARAM_BOOL(engine_version) \
OVERLAY_PARAM_BOOL(histogram) \
OVERLAY_PARAM_BOOL(wine) \
OVERLAY_PARAM_BOOL(gpu_load_change) \
OVERLAY_PARAM_BOOL(cpu_load_change) \
OVERLAY_PARAM_CUSTOM(fps_sampling_period) \
OVERLAY_PARAM_CUSTOM(output_folder) \
OVERLAY_PARAM_CUSTOM(output_file) \
@ -102,7 +104,12 @@ typedef unsigned long KeySym;
OVERLAY_PARAM_CUSTOM(permit_upload) \
OVERLAY_PARAM_CUSTOM(render_mango) \
OVERLAY_PARAM_CUSTOM(benchmark_percentiles) \
OVERLAY_PARAM_CUSTOM(help)
OVERLAY_PARAM_CUSTOM(help) \
OVERLAY_PARAM_CUSTOM(gpu_load_value) \
OVERLAY_PARAM_CUSTOM(cpu_load_value) \
OVERLAY_PARAM_CUSTOM(gpu_load_color) \
OVERLAY_PARAM_CUSTOM(cpu_load_color)
enum overlay_param_position {
LAYER_POSITION_TOP_LEFT,
@ -161,6 +168,10 @@ struct overlay_params {
int gl_vsync;
uint64_t log_duration;
unsigned cpu_color, gpu_color, vram_color, ram_color, engine_color, io_color, frametime_color, background_color, text_color, wine_color;
std::vector<unsigned> gpu_load_color;
std::vector<unsigned> cpu_load_color;
std::vector<unsigned> gpu_load_value;
std::vector<unsigned> cpu_load_value;
unsigned media_player_color;
unsigned tableCols;
unsigned render_mango;
@ -181,7 +192,6 @@ struct overlay_params {
unsigned log_interval;
std::vector<media_player_order> media_player_order;
std::vector<std::string> benchmark_percentiles;
std::string font_file, font_file_text;
uint32_t font_glyph_ranges;

@ -740,7 +740,7 @@ void position_layer(struct swapchain_stats& data, struct overlay_params& params,
}
}
static void right_aligned_text(float off_x, const char *fmt, ...)
static void right_aligned_text(ImVec4& col, float off_x, const char *fmt, ...)
{
ImVec2 pos = ImGui::GetCursorPos();
char buffer[32] {};
@ -752,7 +752,8 @@ static void right_aligned_text(float off_x, const char *fmt, ...)
ImVec2 sz = ImGui::CalcTextSize(buffer);
ImGui::SetCursorPosX(pos.x + off_x - sz.x);
ImGui::Text("%s", buffer);
//ImGui::Text("%s", buffer);
ImGui::TextColored(col,"%s",buffer);
}
float get_ticker_limited_pos(float pos, float tw, float& left_limit, float& right_limit)
@ -934,7 +935,7 @@ void render_mango(swapchain_stats& data, struct overlay_params& params, ImVec2&
gpu_text = params.gpu_text.c_str();
ImGui::TextColored(data.colors.gpu, "%s", gpu_text);
ImGui::TableNextCell();
right_aligned_text(ralign_width, "%i", gpu_info.load);
right_aligned_text(data.colors.text, ralign_width, "%i", gpu_info.load);
ImGui::SameLine(0, 1.0f);
ImGui::Text("%%");
}
@ -947,7 +948,7 @@ void render_mango(swapchain_stats& data, struct overlay_params& params, ImVec2&
cpu_text = params.cpu_text.c_str();
ImGui::TextColored(data.colors.cpu, "%s", cpu_text);
ImGui::TableNextCell();
right_aligned_text(ralign_width, "%d", int(cpuStats.GetCPUDataTotal().percent));
right_aligned_text(data.colors.text, ralign_width, "%d", int(cpuStats.GetCPUDataTotal().percent));
ImGui::SameLine(0, 1.0f);
ImGui::Text("%%");
}
@ -955,7 +956,7 @@ void render_mango(swapchain_stats& data, struct overlay_params& params, ImVec2&
ImGui::TableNextRow();
ImGui::TextColored(data.colors.engine, "%s", is_vulkan ? data.engineName.c_str() : "OpenGL");
ImGui::TableNextCell();
right_aligned_text(ralign_width, "%.0f", data.fps);
right_aligned_text(data.colors.text, ralign_width, "%.0f", data.fps);
ImGui::SameLine(0, 1.0f);
ImGui::PushFont(data.font1);
ImGui::Text("FPS");
@ -989,6 +990,19 @@ void render_mango(swapchain_stats& data, struct overlay_params& params, ImVec2&
window_size = ImVec2(window_size.x, 200);
}
int change_on_load_temp (int info, int high, int med) {
if (info >= high) {
return 1;
}
else if (info >= med && info < high) {
return 2;
}
else {
return 3;
}
}
void render_imgui(swapchain_stats& data, struct overlay_params& params, ImVec2& window_size, bool is_vulkan)
{
ImGui::GetIO().FontGlobalScale = params.font_scale;
@ -1025,14 +1039,36 @@ void render_imgui(swapchain_stats& data, struct overlay_params& params, ImVec2&
gpu_text = params.gpu_text.c_str();
ImGui::TextColored(data.colors.gpu, "%s", gpu_text);
ImGui::TableNextCell();
right_aligned_text(ralign_width, "%i", gpu_info.load);
ImGui::SameLine(0, 1.0f);
ImGui::Text("%%");
// ImGui::SameLine(150);
// ImGui::Text("%s", "%");
auto text_color = data.colors.text;
if (params.enabled[OVERLAY_PARAM_ENABLED_gpu_load_change]){
auto load_color = data.colors.text;
int gpu_load = change_on_load_temp(gpu_info.load, params.gpu_load_value[0], params.gpu_load_value[1]);
// 1 is high, 2 is medium, and 3 is low load/temp
switch (gpu_load) {
case 1:
load_color = data.colors.gpu_load_high;
break;
case 2:
load_color = data.colors.gpu_load_med;
break;
case 3:
load_color = data.colors.gpu_load_low;
break;
}
right_aligned_text(load_color, ralign_width, "%i", gpu_info.load);
ImGui::SameLine(0, 1.0f);
ImGui::TextColored(load_color,"%%");
}
else {
right_aligned_text(text_color, ralign_width, "%i", gpu_info.load);
ImGui::SameLine(0, 1.0f);
ImGui::TextColored(text_color,"%%");
// ImGui::SameLine(150);
// ImGui::Text("%s", "%");
}
if (params.enabled[OVERLAY_PARAM_ENABLED_gpu_temp]){
ImGui::TableNextCell();
right_aligned_text(ralign_width, "%i", gpu_info.temp);
right_aligned_text(text_color, ralign_width, "%i", gpu_info.temp);
ImGui::SameLine(0, 1.0f);
ImGui::Text("°C");
}
@ -1040,7 +1076,7 @@ void render_imgui(swapchain_stats& data, struct overlay_params& params, ImVec2&
ImGui::TableNextRow();
if (params.enabled[OVERLAY_PARAM_ENABLED_gpu_core_clock]){
ImGui::TableNextCell();
right_aligned_text(ralign_width, "%i", gpu_info.CoreClock);
right_aligned_text(text_color, ralign_width, "%i", gpu_info.CoreClock);
ImGui::SameLine(0, 1.0f);
ImGui::PushFont(data.font1);
ImGui::Text("MHz");
@ -1048,7 +1084,7 @@ void render_imgui(swapchain_stats& data, struct overlay_params& params, ImVec2&
}
if (params.enabled[OVERLAY_PARAM_ENABLED_gpu_power]) {
ImGui::TableNextCell();
right_aligned_text(ralign_width, "%i", gpu_info.powerUsage);
right_aligned_text(text_color, ralign_width, "%i", gpu_info.powerUsage);
ImGui::SameLine(0, 1.0f);
ImGui::PushFont(data.font1);
ImGui::Text("W");
@ -1064,15 +1100,38 @@ void render_imgui(swapchain_stats& data, struct overlay_params& params, ImVec2&
cpu_text = params.cpu_text.c_str();
ImGui::TextColored(data.colors.cpu, "%s", cpu_text);
ImGui::TableNextCell();
right_aligned_text(ralign_width, "%d", int(cpuStats.GetCPUDataTotal().percent));
ImGui::SameLine(0, 1.0f);
ImGui::Text("%%");
auto text_color = data.colors.text;
if (params.enabled[OVERLAY_PARAM_ENABLED_cpu_load_change]){
int cpu_load_percent = int(cpuStats.GetCPUDataTotal().percent);
auto load_color = data.colors.text;
int cpu_load = change_on_load_temp(cpu_load_percent, params.cpu_load_value[0], params.cpu_load_value[1]);
// 1 is high, 2 is medium, and 3 is low load/temp
switch (cpu_load) {
case 1:
load_color = data.colors.cpu_load_high;
break;
case 2:
load_color = data.colors.cpu_load_med;
break;
case 3:
load_color = data.colors.cpu_load_low;
break;
}
right_aligned_text(load_color, ralign_width, "%d", cpu_load_percent);
ImGui::SameLine(0, 1.0f);
ImGui::TextColored(load_color, "%%");
}
else {
right_aligned_text(text_color, ralign_width, "%d", int(cpuStats.GetCPUDataTotal().percent));
ImGui::SameLine(0, 1.0f);
ImGui::Text("%%");
}
// ImGui::SameLine(150);
// ImGui::Text("%s", "%");
if (params.enabled[OVERLAY_PARAM_ENABLED_cpu_temp]){
ImGui::TableNextCell();
right_aligned_text(ralign_width, "%i", cpuStats.GetCPUDataTotal().temp);
right_aligned_text(data.colors.text, ralign_width, "%i", cpuStats.GetCPUDataTotal().temp);
ImGui::SameLine(0, 1.0f);
ImGui::Text("°C");
}
@ -1089,11 +1148,11 @@ void render_imgui(swapchain_stats& data, struct overlay_params& params, ImVec2&
ImGui::TextColored(data.colors.cpu,"%i", i);
ImGui::PopFont();
ImGui::TableNextCell();
right_aligned_text(ralign_width, "%i", int(cpuData.percent));
right_aligned_text(data.colors.text, ralign_width, "%i", int(cpuData.percent));
ImGui::SameLine(0, 1.0f);
ImGui::Text("%%");
ImGui::TableNextCell();
right_aligned_text(ralign_width, "%i", cpuData.mhz);
right_aligned_text(data.colors.text, ralign_width, "%i", cpuData.mhz);
ImGui::SameLine(0, 1.0f);
ImGui::PushFont(data.font1);
ImGui::Text("MHz");
@ -1114,7 +1173,7 @@ void render_imgui(swapchain_stats& data, struct overlay_params& params, ImVec2&
if (params.enabled[OVERLAY_PARAM_ENABLED_io_read]){
ImGui::TableNextCell();
float val = data.io.diff.read * 1000000 / sampling;
right_aligned_text(ralign_width, val < 100 ? "%.1f" : "%.f", val);
right_aligned_text(data.colors.text, ralign_width, val < 100 ? "%.1f" : "%.f", val);
ImGui::SameLine(0,1.0f);
ImGui::PushFont(data.font1);
ImGui::Text("MiB/s");
@ -1123,7 +1182,7 @@ void render_imgui(swapchain_stats& data, struct overlay_params& params, ImVec2&
if (params.enabled[OVERLAY_PARAM_ENABLED_io_write]){
ImGui::TableNextCell();
float val = data.io.diff.write * 1000000 / sampling;
right_aligned_text(ralign_width, val < 100 ? "%.1f" : "%.f", val);
right_aligned_text(data.colors.text, ralign_width, val < 100 ? "%.1f" : "%.f", val);
ImGui::SameLine(0,1.0f);
ImGui::PushFont(data.font1);
ImGui::Text("MiB/s");
@ -1134,14 +1193,14 @@ void render_imgui(swapchain_stats& data, struct overlay_params& params, ImVec2&
ImGui::TableNextRow();
ImGui::TextColored(data.colors.vram, "VRAM");
ImGui::TableNextCell();
right_aligned_text(ralign_width, "%.1f", gpu_info.memoryUsed);
right_aligned_text(data.colors.text, ralign_width, "%.1f", gpu_info.memoryUsed);
ImGui::SameLine(0,1.0f);
ImGui::PushFont(data.font1);
ImGui::Text("GiB");
ImGui::PopFont();
if (params.enabled[OVERLAY_PARAM_ENABLED_gpu_mem_clock]){
ImGui::TableNextCell();
right_aligned_text(ralign_width, "%i", gpu_info.MemClock);
right_aligned_text(data.colors.text, ralign_width, "%i", gpu_info.MemClock);
ImGui::SameLine(0, 1.0f);
ImGui::PushFont(data.font1);
ImGui::Text("MHz");
@ -1153,7 +1212,7 @@ void render_imgui(swapchain_stats& data, struct overlay_params& params, ImVec2&
ImGui::TableNextRow();
ImGui::TextColored(data.colors.ram, "RAM");
ImGui::TableNextCell();
right_aligned_text(ralign_width, "%.1f", memused);
right_aligned_text(data.colors.text, ralign_width, "%.1f", memused);
ImGui::SameLine(0,1.0f);
ImGui::PushFont(data.font1);
ImGui::Text("GiB");
@ -1164,13 +1223,13 @@ void render_imgui(swapchain_stats& data, struct overlay_params& params, ImVec2&
ImGui::TableNextRow();
ImGui::TextColored(data.colors.engine, "%s", is_vulkan ? data.engineName.c_str() : "OpenGL");
ImGui::TableNextCell();
right_aligned_text(ralign_width, "%.0f", data.fps);
right_aligned_text(data.colors.text, ralign_width, "%.0f", data.fps);
ImGui::SameLine(0, 1.0f);
ImGui::PushFont(data.font1);
ImGui::Text("FPS");
ImGui::PopFont();
ImGui::TableNextCell();
right_aligned_text(ralign_width, "%.1f", 1000 / data.fps);
right_aligned_text(data.colors.text, ralign_width, "%.1f", 1000 / data.fps);
ImGui::SameLine(0, 1.0f);
ImGui::PushFont(data.font1);
ImGui::Text("ms");
@ -2095,6 +2154,14 @@ void convert_colors(bool do_conv, struct swapchain_stats& sw_stats, struct overl
sw_stats.colors.text = convert(params.text_color);
sw_stats.colors.media_player = convert(params.media_player_color);
sw_stats.colors.wine = convert(params.wine_color);
sw_stats.colors.gpu_load_high = convert(params.gpu_load_color[0]);
sw_stats.colors.gpu_load_med = convert(params.gpu_load_color[1]);
sw_stats.colors.gpu_load_low = convert(params.gpu_load_color[2]);
sw_stats.colors.cpu_load_high = convert(params.cpu_load_color[0]);
sw_stats.colors.cpu_load_med = convert(params.cpu_load_color[1]);
sw_stats.colors.cpu_load_low = convert(params.cpu_load_color[2]);
ImGuiStyle& style = ImGui::GetStyle();
style.Colors[ImGuiCol_PlotLines] = convert(params.frametime_color);

Loading…
Cancel
Save