Skip to content

Commit

Permalink
Windows|libappfw: Use system DPI factor to scale UI elements
Browse files Browse the repository at this point in the history
IssueID #2058
  • Loading branch information
skyjake committed Aug 25, 2015
1 parent 0523f8a commit 2cfe5d0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
1 change: 1 addition & 0 deletions doomsday/sdk/libappfw/include/de/framework/baseguiapp.h
Expand Up @@ -46,6 +46,7 @@ class LIBAPPFW_PUBLIC BaseGuiApp : public GuiApp
BaseGuiApp(int &argc, char **argv);

void initSubsystems(SubsystemInitFlags flags = DefaultSubsystems);
double dpiFactor() const;

public:
static BaseGuiApp &app();
Expand Down
20 changes: 15 additions & 5 deletions doomsday/sdk/libappfw/src/baseguiapp.cpp
Expand Up @@ -88,6 +88,7 @@ DENG2_PIMPL_NOREF(BaseGuiApp)
GLShaderBank shaders;
WaveformBank waveforms;
VRConfig vr;
double dpiFactor = 1.0;
};

BaseGuiApp::BaseGuiApp(int &argc, char **argv)
Expand All @@ -101,23 +102,32 @@ BaseGuiApp::BaseGuiApp(int &argc, char **argv)
<< DENG2_FUNC (App_LoadFont, "loadFont", "fileName");
}

double BaseGuiApp::dpiFactor() const
{
return d->dpiFactor;
}

void BaseGuiApp::initSubsystems(SubsystemInitFlags flags)
{
GuiApp::initSubsystems(flags);

double dpiFactor = 1.0;

#ifdef DENG2_QT_5_0_OR_NEWER
dpiFactor = devicePixelRatio();
# ifdef WIN32
d->dpiFactor = primaryScreen()->logicalDotsPerInch() / 96.0;
# else
d->dpiFactor = devicePixelRatio();
# endif
#else
d->dpiFactor = 1.0;
#endif

// The "-dpi" option overrides the detected DPI factor.
if(auto dpi = commandLine().check("-dpi", 1))
{
dpiFactor = dpi.params.at(0).toDouble();
d->dpiFactor = dpi.params.at(0).toDouble();
}

scriptSystem().nativeModule("DisplayMode").set("DPI_FACTOR", dpiFactor);
scriptSystem().nativeModule("DisplayMode").set("DPI_FACTOR", d->dpiFactor);

d->uiState.reset(new PersistentState("UIState"));
}
Expand Down
2 changes: 1 addition & 1 deletion doomsday/sdk/libappfw/src/guirootwidget.cpp
Expand Up @@ -40,7 +40,7 @@ static DotPath const ID_BOLD_ROUND_CORNERS = "GuiRootWidget.frame.bold";
static DotPath const ID_DOT = "GuiRootWidget.dot";

#ifdef DENG2_QT_5_0_OR_NEWER
# define DPI_SCALED(x) ((x) * qApp->devicePixelRatio())
# define DPI_SCALED(x) ((x) * DENG2_BASE_GUI_APP->dpiFactor())
#else
# define DPI_SCALED(x) (x)
#endif
Expand Down
6 changes: 1 addition & 5 deletions doomsday/sdk/libappfw/src/guiwidget.cpp
Expand Up @@ -366,11 +366,7 @@ DENG2_PIMPL(GuiWidget)

static float toDevicePixels(float logicalPixels)
{
#ifdef DENG2_QT_5_0_OR_NEWER
return logicalPixels * qApp->devicePixelRatio();
#else
return logicalPixels;
#endif
return logicalPixels * DENG2_BASE_GUI_APP->dpiFactor();
}
};

Expand Down

0 comments on commit 2cfe5d0

Please sign in to comment.