Browse Source

[wip] Platform: implement mouse capturing for SDL and GLFW.

TODO: GLFW has it together with normal/hidden/locked in setCursor() and
  those options are mutually exclusive, so maybe do it that way instead
  of setMouseCaptured() like in case of SDL?
TODO: while SDL reports move event coordinates outside of the window,
  GLFW docs in the branch seem to indicate that the mouse position won't
  change -- would this mean the mouse move events won't get reported?
mousecapture
Vladimír Vondruš 6 years ago
parent
commit
4cf68c29fc
  1. 4
      src/Magnum/Platform/GlfwApplication.h
  2. 20
      src/Magnum/Platform/Sdl2Application.h
  3. 5
      src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp

4
src/Magnum/Platform/GlfwApplication.h

@ -625,6 +625,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);

20
src/Magnum/Platform/Sdl2Application.h

@ -967,6 +967,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

5
src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp

@ -97,7 +97,10 @@ struct Sdl2ApplicationTest: Platform::Application {
setWindowTitle("This is a UTF-8 Window Title™!");
}
#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) {

Loading…
Cancel
Save