From 6ad6bffadee64e26d18dcdaaddebc8c6fceecaab Mon Sep 17 00:00:00 2001 From: jackun Date: Tue, 17 Mar 2020 15:00:20 +0200 Subject: [PATCH] Use ImGui's DisplaySize so display size for layer positioning etc can be set the same way for vulkan and OpenGL --- src/gl/inject.cpp | 4 ++-- src/overlay.cpp | 12 ++++++++---- src/overlay.h | 4 ++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/gl/inject.cpp b/src/gl/inject.cpp index 50b6c8d5..3d421015 100644 --- a/src/gl/inject.cpp +++ b/src/gl/inject.cpp @@ -166,8 +166,8 @@ void imgui_render() ImGui::NewFrame(); { std::lock_guard lk(notifier.mutex); - position_layer(params, window_size, vp[2], vp[3]); - render_imgui(sw_stats, params, window_size, vp[2], vp[3], false); + position_layer(params, window_size); + render_imgui(sw_stats, params, window_size, false); } ImGui::PopStyleVar(3); diff --git a/src/overlay.cpp b/src/overlay.cpp index a64d1615..b5fb85a5 100644 --- a/src/overlay.cpp +++ b/src/overlay.cpp @@ -1010,8 +1010,10 @@ static float get_time_stat(void *_data, int _idx) return data->frames_stats[idx].stats[data->stat_selector] / data->time_dividor; } -void position_layer(struct overlay_params& params, ImVec2 window_size, unsigned width, unsigned height) +void position_layer(struct overlay_params& params, ImVec2 window_size) { + unsigned width = ImGui::GetIO().DisplaySize.x; + unsigned height = ImGui::GetIO().DisplaySize.y; float margin = 10.0f; if (params.offset_x > 0 || params.offset_y > 0) margin = 0.0f; @@ -1057,10 +1059,12 @@ static void right_aligned_text(float off_x, const char *fmt, ...) ImGui::Text("%s", buffer); } -void render_imgui(swapchain_stats& data, struct overlay_params& params, ImVec2& window_size, unsigned width, unsigned height, bool is_vulkan) +void render_imgui(swapchain_stats& data, struct overlay_params& params, ImVec2& window_size, bool is_vulkan) { static float char_width = ImGui::CalcTextSize("A").x; window_size = ImVec2(params.width, params.height); + unsigned width = ImGui::GetIO().DisplaySize.x; + unsigned height = ImGui::GetIO().DisplaySize.y; if (!params.no_display){ ImGui::Begin("Main", &open, ImGuiWindowFlags_NoDecoration); @@ -1316,8 +1320,8 @@ static void compute_swapchain_display(struct swapchain_data *data) ImGui::NewFrame(); { scoped_lock lk(instance_data->notifier.mutex); - position_layer(instance_data->params, data->window_size, data->width, data->height); - render_imgui(data->sw_stats, instance_data->params, data->window_size, data->width, data->height, true); + position_layer(instance_data->params, data->window_size); + render_imgui(data->sw_stats, instance_data->params, data->window_size, true); } ImGui::PopStyleVar(3); diff --git a/src/overlay.h b/src/overlay.h index e22ca69f..418c2848 100644 --- a/src/overlay.h +++ b/src/overlay.h @@ -45,8 +45,8 @@ struct fps_limit { extern struct fps_limit fps_limit_stats; -void position_layer(struct overlay_params& params, ImVec2 window_size, unsigned width, unsigned height); -void render_imgui(swapchain_stats& data, struct overlay_params& params, ImVec2& window_size, unsigned width, unsigned height, bool is_vulkan); +void position_layer(struct overlay_params& params, ImVec2 window_size); +void render_imgui(swapchain_stats& data, struct overlay_params& params, ImVec2& window_size, bool is_vulkan); void update_hud_info(struct swapchain_stats& sw_stats, struct overlay_params& params, uint32_t vendorID); void init_gpu_stats(uint32_t& vendorID, overlay_params& params); void init_cpu_stats(overlay_params& params);