diff --git a/source/application/StarApplicationController.hpp b/source/application/StarApplicationController.hpp index 69e9d00..5747268 100644 --- a/source/application/StarApplicationController.hpp +++ b/source/application/StarApplicationController.hpp @@ -41,6 +41,7 @@ public: virtual void setBorderlessWindow() = 0; virtual void setVSyncEnabled(bool vSync) = 0; virtual void setCursorVisible(bool cursorVisible) = 0; + virtual void setCursorPosition(Vec2I cursorPosition) = 0; virtual bool setCursorImage(const String& id, const ImageConstPtr& image, unsigned scale, const Vec2I& offset) = 0; virtual void setAcceptingTextInput(bool acceptingTextInput) = 0; diff --git a/source/application/StarMainApplication_sdl.cpp b/source/application/StarMainApplication_sdl.cpp index 8b8c702..d9a0bd2 100644 --- a/source/application/StarMainApplication_sdl.cpp +++ b/source/application/StarMainApplication_sdl.cpp @@ -589,6 +589,10 @@ private: parent->m_cursorVisible = cursorVisible; } + void setCursorPosition(Vec2I cursorPosition) override { + SDL_WarpMouseInWindow(parent->m_sdlWindow, cursorPosition[0], cursorPosition[1]); + } + bool setCursorImage(const String& id, const ImageConstPtr& image, unsigned scale, const Vec2I& offset) override { return parent->setCursorImage(id, image, scale, offset); } diff --git a/source/frontend/CMakeLists.txt b/source/frontend/CMakeLists.txt index b002155..c213b72 100644 --- a/source/frontend/CMakeLists.txt +++ b/source/frontend/CMakeLists.txt @@ -55,10 +55,10 @@ SET (star_frontend_HEADERS StarSongbookInterface.hpp StarStatusPane.hpp StarTeleportDialog.hpp - StarWireInterface.hpp StarVoice.hpp StarVoiceLuaBindings.hpp StarVoiceSettingsMenu.hpp + StarWireInterface.hpp ) SET (star_frontend_SOURCES @@ -106,10 +106,10 @@ SET (star_frontend_SOURCES StarSongbookInterface.cpp StarStatusPane.cpp StarTeleportDialog.cpp - StarWireInterface.cpp StarVoice.cpp StarVoiceLuaBindings.cpp StarVoiceSettingsMenu.cpp + StarWireInterface.cpp ) ADD_LIBRARY (star_frontend OBJECT ${star_frontend_SOURCES} ${star_frontend_HEADERS}) diff --git a/source/game/StarInput.cpp b/source/game/StarInput.cpp index 5629049..56de074 100644 --- a/source/game/StarInput.cpp +++ b/source/game/StarInput.cpp @@ -411,6 +411,7 @@ bool Input::handleInput(InputEvent const& input, bool gameProcessed) { } } } else if (auto mouseDown = input.ptr()) { + m_mousePosition = mouseDown->mousePosition; if (!gameProcessed) { auto& state = m_mouseStates[mouseDown->mouseButton]; state.pressPositions.append(mouseDown->mousePosition); @@ -422,6 +423,7 @@ bool Input::handleInput(InputEvent const& input, bool gameProcessed) { } } } else if (auto mouseUp = input.ptr()) { + m_mousePosition = mouseUp->mousePosition; if (auto state = m_mouseStates.ptr(mouseUp->mouseButton)) { state->releasePositions.append(mouseUp->mousePosition); state->release(); @@ -434,6 +436,9 @@ bool Input::handleInput(InputEvent const& input, bool gameProcessed) { } } } + else if (auto mouseMove = input.ptr()) { + m_mousePosition = mouseMove->mousePosition; + } return false; } @@ -556,6 +561,10 @@ Maybe> Input::mouseUp(MouseButton button) { return {}; } +Vec2I Input::mousePosition() const { + return m_mousePosition; +} + void Input::resetBinds(String const& categoryId, String const& bindId) { auto& entry = bindEntry(categoryId, bindId); diff --git a/source/game/StarInput.hpp b/source/game/StarInput.hpp index e4355ce..8cdd978 100644 --- a/source/game/StarInput.hpp +++ b/source/game/StarInput.hpp @@ -171,6 +171,8 @@ public: bool mouseHeld(MouseButton button); Maybe> mouseUp (MouseButton button); + Vec2I mousePosition() const; + void resetBinds(String const& categoryId, String const& bindId); void setBinds(String const& categoryId, String const& bindId, Json const& binds); Json getDefaultBinds(String const& categoryId, String const& bindId); @@ -205,6 +207,7 @@ private: KeyMod m_pressedMods; bool m_textInputActive; + Vec2I m_mousePosition; }; } diff --git a/source/game/scripting/StarInputLuaBindings.cpp b/source/game/scripting/StarInputLuaBindings.cpp index 71ba761..1af5a74 100644 --- a/source/game/scripting/StarInputLuaBindings.cpp +++ b/source/game/scripting/StarInputLuaBindings.cpp @@ -1,5 +1,5 @@ #include "StarInputLuaBindings.hpp" -#include "StarLuaGameConverters.hpp" +#include "StarLuaConverters.hpp" #include "StarInput.hpp" namespace Star { @@ -34,7 +34,6 @@ LuaCallbacks LuaBindings::makeInputCallbacks() { auto mouseHeld = [input](String const& buttonName) -> bool { return input->mouseHeld(MouseButtonNames.getLeft(buttonName)); }; callbacks.registerCallback("mouseHeld", mouseHeld); callbacks.registerCallback("mouse", mouseHeld); - callbacks.registerCallback("mouseUp", [input](String const& buttonName) -> Maybe> { return input->mouseUp( MouseButtonNames.getLeft(buttonName)); }); callbacks.registerCallbackWithSignature("resetBinds", bind(mem_fn(&Input::resetBinds), input, _1, _2)); @@ -53,6 +52,8 @@ LuaCallbacks LuaBindings::makeInputCallbacks() { return move(result); }); + callbacks.registerCallbackWithSignature("mousePosition", bind(mem_fn(&Input::mousePosition), input)); + return callbacks; } diff --git a/source/game/scripting/StarInputLuaBindings.hpp b/source/game/scripting/StarInputLuaBindings.hpp index f0c1f4d..77cb2f1 100644 --- a/source/game/scripting/StarInputLuaBindings.hpp +++ b/source/game/scripting/StarInputLuaBindings.hpp @@ -1,7 +1,6 @@ #ifndef STAR_INPUT_LUA_BINDINGS_HPP #define STAR_INPUT_LUA_BINDINGS_HPP -#include "StarGameTypes.hpp" #include "StarLua.hpp" namespace Star { diff --git a/source/game/scripting/StarLuaComponents.hpp b/source/game/scripting/StarLuaComponents.hpp index 2098829..a3d199c 100644 --- a/source/game/scripting/StarLuaComponents.hpp +++ b/source/game/scripting/StarLuaComponents.hpp @@ -6,7 +6,6 @@ #include "StarListener.hpp" #include "StarWorld.hpp" #include "StarWorldLuaBindings.hpp" -#include "StarInputLuaBindings.hpp" namespace Star {