From 1e0d3d3727223328c81070e15d47c3853eb8a7a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 15 Dec 2018 21:02:16 +0100 Subject: [PATCH] Platform: proper feature parity for GlfwApplication::ViewportEvent. Not sure why I omitted this in dba35bac7a9c170931c476719e4781e501c92a65. --- doc/changelog.dox | 8 ++++--- src/Magnum/Platform/GlfwApplication.cpp | 3 ++- src/Magnum/Platform/GlfwApplication.h | 31 +++++++++++++++++++++++-- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/doc/changelog.dox b/doc/changelog.dox index 62a6b4a65..0d52d3c5a 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -76,9 +76,11 @@ See also: @subsubsection changelog-latest-new-platform Platform libraries - Added @ref Platform::AndroidApplication::framebufferSize(), - @ref Platform::AndroidApplication::dpiScaling() and - @ref Platform::AndroidApplication::ViewportEvent::dpiScaling() for - compatibility with other application implementations + @ref Platform::AndroidApplication::dpiScaling(), + @ref Platform::AndroidApplication::ViewportEvent::dpiScaling(), + @ref Platform::GlfwApplication::ViewportEvent::framebufferSize() and + @ref Platform::GlfwApplication::ViewportEvent::dpiScaling() to ensure + feature parity with @ref Sdl2Application - Clarified HiDPI behavior of Android apps and mentioning @ref platforms-android-apps-manifest-screen-compatibility-mode "the necessary steps" in the docs diff --git a/src/Magnum/Platform/GlfwApplication.cpp b/src/Magnum/Platform/GlfwApplication.cpp index 3d035dc9f..9bcec0af9 100644 --- a/src/Magnum/Platform/GlfwApplication.cpp +++ b/src/Magnum/Platform/GlfwApplication.cpp @@ -459,7 +459,8 @@ void GlfwApplication::setupCallbacks() { static_cast(glfwGetWindowUserPointer(window))->drawEvent(); }); glfwSetFramebufferSizeCallback(_window, [](GLFWwindow* const window, const int w, const int h) { - ViewportEvent e{{w, h}}; + auto& app = *static_cast(glfwGetWindowUserPointer(window)); + ViewportEvent e{{w, h}, app.framebufferSize(), app.dpiScaling()}; static_cast(glfwGetWindowUserPointer(window))->viewportEvent(e); }); glfwSetKeyCallback(_window, [](GLFWwindow* const window, const int key, int, const int action, const int mods) { diff --git a/src/Magnum/Platform/GlfwApplication.h b/src/Magnum/Platform/GlfwApplication.h index a17953507..29e0b4764 100644 --- a/src/Magnum/Platform/GlfwApplication.h +++ b/src/Magnum/Platform/GlfwApplication.h @@ -987,6 +987,8 @@ class GlfwApplication::Configuration { * value. The `--magnum-dpi-scaling` command-line option has a priority * over any application-set value. * @see @ref setSize(const Vector2i&, const Vector2&) + * @todo change this on a DPI change event (GLFW 3.3 has a callback: + * https://github.com/mosra/magnum/issues/243#issuecomment-388384089) */ Vector2 dpiScaling() const { return _dpiScaling; } @@ -1138,16 +1140,41 @@ class GlfwApplication::ViewportEvent { /** * @brief Window size * + * On some platforms with HiDPI displays, window size can be different + * from @ref framebufferSize(). See @ref Platform-GlfwApplication-dpi + * for more information. * @see @ref GlfwApplication::windowSize() */ Vector2i windowSize() const { return _windowSize; } + /** + * @brief Framebuffer size + * + * On some platforms with HiDPI displays, framebuffer size can be + * different from @ref windowSize(). See + * @ref Platform-GlfwApplication-dpi for more information. + * @see @ref GlfwApplication::framebufferSize() + */ + Vector2i framebufferSize() const { return _framebufferSize; } + + /** + * @brief DPI scaling + * + * On some platforms moving an app between displays can result in DPI + * scaling value being changed in tandem with a window/framebuffer + * size. Simply resizing a window doesn't change the DPI scaling value. + * See @ref Platform-GlfwApplication-dpi for more information. + * @see @ref GlfwApplication::dpiScaling() + */ + Vector2 dpiScaling() const { return _dpiScaling; } + private: friend GlfwApplication; - explicit ViewportEvent(const Vector2i& windowSize): _windowSize{windowSize} {} + explicit ViewportEvent(const Vector2i& windowSize, const Vector2i& framebufferSize, const Vector2& dpiScaling): _windowSize{windowSize}, _framebufferSize{framebufferSize}, _dpiScaling{dpiScaling} {} - Vector2i _windowSize; + Vector2i _windowSize, _framebufferSize; + Vector2 _dpiScaling; }; /**