From 65743b564720fab0b00615df5067af9a2c525a45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 15 Feb 2020 18:41:23 +0100 Subject: [PATCH] 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. --- doc/changelog.dox | 3 +++ src/Magnum/Platform/GlfwApplication.cpp | 7 ++++--- src/Magnum/Platform/Sdl2Application.cpp | 7 ++++--- src/Magnum/Platform/Test/GlfwApplicationTest.cpp | 14 +++++++++++++- src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp | 15 ++++++++++++++- 5 files changed, 38 insertions(+), 8 deletions(-) diff --git a/doc/changelog.dox b/doc/changelog.dox index 4f147c1b2..0f2145430 100644 --- a/doc/changelog.dox +++ b/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 diff --git a/src/Magnum/Platform/GlfwApplication.cpp b/src/Magnum/Platform/GlfwApplication.cpp index 86e57b359..2f7f19ba5 100644 --- a/src/Magnum/Platform/GlfwApplication.cpp +++ b/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(); diff --git a/src/Magnum/Platform/Sdl2Application.cpp b/src/Magnum/Platform/Sdl2Application.cpp index f7827335c..276c7ee55 100644 --- a/src/Magnum/Platform/Sdl2Application.cpp +++ b/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(); diff --git a/src/Magnum/Platform/Test/GlfwApplicationTest.cpp b/src/Magnum/Platform/Test/GlfwApplicationTest.cpp index 4b56a1bf6..df4a65dd3 100644 --- a/src/Magnum/Platform/Test/GlfwApplicationTest.cpp +++ b/src/Magnum/Platform/Test/GlfwApplicationTest.cpp @@ -25,10 +25,12 @@ #include #include +#include #include #include #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("dpi-scaling")); + create(conf); + /* For testing resize events */ Debug{} << "window size" << windowSize() #ifdef MAGNUM_TARGET_GL diff --git a/src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp b/src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp index f81605217..a16ad9ddf 100644 --- a/src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp +++ b/src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp @@ -25,10 +25,12 @@ #include #include +#include #include #include #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("dpi-scaling")); + create(conf); + /* For testing resize events */ Debug{} << "window size" << windowSize() #ifdef MAGNUM_TARGET_GL