Calculate HighDPI scaling ourselves for UserInterface init.

This commit is contained in:
brunoherbelin
2020-05-11 12:53:54 +02:00
parent f00e26cfbf
commit 91020f5180
3 changed files with 9 additions and 4 deletions

View File

@@ -64,6 +64,7 @@ Rendering::Rendering()
{
main_window_ = nullptr;
request_screenshot_ = false;
dpi_scale_ = 1.f;
}
bool Rendering::Init()
@@ -128,6 +129,9 @@ bool Rendering::Init()
glViewport(0, 0, main_window_attributes_.viewport.x, main_window_attributes_.viewport.y);
main_window_attributes_.clear_color = glm::vec4(COLOR_BGROUND, 1.0);
// DPI scaling (retina)
dpi_scale_ = float(main_window_attributes_.viewport.y) / float(winset.h);
// Gstreamer link to context
g_setenv ("GST_GL_API", "opengl3", FALSE);
gst_init (NULL, NULL);

View File

@@ -24,6 +24,7 @@ class Rendering
// GLFW integration in OS window management
class GLFWwindow* main_window_;
std::string glsl_version;
float dpi_scale_;
// Private Constructor
Rendering();
@@ -86,6 +87,7 @@ public:
float MonitorWidth();
float MonitorHeight();
inline float DPIScale() const { return dpi_scale_; }
private:

View File

@@ -149,13 +149,12 @@ bool UserInterface::Init()
// Setup Platform/Renderer bindings
ImGui_ImplGlfw_InitForOpenGL(Rendering::manager().main_window_, true);
ImGui_ImplOpenGL3_Init(Rendering::manager().glsl_version.c_str());
ImGui_ImplGlfw_NewFrame();
// Setup Dear ImGui style
ImGuiToolkit::SetAccentColor(static_cast<ImGuiToolkit::accent_color>(Settings::application.accent_color));
// Load Fonts (using resource manager, NB: a temporary copy of the raw data is necessary)
float base_font_size = (Rendering::manager().MonitorHeight() * ImGui::GetIO().DisplayFramebufferScale.y) / 100.f ;
float base_font_size = (Rendering::manager().MonitorHeight() * Rendering::manager().DPIScale()) / 100.f ;
ImGuiToolkit::SetFont(ImGuiToolkit::FONT_DEFAULT, "Roboto-Regular", int(base_font_size) );
ImGuiToolkit::SetFont(ImGuiToolkit::FONT_BOLD, "Roboto-Bold", int(base_font_size) );
ImGuiToolkit::SetFont(ImGuiToolkit::FONT_ITALIC, "Roboto-Italic", int(base_font_size) );
@@ -165,8 +164,8 @@ bool UserInterface::Init()
// info
Log::Info("Monitor (%.1f,%.1f)", Rendering::manager().MonitorWidth(), Rendering::manager().MonitorHeight());
Log::Info("DPI Scale (%.1f,%.1f)", ImGui::GetIO().DisplayFramebufferScale.x, ImGui::GetIO().DisplayFramebufferScale.y);
Log::Info("Font size %d", base_font_size);
Log::Info("DPI Scale %.1f", Rendering::manager().DPIScale());
Log::Info("Font size %.1f", base_font_size);
// Style
ImGuiStyle& style = ImGui::GetStyle();