From d40e4f2dead6d94a9fc38f34675324fc8dd63784 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 18 Nov 2018 23:46:33 +0100 Subject: [PATCH] Platform: added AndroidApplication::framebufferSize() and dpiScaling(). Doesn't provide any new interesting values, just for compatibility with other toolkits. --- doc/changelog.dox | 7 +++ src/Magnum/Platform/AbstractXApplication.h | 16 ++++++- src/Magnum/Platform/AndroidApplication.cpp | 2 +- src/Magnum/Platform/AndroidApplication.h | 53 ++++++++++++++++++++-- 4 files changed, 72 insertions(+), 6 deletions(-) diff --git a/doc/changelog.dox b/doc/changelog.dox index 752aafce4..b8dfb56ba 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -61,6 +61,13 @@ r>>) @ref Math::Color3 and @ref Math::Color4 literals with the new experimental @ref Corrade::Utility::Tweakable utility. See also @ref tweakableliterals. +@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 + @subsection changelog-latest-changes Changes and improvements @subsubsection changelog-latest-changes-gl GL library diff --git a/src/Magnum/Platform/AbstractXApplication.h b/src/Magnum/Platform/AbstractXApplication.h index 2d28263c0..b2f07d13e 100644 --- a/src/Magnum/Platform/AbstractXApplication.h +++ b/src/Magnum/Platform/AbstractXApplication.h @@ -212,7 +212,21 @@ class AbstractXApplication { #else private: #endif - /** @copydoc GlfwApplication::viewportEvent(ViewportEvent&) */ + /** + * @brief Viewport event + * + * Called when window size changes. The default implementation does + * nothing. If you want to respond to size changes, you should pass the + * new size to @ref GL::DefaultFramebuffer::setViewport() (if using + * OpenGL) and possibly elsewhere (to + * @ref SceneGraph::Camera::setViewport(), other framebuffers...). + * + * Note that this function might not get called at all if the window + * size doesn't change. You should configure the initial state of your + * cameras, framebuffers etc. in application constructor rather than + * relying on this function to be called. Size of the window can be + * retrieved using @ref windowSize(). + */ virtual void viewportEvent(ViewportEvent& event); #ifdef MAGNUM_BUILD_DEPRECATED diff --git a/src/Magnum/Platform/AndroidApplication.cpp b/src/Magnum/Platform/AndroidApplication.cpp index 448859708..0325aa03a 100644 --- a/src/Magnum/Platform/AndroidApplication.cpp +++ b/src/Magnum/Platform/AndroidApplication.cpp @@ -165,7 +165,7 @@ bool AndroidApplication::tryCreate(const Configuration& configuration, const GLC return _context->tryCreate(); } -Vector2i AndroidApplication::windowSize() const { +Vector2i AndroidApplication::framebufferSize() const { return {ANativeWindow_getWidth(_state->window), ANativeWindow_getHeight(_state->window)}; } diff --git a/src/Magnum/Platform/AndroidApplication.h b/src/Magnum/Platform/AndroidApplication.h index 4449c6761..8b7f63a1b 100644 --- a/src/Magnum/Platform/AndroidApplication.h +++ b/src/Magnum/Platform/AndroidApplication.h @@ -306,8 +306,45 @@ class AndroidApplication { * @brief Window size * * Window size to which all input event coordinates can be related. + * Expects that a window is already created, equivalent to + * @ref framebufferSize(). + * + * @attention The reported value will be incorrect in case you use + * the [Screen Compatibility Mode](http://www.androiddocs.com/guide/practices/screen-compat-mode.html). + * See @ref platforms-android-apps-manifest-screen-compatibility-mode + * for details. + */ + Vector2i windowSize() const { return framebufferSize(); } + + /** + * @brief Framebuffer size + * + * Size of the default framebuffer, equivalent to @ref windowSize(). + * Expects that a window is already created. + * @see @ref dpiScaling() + */ + Vector2i framebufferSize() const; + + /** + * @brief DPI scaling + * + * Provided only for compatibility with other toolkits. Returns always + * @cpp {1.0f, 1.0f} @ce. + * @see @ref framebufferSize() */ - Vector2i windowSize() const; + Vector2 dpiScaling() const { return Vector2{1.0f}; } + + /** + * @brief DPI scaling for given configuration + * + * Provided only for compatibility with other toolkits. Returns always + * @cpp {1.0f, 1.0f} @ce. + * @see @ref framebufferSize() + */ + Vector2 dpiScaling(const Configuration& configuration) const { + static_cast(configuration); + return Vector2{1.0f}; + } /** * @brief Swap buffers @@ -521,18 +558,26 @@ class AndroidApplication::ViewportEvent { /** * @brief Window size * - * @see @ref AndroidApplication::windowSize() + * The same as @ref framebufferSize(). See + * @ref AndroidApplication::windowSize() for possible caveats. */ Vector2i windowSize() const { return _windowSize; } /** * @brief Framebuffer size * - * The same as @ref windowSize(). - * @todo this might not be true, implement properly! + * The same as @ref windowSize(). See + * @ref AndroidApplication::framebufferSize() for possible caveats. */ Vector2i framebufferSize() const { return _windowSize; } + /** + * @brief DPI scaling + * + * Always @cpp {1.0f, 1.0f} @ce. + */ + Vector2 dpiScaling() const { return Vector2{1.0f}; } + private: friend AndroidApplication;