Skip to content

Commit

Permalink
Rename BackendWindowHelper::GetDisplayFramebufferScale
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed Apr 10, 2024
1 parent a67e9f3 commit 72d8c68
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 10 deletions.
5 changes: 4 additions & 1 deletion src/hello_imgui/dpi_aware.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ struct DpiAwareParams
// factor by which font size should be multiplied at loading time to get a similar
// visible size on different OSes.
// The size will be equivalent to a size given for a 96 PPI screen
float DpiFontLoadingFactor() { return dpiWindowSizeFactor / fontRenderingScale;};
float DpiFontLoadingFactor() {
float r = dpiWindowSizeFactor / fontRenderingScale;
return r;
};
};

// ----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/hello_imgui/internal/backend_impls/abstract_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ void AbstractRunner::SetupDpiAwareParams()
}

ImGui::GetIO().FontGlobalScale = params.dpiAwareParams.fontRenderingScale;
ImGui::GetIO().DisplayFramebufferScale = mBackendWindowHelper->GetWindowScaleFactor(mWindow);
ImGui::GetIO().DisplayFramebufferScale = mBackendWindowHelper->GetDisplayFramebufferScale(mWindow);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace HelloImGui { namespace BackendApi
virtual void WaitForEventTimeout(double timeout_seconds) = 0;

// Return the ratio FrameBufferSize / WindowSize
virtual ImVec2 GetWindowScaleFactor(WindowPointer window) = 0;
virtual ImVec2 GetDisplayFramebufferScale(WindowPointer window) = 0;

// Return the ratio by which the window size should be scaled to account for HighDPI
// (i.e. the same size given at creation create the same physical size in mm on the screen)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ namespace HelloImGui { namespace BackendApi
glfwWaitEventsTimeout(timeout_seconds);
}

ImVec2 GlfwWindowHelper::GetWindowScaleFactor(HelloImGui::BackendApi::WindowPointer window)
ImVec2 GlfwWindowHelper::GetDisplayFramebufferScale(HelloImGui::BackendApi::WindowPointer window)
{
float x_scale, y_scale;
glfwGetWindowContentScale((GLFWwindow *) window, &x_scale, &y_scale);
Expand All @@ -201,7 +201,7 @@ namespace HelloImGui { namespace BackendApi
#ifdef __APPLE__
return 1.f;
#else
ImVec2 scale = GetWindowScaleFactor(window);
ImVec2 scale = GetDisplayFramebufferScale(window);
return scale.x;
#endif
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace HelloImGui { namespace BackendApi

void WaitForEventTimeout(double timeout_seconds) override;

ImVec2 GetWindowScaleFactor(WindowPointer window) override;
ImVec2 GetDisplayFramebufferScale(WindowPointer window) override;
float GetWindowSizeDpiScaleFactor(WindowPointer window) override;

void HideWindow(WindowPointer window) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace HelloImGui { namespace BackendApi
std::this_thread::sleep_for(std::chrono::milliseconds((int)(timeout_seconds * 1000)));
}

ImVec2 GetWindowScaleFactor(WindowPointer window) override { return NullConfig::GetWindowScaleFactor(); }
ImVec2 GetDisplayFramebufferScale(WindowPointer window) override { return NullConfig::GetDisplayFramebufferScale(); }
float GetWindowSizeDpiScaleFactor(WindowPointer window) override { return NullConfig::GetWindowSizeDpiScaleFactor(); }

void HideWindow(WindowPointer window) override {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ namespace HelloImGui { namespace BackendApi
SDL_WaitEventTimeout(NULL, timeout_ms);
}

ImVec2 SdlWindowHelper::GetWindowScaleFactor(WindowPointer window)
ImVec2 SdlWindowHelper::GetDisplayFramebufferScale(WindowPointer window)
{
int win_w, win_h, fb_w, fb_h;
SDL_GetWindowSize((SDL_Window *) window, &win_w, &win_h);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace HelloImGui { namespace BackendApi

void WaitForEventTimeout(double timeout_seconds) override;

ImVec2 GetWindowScaleFactor(WindowPointer window) override;
ImVec2 GetDisplayFramebufferScale(WindowPointer window) override;
float GetWindowSizeDpiScaleFactor(WindowPointer window) override;

void HideWindow(WindowPointer window) override;
Expand Down
4 changes: 3 additions & 1 deletion src/hello_imgui/internal/backend_impls/null_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ namespace NullConfig
return {GetScreenBounds()};
}

ImVec2 GetWindowScaleFactor() { return {1.f, 1.f}; }
ImVec2 GetDisplayFramebufferScale() {
return {1.f, 1.f};
}
float GetWindowSizeDpiScaleFactor() { return 1.f; }

}
Expand Down

0 comments on commit 72d8c68

Please sign in to comment.