1
0
mirror of synced 2024-11-12 10:10:53 +01:00

sys: Fixed hidpi framebuffer scaling

Actually fixes #598
This commit is contained in:
WerWolv 2022-07-29 17:37:30 +02:00
parent 19222aefcc
commit 6f3a5e896c
5 changed files with 28 additions and 12 deletions

View File

@ -155,6 +155,7 @@ namespace hex {
void setMainDockSpaceId(ImGuiID id);
void setGlobalScale(float scale);
void setNativeScale(float scale);
void setProgramArguments(int argc, char **argv, char **envp);
@ -184,6 +185,7 @@ namespace hex {
void setTargetFPS(float fps);
float getGlobalScale();
float getNativeScale();
ImVec2 getMainWindowPosition();
ImVec2 getMainWindowSize();

View File

@ -314,6 +314,11 @@ namespace hex {
s_globalScale = scale;
}
static float s_nativeScale = 1.0;
void setNativeScale(float scale) {
s_nativeScale = scale;
}
static ProgramArguments s_programArguments;
void setProgramArguments(int argc, char **argv, char **envp) {
@ -364,6 +369,10 @@ namespace hex {
return impl::s_globalScale;
}
float getNativeScale() {
return impl::s_nativeScale;
}
ImVec2 getMainWindowPosition() {
return impl::s_mainWindowPos;

View File

@ -167,9 +167,16 @@ namespace hex::init {
glfwWindowHint(GLFW_DECORATED, GLFW_FALSE);
glfwWindowHint(GLFW_FLOATING, GLFW_FALSE);
if (GLFWmonitor *monitor = glfwGetPrimaryMonitor(); monitor != nullptr) {
this->m_window = glfwCreateWindow(1, 400, "Starting ImHex...", nullptr, nullptr);
if (this->m_window == nullptr) {
log::fatal("Failed to create GLFW window!");
exit(EXIT_FAILURE);
}
// Calculate native scale factor for hidpi displays
{
float xScale = 0, yScale = 0;
glfwGetMonitorContentScale(monitor, &xScale, &yScale);
glfwGetWindowContentScale(this->m_window, &xScale, &yScale);
auto meanScale = std::midpoint(xScale, yScale);
@ -185,16 +192,12 @@ namespace hex::init {
}
ImHexApi::System::impl::setGlobalScale(meanScale);
} else {
ImHexApi::System::impl::setGlobalScale(1.0);
}
this->m_window = glfwCreateWindow(640_scaled, 400_scaled, "Starting ImHex...", nullptr, nullptr);
if (this->m_window == nullptr) {
log::fatal("Failed to create GLFW window!");
exit(EXIT_FAILURE);
ImHexApi::System::impl::setNativeScale(meanScale);
log::info("Native scaling set to: {}", meanScale);
}
glfwSetWindowSize(this->m_window, 640_scaled, 400_scaled);
centerWindow(this->m_window);
glfwMakeContextCurrent(this->m_window);

View File

@ -697,7 +697,9 @@ namespace hex {
io.UserData = new ImGui::ImHexCustomData();
style.ScaleAllSizes(ImHexApi::System::getGlobalScale());
auto scale = ImHexApi::System::getGlobalScale();
style.ScaleAllSizes(scale);
io.DisplayFramebufferScale = ImVec2(scale, scale);
{
GLsizei width, height;

View File

@ -427,7 +427,7 @@ namespace hex::plugin::builtin {
switch (ContentRegistry::Settings::read("hex.builtin.setting.interface", "hex.builtin.setting.interface.scaling", 0)) {
default:
case 0:
// Native scaling
interfaceScaling = ImHexApi::System::getNativeScale();
break;
case 1:
interfaceScaling = 0.5F;