diff --git a/source/app/rendering/graphcomponentrenderer.cpp b/source/app/rendering/graphcomponentrenderer.cpp index 6adc840d2..6679ccbfe 100644 --- a/source/app/rendering/graphcomponentrenderer.cpp +++ b/source/app/rendering/graphcomponentrenderer.cpp @@ -419,7 +419,7 @@ void GraphComponentRenderer::setAlpha(float alpha) } } -void GraphComponentRenderer::zoom(float delta, bool doTransition) +void GraphComponentRenderer::zoom(float delta, NamedBool<"doTransition"> doTransition) { Q_ASSERT(_graphRenderer != nullptr); diff --git a/source/app/rendering/graphcomponentrenderer.h b/source/app/rendering/graphcomponentrenderer.h index 14eff138e..2a8a5ed00 100644 --- a/source/app/rendering/graphcomponentrenderer.h +++ b/source/app/rendering/graphcomponentrenderer.h @@ -27,6 +27,7 @@ #include "shared/graph/igraph.h" #include "shared/graph/grapharray.h" +#include "shared/utils/namedbool.h" #include "limitconstants.h" @@ -119,7 +120,7 @@ class GraphComponentRenderer CameraAndLighting* cameraAndLighting() { return &_viewData._cameraAndLighting; } const CameraAndLighting* cameraAndLighting() const { return &_viewData._cameraAndLighting; } - void zoom(float delta, bool doTransition); + void zoom(float delta, NamedBool<"doTransition"> doTransition); void zoomToDistance(float distance); void cloneViewDataFrom(const GraphComponentRenderer& other); diff --git a/source/app/rendering/graphcomponentscene.cpp b/source/app/rendering/graphcomponentscene.cpp index aa9ebcc22..43b905757 100644 --- a/source/app/rendering/graphcomponentscene.cpp +++ b/source/app/rendering/graphcomponentscene.cpp @@ -140,7 +140,7 @@ void GraphComponentScene::onHide() clearQueuedTransition(); } -void GraphComponentScene::finishComponentTransition(ComponentId componentId, bool doTransition) +void GraphComponentScene::finishComponentTransition(ComponentId componentId, NamedBool<"doTransition"> doTransition) { // KEEP IN MIND: at this point _componentId may refer to a frozen component that is no longer // in the graph, and is only being kept around to refer to its renderer; in other words don't @@ -229,7 +229,7 @@ void GraphComponentScene::finishComponentTransition(ComponentId componentId, boo updateRendererVisibility(); } -void GraphComponentScene::finishComponentTransitionOnRendererThread(ComponentId componentId, bool doTransition) +void GraphComponentScene::finishComponentTransitionOnRendererThread(ComponentId componentId, NamedBool<"doTransition"> doTransition) { _graphRenderer->executeOnRendererThread([this, componentId, doTransition] { @@ -266,7 +266,7 @@ bool GraphComponentScene::componentTransitionActive() const return !_transitioningComponentId.isNull(); } -void GraphComponentScene::setComponentId(ComponentId componentId, bool doTransition) +void GraphComponentScene::setComponentId(ComponentId componentId, NamedBool<"doTransition"> doTransition) { _beingRemoved = false; @@ -286,16 +286,16 @@ void GraphComponentScene::setComponentId(ComponentId componentId, bool doTransit [this, componentId] { _graphRenderer->transition().willBeImmediatelyReused(); - finishComponentTransitionOnRendererThread(componentId, true); + finishComponentTransitionOnRendererThread(componentId, "doTransition"_yes); }); - resetView(false); + resetView("doTransition"_no); } else - finishComponentTransitionOnRendererThread(componentId, true); + finishComponentTransitionOnRendererThread(componentId, "doTransition"_yes); } else - finishComponentTransition(componentId, false); + finishComponentTransition(componentId, "doTransition"_no); } void GraphComponentScene::saveViewData() const @@ -318,7 +318,7 @@ void GraphComponentScene::restoreViewData() const componentRenderer()->restoreViewData(); } -void GraphComponentScene::resetView(bool doTransition) +void GraphComponentScene::resetView(NamedBool<"doTransition"> doTransition) { if(componentRenderer() != nullptr) { @@ -385,7 +385,7 @@ void GraphComponentScene::moveFocusToNode(NodeId nodeId, float radius) newComponentRenderer->saveViewData(); newComponentRenderer->resetView(); - setComponentId(componentId, true); + setComponentId(componentId, "doTransition"_yes); } else if(!componentTransitionRequired && !componentTransitionActive()) { @@ -509,7 +509,7 @@ void GraphComponentScene::onComponentAdded(const Graph*, ComponentId componentId _graphRenderer->executeOnRendererThread([this, componentId] { if(_componentId.isNull()) - setComponentId(componentId, visible()); + setComponentId(componentId, NamedBool<"doTransition">(visible())); }, u"GraphComponentScene::onComponentAdded"_s); } @@ -564,7 +564,7 @@ void GraphComponentScene::onGraphChanged(const Graph* graph, bool changed) if(_beingRemoved) { - setComponentId(_defaultComponentId, true); + setComponentId(_defaultComponentId, "doTransition"_yes); return true; } @@ -642,7 +642,7 @@ void GraphComponentScene::setProjection(Projection projection) startProjectionTransition(); }); - resetView(false); + resetView("doTransition"_no); } else startProjectionTransition(); diff --git a/source/app/rendering/graphcomponentscene.h b/source/app/rendering/graphcomponentscene.h index ffb45c504..c92628a46 100644 --- a/source/app/rendering/graphcomponentscene.h +++ b/source/app/rendering/graphcomponentscene.h @@ -52,7 +52,7 @@ class GraphComponentScene : void onHide() override; ComponentId componentId() const { return _componentId; } - void setComponentId(ComponentId componentId, bool doTransition = false); + void setComponentId(ComponentId componentId, NamedBool<"doTransition"> doTransition = "doTransition"_no); int width() const { return _width; } int height() const { return _height; } @@ -61,7 +61,7 @@ class GraphComponentScene : bool savedViewIsReset() const; void restoreViewData() const; - void resetView(bool doTransition) override; + void resetView(NamedBool<"doTransition"> doTransition) override; bool viewIsReset() const override; void setProjection(Projection projection) override; @@ -99,8 +99,8 @@ class GraphComponentScene : void updateRendererVisibility(); - void finishComponentTransition(ComponentId componentId, bool doTransition); - void finishComponentTransitionOnRendererThread(ComponentId componentId, bool doTransition); + void finishComponentTransition(ComponentId componentId, NamedBool<"doTransition"> doTransition); + void finishComponentTransitionOnRendererThread(ComponentId componentId, NamedBool<"doTransition"> doTransition); void clearQueuedTransition(); bool performQueuedTransition(); diff --git a/source/app/rendering/graphoverviewscene.cpp b/source/app/rendering/graphoverviewscene.cpp index 7856c604d..052d976b8 100644 --- a/source/app/rendering/graphoverviewscene.cpp +++ b/source/app/rendering/graphoverviewscene.cpp @@ -148,7 +148,7 @@ void GraphOverviewScene::onHide() setVisible(false); } -void GraphOverviewScene::resetView(bool doTransition) +void GraphOverviewScene::resetView(NamedBool<"doTransition"> doTransition) { setZoomFactor(minZoomFactor()); setOffset(defaultOffset()); @@ -178,7 +178,7 @@ void GraphOverviewScene::pan(float dx, float dy) updateZoomedComponentLayoutData(); } -void GraphOverviewScene::zoom(float delta, float x, float y, bool doTransition) +void GraphOverviewScene::zoom(float delta, float x, float y, NamedBool<"doTransition"> doTransition) { const float oldCentreX = x / _zoomFactor; const float oldCentreY = y / _zoomFactor; @@ -204,7 +204,7 @@ void GraphOverviewScene::zoom(float delta, float x, float y, bool doTransition) updateZoomedComponentLayoutData(); } -void GraphOverviewScene::zoomTo(const std::vector& componentIds, bool doTransition) +void GraphOverviewScene::zoomTo(const std::vector& componentIds, NamedBool<"doTransition"> doTransition) { Q_ASSERT(!componentIds.empty()); @@ -317,7 +317,7 @@ Transition& GraphOverviewScene::startTransitionFromComponentMode(ComponentId com } if(!focusComponentIds.empty()) - zoomTo(focusComponentIds, false); + zoomTo(focusComponentIds, "doTransition"_no); auto& transition = startTransition(duration, transitionType); diff --git a/source/app/rendering/graphoverviewscene.h b/source/app/rendering/graphoverviewscene.h index 538265aff..98677c032 100644 --- a/source/app/rendering/graphoverviewscene.h +++ b/source/app/rendering/graphoverviewscene.h @@ -68,15 +68,15 @@ class GraphOverviewScene : const ComponentLayoutData& componentLayout() { return _zoomedComponentLayoutData; } - void resetView(bool doTransition = true) override; + void resetView(NamedBool<"doTransition"> doTransition = "doTransition"_yes) override; bool viewIsReset() const override; void setProjection(Projection projection) override; void pan(float dx, float dy); - void zoom(float delta, float x, float y, bool doTransition); + void zoom(float delta, float x, float y, NamedBool<"doTransition"> doTransition); - void zoomTo(const std::vector& componentIds, bool doTransition = true); + void zoomTo(const std::vector& componentIds, NamedBool<"doTransition"> doTransition = "doTransition"_yes); Transition& startTransitionFromComponentMode(ComponentId componentModeComponentId, const std::vector& focusComponentIds, diff --git a/source/app/rendering/graphrenderer.cpp b/source/app/rendering/graphrenderer.cpp index fb90ed091..b167870e6 100644 --- a/source/app/rendering/graphrenderer.cpp +++ b/source/app/rendering/graphrenderer.cpp @@ -142,9 +142,9 @@ GraphRenderer::GraphRenderer(GraphModel* graphModel, CommandManager* commandMana // If the graph is a single component or empty, use component mode by default if(graph->numComponents() <= 1) - switchToComponentMode(false); + switchToComponentMode("doTransition"_no); else - switchToOverviewMode(false); + switchToOverviewMode("doTransition"_no); updateText(); @@ -552,7 +552,7 @@ void GraphRenderer::moveFocusToNode(NodeId nodeId, float radius) { // To focus on a node, we need to be in component mode auto componentId = _graphModel->graph().componentIdOfNode(nodeId); - switchToComponentMode(true, componentId, nodeId, radius); + switchToComponentMode("doTransition"_yes, componentId, nodeId, radius); } } @@ -563,7 +563,7 @@ void GraphRenderer::moveFocusToComponent(ComponentId componentId) if(componentId != _graphComponentScene->componentId()) rendererStartedTransition(); - _graphComponentScene->setComponentId(componentId, true); + _graphComponentScene->setComponentId(componentId, "doTransition"_yes); } } @@ -656,7 +656,7 @@ void GraphRenderer::onEdgeMovedBetweenComponents(const Graph*, EdgeId edgeId, Co _hiddenEdges.set(edgeId, true); } -void GraphRenderer::finishTransitionToOverviewMode(bool doTransition, +void GraphRenderer::finishTransitionToOverviewMode(NamedBool<"doTransition"> doTransition, const std::vector& focusComponentIds) { // If component mode has a queued transition nodeId, cancel the switch to overview @@ -667,7 +667,7 @@ void GraphRenderer::finishTransitionToOverviewMode(bool doTransition, setScene(_graphOverviewScene); setInteractor(_graphOverviewInteractor); - _graphOverviewScene->resetView(false); + _graphOverviewScene->resetView("doTransition"_no); if(doTransition) { @@ -686,7 +686,7 @@ void GraphRenderer::finishTransitionToOverviewMode(bool doTransition, updateGPUData(When::Later); } -void GraphRenderer::finishTransitionToOverviewModeOnRendererThread(bool doTransition, +void GraphRenderer::finishTransitionToOverviewModeOnRendererThread(NamedBool<"doTransition"> doTransition, const std::vector& focusComponentIds) { executeOnRendererThread([this, doTransition, focusComponentIds] @@ -695,7 +695,7 @@ void GraphRenderer::finishTransitionToOverviewModeOnRendererThread(bool doTransi }, u"GraphRenderer::finishTransitionToOverviewMode"_s); } -void GraphRenderer::finishTransitionToComponentMode(bool doTransition) +void GraphRenderer::finishTransitionToComponentMode(NamedBool<"doTransition"> doTransition) { setMode(GraphRenderer::Mode::Component); setScene(_graphComponentScene); @@ -711,7 +711,7 @@ void GraphRenderer::finishTransitionToComponentMode(bool doTransition) updateGPUData(When::Later); } -void GraphRenderer::finishTransitionToComponentModeOnRendererThread(bool doTransition) +void GraphRenderer::finishTransitionToComponentModeOnRendererThread(NamedBool<"doTransition"> doTransition) { executeOnRendererThread([this, doTransition] { @@ -719,7 +719,7 @@ void GraphRenderer::finishTransitionToComponentModeOnRendererThread(bool doTrans }, u"GraphRenderer::finishTransitionToComponentMode"_s); } -void GraphRenderer::switchToOverviewMode(bool doTransition, const std::vector& focusComponentIds) +void GraphRenderer::switchToOverviewMode(NamedBool<"doTransition"> doTransition, const std::vector& focusComponentIds) { // Refuse to switch to overview mode if there is nothing to display if(_graphModel->graph().numComponents() <= 1) @@ -744,13 +744,13 @@ void GraphRenderer::switchToOverviewMode(bool doTransition, const std::vectorviewIsReset()) { _graphComponentScene->startTransition().then(doPostViewResetTransition); - _graphComponentScene->resetView(false); + _graphComponentScene->resetView("doTransition"_no); } else if(_graphComponentScene->transitionActive()) { @@ -759,15 +759,15 @@ void GraphRenderer::switchToOverviewMode(bool doTransition, const std::vector doTransition, ComponentId componentId, NodeId nodeId, float radius) { doTransition = doTransition && mode() != GraphRenderer::Mode::Component; @@ -792,14 +792,14 @@ void GraphRenderer::switchToComponentMode(bool doTransition, ComponentId compone if(!_graphComponentScene->savedViewIsReset()) { _transition.willBeImmediatelyReused(); - finishTransitionToComponentModeOnRendererThread(true); + finishTransitionToComponentModeOnRendererThread("doTransition"_yes); } else - finishTransitionToComponentModeOnRendererThread(false); + finishTransitionToComponentModeOnRendererThread("doTransition"_no); }); } else - finishTransitionToComponentMode(false); + finishTransitionToComponentMode("doTransition"_no); }, u"GraphRenderer::switchToComponentMode"_s); } @@ -1245,13 +1245,13 @@ void GraphRenderer::synchronize(QQuickFramebufferObject* item) const ComponentId focusComponentId = graphDisplay->desiredFocusComponentId(); if(mode() == Mode::Component && targetMode == Mode::Overview) - switchToOverviewMode(true, u::vectorFrom(componentIds)); + switchToOverviewMode("doTransition"_yes, u::vectorFrom(componentIds)); else if(!focusNodeId.isNull()) moveFocusToNode(focusNodeId, radius); else if(!focusComponentId.isNull()) { if(mode() == Mode::Overview) - switchToComponentMode(true, focusComponentId); + switchToComponentMode("doTransition"_yes, focusComponentId); else moveFocusToComponent(focusComponentId); } diff --git a/source/app/rendering/graphrenderer.h b/source/app/rendering/graphrenderer.h index 917d8e1d4..c6f3975b6 100644 --- a/source/app/rendering/graphrenderer.h +++ b/source/app/rendering/graphrenderer.h @@ -35,6 +35,7 @@ #include "shared/utils/movablepointer.h" #include "shared/utils/deferredexecutor.h" #include "shared/utils/performancecounter.h" +#include "shared/utils/namedbool.h" #include "app/preferences.h" @@ -115,9 +116,9 @@ class GraphRenderer : bool viewIsReset() const; void setTextColor(QColor textColor); - void switchToOverviewMode(bool doTransition = true, + void switchToOverviewMode(NamedBool<"doTransition"> doTransition = "doTransition"_yes, const std::vector& focusComponentIds = {}); - void switchToComponentMode(bool doTransition = true, + void switchToComponentMode(NamedBool<"doTransition"> doTransition = "doTransition"_yes, ComponentId componentId = {}, NodeId nodeId = {}, float radius = -1.0f); void rendererStartedTransition(); void rendererFinishedTransition(); @@ -269,10 +270,10 @@ public slots: void render() override; void synchronize(QQuickFramebufferObject* item) override; - void finishTransitionToOverviewMode(bool doTransition, const std::vector& focusComponentIds); - void finishTransitionToOverviewModeOnRendererThread(bool doTransition, const std::vector& focusComponentIds); - void finishTransitionToComponentMode(bool doTransition); - void finishTransitionToComponentModeOnRendererThread(bool doTransition); + void finishTransitionToOverviewMode(NamedBool<"doTransition"> doTransition, const std::vector& focusComponentIds); + void finishTransitionToOverviewModeOnRendererThread(NamedBool<"doTransition"> doTransition, const std::vector& focusComponentIds); + void finishTransitionToComponentMode(NamedBool<"doTransition"> doTransition); + void finishTransitionToComponentModeOnRendererThread(NamedBool<"doTransition"> doTransition); void setScene(Scene* scene); void setInteractor(Interactor* interactor) { _interactor = interactor; } diff --git a/source/app/rendering/scene.h b/source/app/rendering/scene.h index 3397f12f9..bfd1c94b1 100644 --- a/source/app/rendering/scene.h +++ b/source/app/rendering/scene.h @@ -21,6 +21,8 @@ #include "graphrenderertypes.h" +#include "shared/utils/namedbool.h" + #include #include @@ -46,7 +48,7 @@ class Scene : public QObject virtual void onShow() {} virtual void onHide() {} - virtual void resetView(bool doTransition = true) = 0; + virtual void resetView(NamedBool<"doTransition"> doTransition = "doTransition"_yes) = 0; virtual bool viewIsReset() const = 0; virtual void setProjection(Projection projection) = 0; diff --git a/source/app/ui/graphcomponentinteractor.cpp b/source/app/ui/graphcomponentinteractor.cpp index 7a86c5e16..15f407554 100644 --- a/source/app/ui/graphcomponentinteractor.cpp +++ b/source/app/ui/graphcomponentinteractor.cpp @@ -122,7 +122,7 @@ void GraphComponentInteractor::wheelMove(float angle, float, float) { const float WHEEL_STEP_TRANSITION_SIZE = 0.2f / 120.0f; - renderer->zoom(angle * WHEEL_STEP_TRANSITION_SIZE, true); + renderer->zoom(angle * WHEEL_STEP_TRANSITION_SIZE, "doTransition"_yes); } } @@ -131,7 +131,7 @@ void GraphComponentInteractor::trackpadZoomGesture(float value, float, float) auto* renderer = componentRendererUnderCursor(); if(renderer != nullptr) - renderer->zoom(value, false); + renderer->zoom(value, "doTransition"_no); } void GraphComponentInteractor::trackpadPanGesture(float dx, float dy, float x, float y) diff --git a/source/app/ui/graphoverviewinteractor.cpp b/source/app/ui/graphoverviewinteractor.cpp index 0e1433f64..f59036667 100644 --- a/source/app/ui/graphoverviewinteractor.cpp +++ b/source/app/ui/graphoverviewinteractor.cpp @@ -71,7 +71,7 @@ void GraphOverviewInteractor::leftDoubleClick() auto componentId = componentIdAtPosition(cursorPosition()); if(!componentId.isNull()) - _graphRenderer->switchToComponentMode(true, componentId, clickedNodeId()); + _graphRenderer->switchToComponentMode("doTransition"_yes, componentId, clickedNodeId()); else _scene->resetView(); } @@ -80,12 +80,12 @@ void GraphOverviewInteractor::wheelMove(float angle, float x, float y) { const float WHEEL_STEP_TRANSITION_SIZE = 0.2f / 120.0f; - _scene->zoom(angle * WHEEL_STEP_TRANSITION_SIZE, x, y, true); + _scene->zoom(angle * WHEEL_STEP_TRANSITION_SIZE, x, y, "doTransition"_yes); } void GraphOverviewInteractor::trackpadZoomGesture(float value, float x, float y) { - _scene->zoom(value, x, y, false); + _scene->zoom(value, x, y, "doTransition"_no); } void GraphOverviewInteractor::trackpadPanGesture(float dx, float dy, float x, float y) diff --git a/source/app/ui/qml/Graphia/graphdisplay.h b/source/app/ui/qml/Graphia/graphdisplay.h index f6e315939..0b2270a03 100644 --- a/source/app/ui/qml/Graphia/graphdisplay.h +++ b/source/app/ui/qml/Graphia/graphdisplay.h @@ -22,6 +22,8 @@ #include "app/graph/qmlelementid.h" #include "app/rendering/graphrenderertypes.h" +#include "shared/utils/namedbool.h" + #include #include #include