Add input.mousePosition
This commit is contained in:
parent
2cf97d763c
commit
0497048b44
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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})
|
||||
|
@ -411,6 +411,7 @@ bool Input::handleInput(InputEvent const& input, bool gameProcessed) {
|
||||
}
|
||||
}
|
||||
} else if (auto mouseDown = input.ptr<MouseButtonDownEvent>()) {
|
||||
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<MouseButtonUpEvent>()) {
|
||||
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<MouseMoveEvent>()) {
|
||||
m_mousePosition = mouseMove->mousePosition;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -556,6 +561,10 @@ Maybe<List<Vec2I>> 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);
|
||||
|
||||
|
@ -171,6 +171,8 @@ public:
|
||||
bool mouseHeld(MouseButton button);
|
||||
Maybe<List<Vec2I>> 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;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -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<List<Vec2I>> { return input->mouseUp( MouseButtonNames.getLeft(buttonName)); });
|
||||
|
||||
callbacks.registerCallbackWithSignature<void, String, String>("resetBinds", bind(mem_fn(&Input::resetBinds), input, _1, _2));
|
||||
@ -53,6 +52,8 @@ LuaCallbacks LuaBindings::makeInputCallbacks() {
|
||||
return move(result);
|
||||
});
|
||||
|
||||
callbacks.registerCallbackWithSignature<Vec2I>("mousePosition", bind(mem_fn(&Input::mousePosition), input));
|
||||
|
||||
return callbacks;
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
#ifndef STAR_INPUT_LUA_BINDINGS_HPP
|
||||
#define STAR_INPUT_LUA_BINDINGS_HPP
|
||||
|
||||
#include "StarGameTypes.hpp"
|
||||
#include "StarLua.hpp"
|
||||
|
||||
namespace Star {
|
||||
|
@ -6,7 +6,6 @@
|
||||
#include "StarListener.hpp"
|
||||
#include "StarWorld.hpp"
|
||||
#include "StarWorldLuaBindings.hpp"
|
||||
#include "StarInputLuaBindings.hpp"
|
||||
|
||||
namespace Star {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user