mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-15 22:49:48 +00:00
Mouse input engine handlers
This commit is contained in:
parent
3301ebb2cb
commit
c68dee214e
@ -81,6 +81,12 @@ namespace MWBase
|
||||
|
||||
struct InputEvent
|
||||
{
|
||||
struct WheelChange
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
KeyPressed,
|
||||
@ -91,8 +97,11 @@ namespace MWBase
|
||||
TouchPressed,
|
||||
TouchReleased,
|
||||
TouchMoved,
|
||||
MouseButtonPressed,
|
||||
MouseButtonReleased,
|
||||
MouseWheel,
|
||||
} mType;
|
||||
std::variant<SDL_Keysym, int, SDLUtil::TouchEvent> mValue;
|
||||
std::variant<SDL_Keysym, int, SDLUtil::TouchEvent, WheelChange> mValue;
|
||||
};
|
||||
virtual void inputEvent(const InputEvent& event) = 0;
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwbase/inputmanager.hpp"
|
||||
#include "../mwbase/luamanager.hpp"
|
||||
#include "../mwbase/windowmanager.hpp"
|
||||
#include "../mwbase/world.hpp"
|
||||
|
||||
@ -118,6 +119,8 @@ namespace MWInput
|
||||
|
||||
mBindingsManager->setPlayerControlsEnabled(!guiMode);
|
||||
mBindingsManager->mouseReleased(arg, id);
|
||||
MWBase::Environment::get().getLuaManager()->inputEvent(
|
||||
{ MWBase::LuaManager::InputEvent::MouseButtonReleased, arg.button });
|
||||
}
|
||||
}
|
||||
|
||||
@ -125,7 +128,11 @@ namespace MWInput
|
||||
{
|
||||
MWBase::InputManager* input = MWBase::Environment::get().getInputManager();
|
||||
if (mBindingsManager->isDetectingBindingState() || !input->controlsDisabled())
|
||||
{
|
||||
mBindingsManager->mouseWheelMoved(arg);
|
||||
MWBase::Environment::get().getLuaManager()->inputEvent({ MWBase::LuaManager::InputEvent::MouseWheel,
|
||||
MWBase::LuaManager::InputEvent::WheelChange{ arg.x, arg.y } });
|
||||
}
|
||||
|
||||
input->setJoystickLastUsed(false);
|
||||
}
|
||||
@ -161,7 +168,11 @@ namespace MWInput
|
||||
const MWGui::SettingsWindow* settingsWindow
|
||||
= MWBase::Environment::get().getWindowManager()->getSettingsWindow();
|
||||
if ((!settingsWindow || !settingsWindow->isVisible()) && !input->controlsDisabled())
|
||||
{
|
||||
mBindingsManager->mousePressed(arg, id);
|
||||
MWBase::Environment::get().getLuaManager()->inputEvent(
|
||||
{ MWBase::LuaManager::InputEvent::MouseButtonPressed, arg.button });
|
||||
}
|
||||
}
|
||||
|
||||
void MouseManager::updateCursorMode()
|
||||
|
@ -18,7 +18,7 @@ namespace MWLua
|
||||
{
|
||||
mScriptsContainer->registerEngineHandlers({ &mKeyPressHandlers, &mKeyReleaseHandlers,
|
||||
&mControllerButtonPressHandlers, &mControllerButtonReleaseHandlers, &mActionHandlers, &mTouchpadPressed,
|
||||
&mTouchpadReleased, &mTouchpadMoved });
|
||||
&mTouchpadReleased, &mTouchpadMoved, &mMouseButtonPress, &mMouseButtonRelease, &mMouseWheel });
|
||||
}
|
||||
|
||||
void processInputEvent(const MWBase::LuaManager::InputEvent& event)
|
||||
@ -53,6 +53,16 @@ namespace MWLua
|
||||
case InputEvent::TouchMoved:
|
||||
mScriptsContainer->callEngineHandlers(mTouchpadMoved, std::get<SDLUtil::TouchEvent>(event.mValue));
|
||||
break;
|
||||
case InputEvent::MouseButtonPressed:
|
||||
mScriptsContainer->callEngineHandlers(mMouseButtonPress, std::get<int>(event.mValue));
|
||||
break;
|
||||
case InputEvent::MouseButtonReleased:
|
||||
mScriptsContainer->callEngineHandlers(mMouseButtonRelease, std::get<int>(event.mValue));
|
||||
break;
|
||||
case InputEvent::MouseWheel:
|
||||
auto wheelEvent = std::get<MWBase::LuaManager::InputEvent::WheelChange>(event.mValue);
|
||||
mScriptsContainer->callEngineHandlers(mMouseWheel, wheelEvent.y, wheelEvent.x);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,6 +76,9 @@ namespace MWLua
|
||||
typename Container::EngineHandlerList mTouchpadPressed{ "onTouchPress" };
|
||||
typename Container::EngineHandlerList mTouchpadReleased{ "onTouchRelease" };
|
||||
typename Container::EngineHandlerList mTouchpadMoved{ "onTouchMove" };
|
||||
typename Container::EngineHandlerList mMouseButtonPress{ "onMouseButtonPress" };
|
||||
typename Container::EngineHandlerList mMouseButtonRelease{ "onMouseButtonRelease" };
|
||||
typename Container::EngineHandlerList mMouseWheel{ "onMouseWheel" };
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -124,6 +124,15 @@ Engine handler is a function defined by a script, that can be called by the engi
|
||||
* - onTouchMove(touchEvent)
|
||||
- | A finger moved on a touch device.
|
||||
| `Touch event <openmw_input.html##(TouchEvent)>`_.
|
||||
* - onMouseButtonPress(button)
|
||||
- | A mouse button was pressed
|
||||
| Button id
|
||||
* - onMouseButtonRelease(button)
|
||||
- | A mouse button was released
|
||||
| Button id
|
||||
* - onMouseWheel(vertical, horizontal)
|
||||
- | Mouse wheel was scrolled
|
||||
| vertical and horizontal mouse wheel change
|
||||
* - | onConsoleCommand(
|
||||
| mode, command, selectedObject)
|
||||
- | User entered `command` in in-game console. Called if either
|
||||
|
Loading…
Reference in New Issue
Block a user