Browse Source

Platform: make it possible to override DPI scaling from the app.

This was sadly broken since probably ever. Since it was hard to wrap my
head around this, added also some code to test this.
dpi-change-events
Vladimír Vondruš 6 years ago
parent
commit
65743b5647
  1. 3
      doc/changelog.dox
  2. 7
      src/Magnum/Platform/GlfwApplication.cpp
  3. 7
      src/Magnum/Platform/Sdl2Application.cpp
  4. 14
      src/Magnum/Platform/Test/GlfwApplicationTest.cpp
  5. 15
      src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp

3
doc/changelog.dox

@ -268,6 +268,9 @@ See also:
- Calling @ref Platform::Sdl2Application::setSwapInterval() with @cpp 0 @ce
caused @ref Platform::Sdl2Application::setMinimalLoopPeriod() "setMinimalLoopPeriod()"
to be ignored even though Vsync was in fact not enabled.
- It was not possible to override DPI scaling using
@ref Platform::Sdl2Application::Configuration as command-line arguments
always got a priority (see [mosra/magnum#416](https://github.com/mosra/magnum/issues/416))
- Fixed an otherwise harmless OOB access in @ref MeshTools::tipsify() that
could trigger ASan or debug iterator errors
- With @ref Corrade/Utility/DebugStl.h not being included, @ref std::string

7
src/Magnum/Platform/GlfwApplication.cpp

@ -145,13 +145,14 @@ Vector2 GlfwApplication::dpiScaling(const Configuration& configuration) {
/** @todo */
#endif
/* Use values from the configuration only if not overriden on command line.
In any case explicit scaling has a precedence before the policy. */
/* Use values from the configuration only if not overriden on command line
to something non-default. In any case explicit scaling has a precedence
before the policy. */
Implementation::GlfwDpiScalingPolicy dpiScalingPolicy{};
if(!_commandLineDpiScaling.isZero()) {
Debug{verbose} << "Platform::GlfwApplication: user-defined DPI scaling" << _commandLineDpiScaling.x();
return _commandLineDpiScaling;
} else if(UnsignedByte(_commandLineDpiScalingPolicy)) {
} else if(_commandLineDpiScalingPolicy != Implementation::GlfwDpiScalingPolicy::Default) {
dpiScalingPolicy = _commandLineDpiScalingPolicy;
} else if(!configuration.dpiScaling().isZero()) {
Debug{verbose} << "Platform::GlfwApplication: app-defined DPI scaling" << _commandLineDpiScaling.x();

7
src/Magnum/Platform/Sdl2Application.cpp

@ -206,13 +206,14 @@ Vector2 Sdl2Application::dpiScaling(const Configuration& configuration) {
/* Handled below, warning printed only when using virtual DPI scaling */
#endif
/* Use values from the configuration only if not overriden on command line.
In any case explicit scaling has a precedence before the policy. */
/* Use values from the configuration only if not overriden on command line
to something non-default. In any case explicit scaling has a precedence
before the policy. */
Implementation::Sdl2DpiScalingPolicy dpiScalingPolicy{};
if(!_commandLineDpiScaling.isZero()) {
Debug{verbose} << "Platform::Sdl2Application: user-defined DPI scaling" << _commandLineDpiScaling.x();
return _commandLineDpiScaling;
} else if(UnsignedByte(_commandLineDpiScalingPolicy)) {
} else if(_commandLineDpiScalingPolicy != Implementation::Sdl2DpiScalingPolicy::Default) {
dpiScalingPolicy = _commandLineDpiScalingPolicy;
} else if(!configuration.dpiScaling().isZero()) {
Debug{verbose} << "Platform::Sdl2Application: app-defined DPI scaling" << _commandLineDpiScaling.x();

14
src/Magnum/Platform/Test/GlfwApplicationTest.cpp

@ -25,10 +25,12 @@
#include <Corrade/Containers/Optional.h>
#include <Corrade/PluginManager/Manager.h>
#include <Corrade/Utility/Arguments.h>
#include <Corrade/Utility/DebugStl.h>
#include <Corrade/Utility/Resource.h>
#include "Magnum/ImageView.h"
#include "Magnum/Math/ConfigurationValue.h"
#include "Magnum/Platform/GlfwApplication.h"
#include "Magnum/Trade/AbstractImporter.h"
#include "Magnum/Trade/ImageData.h"
@ -96,7 +98,17 @@ struct GlfwApplicationTest: Platform::Application {
void drawEvent() override {}
};
GlfwApplicationTest::GlfwApplicationTest(const Arguments& arguments): Platform::Application{arguments, Configuration{}.setWindowFlags(Configuration::WindowFlag::Resizable)} {
GlfwApplicationTest::GlfwApplicationTest(const Arguments& arguments): Platform::Application{arguments, NoCreate} {
Utility::Arguments args;
args.addOption("dpi-scaling").setHelp("dpi-scaling", "DPI scaled passed via Configuration instead of --magnum-dpi-scaling, to test app overrides")
.parse(arguments.argc, arguments.argv);
Configuration conf;
conf.setWindowFlags(Configuration::WindowFlag::Resizable);
if(!args.value("dpi-scaling").empty())
conf.setSize({800, 600}, args.value<Vector2>("dpi-scaling"));
create(conf);
/* For testing resize events */
Debug{} << "window size" << windowSize()
#ifdef MAGNUM_TARGET_GL

15
src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp

@ -25,10 +25,12 @@
#include <Corrade/Containers/Optional.h>
#include <Corrade/PluginManager/Manager.h>
#include <Corrade/Utility/Arguments.h>
#include <Corrade/Utility/DebugStl.h>
#include <Corrade/Utility/Resource.h>
#include "Magnum/ImageView.h"
#include "Magnum/Math/ConfigurationValue.h"
#include "Magnum/Platform/Sdl2Application.h"
#include "Magnum/Trade/AbstractImporter.h"
#include "Magnum/Trade/ImageData.h"
@ -141,7 +143,18 @@ struct Sdl2ApplicationTest: Platform::Application {
#endif
};
Sdl2ApplicationTest::Sdl2ApplicationTest(const Arguments& arguments): Platform::Application{arguments, Configuration{}.setWindowFlags(Configuration::WindowFlag::Resizable)} {
Sdl2ApplicationTest::Sdl2ApplicationTest(const Arguments& arguments): Platform::Application{arguments, NoCreate} {
Utility::Arguments args;
args.addOption("dpi-scaling").setHelp("dpi-scaling", "DPI scaled passed via Configuration instead of --magnum-dpi-scaling, to test app overrides")
.addSkippedPrefix("magnum", "engine-specific options")
.parse(arguments.argc, arguments.argv);
Configuration conf;
conf.setWindowFlags(Configuration::WindowFlag::Resizable);
if(!args.value("dpi-scaling").empty())
conf.setSize({800, 600}, args.value<Vector2>("dpi-scaling"));
create(conf);
/* For testing resize events */
Debug{} << "window size" << windowSize()
#ifdef MAGNUM_TARGET_GL

Loading…
Cancel
Save