diff options
author | Andrei E <andreien@proton.me> | 2022-08-01 21:28:36 +0100 |
---|---|---|
committer | sfan5 <sfan5@live.de> | 2022-10-24 21:19:11 +0200 |
commit | a549d0bfed02801d642ef281697f8ac7c3dbc2cf (patch) | |
tree | 47cc564eeaa486d52fe09c3794bebaa706de6e24 | |
parent | a0af653c3d1d0e4a17c9c9408ff7eb0fc697ad4b (diff) | |
download | irrlicht-a549d0bfed02801d642ef281697f8ac7c3dbc2cf.tar.xz |
Add setRelativeMode for SDL driver (#123)
-rw-r--r-- | include/ICursorControl.h | 3 | ||||
-rw-r--r-- | source/Irrlicht/CIrrDeviceSDL.h | 17 |
2 files changed, 20 insertions, 0 deletions
diff --git a/include/ICursorControl.h b/include/ICursorControl.h index 13c99c4..de9c499 100644 --- a/include/ICursorControl.h +++ b/include/ICursorControl.h @@ -160,6 +160,9 @@ namespace gui \param rect: A pointer to an reference rectangle or 0 to disable the reference rectangle.*/
virtual void setReferenceRect(core::rect<s32>* rect=0) = 0;
+ //! Internally fixes the mouse position, and reports relative mouse movement compared to the old position
+ /** Specific to SDL */
+ virtual void setRelativeMode(bool relative) {};
//! Sets the active cursor icon
/** Setting cursor icons is so far only supported on Win32 and Linux */
diff --git a/source/Irrlicht/CIrrDeviceSDL.h b/source/Irrlicht/CIrrDeviceSDL.h index e2e3654..e858399 100644 --- a/source/Irrlicht/CIrrDeviceSDL.h +++ b/source/Irrlicht/CIrrDeviceSDL.h @@ -146,6 +146,12 @@ namespace irr void setPosition(s32 x, s32 y) override
{
SDL_WarpMouseInWindow(Device->Window, x, y);
+
+ if (SDL_GetRelativeMouseMode()) {
+ // There won't be an event for this warp (details on libsdl-org/SDL/issues/6034)
+ Device->MouseX = x;
+ Device->MouseY = y;
+ }
}
//! Returns the current position of the mouse cursor.
@@ -169,6 +175,17 @@ namespace irr {
}
+ virtual void setRelativeMode(bool relative) _IRR_OVERRIDE_
+ {
+ // Only change it when necessary, as it flushes mouse motion when enabled
+ if ( relative != SDL_GetRelativeMouseMode()) {
+ if ( relative )
+ SDL_SetRelativeMouseMode( SDL_TRUE );
+ else
+ SDL_SetRelativeMouseMode( SDL_FALSE );
+ }
+ }
+
private:
void updateCursorPos()
|