mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-22 04:49:12 -06:00
Make it possible to click on the friction markers in the image to toggle the friction (closes issue #576)
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
@@ -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<ghoul::fontrendering::Font> _fontInfo = nullptr;
|
||||
std::shared_ptr<ghoul::fontrendering::Font> _fontDate = nullptr;
|
||||
std::shared_ptr<ghoul::fontrendering::Font> _fontLog = nullptr;
|
||||
|
||||
struct {
|
||||
glm::ivec4 rotation;
|
||||
glm::ivec4 zoom;
|
||||
glm::ivec4 roll;
|
||||
} _cameraButtonLocations;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user