diff --git a/src/Magnum/Platform/GlfwApplication.h b/src/Magnum/Platform/GlfwApplication.h index d3a6089d7..ba05d6526 100644 --- a/src/Magnum/Platform/GlfwApplication.h +++ b/src/Magnum/Platform/GlfwApplication.h @@ -673,6 +673,10 @@ class GlfwApplication { glfwSetCursorPos(_window, Double(position.x()), Double(position.y())); } + /** @todo GLFW_CURSOR_CAPTURED, currently only in a branch: + https://github.com/glfw/glfw/issues/58 + https://github.com/glfw/glfw/compare/captured-cursor-mode-r2 */ + private: /** @copydoc Sdl2Application::mousePressEvent() */ virtual void mousePressEvent(MouseEvent& event); diff --git a/src/Magnum/Platform/Sdl2Application.h b/src/Magnum/Platform/Sdl2Application.h index 31a96ecae..35ca97477 100644 --- a/src/Magnum/Platform/Sdl2Application.h +++ b/src/Magnum/Platform/Sdl2Application.h @@ -1060,6 +1060,26 @@ class Sdl2Application { void warpCursor(const Vector2i& position) { SDL_WarpMouseInWindow(_window, position.x(), position.y()); } + + /** + * @brief Whether the mouse is captured + * @m_since_latest + * + * @note Not available in @ref CORRADE_TARGET_EMSCRIPTEN "Emscripten". + */ + bool isMouseCaptured() { + return SDL_GetWindowFlags(_window) & SDL_WINDOW_MOUSE_CAPTURE; + } + + /** + * @brief Capture mouse + * @m_since_latest + * + * @note Not available in @ref CORRADE_TARGET_EMSCRIPTEN "Emscripten". + */ + void setMouseCaptured(bool enabled) { + SDL_CaptureMouse(enabled ? SDL_TRUE : SDL_FALSE); + } #endif #ifdef MAGNUM_BUILD_DEPRECATED diff --git a/src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp b/src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp index 3ae58db5a..813499fb1 100644 --- a/src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp +++ b/src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp @@ -254,7 +254,10 @@ struct Sdl2ApplicationTest: Platform::Application { setWindowTitle("This is a UTF-8 Window Titleā„¢ and it should have no exclamation mark!!"_s.exceptSuffix(2)); } #ifndef CORRADE_TARGET_EMSCRIPTEN - else if(event.key() == KeyEvent::Key::S) { + else if(event.key() == KeyEvent::Key::C) { + Debug{} << "toggling mouse capture to" << !isMouseCaptured(); + setMouseCaptured(!isMouseCaptured()); + } else if(event.key() == KeyEvent::Key::S) { Debug{} << "setting window size, which should trigger a viewport event"; setWindowSize(Vector2i{300, 200}); } else if(event.key() == KeyEvent::Key::W) {