Add input.mousePosition
This commit is contained in:
parent
2cf97d763c
commit
0497048b44
@ -41,6 +41,7 @@ public:
|
|||||||
virtual void setBorderlessWindow() = 0;
|
virtual void setBorderlessWindow() = 0;
|
||||||
virtual void setVSyncEnabled(bool vSync) = 0;
|
virtual void setVSyncEnabled(bool vSync) = 0;
|
||||||
virtual void setCursorVisible(bool cursorVisible) = 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 bool setCursorImage(const String& id, const ImageConstPtr& image, unsigned scale, const Vec2I& offset) = 0;
|
||||||
virtual void setAcceptingTextInput(bool acceptingTextInput) = 0;
|
virtual void setAcceptingTextInput(bool acceptingTextInput) = 0;
|
||||||
|
|
||||||
|
@ -589,6 +589,10 @@ private:
|
|||||||
parent->m_cursorVisible = cursorVisible;
|
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 {
|
bool setCursorImage(const String& id, const ImageConstPtr& image, unsigned scale, const Vec2I& offset) override {
|
||||||
return parent->setCursorImage(id, image, scale, offset);
|
return parent->setCursorImage(id, image, scale, offset);
|
||||||
}
|
}
|
||||||
|
@ -55,10 +55,10 @@ SET (star_frontend_HEADERS
|
|||||||
StarSongbookInterface.hpp
|
StarSongbookInterface.hpp
|
||||||
StarStatusPane.hpp
|
StarStatusPane.hpp
|
||||||
StarTeleportDialog.hpp
|
StarTeleportDialog.hpp
|
||||||
StarWireInterface.hpp
|
|
||||||
StarVoice.hpp
|
StarVoice.hpp
|
||||||
StarVoiceLuaBindings.hpp
|
StarVoiceLuaBindings.hpp
|
||||||
StarVoiceSettingsMenu.hpp
|
StarVoiceSettingsMenu.hpp
|
||||||
|
StarWireInterface.hpp
|
||||||
)
|
)
|
||||||
|
|
||||||
SET (star_frontend_SOURCES
|
SET (star_frontend_SOURCES
|
||||||
@ -106,10 +106,10 @@ SET (star_frontend_SOURCES
|
|||||||
StarSongbookInterface.cpp
|
StarSongbookInterface.cpp
|
||||||
StarStatusPane.cpp
|
StarStatusPane.cpp
|
||||||
StarTeleportDialog.cpp
|
StarTeleportDialog.cpp
|
||||||
StarWireInterface.cpp
|
|
||||||
StarVoice.cpp
|
StarVoice.cpp
|
||||||
StarVoiceLuaBindings.cpp
|
StarVoiceLuaBindings.cpp
|
||||||
StarVoiceSettingsMenu.cpp
|
StarVoiceSettingsMenu.cpp
|
||||||
|
StarWireInterface.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
ADD_LIBRARY (star_frontend OBJECT ${star_frontend_SOURCES} ${star_frontend_HEADERS})
|
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>()) {
|
} else if (auto mouseDown = input.ptr<MouseButtonDownEvent>()) {
|
||||||
|
m_mousePosition = mouseDown->mousePosition;
|
||||||
if (!gameProcessed) {
|
if (!gameProcessed) {
|
||||||
auto& state = m_mouseStates[mouseDown->mouseButton];
|
auto& state = m_mouseStates[mouseDown->mouseButton];
|
||||||
state.pressPositions.append(mouseDown->mousePosition);
|
state.pressPositions.append(mouseDown->mousePosition);
|
||||||
@ -422,6 +423,7 @@ bool Input::handleInput(InputEvent const& input, bool gameProcessed) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (auto mouseUp = input.ptr<MouseButtonUpEvent>()) {
|
} else if (auto mouseUp = input.ptr<MouseButtonUpEvent>()) {
|
||||||
|
m_mousePosition = mouseUp->mousePosition;
|
||||||
if (auto state = m_mouseStates.ptr(mouseUp->mouseButton)) {
|
if (auto state = m_mouseStates.ptr(mouseUp->mouseButton)) {
|
||||||
state->releasePositions.append(mouseUp->mousePosition);
|
state->releasePositions.append(mouseUp->mousePosition);
|
||||||
state->release();
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
@ -556,6 +561,10 @@ Maybe<List<Vec2I>> Input::mouseUp(MouseButton button) {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vec2I Input::mousePosition() const {
|
||||||
|
return m_mousePosition;
|
||||||
|
}
|
||||||
|
|
||||||
void Input::resetBinds(String const& categoryId, String const& bindId) {
|
void Input::resetBinds(String const& categoryId, String const& bindId) {
|
||||||
auto& entry = bindEntry(categoryId, bindId);
|
auto& entry = bindEntry(categoryId, bindId);
|
||||||
|
|
||||||
|
@ -171,6 +171,8 @@ public:
|
|||||||
bool mouseHeld(MouseButton button);
|
bool mouseHeld(MouseButton button);
|
||||||
Maybe<List<Vec2I>> mouseUp (MouseButton button);
|
Maybe<List<Vec2I>> mouseUp (MouseButton button);
|
||||||
|
|
||||||
|
Vec2I mousePosition() const;
|
||||||
|
|
||||||
void resetBinds(String const& categoryId, String const& bindId);
|
void resetBinds(String const& categoryId, String const& bindId);
|
||||||
void setBinds(String const& categoryId, String const& bindId, Json const& binds);
|
void setBinds(String const& categoryId, String const& bindId, Json const& binds);
|
||||||
Json getDefaultBinds(String const& categoryId, String const& bindId);
|
Json getDefaultBinds(String const& categoryId, String const& bindId);
|
||||||
@ -205,6 +207,7 @@ private:
|
|||||||
|
|
||||||
KeyMod m_pressedMods;
|
KeyMod m_pressedMods;
|
||||||
bool m_textInputActive;
|
bool m_textInputActive;
|
||||||
|
Vec2I m_mousePosition;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#include "StarInputLuaBindings.hpp"
|
#include "StarInputLuaBindings.hpp"
|
||||||
#include "StarLuaGameConverters.hpp"
|
#include "StarLuaConverters.hpp"
|
||||||
#include "StarInput.hpp"
|
#include "StarInput.hpp"
|
||||||
|
|
||||||
namespace Star {
|
namespace Star {
|
||||||
@ -34,7 +34,6 @@ LuaCallbacks LuaBindings::makeInputCallbacks() {
|
|||||||
auto mouseHeld = [input](String const& buttonName) -> bool { return input->mouseHeld(MouseButtonNames.getLeft(buttonName)); };
|
auto mouseHeld = [input](String const& buttonName) -> bool { return input->mouseHeld(MouseButtonNames.getLeft(buttonName)); };
|
||||||
callbacks.registerCallback("mouseHeld", mouseHeld);
|
callbacks.registerCallback("mouseHeld", mouseHeld);
|
||||||
callbacks.registerCallback("mouse", mouseHeld);
|
callbacks.registerCallback("mouse", mouseHeld);
|
||||||
|
|
||||||
callbacks.registerCallback("mouseUp", [input](String const& buttonName) -> Maybe<List<Vec2I>> { return input->mouseUp( MouseButtonNames.getLeft(buttonName)); });
|
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));
|
callbacks.registerCallbackWithSignature<void, String, String>("resetBinds", bind(mem_fn(&Input::resetBinds), input, _1, _2));
|
||||||
@ -53,6 +52,8 @@ LuaCallbacks LuaBindings::makeInputCallbacks() {
|
|||||||
return move(result);
|
return move(result);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
callbacks.registerCallbackWithSignature<Vec2I>("mousePosition", bind(mem_fn(&Input::mousePosition), input));
|
||||||
|
|
||||||
return callbacks;
|
return callbacks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#ifndef STAR_INPUT_LUA_BINDINGS_HPP
|
#ifndef STAR_INPUT_LUA_BINDINGS_HPP
|
||||||
#define STAR_INPUT_LUA_BINDINGS_HPP
|
#define STAR_INPUT_LUA_BINDINGS_HPP
|
||||||
|
|
||||||
#include "StarGameTypes.hpp"
|
|
||||||
#include "StarLua.hpp"
|
#include "StarLua.hpp"
|
||||||
|
|
||||||
namespace Star {
|
namespace Star {
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
#include "StarListener.hpp"
|
#include "StarListener.hpp"
|
||||||
#include "StarWorld.hpp"
|
#include "StarWorld.hpp"
|
||||||
#include "StarWorldLuaBindings.hpp"
|
#include "StarWorldLuaBindings.hpp"
|
||||||
#include "StarInputLuaBindings.hpp"
|
|
||||||
|
|
||||||
namespace Star {
|
namespace Star {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user