mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-14 11:49:59 +01:00
Fixed resolution issue with different monitor DPI.
This commit is contained in:
@@ -503,6 +503,8 @@ GLFWmonitor *RenderingWindow::monitor()
|
|||||||
int x, y;
|
int x, y;
|
||||||
glfwGetWindowPos(window_, &x, &y);
|
glfwGetWindowPos(window_, &x, &y);
|
||||||
|
|
||||||
|
Log::Info("testing window monitor at %d %d", x, y );
|
||||||
|
|
||||||
return monitorAt(x, y);
|
return monitorAt(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -554,9 +556,18 @@ int RenderingWindow::height()
|
|||||||
return window_attributes_.viewport.y;
|
return window_attributes_.viewport.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
int RenderingWindow::maxHeight()
|
int RenderingWindow::pixelsforRealHeight(float milimeters)
|
||||||
{
|
{
|
||||||
return static_cast<int>( static_cast<float>(glfwGetVideoMode(monitor())->height) * dpi_scale_);
|
GLFWmonitor *mo = monitor();
|
||||||
|
|
||||||
|
int mm_w = 0;
|
||||||
|
int mm_h = 0;
|
||||||
|
glfwGetMonitorPhysicalSize(mo, &mm_w, &mm_h);
|
||||||
|
|
||||||
|
float pixels = milimeters * static_cast<float>(glfwGetVideoMode(mo)->height) / static_cast<float>(mm_h);
|
||||||
|
pixels *= dpi_scale_;
|
||||||
|
|
||||||
|
return static_cast<int>( pixels );
|
||||||
}
|
}
|
||||||
|
|
||||||
float RenderingWindow::aspectRatio()
|
float RenderingWindow::aspectRatio()
|
||||||
@@ -583,10 +594,14 @@ bool RenderingWindow::init(int id, GLFWwindow *share)
|
|||||||
Log::Error("Failed to create GLFW Window %d", id_);
|
Log::Error("Failed to create GLFW Window %d", id_);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Log::Info("Window size %d %d", winset.w, winset.h);
|
||||||
|
|
||||||
|
|
||||||
// set position
|
// set position
|
||||||
glfwSetWindowPos(window_, winset.x, winset.y);
|
glfwSetWindowPos(window_, winset.x, winset.y);
|
||||||
|
|
||||||
|
Log::Info("Window position %d %d", winset.x, winset.y);
|
||||||
|
|
||||||
/// CALLBACKS
|
/// CALLBACKS
|
||||||
// store global ref to pointers (used by callbacks)
|
// store global ref to pointers (used by callbacks)
|
||||||
GLFW_window_[window_] = this;
|
GLFW_window_[window_] = this;
|
||||||
@@ -616,6 +631,8 @@ bool RenderingWindow::init(int id, GLFWwindow *share)
|
|||||||
// DPI scaling (retina)
|
// DPI scaling (retina)
|
||||||
dpi_scale_ = float(window_attributes_.viewport.y) / float(winset.h);
|
dpi_scale_ = float(window_attributes_.viewport.y) / float(winset.h);
|
||||||
|
|
||||||
|
Log::Info("Window Frame Buffer sixe %d %d", window_attributes_.viewport.x, window_attributes_.viewport.y);
|
||||||
|
|
||||||
// This hint can improve the speed of texturing when perspective-correct texture coordinate interpolation isn't needed
|
// This hint can improve the speed of texturing when perspective-correct texture coordinate interpolation isn't needed
|
||||||
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
|
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -67,8 +67,8 @@ public:
|
|||||||
int height();
|
int height();
|
||||||
// get aspect ratio of rendering area
|
// get aspect ratio of rendering area
|
||||||
float aspectRatio();
|
float aspectRatio();
|
||||||
// get total height available in monitor
|
// get number of pixels to render X milimeters in height
|
||||||
int maxHeight();
|
int pixelsforRealHeight(float milimeters);
|
||||||
|
|
||||||
inline float dpiScale() const { return dpi_scale_; }
|
inline float dpiScale() const { return dpi_scale_; }
|
||||||
|
|
||||||
|
|||||||
@@ -178,7 +178,7 @@ bool UserInterface::Init()
|
|||||||
ImGuiToolkit::SetAccentColor(static_cast<ImGuiToolkit::accent_color>(Settings::application.accent_color));
|
ImGuiToolkit::SetAccentColor(static_cast<ImGuiToolkit::accent_color>(Settings::application.accent_color));
|
||||||
|
|
||||||
// Estalish the base size from the resolution of the monitor
|
// Estalish the base size from the resolution of the monitor
|
||||||
float base_font_size = float(Rendering::manager().mainWindow().maxHeight()) / 100.f ;
|
float base_font_size = float(Rendering::manager().mainWindow().pixelsforRealHeight(4.f)) ;
|
||||||
// Load Fonts (using resource manager, NB: a temporary copy of the raw data is necessary)
|
// Load Fonts (using resource manager, NB: a temporary copy of the raw data is necessary)
|
||||||
ImGuiToolkit::SetFont(ImGuiToolkit::FONT_DEFAULT, "Roboto-Regular", int(base_font_size) );
|
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_BOLD, "Roboto-Bold", int(base_font_size) );
|
||||||
@@ -2336,15 +2336,20 @@ void Navigator::RenderMainPannel()
|
|||||||
if (b || o || g)
|
if (b || o || g)
|
||||||
ImGuiToolkit::SetAccentColor(static_cast<ImGuiToolkit::accent_color>(Settings::application.accent_color));
|
ImGuiToolkit::SetAccentColor(static_cast<ImGuiToolkit::accent_color>(Settings::application.accent_color));
|
||||||
|
|
||||||
// Bottom aligned Logo & About
|
|
||||||
static unsigned int vimixicon = Resource::getTextureImage("images/vimix_256x256.png");
|
static unsigned int vimixicon = Resource::getTextureImage("images/vimix_256x256.png");
|
||||||
static float h = 4.f * ImGui::GetTextLineHeightWithSpacing();
|
static float height_about = 3.f * ImGui::GetTextLineHeightWithSpacing();
|
||||||
if ( ImGui::GetCursorPosY() + h + 128.f < height_ ) {
|
bool show_icon = ImGui::GetCursorPosY() + height_about + 128.f < height_ ;
|
||||||
ImGui::SetCursorPos(ImVec2(pannel_width_ / 2.f - 64.f, height_ -h - 128.f));
|
bool show_about = ImGui::GetCursorPosY() + height_about < height_ ;
|
||||||
|
|
||||||
|
// Bottom aligned About buttons
|
||||||
|
if ( show_about) {
|
||||||
|
// Bottom aligned Logo
|
||||||
|
if ( show_icon ) {
|
||||||
|
ImGui::SetCursorPos(ImVec2(pannel_width_ / 2.f - 64.f, height_ -height_about - 128.f));
|
||||||
ImGui::Image((void*)(intptr_t)vimixicon, ImVec2(128, 128));
|
ImGui::Image((void*)(intptr_t)vimixicon, ImVec2(128, 128));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ImGui::SetCursorPosY(height_ -h);
|
ImGui::SetCursorPosY(height_ -height_about);
|
||||||
}
|
}
|
||||||
ImGui::Spacing();
|
ImGui::Spacing();
|
||||||
if ( ImGui::Button( ICON_FA_CROW " vimix", ImVec2(ImGui::GetContentRegionAvail().x, 0)) )
|
if ( ImGui::Button( ICON_FA_CROW " vimix", ImVec2(ImGui::GetContentRegionAvail().x, 0)) )
|
||||||
@@ -2357,6 +2362,7 @@ void Navigator::RenderMainPannel()
|
|||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
if ( ImGui::Button("OpenGL", ImVec2(ImGui::GetContentRegionAvail().x, 0)))
|
if ( ImGui::Button("OpenGL", ImVec2(ImGui::GetContentRegionAvail().x, 0)))
|
||||||
UserInterface::manager().show_opengl_about = true;
|
UserInterface::manager().show_opengl_about = true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|||||||
Reference in New Issue
Block a user