mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-04 18:11:01 -05:00
Move interaction/input related code form navigation handler to a global interaction handler
This commit is contained in:
@@ -37,6 +37,7 @@ namespace interaction {
|
||||
struct WebsocketInputStates;
|
||||
class ActionManager;
|
||||
class InteractionMonitor;
|
||||
class InteractionHandler;
|
||||
class KeybindingManager;
|
||||
class KeyframeRecordingHandler;
|
||||
class NavigationHandler;
|
||||
@@ -91,7 +92,8 @@ inline VersionChecker* versionChecker;
|
||||
inline WindowDelegate* windowDelegate;
|
||||
inline Configuration* configuration;
|
||||
inline interaction::ActionManager* actionManager;
|
||||
inline interaction::InteractionMonitor* interactionMonitor;
|
||||
inline interaction::InteractionMonitor* interactionMonitor; // TODO: Move into interactionhandler
|
||||
inline interaction::InteractionHandler* interactionHandler;
|
||||
inline interaction::JoystickInputStates* joystickInputStates;
|
||||
inline interaction::WebsocketInputStates* websocketInputStates;
|
||||
inline interaction::KeybindingManager* keybindingManager;
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2025 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef __OPENSPACE_CORE___INTERACTIONHANDLER___H__
|
||||
#define __OPENSPACE_CORE___INTERACTIONHANDLER___H__
|
||||
|
||||
#include <openspace/properties/propertyowner.h>
|
||||
|
||||
#include <openspace/interaction/keyboardinputstate.h>
|
||||
#include <openspace/interaction/mouseinputstate.h>
|
||||
#include <openspace/properties/scalar/boolproperty.h>
|
||||
#include <openspace/properties/scalar/floatproperty.h>
|
||||
#include <openspace/properties/vector/vec4property.h>
|
||||
|
||||
namespace openspace::interaction {
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
class InteractionHandler: public properties::PropertyOwner {
|
||||
public:
|
||||
InteractionHandler();
|
||||
virtual ~InteractionHandler() override;
|
||||
|
||||
void initialize();
|
||||
void deinitialize();
|
||||
|
||||
const MouseInputState& mouseInputState() const;
|
||||
const KeyboardInputState& keyboardInputState() const;
|
||||
|
||||
bool disabledKeybindings() const;
|
||||
bool disabledMouse() const;
|
||||
bool disabledJoystick() const;
|
||||
|
||||
void keyboardCallback(Key key, KeyModifier modifier, KeyAction action);
|
||||
|
||||
void mouseButtonCallback(MouseButton button, MouseAction action);
|
||||
void mousePositionCallback(double x, double y);
|
||||
void mouseScrollWheelCallback(double pos);
|
||||
|
||||
void renderOverlay() const;
|
||||
|
||||
void clearGlobalJoystickStates();
|
||||
|
||||
private:
|
||||
MouseInputState _mouseInputState;
|
||||
KeyboardInputState _keyboardInputState;
|
||||
|
||||
// TODO: add joystick and websocket input state
|
||||
|
||||
properties::BoolProperty _disableKeybindings;
|
||||
properties::BoolProperty _disableMouseInputs;
|
||||
properties::BoolProperty _disableJoystickInputs;
|
||||
|
||||
struct {
|
||||
properties::PropertyOwner owner;
|
||||
properties::BoolProperty enable;
|
||||
properties::Vec4Property color;
|
||||
|
||||
bool isMouseFirstPress = false;
|
||||
bool isMousePressed = false;
|
||||
glm::vec2 clickPosition;
|
||||
glm::vec2 currentPosition;
|
||||
} _mouseVisualizer;
|
||||
};
|
||||
|
||||
} // namespace openspace::interaction
|
||||
|
||||
#endif // __OPENSPACE_CORE___INTERACTIONHANDLER___H__
|
||||
@@ -58,6 +58,10 @@ namespace openspace::interaction {
|
||||
struct NavigationState;
|
||||
struct NodeCameraStateSpec;
|
||||
|
||||
/**
|
||||
* The NavigationHandler is responsible for updating the camera, and switching between
|
||||
* different navigation modes (navigators).
|
||||
*/
|
||||
class NavigationHandler : public properties::PropertyOwner {
|
||||
public:
|
||||
NavigationHandler();
|
||||
@@ -78,8 +82,7 @@ public:
|
||||
// Accessors
|
||||
Camera* camera() const;
|
||||
const SceneGraphNode* anchorNode() const;
|
||||
const MouseInputState& mouseInputState() const;
|
||||
const KeyboardInputState& keyboardInputState() const;
|
||||
|
||||
const OrbitalNavigator& orbitalNavigator() const;
|
||||
OrbitalNavigator& orbitalNavigator();
|
||||
KeyframeNavigator& keyframeNavigator();
|
||||
@@ -89,19 +92,6 @@ public:
|
||||
float jumpToFadeDuration() const;
|
||||
float interpolationTime() const;
|
||||
|
||||
// Callback functions
|
||||
void keyboardCallback(Key key, KeyModifier modifier, KeyAction action);
|
||||
|
||||
bool disabledKeybindings() const;
|
||||
bool disabledMouse() const;
|
||||
bool disabledJoystick() const;
|
||||
|
||||
void mouseButtonCallback(MouseButton button, MouseAction action);
|
||||
void mousePositionCallback(double x, double y);
|
||||
void mouseScrollWheelCallback(double pos);
|
||||
|
||||
void renderOverlay() const;
|
||||
|
||||
NavigationState navigationState() const;
|
||||
NavigationState navigationState(const SceneGraphNode& referenceFrame) const;
|
||||
|
||||
@@ -149,10 +139,7 @@ public:
|
||||
private:
|
||||
void applyPendingState();
|
||||
void updateCameraTransitions();
|
||||
void clearGlobalJoystickStates();
|
||||
|
||||
MouseInputState _mouseInputState;
|
||||
KeyboardInputState _keyboardInputState;
|
||||
Camera* _camera = nullptr;
|
||||
std::function<void()> _playbackEndCallback;
|
||||
|
||||
@@ -166,22 +153,8 @@ private:
|
||||
|
||||
std::optional<std::variant<NodeCameraStateSpec, NavigationState>> _pendingState;
|
||||
|
||||
properties::BoolProperty _disableKeybindings;
|
||||
properties::BoolProperty _disableMouseInputs;
|
||||
properties::BoolProperty _disableJoystickInputs;
|
||||
properties::BoolProperty _useKeyFrameInteraction;
|
||||
properties::FloatProperty _jumpToFadeDuration;
|
||||
|
||||
struct {
|
||||
properties::PropertyOwner owner;
|
||||
properties::BoolProperty enable;
|
||||
properties::Vec4Property color;
|
||||
|
||||
bool isMouseFirstPress = false;
|
||||
bool isMousePressed = false;
|
||||
glm::vec2 clickPosition;
|
||||
glm::vec2 currentPosition;
|
||||
} _mouseVisualizer;
|
||||
};
|
||||
|
||||
} // namespace openspace::interaction
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
#include <openspace/documentation/documentation.h>
|
||||
#include <openspace/engine/globals.h>
|
||||
#include <openspace/navigation/navigationhandler.h>
|
||||
#include <openspace/interaction/interactionhandler.h>
|
||||
#include <ghoul/misc/dictionary.h>
|
||||
#include <ghoul/misc/profiling.h>
|
||||
#include <ghoul/misc/stringhelper.h>
|
||||
@@ -133,7 +133,7 @@ void DashboardItemInputState::update() {
|
||||
|
||||
std::vector<std::string> text;
|
||||
if (_showKeyboard) {
|
||||
if (global::navigationHandler->disabledKeybindings()) {
|
||||
if (global::interactionHandler->disabledKeybindings()) {
|
||||
if (_showWhenDisabled) {
|
||||
text.emplace_back("Keyboard shortcuts disabled");
|
||||
}
|
||||
@@ -146,7 +146,7 @@ void DashboardItemInputState::update() {
|
||||
}
|
||||
|
||||
if (_showMouse) {
|
||||
if (global::navigationHandler->disabledMouse()) {
|
||||
if (global::interactionHandler->disabledMouse()) {
|
||||
if (_showWhenDisabled) {
|
||||
text.emplace_back("Mouse input disabled");
|
||||
}
|
||||
@@ -159,7 +159,7 @@ void DashboardItemInputState::update() {
|
||||
}
|
||||
|
||||
if (_showJoystick) {
|
||||
if (global::navigationHandler->disabledJoystick()) {
|
||||
if (global::interactionHandler->disabledJoystick()) {
|
||||
if (_showWhenDisabled) {
|
||||
text.emplace_back("Joystick input disabled");
|
||||
}
|
||||
|
||||
@@ -28,9 +28,9 @@
|
||||
#include <openspace/engine/globalscallbacks.h>
|
||||
#include <openspace/engine/globals.h>
|
||||
#include <openspace/engine/windowdelegate.h>
|
||||
#include <openspace/interaction/interactionhandler.h>
|
||||
#include <openspace/interaction/interactionmonitor.h>
|
||||
#include <openspace/interaction/keyboardinputstate.h>
|
||||
#include <openspace/navigation/navigationhandler.h>
|
||||
#include <ghoul/format.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <algorithm>
|
||||
@@ -548,7 +548,7 @@ CefTouchEvent EventHandler::touchEvent(const TouchInput& input,
|
||||
event.y = windowPos.y;
|
||||
event.type = eventType;
|
||||
const std::vector<std::pair<Key, KeyModifier>>& keyMods =
|
||||
global::navigationHandler->keyboardInputState().pressedKeys();
|
||||
global::interactionHandler->keyboardInputState().pressedKeys();
|
||||
for (const std::pair<Key, KeyModifier>& p : keyMods) {
|
||||
const KeyModifier mods = p.second;
|
||||
event.modifiers |= static_cast<uint32_t>(mapToCefModifiers(mods));
|
||||
|
||||
+4
-2
@@ -51,14 +51,15 @@ set(OPENSPACE_SOURCE
|
||||
events/eventengine_lua.inl
|
||||
interaction/actionmanager.cpp
|
||||
interaction/actionmanager_lua.inl
|
||||
interaction/interactionhandler.cpp
|
||||
interaction/interactionmonitor.cpp
|
||||
interaction/mouseinputstate.cpp
|
||||
interaction/joystickinputstate.cpp
|
||||
interaction/keybindingmanager.cpp
|
||||
interaction/keybindingmanager_lua.inl
|
||||
interaction/keyframerecordinghandler.cpp
|
||||
interaction/keyframerecordinghandler_lua.inl
|
||||
interaction/keyboardinputstate.cpp
|
||||
interaction/mouseinputstate.cpp
|
||||
interaction/sessionrecording.cpp
|
||||
interaction/sessionrecordinghandler.cpp
|
||||
interaction/sessionrecordinghandler_lua.inl
|
||||
@@ -251,7 +252,7 @@ set(OPENSPACE_HEADER
|
||||
${PROJECT_SOURCE_DIR}/include/openspace/events/eventengine.inl
|
||||
${PROJECT_SOURCE_DIR}/include/openspace/interaction/action.h
|
||||
${PROJECT_SOURCE_DIR}/include/openspace/interaction/actionmanager.h
|
||||
${PROJECT_SOURCE_DIR}/include/openspace/interaction/mouseinputstate.h
|
||||
${PROJECT_SOURCE_DIR}/include/openspace/interaction/interactionhandler.h
|
||||
${PROJECT_SOURCE_DIR}/include/openspace/interaction/interactionmonitor.h
|
||||
${PROJECT_SOURCE_DIR}/include/openspace/interaction/interpolator.h
|
||||
${PROJECT_SOURCE_DIR}/include/openspace/interaction/interpolator.inl
|
||||
@@ -259,6 +260,7 @@ set(OPENSPACE_HEADER
|
||||
${PROJECT_SOURCE_DIR}/include/openspace/interaction/keybindingmanager.h
|
||||
${PROJECT_SOURCE_DIR}/include/openspace/interaction/keyboardinputstate.h
|
||||
${PROJECT_SOURCE_DIR}/include/openspace/interaction/keyframerecordinghandler.h
|
||||
${PROJECT_SOURCE_DIR}/include/openspace/interaction/mouseinputstate.h
|
||||
${PROJECT_SOURCE_DIR}/include/openspace/interaction/sessionrecording.h
|
||||
${PROJECT_SOURCE_DIR}/include/openspace/interaction/sessionrecordinghandler.h
|
||||
${PROJECT_SOURCE_DIR}/include/openspace/interaction/websocketinputstate.h
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <openspace/engine/windowdelegate.h>
|
||||
#include <openspace/events/eventengine.h>
|
||||
#include <openspace/interaction/actionmanager.h>
|
||||
#include <openspace/interaction/interactionhandler.h>
|
||||
#include <openspace/interaction/interactionmonitor.h>
|
||||
#include <openspace/interaction/keybindingmanager.h>
|
||||
#include <openspace/interaction/keyframerecordinghandler.h>
|
||||
@@ -94,6 +95,7 @@ namespace {
|
||||
sizeof(WindowDelegate) +
|
||||
sizeof(Configuration) +
|
||||
sizeof(interaction::ActionManager) +
|
||||
sizeof(interaction::InteractionHandler) +
|
||||
sizeof(interaction::InteractionMonitor) +
|
||||
sizeof(interaction::JoystickInputStates) +
|
||||
sizeof(interaction::WebsocketInputStates) +
|
||||
@@ -302,6 +304,14 @@ void create() {
|
||||
interactionMonitor = new interaction::InteractionMonitor;
|
||||
#endif // WIN32
|
||||
|
||||
#ifdef WIN32
|
||||
interactionHandler = new (currentPos) interaction::InteractionHandler;
|
||||
ghoul_assert(interactionHandler, "No interactionHandler");
|
||||
currentPos += sizeof(interaction::InteractionHandler);
|
||||
#else // ^^^ WIN32 / !WIN32 vvv
|
||||
interactionHandler = new interaction::InteractionHandler;
|
||||
#endif // WIN32
|
||||
|
||||
#ifdef WIN32
|
||||
joystickInputStates = new (currentPos) interaction::JoystickInputStates;
|
||||
ghoul_assert(joystickInputStates, "No joystickInputStates");
|
||||
@@ -408,6 +418,7 @@ void initialize() {
|
||||
// New property subowners also have to be added to the ImGuiModule callback!
|
||||
rootPropertyOwner->addPropertySubOwner(global::navigationHandler);
|
||||
rootPropertyOwner->addPropertySubOwner(global::keyframeRecording);
|
||||
rootPropertyOwner->addPropertySubOwner(global::interactionHandler);
|
||||
rootPropertyOwner->addPropertySubOwner(global::interactionMonitor);
|
||||
rootPropertyOwner->addPropertySubOwner(global::sessionRecordingHandler);
|
||||
rootPropertyOwner->addPropertySubOwner(global::timeManager);
|
||||
@@ -515,6 +526,13 @@ void destroy() {
|
||||
delete interactionMonitor;
|
||||
#endif // WIN32
|
||||
|
||||
LDEBUGC("Globals", "Destroying 'InteractionHandler'");
|
||||
#ifdef WIN32
|
||||
interactionHandler->~InteractionHandler();
|
||||
#else // ^^^ WIN32 / !WIN32 vvv
|
||||
delete interactionHandler;
|
||||
#endif // WIN32
|
||||
|
||||
LDEBUGC("Globals", "Destorying 'ActionManager'");
|
||||
#ifdef WIN32
|
||||
actionManager->~ActionManager();
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#include <openspace/events/eventengine.h>
|
||||
#include <openspace/interaction/action.h>
|
||||
#include <openspace/interaction/actionmanager.h>
|
||||
#include <openspace/interaction/interactionhandler.h>
|
||||
#include <openspace/interaction/interactionmonitor.h>
|
||||
#include <openspace/interaction/keybindingmanager.h>
|
||||
#include <openspace/interaction/sessionrecordinghandler.h>
|
||||
@@ -1324,7 +1325,7 @@ void OpenSpaceEngine::drawOverlays() {
|
||||
if (isGuiWindow) {
|
||||
global::renderEngine->renderOverlays(_shutdown);
|
||||
global::sessionRecordingHandler->render();
|
||||
global::navigationHandler->renderOverlay();
|
||||
global::interactionHandler->renderOverlay();
|
||||
}
|
||||
|
||||
for (const std::function<void()>& func : *global::callback::draw2D) {
|
||||
@@ -1429,9 +1430,9 @@ void OpenSpaceEngine::keyboardCallback(Key key, KeyModifier mod, KeyAction actio
|
||||
}
|
||||
}
|
||||
|
||||
global::navigationHandler->keyboardCallback(key, mod, action);
|
||||
global::interactionHandler->keyboardCallback(key, mod, action);
|
||||
|
||||
if (!global::navigationHandler->disabledKeybindings()) {
|
||||
if (!global::interactionHandler->disabledKeybindings()) {
|
||||
global::keybindingManager->keyboardCallback(key, mod, action);
|
||||
}
|
||||
|
||||
@@ -1498,7 +1499,7 @@ void OpenSpaceEngine::mouseButtonCallback(MouseButton button, MouseAction action
|
||||
}
|
||||
}
|
||||
|
||||
global::navigationHandler->mouseButtonCallback(button, action);
|
||||
global::interactionHandler->mouseButtonCallback(button, action);
|
||||
global::interactionMonitor->markInteraction();
|
||||
|
||||
if (_shutdown.inShutdown) {
|
||||
@@ -1521,7 +1522,7 @@ void OpenSpaceEngine::mousePositionCallback(double x, double y, IsGuiWindow isGu
|
||||
func(x, y, isGuiWindow);
|
||||
}
|
||||
|
||||
global::navigationHandler->mousePositionCallback(x, y);
|
||||
global::interactionHandler->mousePositionCallback(x, y);
|
||||
global::interactionMonitor->markInteraction();
|
||||
|
||||
_mousePosition = glm::vec2(static_cast<float>(x), static_cast<float>(y));
|
||||
@@ -1544,7 +1545,7 @@ void OpenSpaceEngine::mouseScrollWheelCallback(double posX, double posY,
|
||||
}
|
||||
}
|
||||
|
||||
global::navigationHandler->mouseScrollWheelCallback(posY);
|
||||
global::interactionHandler->mouseScrollWheelCallback(posY);
|
||||
global::interactionMonitor->markInteraction();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,212 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2025 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <openspace/interaction/interactionhandler.h>
|
||||
|
||||
#include <openspace/engine/globals.h>
|
||||
#include <openspace/engine/windowdelegate.h>
|
||||
#include <openspace/interaction/joystickinputstate.h>
|
||||
#include <openspace/rendering/helper.h>
|
||||
|
||||
namespace {
|
||||
constexpr openspace::properties::Property::PropertyInfo DisableKeybindingsInfo = {
|
||||
"DisableKeybindings",
|
||||
"Disable all keybindings",
|
||||
"Disables all keybindings without removing them. Please note that this does not "
|
||||
"apply to the key to open the console.",
|
||||
openspace::properties::Property::Visibility::AdvancedUser
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo DisableMouseInputInfo = {
|
||||
"DisableMouseInputs",
|
||||
"Disable all mouse inputs",
|
||||
"Disables all mouse inputs and prevents them from affecting the camera.",
|
||||
openspace::properties::Property::Visibility::AdvancedUser
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo DisableJoystickInputInfo = {
|
||||
"DisableJoystickInputs",
|
||||
"Disable all joystick inputs",
|
||||
"Disables all joystick inputs and prevents them from affecting the camera.",
|
||||
openspace::properties::Property::Visibility::User
|
||||
};
|
||||
|
||||
const openspace::properties::PropertyOwner::PropertyOwnerInfo MouseVisualizerInfo = {
|
||||
"MouseInteractionVisualizer",
|
||||
"Mouse Interaction Visualizer",
|
||||
"The mouse interaction visualizer shows the distance the mouse has been moved "
|
||||
"since it was pressed down."
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo MouseVisualizerEnabledInfo = {
|
||||
"Enabled",
|
||||
"Enabled",
|
||||
"If this setting is enabled, the mouse interaction will be visualized on the "
|
||||
"screen by showing the distance the mouse has been moved since it was pressed "
|
||||
"down."
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo MouseVisualizerColorInfo = {
|
||||
"Color",
|
||||
"Color",
|
||||
"The color used to render the line showing the mouse visualizer."
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace openspace::interaction {
|
||||
|
||||
InteractionHandler::InteractionHandler()
|
||||
: properties::PropertyOwner({ "InteractionHandler", "Interaction Handler" })
|
||||
, _disableKeybindings(DisableKeybindingsInfo, false)
|
||||
, _disableMouseInputs(DisableMouseInputInfo, false)
|
||||
, _disableJoystickInputs(DisableJoystickInputInfo, false)
|
||||
, _mouseVisualizer({
|
||||
properties::PropertyOwner(MouseVisualizerInfo),
|
||||
properties::BoolProperty(MouseVisualizerEnabledInfo, false),
|
||||
properties::Vec4Property(
|
||||
MouseVisualizerColorInfo,
|
||||
glm::vec4(1.f),
|
||||
glm::vec4(0.f),
|
||||
glm::vec4(1.f)
|
||||
),
|
||||
false,
|
||||
false,
|
||||
glm::vec2(0.f),
|
||||
glm::vec2(0.f)
|
||||
})
|
||||
{
|
||||
addProperty(_disableKeybindings);
|
||||
addProperty(_disableMouseInputs);
|
||||
addProperty(_disableJoystickInputs);
|
||||
|
||||
_disableJoystickInputs.onChange([this]() {
|
||||
if (_disableJoystickInputs) {
|
||||
clearGlobalJoystickStates();
|
||||
}
|
||||
});
|
||||
|
||||
addPropertySubOwner(_mouseVisualizer.owner);
|
||||
_mouseVisualizer.owner.addProperty(_mouseVisualizer.enable);
|
||||
_mouseVisualizer.color.setViewOption(properties::Property::ViewOptions::Color);
|
||||
_mouseVisualizer.owner.addProperty(_mouseVisualizer.color);
|
||||
}
|
||||
|
||||
InteractionHandler::~InteractionHandler() {}
|
||||
|
||||
void InteractionHandler::initialize() {
|
||||
ZoneScoped;
|
||||
}
|
||||
|
||||
void InteractionHandler::deinitialize() {
|
||||
ZoneScoped;
|
||||
}
|
||||
|
||||
const MouseInputState& InteractionHandler::mouseInputState() const {
|
||||
return _mouseInputState;
|
||||
}
|
||||
|
||||
const KeyboardInputState& InteractionHandler::keyboardInputState() const {
|
||||
return _keyboardInputState;
|
||||
}
|
||||
|
||||
bool InteractionHandler::disabledKeybindings() const {
|
||||
return _disableKeybindings;
|
||||
}
|
||||
|
||||
bool InteractionHandler::disabledMouse() const {
|
||||
return _disableMouseInputs;
|
||||
}
|
||||
|
||||
bool InteractionHandler::disabledJoystick() const {
|
||||
return _disableJoystickInputs;
|
||||
}
|
||||
|
||||
void InteractionHandler::mouseButtonCallback(MouseButton button, MouseAction action) {
|
||||
if (!_disableMouseInputs) {
|
||||
_mouseInputState.mouseButtonCallback(button, action);
|
||||
|
||||
if (_mouseVisualizer.enable) {
|
||||
if (action == MouseAction::Press) {
|
||||
_mouseVisualizer.isMouseFirstPress = true;
|
||||
_mouseVisualizer.isMousePressed = true;
|
||||
}
|
||||
else if (action == MouseAction::Release) {
|
||||
_mouseVisualizer.isMousePressed = false;
|
||||
_mouseVisualizer.currentPosition = glm::vec2(0.f);
|
||||
_mouseVisualizer.clickPosition = glm::vec2(0.f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void InteractionHandler::mousePositionCallback(double x, double y) {
|
||||
if (!_disableMouseInputs) {
|
||||
_mouseInputState.mousePositionCallback(x, y);
|
||||
|
||||
if (_mouseVisualizer.enable && _mouseVisualizer.isMousePressed) {
|
||||
if (_mouseVisualizer.isMouseFirstPress) {
|
||||
_mouseVisualizer.clickPosition = glm::vec2(x, y);
|
||||
_mouseVisualizer.isMouseFirstPress = false;
|
||||
}
|
||||
|
||||
_mouseVisualizer.currentPosition = glm::vec2(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void InteractionHandler::mouseScrollWheelCallback(double pos) {
|
||||
if (!_disableMouseInputs) {
|
||||
_mouseInputState.mouseScrollWheelCallback(pos);
|
||||
}
|
||||
}
|
||||
|
||||
void InteractionHandler::keyboardCallback(Key key, KeyModifier modifier, KeyAction action)
|
||||
{
|
||||
// There is no need to disable the keyboard callback based on a property as the vast
|
||||
// majority of input is coming through Lua scripts anyway which are not blocked here
|
||||
_keyboardInputState.keyboardCallback(key, modifier, action);
|
||||
}
|
||||
|
||||
void InteractionHandler::renderOverlay() const {
|
||||
if (_mouseVisualizer.enable && _mouseVisualizer.isMousePressed) {
|
||||
constexpr glm::vec4 StartColor = glm::vec4(0.4f, 0.4f, 0.4f, 0.25f);
|
||||
rendering::helper::renderLine(
|
||||
_mouseVisualizer.clickPosition,
|
||||
_mouseVisualizer.currentPosition,
|
||||
global::windowDelegate->currentWindowSize(),
|
||||
StartColor,
|
||||
_mouseVisualizer.color
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void InteractionHandler::clearGlobalJoystickStates() {
|
||||
std::fill(
|
||||
global::joystickInputStates->begin(),
|
||||
global::joystickInputStates->end(),
|
||||
JoystickInputState()
|
||||
);
|
||||
}
|
||||
|
||||
} // namespace openspace::interaction
|
||||
@@ -27,15 +27,14 @@
|
||||
#include <openspace/camera/camera.h>
|
||||
#include <openspace/engine/globals.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/engine/windowdelegate.h>
|
||||
#include <openspace/events/event.h>
|
||||
#include <openspace/events/eventengine.h>
|
||||
#include <openspace/interaction/actionmanager.h>
|
||||
#include <openspace/interaction/interactionhandler.h>
|
||||
#include <openspace/navigation/waypoint.h>
|
||||
#include <openspace/network/parallelconnection.h>
|
||||
#include <openspace/network/parallelpeer.h>
|
||||
#include <openspace/query/query.h>
|
||||
#include <openspace/rendering/helper.h>
|
||||
#include <openspace/scene/scene.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
#include <openspace/scripting/lualibrary.h>
|
||||
@@ -71,28 +70,6 @@ namespace {
|
||||
|
||||
constexpr std::string_view _loggerCat = "NavigationHandler";
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo DisableKeybindingsInfo = {
|
||||
"DisableKeybindings",
|
||||
"Disable all keybindings",
|
||||
"Disables all keybindings without removing them. Please note that this does not "
|
||||
"apply to the key to open the console.",
|
||||
openspace::properties::Property::Visibility::AdvancedUser
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo DisableMouseInputInfo = {
|
||||
"DisableMouseInputs",
|
||||
"Disable all mouse inputs",
|
||||
"Disables all mouse inputs and prevents them from affecting the camera.",
|
||||
openspace::properties::Property::Visibility::AdvancedUser
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo DisableJoystickInputInfo = {
|
||||
"DisableJoystickInputs",
|
||||
"Disable all joystick inputs",
|
||||
"Disables all joystick inputs and prevents them from affecting the camera.",
|
||||
openspace::properties::Property::Visibility::User
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo FrameInfo = {
|
||||
"UseKeyFrameInteraction",
|
||||
"Use keyframe interaction",
|
||||
@@ -110,66 +87,20 @@ namespace {
|
||||
"again.",
|
||||
openspace::properties::Property::Visibility::User
|
||||
};
|
||||
|
||||
const openspace::properties::PropertyOwner::PropertyOwnerInfo MouseVisualizerInfo = {
|
||||
"MouseInteractionVisualizer",
|
||||
"Mouse Interaction Visualizer",
|
||||
"The mouse interaction visualizer shows the distance the mouse has been moved "
|
||||
"since it was pressed down."
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo MouseVisualizerEnabledInfo = {
|
||||
"Enabled",
|
||||
"Enabled",
|
||||
"If this setting is enabled, the mouse interaction will be visualized on the "
|
||||
"screen by showing the distance the mouse has been moved since it was pressed "
|
||||
"down."
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo MouseVisualizerColorInfo = {
|
||||
"Color",
|
||||
"Color",
|
||||
"The color used to render the line showing the mouse visualizer."
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace openspace::interaction {
|
||||
|
||||
NavigationHandler::NavigationHandler()
|
||||
: properties::PropertyOwner({ "NavigationHandler", "Navigation Handler" })
|
||||
, _disableKeybindings(DisableKeybindingsInfo, false)
|
||||
, _disableMouseInputs(DisableMouseInputInfo, false)
|
||||
, _disableJoystickInputs(DisableJoystickInputInfo, false)
|
||||
, _useKeyFrameInteraction(FrameInfo, false)
|
||||
, _jumpToFadeDuration(JumpToFadeDurationInfo, 1.f, 0.f, 10.f)
|
||||
, _mouseVisualizer({
|
||||
properties::PropertyOwner(MouseVisualizerInfo),
|
||||
properties::BoolProperty(MouseVisualizerEnabledInfo, false),
|
||||
properties::Vec4Property(
|
||||
MouseVisualizerColorInfo,
|
||||
glm::vec4(1.f),
|
||||
glm::vec4(0.f),
|
||||
glm::vec4(1.f)
|
||||
),
|
||||
false,
|
||||
false,
|
||||
glm::vec2(0.f),
|
||||
glm::vec2(0.f)
|
||||
})
|
||||
{
|
||||
addPropertySubOwner(_orbitalNavigator);
|
||||
addPropertySubOwner(_pathNavigator);
|
||||
|
||||
addProperty(_disableKeybindings);
|
||||
addProperty(_disableMouseInputs);
|
||||
addProperty(_disableJoystickInputs);
|
||||
addProperty(_useKeyFrameInteraction);
|
||||
addProperty(_jumpToFadeDuration);
|
||||
|
||||
addPropertySubOwner(_mouseVisualizer.owner);
|
||||
_mouseVisualizer.owner.addProperty(_mouseVisualizer.enable);
|
||||
_mouseVisualizer.color.setViewOption(properties::Property::ViewOptions::Color);
|
||||
_mouseVisualizer.owner.addProperty(_mouseVisualizer.color);
|
||||
}
|
||||
|
||||
NavigationHandler::~NavigationHandler() {}
|
||||
@@ -303,12 +234,9 @@ void NavigationHandler::updateCamera(double deltaTime) {
|
||||
updateCameraTransitions();
|
||||
}
|
||||
else { // orbital navigator
|
||||
if (_disableJoystickInputs) {
|
||||
clearGlobalJoystickStates();
|
||||
}
|
||||
_orbitalNavigator.updateStatesFromInput(
|
||||
_mouseInputState,
|
||||
_keyboardInputState,
|
||||
global::interactionHandler->mouseInputState(),
|
||||
global::interactionHandler->keyboardInputState(),
|
||||
deltaTime
|
||||
);
|
||||
_orbitalNavigator.updateCameraStateFromStates(deltaTime);
|
||||
@@ -534,85 +462,6 @@ Camera* NavigationHandler::camera() const {
|
||||
return _camera;
|
||||
}
|
||||
|
||||
const MouseInputState& NavigationHandler::mouseInputState() const {
|
||||
return _mouseInputState;
|
||||
}
|
||||
|
||||
const KeyboardInputState& NavigationHandler::keyboardInputState() const {
|
||||
return _keyboardInputState;
|
||||
}
|
||||
|
||||
void NavigationHandler::mouseButtonCallback(MouseButton button, MouseAction action) {
|
||||
if (!_disableMouseInputs) {
|
||||
_mouseInputState.mouseButtonCallback(button, action);
|
||||
|
||||
if (_mouseVisualizer.enable) {
|
||||
if (action == MouseAction::Press) {
|
||||
_mouseVisualizer.isMouseFirstPress = true;
|
||||
_mouseVisualizer.isMousePressed = true;
|
||||
}
|
||||
else if (action == MouseAction::Release) {
|
||||
_mouseVisualizer.isMousePressed = false;
|
||||
_mouseVisualizer.currentPosition = glm::vec2(0.f);
|
||||
_mouseVisualizer.clickPosition = glm::vec2(0.f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NavigationHandler::mousePositionCallback(double x, double y) {
|
||||
if (!_disableMouseInputs) {
|
||||
_mouseInputState.mousePositionCallback(x, y);
|
||||
|
||||
if (_mouseVisualizer.enable && _mouseVisualizer.isMousePressed) {
|
||||
if (_mouseVisualizer.isMouseFirstPress) {
|
||||
_mouseVisualizer.clickPosition = glm::vec2(x, y);
|
||||
_mouseVisualizer.isMouseFirstPress = false;
|
||||
}
|
||||
|
||||
_mouseVisualizer.currentPosition = glm::vec2(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NavigationHandler::mouseScrollWheelCallback(double pos) {
|
||||
if (!_disableMouseInputs) {
|
||||
_mouseInputState.mouseScrollWheelCallback(pos);
|
||||
}
|
||||
}
|
||||
|
||||
void NavigationHandler::keyboardCallback(Key key, KeyModifier modifier, KeyAction action)
|
||||
{
|
||||
// There is no need to disable the keyboard callback based on a property as the vast
|
||||
// majority of input is coming through Lua scripts anyway which are not blocked here
|
||||
_keyboardInputState.keyboardCallback(key, modifier, action);
|
||||
}
|
||||
|
||||
void NavigationHandler::renderOverlay() const {
|
||||
if (_mouseVisualizer.enable && _mouseVisualizer.isMousePressed) {
|
||||
constexpr glm::vec4 StartColor = glm::vec4(0.4f, 0.4f, 0.4f, 0.25f);
|
||||
rendering::helper::renderLine(
|
||||
_mouseVisualizer.clickPosition,
|
||||
_mouseVisualizer.currentPosition,
|
||||
global::windowDelegate->currentWindowSize(),
|
||||
StartColor,
|
||||
_mouseVisualizer.color
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
bool NavigationHandler::disabledKeybindings() const {
|
||||
return _disableKeybindings;
|
||||
}
|
||||
|
||||
bool NavigationHandler::disabledMouse() const {
|
||||
return _disableMouseInputs;
|
||||
}
|
||||
|
||||
bool NavigationHandler::disabledJoystick() const {
|
||||
return _disableJoystickInputs;
|
||||
}
|
||||
|
||||
NavigationState NavigationHandler::navigationState() const {
|
||||
const SceneGraphNode* referenceFrame = _orbitalNavigator.followingAnchorRotation() ?
|
||||
_orbitalNavigator.anchorNode() :
|
||||
@@ -746,14 +595,6 @@ void NavigationHandler::loadNavigationState(const std::string& filepath,
|
||||
}
|
||||
}
|
||||
|
||||
void NavigationHandler::clearGlobalJoystickStates() {
|
||||
std::fill(
|
||||
global::joystickInputStates->begin(),
|
||||
global::joystickInputStates->end(),
|
||||
JoystickInputState()
|
||||
);
|
||||
}
|
||||
|
||||
scripting::LuaLibrary NavigationHandler::luaLibrary() {
|
||||
return {
|
||||
"navigation",
|
||||
|
||||
Reference in New Issue
Block a user