Skip to content

Commit c82ec2e

Browse files
BruegelNnmwsharp
andauthored
DPI scaling (#326)
* Add option for dpiScale to globalContext and scale font with dpiScale factor * Scale everthing with the dpiScale factor * set GLFW_SCALE_TO_MONITOR for proper windows size on start up * Make sure the dpiScale factor is in a reasonable range (1x-10x) * some refactor/renaming, plus bugfixes for nested context push * remove global font atlas engine pointer * autoset uiscale and restore from prefs file * disable GLFW_SCALE_TO_MONITOR * remove debug code * set uiScale on non-glfw backends * fix imgui init calls for non-GLFW backends --------- Co-authored-by: Nicholas Sharp <[email protected]>
1 parent f0245f3 commit c82ec2e

28 files changed

+185
-79
lines changed

examples/demo-app/demo_app.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ void callback() {
780780
static int loadedMat = 1;
781781
static bool depthClick = false;
782782

783-
ImGui::PushItemWidth(100);
783+
ImGui::PushItemWidth(100 * polyscope::options::uiScale);
784784

785785
ImGui::InputInt("num points", &numPoints);
786786
ImGui::InputFloat("param value", &param);

include/polyscope/options.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ extern std::string screenshotExtension; // sets the extension used for automatic
9393
// SSAA scaling in pixel multiples
9494
extern int ssaaFactor;
9595

96+
// DPI scaling to scale the UI on high-resolutoin screens
97+
extern float uiScale;
98+
9699
// Transparency settings for the renderer
97100
extern TransparencyMode transparencyMode;
98101
extern int transparencyRenderPasses;

include/polyscope/parameterization_quantity.ipp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ ParameterizationQuantity<QuantityT>::ParameterizationQuantity(QuantityT& quantit
6161
template <typename QuantityT>
6262
void ParameterizationQuantity<QuantityT>::buildParameterizationUI() {
6363
64-
ImGui::PushItemWidth(100);
64+
ImGui::PushItemWidth(100 * options::uiScale);
6565
6666
// Modulo stripey width
6767
if (ImGui::DragFloat("period", &checkerSize.get(), .001, 0.0001, 1.0, "%.4f",
@@ -82,7 +82,7 @@ void ParameterizationQuantity<QuantityT>::buildParameterizationUI() {
8282
setCheckerColors(getCheckerColors());
8383
break;
8484
case ParamVizStyle::CHECKER_ISLANDS:
85-
ImGui::PushItemWidth(100);
85+
ImGui::PushItemWidth(100 * options::uiScale);
8686
if (ImGui::DragFloat("alt darkness", &altDarkness.get(), 0.01, 0., 1.)) {
8787
altDarkness.manuallyChanged();
8888
requestRedraw();
@@ -103,7 +103,7 @@ void ParameterizationQuantity<QuantityT>::buildParameterizationUI() {
103103
case ParamVizStyle::LOCAL_CHECK:
104104
case ParamVizStyle::LOCAL_RAD: {
105105
// Angle slider
106-
ImGui::PushItemWidth(100);
106+
ImGui::PushItemWidth(100 * options::uiScale);
107107
ImGui::SliderAngle("angle shift", &localRot, -180,
108108
180); // displays in degrees, works in radians TODO refresh/update/persist
109109
if (ImGui::DragFloat("alt darkness", &altDarkness.get(), 0.01, 0., 1.)) {

include/polyscope/render/engine.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,6 @@ class Engine {
518518
virtual void ImGuiRender() = 0;
519519

520520
void setImGuiStyle();
521-
ImFontAtlas* getImGuiGlobalFontAtlas();
522521

523522
// Display an ImGui window showing a texture
524523
// WARNING: you must ensure that the texture buffer pointer stays valid until after the ImGui frame is rendered, which
@@ -629,7 +628,7 @@ class Engine {
629628
bool useAltDisplayBuffer = false; // if true, push final render results offscreen to the alt buffer instead
630629

631630
// Internal windowing and engine details
632-
ImFontAtlas* globalFontAtlas = nullptr;
631+
virtual void configureImGui() {}; // generates font things
633632
ImFont* regularFont = nullptr;
634633
ImFont* monoFont = nullptr;
635634
FrameBuffer* currRenderFramebuffer = nullptr;
@@ -658,7 +657,6 @@ class Engine {
658657
TransparencyMode currLightingTransparencyMode = TransparencyMode::None;
659658

660659
// Helpers
661-
void configureImGui();
662660
void loadDefaultMaterials();
663661
void loadDefaultMaterial(std::string name);
664662
std::shared_ptr<TextureBuffer> loadMaterialTexture(float* data, int width, int height);

include/polyscope/render/mock_opengl/mock_gl_engine.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ class MockGLEngine : public Engine {
358358

359359
// ImGui
360360
void initializeImGui() override;
361+
void configureImGui() override;
361362
void shutdownImGui() override;
362363
void ImGuiNewFrame() override;
363364
void ImGuiRender() override;

include/polyscope/render/opengl/gl_engine_egl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class GLEngineEGL : public GLEngine {
6969
// === ImGui
7070

7171
void initializeImGui() override;
72+
void configureImGui() override;
7273
void shutdownImGui() override;
7374
void ImGuiNewFrame() override;
7475
void ImGuiRender() override;

include/polyscope/render/opengl/gl_engine_glfw.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,13 @@ class GLEngineGLFW : public GLEngine {
7777
void shutdownImGui() override;
7878
void ImGuiNewFrame() override;
7979
void ImGuiRender() override;
80+
void configureImGui() override;
8081

8182
protected:
8283
// Internal windowing and engine details
8384
GLFWwindow* mainWindow = nullptr;
85+
86+
void setUIScaleFromSystemDPI();
8487
};
8588

8689
} // namespace backend_openGL3

include/polyscope/scalar_quantity.ipp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ void ScalarQuantity<QuantityT>::buildScalarUI() {
147147
// Isolines
148148
if (isolinesEnabled.get()) {
149149

150-
ImGui::PushItemWidth(100);
150+
ImGui::PushItemWidth(100 * options::uiScale);
151151

152152

153153
auto styleName = [](const IsolineStyle& m) -> std::string {

src/camera_view.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ void CameraView::buildCustomUI() {
386386

387387
void CameraView::buildCustomOptionsUI() {
388388

389-
ImGui::PushItemWidth(150);
389+
ImGui::PushItemWidth(150 * options::uiScale);
390390

391391
if (widgetFocalLengthUpper == -777) widgetFocalLengthUpper = 2. * (*widgetFocalLength.get().getValuePtr());
392392
if (ImGui::SliderFloat("widget focal length", widgetFocalLength.get().getValuePtr(), 0, widgetFocalLengthUpper,

src/curve_network.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ void CurveNetwork::buildCustomUI() {
411411
setColor(getColor());
412412
}
413413
ImGui::SameLine();
414-
ImGui::PushItemWidth(100);
414+
ImGui::PushItemWidth(100 * options::uiScale);
415415
if (ImGui::SliderFloat("Radius", radius.get().getValuePtr(), 0.0, .1, "%.5f",
416416
ImGuiSliderFlags_Logarithmic | ImGuiSliderFlags_NoRoundToFormat)) {
417417
radius.manuallyChanged();

0 commit comments

Comments
 (0)