diff --git a/src/Magnum/Platform/GlfwApplication.cpp b/src/Magnum/Platform/GlfwApplication.cpp index 6316cfee9..a2d6bf0f7 100644 --- a/src/Magnum/Platform/GlfwApplication.cpp +++ b/src/Magnum/Platform/GlfwApplication.cpp @@ -465,7 +465,11 @@ void GlfwApplication::setupCallbacks() { }); glfwSetFramebufferSizeCallback(_window, [](GLFWwindow* const window, const int w, const int h) { auto& app = *static_cast(glfwGetWindowUserPointer(window)); - ViewportEvent e{{w, h}, app.framebufferSize(), app.dpiScaling()}; + ViewportEvent e{{w, h} + #ifdef MAGNUM_TARGET_GL + , app.framebufferSize() + #endif + , app.dpiScaling()}; static_cast(glfwGetWindowUserPointer(window))->viewportEvent(e); }); glfwSetKeyCallback(_window, [](GLFWwindow* const window, const int key, int, const int action, const int mods) { @@ -523,6 +527,7 @@ Vector2i GlfwApplication::windowSize() const { return size; } +#ifdef MAGNUM_TARGET_GL Vector2i GlfwApplication::framebufferSize() const { CORRADE_ASSERT(_window, "Platform::GlfwApplication::framebufferSize(): no window opened", {}); @@ -530,6 +535,7 @@ Vector2i GlfwApplication::framebufferSize() const { glfwGetFramebufferSize(_window, &size.x(), &size.y()); return size; } +#endif void GlfwApplication::setSwapInterval(const Int interval) { glfwSwapInterval(interval); diff --git a/src/Magnum/Platform/GlfwApplication.h b/src/Magnum/Platform/GlfwApplication.h index 34ea7cf11..cc46930f0 100644 --- a/src/Magnum/Platform/GlfwApplication.h +++ b/src/Magnum/Platform/GlfwApplication.h @@ -1206,15 +1206,22 @@ class GlfwApplication::ViewportEvent { */ Vector2i windowSize() const { return _windowSize; } + #if defined(MAGNUM_TARGET_GL) || defined(DOXYGEN_GENERATING_OUTPUT) /** * @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() + * + * @note This function is available only if Magnum is compiled with + * @ref MAGNUM_TARGET_GL enabled (done by default). See + * @ref building-features for more information. + * + * @see @ref GlfwApplication::framebufferSize(), @ref dpiScaling() */ Vector2i framebufferSize() const { return _framebufferSize; } + #endif /** * @brief DPI scaling @@ -1223,17 +1230,27 @@ class GlfwApplication::ViewportEvent { * 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() + * @see @ref GlfwApplication::dpiScaling(), @ref framebufferSize() */ Vector2 dpiScaling() const { return _dpiScaling; } private: friend GlfwApplication; - explicit ViewportEvent(const Vector2i& windowSize, const Vector2i& framebufferSize, const Vector2& dpiScaling): _windowSize{windowSize}, _framebufferSize{framebufferSize}, _dpiScaling{dpiScaling} {} + explicit ViewportEvent(const Vector2i& windowSize, + #ifdef MAGNUM_TARGET_GL + const Vector2i& framebufferSize, + #endif + const Vector2& dpiScaling): _windowSize{windowSize}, + #ifdef MAGNUM_TARGET_GL + _framebufferSize{framebufferSize}, + #endif + _dpiScaling{dpiScaling} {} const Vector2i _windowSize; + #ifdef MAGNUM_TARGET_GL const Vector2i _framebufferSize; + #endif const Vector2 _dpiScaling; }; diff --git a/src/Magnum/Platform/Sdl2Application.cpp b/src/Magnum/Platform/Sdl2Application.cpp index 71289ebb1..44ad30403 100644 --- a/src/Magnum/Platform/Sdl2Application.cpp +++ b/src/Magnum/Platform/Sdl2Application.cpp @@ -547,6 +547,7 @@ Vector2i Sdl2Application::windowSize() const { return size; } +#ifdef MAGNUM_TARGET_GL Vector2i Sdl2Application::framebufferSize() const { Vector2i size; #ifndef CORRADE_TARGET_EMSCRIPTEN @@ -558,6 +559,7 @@ Vector2i Sdl2Application::framebufferSize() const { #endif return size; } +#endif #ifdef CORRADE_TARGET_EMSCRIPTEN void Sdl2Application::setContainerCssClass(const std::string& cssClass) { @@ -671,7 +673,11 @@ void Sdl2Application::mainLoopIteration() { https://github.com/kripken/emscripten/issues/1731 */ CORRADE_ASSERT_UNREACHABLE(); #else - ViewportEvent e{event, {event.window.data1, event.window.data2}, framebufferSize(), _dpiScaling}; + ViewportEvent e{event, {event.window.data1, event.window.data2}, + #ifdef MAGNUM_TARGET_GL + framebufferSize(), + #endif + _dpiScaling}; /** @todo handle also WM_DPICHANGED events when a window is moved between displays with different DPI */ viewportEvent(e); _flags |= Flag::Redraw; @@ -835,7 +841,13 @@ void Sdl2Application::anyEvent(SDL_Event&) { void Sdl2Application::viewportEvent(ViewportEvent& event) { #ifdef MAGNUM_BUILD_DEPRECATED CORRADE_IGNORE_DEPRECATED_PUSH - viewportEvent(event.framebufferSize()); + viewportEvent( + #ifdef MAGNUM_TARGET_GL + event.framebufferSize() + #else + event.windowSize() + #endif + ); CORRADE_IGNORE_DEPRECATED_POP #else static_cast(event); diff --git a/src/Magnum/Platform/Sdl2Application.h b/src/Magnum/Platform/Sdl2Application.h index 613b9a190..9a5ddba96 100644 --- a/src/Magnum/Platform/Sdl2Application.h +++ b/src/Magnum/Platform/Sdl2Application.h @@ -657,7 +657,7 @@ class Sdl2Application { * @ref MAGNUM_TARGET_GL enabled (done by default). See * @ref building-features for more information. * - * @see @ref dpiScaling() + * @see @ref Sdl2Application::framebufferSize(), @ref dpiScaling() */ Vector2i framebufferSize() const; #endif @@ -670,7 +670,7 @@ class Sdl2Application { * zero vector, use @ref dpiScaling(const Configuration&) const for * calculating a value independently. See @ref Platform-Sdl2Application-dpi * for more information. - * @see @ref framebufferSize() + * @see @ref Sdl2Application::dpiScaling(), @ref framebufferSize() */ Vector2 dpiScaling() const { return _dpiScaling; } @@ -1740,15 +1740,22 @@ class Sdl2Application::ViewportEvent { */ Vector2i windowSize() const { return _windowSize; } + #if defined(MAGNUM_TARGET_GL) || defined(DOXYGEN_GENERATING_OUTPUT) /** * @brief Framebuffer size * * On some platforms with HiDPI displays, framebuffer size can be * different from @ref windowSize(). See * @ref Platform-Sdl2Application-dpi for more information. + * + * @note This function is available only if Magnum is compiled with + * @ref MAGNUM_TARGET_GL enabled (done by default). See + * @ref building-features for more information. + * * @see @ref Sdl2Application::framebufferSize() */ Vector2i framebufferSize() const { return _framebufferSize; } + #endif /** * @brief DPI scaling @@ -1779,17 +1786,27 @@ class Sdl2Application::ViewportEvent { #ifndef CORRADE_TARGET_EMSCRIPTEN const SDL_Event& event, #endif - const Vector2i& windowSize, const Vector2i& framebufferSize, const Vector2& dpiScaling): + const Vector2i& windowSize, + #ifdef MAGNUM_TARGET_GL + const Vector2i& framebufferSize, + #endif + const Vector2& dpiScaling): #ifndef CORRADE_TARGET_EMSCRIPTEN _event(event), #endif - _windowSize{windowSize}, _framebufferSize{framebufferSize}, _dpiScaling{dpiScaling} {} + _windowSize{windowSize}, + #ifdef MAGNUM_TARGET_GL + _framebufferSize{framebufferSize}, + #endif + _dpiScaling{dpiScaling} {} #ifndef CORRADE_TARGET_EMSCRIPTEN const SDL_Event& _event; #endif const Vector2i _windowSize; + #ifdef MAGNUM_TARGET_GL const Vector2i _framebufferSize; + #endif const Vector2 _dpiScaling; }; diff --git a/src/Magnum/Platform/Test/GlfwApplicationTest.cpp b/src/Magnum/Platform/Test/GlfwApplicationTest.cpp index 0a1b6655e..97fdb18c0 100644 --- a/src/Magnum/Platform/Test/GlfwApplicationTest.cpp +++ b/src/Magnum/Platform/Test/GlfwApplicationTest.cpp @@ -30,6 +30,15 @@ namespace Magnum { namespace Platform { namespace Test { namespace { struct GlfwApplicationTest: Platform::Application { explicit GlfwApplicationTest(const Arguments& arguments): Platform::Application{arguments} {} + /* For testing HiDPI resize events */ + void viewportEvent(ViewportEvent& event) override { + Debug{} << "viewport event" << event.windowSize() + #ifdef MAGNUM_TARGET_GL + << event.framebufferSize() + #endif + << event.dpiScaling(); + } + void keyPressEvent(KeyEvent& event) override { #if GLFW_VERSION_MAJOR*100 + GLFW_VERSION_MINOR >= 302 Debug{} << "key press event:" << event.keyName(); diff --git a/src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp b/src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp index 02b6bff63..688fc39db 100644 --- a/src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp +++ b/src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp @@ -42,7 +42,11 @@ struct Sdl2ApplicationTest: Platform::Application { /* For testing HiDPI resize events */ void viewportEvent(ViewportEvent& event) override { - Debug{} << "viewport event" << event.windowSize() << event.framebufferSize() << event.dpiScaling(); + Debug{} << "viewport event" << event.windowSize() + #ifdef MAGNUM_TARGET_GL + << event.framebufferSize() + #endif + << event.dpiScaling(); } /* For testing event coordinates */