mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-26 09:35:28 +00:00
Move cursor update to the MouseManager
This commit is contained in:
parent
b3b8480d49
commit
b00d72b9e4
@ -30,8 +30,7 @@ namespace MWInput
|
|||||||
osgViewer::ScreenCaptureHandler::CaptureOperation *screenCaptureOperation,
|
osgViewer::ScreenCaptureHandler::CaptureOperation *screenCaptureOperation,
|
||||||
const std::string& userFile, bool userFileExists, const std::string& userControllerBindingsFile,
|
const std::string& userFile, bool userFileExists, const std::string& userControllerBindingsFile,
|
||||||
const std::string& controllerBindingsFile, bool grab)
|
const std::string& controllerBindingsFile, bool grab)
|
||||||
: mGrabCursor(Settings::Manager::getBool("grab cursor", "Input"))
|
: mControlsDisabled(false)
|
||||||
, mControlsDisabled(false)
|
|
||||||
{
|
{
|
||||||
mInputWrapper = new SDLUtil::InputWrapper(window, viewer, grab);
|
mInputWrapper = new SDLUtil::InputWrapper(window, viewer, grab);
|
||||||
mInputWrapper->setWindowEventCallback(MWBase::Environment::get().getWindowManager());
|
mInputWrapper->setWindowEventCallback(MWBase::Environment::get().getWindowManager());
|
||||||
@ -81,29 +80,6 @@ namespace MWInput
|
|||||||
mActionManager->setAttemptJump(jumping);
|
mActionManager->setAttemptJump(jumping);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputManager::updateCursorMode()
|
|
||||||
{
|
|
||||||
bool grab = !MWBase::Environment::get().getWindowManager()->containsMode(MWGui::GM_MainMenu)
|
|
||||||
&& !MWBase::Environment::get().getWindowManager()->isConsoleMode();
|
|
||||||
|
|
||||||
bool wasRelative = mInputWrapper->getMouseRelative();
|
|
||||||
bool isRelative = !MWBase::Environment::get().getWindowManager()->isGuiMode();
|
|
||||||
|
|
||||||
// don't keep the pointer away from the window edge in gui mode
|
|
||||||
// stop using raw mouse motions and switch to system cursor movements
|
|
||||||
mInputWrapper->setMouseRelative(isRelative);
|
|
||||||
|
|
||||||
//we let the mouse escape in the main menu
|
|
||||||
mInputWrapper->setGrabPointer(grab && (mGrabCursor || isRelative));
|
|
||||||
|
|
||||||
//we switched to non-relative mode, move our cursor to where the in-game
|
|
||||||
//cursor is
|
|
||||||
if (!isRelative && wasRelative != isRelative)
|
|
||||||
{
|
|
||||||
mMouseManager->warpMouse();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void InputManager::update(float dt, bool disableControls, bool disableEvents)
|
void InputManager::update(float dt, bool disableControls, bool disableEvents)
|
||||||
{
|
{
|
||||||
mControlsDisabled = disableControls;
|
mControlsDisabled = disableControls;
|
||||||
@ -113,13 +89,13 @@ namespace MWInput
|
|||||||
|
|
||||||
if (disableControls)
|
if (disableControls)
|
||||||
{
|
{
|
||||||
updateCursorMode();
|
mMouseManager->updateCursorMode();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mBindingsManager->update(dt);
|
mBindingsManager->update(dt);
|
||||||
|
|
||||||
updateCursorMode();
|
mMouseManager->updateCursorMode();
|
||||||
|
|
||||||
bool controllerMove = mControllerManager->update(dt);
|
bool controllerMove = mControllerManager->update(dt);
|
||||||
mMouseManager->update(dt);
|
mMouseManager->update(dt);
|
||||||
@ -153,12 +129,6 @@ namespace MWInput
|
|||||||
|
|
||||||
void InputManager::processChangedSettings(const Settings::CategorySettingVector& changed)
|
void InputManager::processChangedSettings(const Settings::CategorySettingVector& changed)
|
||||||
{
|
{
|
||||||
for (const auto& setting : changed)
|
|
||||||
{
|
|
||||||
if (setting.first == "Input" && setting.second == "grab cursor")
|
|
||||||
mGrabCursor = Settings::Manager::getBool("grab cursor", "Input");
|
|
||||||
}
|
|
||||||
|
|
||||||
mMouseManager->processChangedSettings(changed);
|
mMouseManager->processChangedSettings(changed);
|
||||||
mSensorManager->processChangedSettings(changed);
|
mSensorManager->processChangedSettings(changed);
|
||||||
}
|
}
|
||||||
|
@ -101,8 +101,6 @@ namespace MWInput
|
|||||||
|
|
||||||
void handleGuiArrowKey(int action);
|
void handleGuiArrowKey(int action);
|
||||||
|
|
||||||
void updateCursorMode();
|
|
||||||
|
|
||||||
void quickKey(int index);
|
void quickKey(int index);
|
||||||
void showQuickKeysMenu();
|
void showQuickKeysMenu();
|
||||||
|
|
||||||
@ -111,7 +109,6 @@ namespace MWInput
|
|||||||
|
|
||||||
SDLUtil::InputWrapper* mInputWrapper;
|
SDLUtil::InputWrapper* mInputWrapper;
|
||||||
|
|
||||||
bool mGrabCursor;
|
|
||||||
bool mControlsDisabled;
|
bool mControlsDisabled;
|
||||||
|
|
||||||
ControlSwitch* mControlSwitch;
|
ControlSwitch* mControlSwitch;
|
||||||
|
@ -24,8 +24,9 @@ namespace MWInput
|
|||||||
MouseManager::MouseManager(BindingsManager* bindingsManager, SDLUtil::InputWrapper* inputWrapper, SDL_Window* window)
|
MouseManager::MouseManager(BindingsManager* bindingsManager, SDLUtil::InputWrapper* inputWrapper, SDL_Window* window)
|
||||||
: mInvertX(Settings::Manager::getBool("invert x axis", "Input"))
|
: mInvertX(Settings::Manager::getBool("invert x axis", "Input"))
|
||||||
, mInvertY(Settings::Manager::getBool("invert y axis", "Input"))
|
, mInvertY(Settings::Manager::getBool("invert y axis", "Input"))
|
||||||
, mCameraSensitivity (Settings::Manager::getFloat("camera sensitivity", "Input"))
|
, mGrabCursor(Settings::Manager::getBool("grab cursor", "Input"))
|
||||||
, mCameraYMultiplier (Settings::Manager::getFloat("camera y multiplier", "Input"))
|
, mCameraSensitivity(Settings::Manager::getFloat("camera sensitivity", "Input"))
|
||||||
|
, mCameraYMultiplier(Settings::Manager::getFloat("camera y multiplier", "Input"))
|
||||||
, mBindingsManager(bindingsManager)
|
, mBindingsManager(bindingsManager)
|
||||||
, mInputWrapper(inputWrapper)
|
, mInputWrapper(inputWrapper)
|
||||||
, mInvUiScalingFactor(1.f)
|
, mInvUiScalingFactor(1.f)
|
||||||
@ -58,6 +59,9 @@ namespace MWInput
|
|||||||
|
|
||||||
if (setting.first == "Input" && setting.second == "camera sensitivity")
|
if (setting.first == "Input" && setting.second == "camera sensitivity")
|
||||||
mCameraSensitivity = Settings::Manager::getFloat("camera sensitivity", "Input");
|
mCameraSensitivity = Settings::Manager::getFloat("camera sensitivity", "Input");
|
||||||
|
|
||||||
|
if (setting.first == "Input" && setting.second == "grab cursor")
|
||||||
|
mGrabCursor = Settings::Manager::getBool("grab cursor", "Input");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,6 +173,29 @@ namespace MWInput
|
|||||||
mBindingsManager->mousePressed(arg, id);
|
mBindingsManager->mousePressed(arg, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MouseManager::updateCursorMode()
|
||||||
|
{
|
||||||
|
bool grab = !MWBase::Environment::get().getWindowManager()->containsMode(MWGui::GM_MainMenu)
|
||||||
|
&& !MWBase::Environment::get().getWindowManager()->isConsoleMode();
|
||||||
|
|
||||||
|
bool wasRelative = mInputWrapper->getMouseRelative();
|
||||||
|
bool isRelative = !MWBase::Environment::get().getWindowManager()->isGuiMode();
|
||||||
|
|
||||||
|
// don't keep the pointer away from the window edge in gui mode
|
||||||
|
// stop using raw mouse motions and switch to system cursor movements
|
||||||
|
mInputWrapper->setMouseRelative(isRelative);
|
||||||
|
|
||||||
|
//we let the mouse escape in the main menu
|
||||||
|
mInputWrapper->setGrabPointer(grab && (mGrabCursor || isRelative));
|
||||||
|
|
||||||
|
//we switched to non-relative mode, move our cursor to where the in-game
|
||||||
|
//cursor is
|
||||||
|
if (!isRelative && wasRelative != isRelative)
|
||||||
|
{
|
||||||
|
warpMouse();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MouseManager::update(float dt)
|
void MouseManager::update(float dt)
|
||||||
{
|
{
|
||||||
if (!mMouseLookEnabled)
|
if (!mMouseLookEnabled)
|
||||||
|
@ -20,6 +20,7 @@ namespace MWInput
|
|||||||
|
|
||||||
virtual ~MouseManager() = default;
|
virtual ~MouseManager() = default;
|
||||||
|
|
||||||
|
void updateCursorMode();
|
||||||
void update(float dt);
|
void update(float dt);
|
||||||
|
|
||||||
virtual void mouseMoved(const SDLUtil::MouseMotionEvent &arg);
|
virtual void mouseMoved(const SDLUtil::MouseMotionEvent &arg);
|
||||||
@ -40,6 +41,7 @@ namespace MWInput
|
|||||||
private:
|
private:
|
||||||
bool mInvertX;
|
bool mInvertX;
|
||||||
bool mInvertY;
|
bool mInvertY;
|
||||||
|
bool mGrabCursor;
|
||||||
float mCameraSensitivity;
|
float mCameraSensitivity;
|
||||||
float mCameraYMultiplier;
|
float mCameraYMultiplier;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user