mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-03-29 19:06:41 +00:00
use native relative mouse movements where available, have the cursor follow the hardware cursor in the main menu
This commit is contained in:
parent
02ccb75894
commit
53cff0ba68
3 changed files with 68 additions and 13 deletions
|
@ -218,11 +218,23 @@ namespace MWInput
|
||||||
|
|
||||||
if(!mDebug)
|
if(!mDebug)
|
||||||
{
|
{
|
||||||
//don't keep the pointer away from the window edge in GUI mode
|
bool main_menu = mWindows.containsMode(MWGui::GM_MainMenu);
|
||||||
mInputManager->setWrapPointer(!mWindows.isGuiMode());
|
|
||||||
|
bool was_relative = mInputManager->getMouseRelative();
|
||||||
|
bool is_relative = !main_menu;
|
||||||
|
|
||||||
|
//don't keep the pointer away from the window edge in the main menu
|
||||||
|
mInputManager->setMouseRelative(is_relative);
|
||||||
|
|
||||||
|
//we switched to non-relative mode, move our cursor to where the in-game
|
||||||
|
//cursor is
|
||||||
|
if( !is_relative && was_relative != is_relative )
|
||||||
|
{
|
||||||
|
mInputManager->warpMouse(mMouseX, mMouseY);
|
||||||
|
}
|
||||||
|
|
||||||
//we let the mouse escape in the main menu
|
//we let the mouse escape in the main menu
|
||||||
mInputManager->setGrabPointer(!mWindows.containsMode(MWGui::GM_MainMenu));
|
mInputManager->setGrabPointer(!main_menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable movement in Gui mode
|
// Disable movement in Gui mode
|
||||||
|
@ -454,8 +466,19 @@ namespace MWInput
|
||||||
|
|
||||||
// We keep track of our own mouse position, so that moving the mouse while in
|
// We keep track of our own mouse position, so that moving the mouse while in
|
||||||
// game mode does not move the position of the GUI cursor
|
// game mode does not move the position of the GUI cursor
|
||||||
mMouseX += float(arg.xrel) * mUISensitivity;
|
|
||||||
mMouseY += float(arg.yrel) * mUISensitivity * mUIYMultiplier;
|
//FIXME: Except in the main menu, since we let the pointer escape
|
||||||
|
if(!mWindows.containsMode(MWGui::GM_MainMenu))
|
||||||
|
{
|
||||||
|
mMouseX += float(arg.xrel) * mUISensitivity;
|
||||||
|
mMouseY += float(arg.yrel) * mUISensitivity * mUIYMultiplier;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mMouseX = arg.x;
|
||||||
|
mMouseY = arg.y;
|
||||||
|
}
|
||||||
|
|
||||||
mMouseX = std::max(0.f, std::min(mMouseX, float(viewSize.width)));
|
mMouseX = std::max(0.f, std::min(mMouseX, float(viewSize.width)));
|
||||||
mMouseY = std::max(0.f, std::min(mMouseY, float(viewSize.height)));
|
mMouseY = std::max(0.f, std::min(mMouseY, float(viewSize.height)));
|
||||||
|
|
||||||
|
@ -499,10 +522,11 @@ namespace MWInput
|
||||||
|
|
||||||
void InputManager::toggleMainMenu()
|
void InputManager::toggleMainMenu()
|
||||||
{
|
{
|
||||||
if (mWindows.isGuiMode () && (mWindows.getMode () == MWGui::GM_MainMenu || mWindows.getMode () == MWGui::GM_Settings))
|
//TODO: should this be here?
|
||||||
mWindows.popGuiMode();
|
if (mWindows.isGuiMode () && mWindows.getMode () == MWGui::GM_Video)
|
||||||
else if (mWindows.isGuiMode () && mWindows.getMode () == MWGui::GM_Video)
|
|
||||||
MWBase::Environment::get().getWorld ()->stopVideo ();
|
MWBase::Environment::get().getWorld ()->stopVideo ();
|
||||||
|
else if (mWindows.containsMode(MWGui::GM_MainMenu))
|
||||||
|
mWindows.popGuiMode();
|
||||||
else
|
else
|
||||||
mWindows.pushGuiMode (MWGui::GM_MainMenu);
|
mWindows.pushGuiMode (MWGui::GM_MainMenu);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,9 @@ namespace MWInput
|
||||||
mWindow(window),
|
mWindow(window),
|
||||||
mSDLWindow(NULL),
|
mSDLWindow(NULL),
|
||||||
mWarpCompensate(false),
|
mWarpCompensate(false),
|
||||||
mWrapPointer(false),
|
mMouseRelative(false),
|
||||||
mGrabPointer(false)
|
mGrabPointer(false),
|
||||||
|
mWrapPointer(false)
|
||||||
{
|
{
|
||||||
_start();
|
_start();
|
||||||
}
|
}
|
||||||
|
@ -166,9 +167,34 @@ namespace MWInput
|
||||||
SDL_SetWindowGrab(mSDLWindow, sdlGrab);
|
SDL_SetWindowGrab(mSDLWindow, sdlGrab);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MWSDLInputWrapper::setMouseRelative(bool relative)
|
||||||
|
{
|
||||||
|
if(mMouseRelative == relative)
|
||||||
|
return;
|
||||||
|
|
||||||
|
mMouseRelative = relative;
|
||||||
|
|
||||||
|
mWrapPointer = false;
|
||||||
|
|
||||||
|
//eep, wrap the pointer manually if the input driver doesn't support
|
||||||
|
//relative positioning natively
|
||||||
|
if(SDL_SetRelativeMouseMode(relative ? SDL_TRUE : SDL_FALSE) == -1)
|
||||||
|
{
|
||||||
|
if(relative)
|
||||||
|
mWrapPointer = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//now remove all mouse events using the old setting from the queue
|
||||||
|
SDL_PumpEvents();
|
||||||
|
|
||||||
|
SDL_Event dummy[20];
|
||||||
|
SDL_PeepEvents(dummy, 20, SDL_GETEVENT, SDL_MOUSEMOTION, SDL_MOUSEMOTION);
|
||||||
|
}
|
||||||
|
|
||||||
bool MWSDLInputWrapper::_handleWarpMotion(const SDL_MouseMotionEvent& evt)
|
bool MWSDLInputWrapper::_handleWarpMotion(const SDL_MouseMotionEvent& evt)
|
||||||
{
|
{
|
||||||
if(!mWarpCompensate) return false;
|
if(!mWarpCompensate)
|
||||||
|
return false;
|
||||||
|
|
||||||
//this was a warp event, signal the caller to eat it.
|
//this was a warp event, signal the caller to eat it.
|
||||||
if(evt.x == mWarpX && evt.y == mWarpY)
|
if(evt.x == mWarpX && evt.y == mWarpY)
|
||||||
|
@ -182,7 +208,10 @@ namespace MWInput
|
||||||
|
|
||||||
void MWSDLInputWrapper::_wrapMousePointer(const SDL_MouseMotionEvent& evt)
|
void MWSDLInputWrapper::_wrapMousePointer(const SDL_MouseMotionEvent& evt)
|
||||||
{
|
{
|
||||||
if(!mWrapPointer || !mGrabPointer) return;
|
//don't wrap if we don't want relative movements, support relative
|
||||||
|
//movements natively, or aren't grabbing anyways
|
||||||
|
if(!mMouseRelative || !mWrapPointer || !mGrabPointer)
|
||||||
|
return;
|
||||||
|
|
||||||
int width = 0;
|
int width = 0;
|
||||||
int height = 0;
|
int height = 0;
|
||||||
|
|
|
@ -21,7 +21,8 @@ namespace MWInput
|
||||||
void capture();
|
void capture();
|
||||||
bool isModifierHeld(int mod);
|
bool isModifierHeld(int mod);
|
||||||
|
|
||||||
void setWrapPointer(bool wrap) { mWrapPointer = wrap; }
|
void setMouseRelative(bool relative);
|
||||||
|
bool getMouseRelative() { return mMouseRelative; }
|
||||||
void setGrabPointer(bool grab);
|
void setGrabPointer(bool grab);
|
||||||
|
|
||||||
void warpMouse(int x, int y);
|
void warpMouse(int x, int y);
|
||||||
|
@ -38,6 +39,7 @@ namespace MWInput
|
||||||
Uint16 mWarpX;
|
Uint16 mWarpX;
|
||||||
Uint16 mWarpY;
|
Uint16 mWarpY;
|
||||||
bool mWarpCompensate;
|
bool mWarpCompensate;
|
||||||
|
bool mMouseRelative;
|
||||||
bool mWrapPointer;
|
bool mWrapPointer;
|
||||||
bool mGrabPointer;
|
bool mGrabPointer;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue