From 7068637c9d1fe42746e13d0dac5cf05b783e2e46 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Sat, 21 Apr 2018 19:04:47 +0000 Subject: [PATCH] Make it possible to click on the friction markers in the image to toggle the friction (closes issue #576) --- include/openspace/engine/openspaceengine.h | 2 + include/openspace/rendering/renderengine.h | 8 +++ src/engine/openspaceengine.cpp | 11 ++++ src/rendering/renderengine.cpp | 64 ++++++++++++++++++++++ 4 files changed, 85 insertions(+) diff --git a/include/openspace/engine/openspaceengine.h b/include/openspace/engine/openspaceengine.h index c93deb2e71..140c857b73 100644 --- a/include/openspace/engine/openspaceengine.h +++ b/include/openspace/engine/openspaceengine.h @@ -273,6 +273,8 @@ private: // disable the synchronization; otherwise a hardware sync will kill us after 1 minute bool _isFirstRenderingFirstFrame = true; + glm::dvec2 _mousePosition; + static OpenSpaceEngine* _engine; }; diff --git a/include/openspace/rendering/renderengine.h b/include/openspace/rendering/renderengine.h index 5520ca9e3e..804cc9d386 100644 --- a/include/openspace/rendering/renderengine.h +++ b/include/openspace/rendering/renderengine.h @@ -90,6 +90,8 @@ public: void render(const glm::mat4& sceneMatrix, const glm::mat4& viewMatrix, const glm::mat4& projectionMatrix); + bool mouseActivationCallback(const glm::dvec2& mousePosition) const; + void renderOverlays(const ShutdownInformation& shutdownInfo); void postDraw(); @@ -216,6 +218,12 @@ private: std::shared_ptr _fontInfo = nullptr; std::shared_ptr _fontDate = nullptr; std::shared_ptr _fontLog = nullptr; + + struct { + glm::ivec4 rotation; + glm::ivec4 zoom; + glm::ivec4 roll; + } _cameraButtonLocations; }; } // namespace openspace diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 8332259a6f..7403e05ce0 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -1375,6 +1375,15 @@ void OpenSpaceEngine::mouseButtonCallback(MouseButton button, MouseAction action } } + // Check if the user clicked on one of the 'buttons' the RenderEngine is drawing + if (action == MouseAction::Press) { + bool isConsumed = _renderEngine->mouseActivationCallback(_mousePosition); + + if (isConsumed) { + return; + } + } + _navigationHandler->mouseButtonCallback(button, action); } @@ -1384,6 +1393,8 @@ void OpenSpaceEngine::mousePositionCallback(double x, double y) { func(x, y); } + _mousePosition = { x, y }; + _navigationHandler->mousePositionCallback(x, y); } diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index bdc25c82fc..6bb1b2ba6d 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -584,6 +584,52 @@ void RenderEngine::render(const glm::mat4& sceneMatrix, const glm::mat4& viewMat LTRACE("RenderEngine::render(end)"); } +bool RenderEngine::mouseActivationCallback(const glm::dvec2& mousePosition) const { + auto intersects = [](const glm::dvec2& mousePos, const glm::ivec4& bbox) { + return mousePos.x >= bbox.x && mousePos.x <= bbox.x + bbox.z && + mousePos.y <= bbox.y && mousePos.y >= bbox.y - bbox.w; + }; + + + if (intersects(mousePosition, _cameraButtonLocations.rotation)) { + constexpr const char* ToggleRotationFrictionScript = R"( + local f = 'NavigationHandler.OrbitalNavigator.Friction.RotationalFriction'; + openspace.setPropertyValue(f, not openspace.getPropertyValue(f));)"; + + OsEng.scriptEngine().queueScript( + ToggleRotationFrictionScript, + scripting::ScriptEngine::RemoteScripting::Yes + ); + return true; + } + + if (intersects(mousePosition, _cameraButtonLocations.zoom)) { + constexpr const char* ToggleZoomFrictionScript = R"( + local f = 'NavigationHandler.OrbitalNavigator.Friction.ZoomFriction'; + openspace.setPropertyValue(f, not openspace.getPropertyValue(f));)"; + + OsEng.scriptEngine().queueScript( + ToggleZoomFrictionScript, + scripting::ScriptEngine::RemoteScripting::Yes + ); + return true; + } + + if (intersects(mousePosition, _cameraButtonLocations.roll)) { + constexpr const char* ToggleRollFrictionScript = R"( + local f = 'NavigationHandler.OrbitalNavigator.Friction.RollFriction'; + openspace.setPropertyValue(f, not openspace.getPropertyValue(f));)"; + + OsEng.scriptEngine().queueScript( + ToggleRollFrictionScript, + scripting::ScriptEngine::RemoteScripting::Yes + ); + return true; + } + + return false; +} + void RenderEngine::renderOverlays(const ShutdownInformation& info) { const bool isMaster = OsEng.windowWrapper().isMaster(); if (isMaster || _showOverlayOnSlaves) { @@ -1030,6 +1076,12 @@ void RenderEngine::renderCameraInformation() { interaction::OrbitalNavigator nav = OsEng.navigationHandler().orbitalNavigator(); + _cameraButtonLocations.rotation = { + fontResolution().x - rotationBox.boundingBox.x - XSeparation, + fontResolution().y - penPosY, + rotationBox.boundingBox.x, + rotationBox.boundingBox.y + }; FR::defaultRenderer().render( *_fontInfo, glm::vec2(fontResolution().x - rotationBox.boundingBox.x - XSeparation, penPosY), @@ -1045,6 +1097,12 @@ void RenderEngine::renderCameraInformation() { "Zoom" ); + _cameraButtonLocations.zoom = { + fontResolution().x - zoomBox.boundingBox.x - XSeparation, + fontResolution().y - penPosY, + zoomBox.boundingBox.x, + zoomBox.boundingBox.y + }; FR::defaultRenderer().render( *_fontInfo, glm::vec2(fontResolution().x - zoomBox.boundingBox.x - XSeparation, penPosY), @@ -1060,6 +1118,12 @@ void RenderEngine::renderCameraInformation() { "Roll" ); + _cameraButtonLocations.roll = { + fontResolution().x - rollBox.boundingBox.x - XSeparation, + fontResolution().y - penPosY, + rollBox.boundingBox.x, + rollBox.boundingBox.y + }; FR::defaultRenderer().render( *_fontInfo, glm::vec2(fontResolution().x - rollBox.boundingBox.x - XSeparation, penPosY),