Skip to content

Commit

Permalink
Use NamedBool<> for doTransition parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
timangus committed Jun 5, 2024
1 parent b284e2c commit 7d34a3f
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 57 deletions.
2 changes: 1 addition & 1 deletion source/app/rendering/graphcomponentrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion source/app/rendering/graphcomponentrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include "shared/graph/igraph.h"
#include "shared/graph/grapharray.h"
#include "shared/utils/namedbool.h"

#include "limitconstants.h"

Expand Down Expand Up @@ -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);
Expand Down
24 changes: 12 additions & 12 deletions source/app/rendering/graphcomponentscene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
{
Expand Down Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -318,7 +318,7 @@ void GraphComponentScene::restoreViewData() const
componentRenderer()->restoreViewData();
}

void GraphComponentScene::resetView(bool doTransition)
void GraphComponentScene::resetView(NamedBool<"doTransition"> doTransition)
{
if(componentRenderer() != nullptr)
{
Expand Down Expand Up @@ -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())
{
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -564,7 +564,7 @@ void GraphComponentScene::onGraphChanged(const Graph* graph, bool changed)

if(_beingRemoved)
{
setComponentId(_defaultComponentId, true);
setComponentId(_defaultComponentId, "doTransition"_yes);
return true;
}

Expand Down Expand Up @@ -642,7 +642,7 @@ void GraphComponentScene::setProjection(Projection projection)
startProjectionTransition();
});

resetView(false);
resetView("doTransition"_no);
}
else
startProjectionTransition();
Expand Down
8 changes: 4 additions & 4 deletions source/app/rendering/graphcomponentscene.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions source/app/rendering/graphoverviewscene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ void GraphOverviewScene::onHide()
setVisible(false);
}

void GraphOverviewScene::resetView(bool doTransition)
void GraphOverviewScene::resetView(NamedBool<"doTransition"> doTransition)
{
setZoomFactor(minZoomFactor());
setOffset(defaultOffset());
Expand Down Expand Up @@ -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;
Expand All @@ -204,7 +204,7 @@ void GraphOverviewScene::zoom(float delta, float x, float y, bool doTransition)
updateZoomedComponentLayoutData();
}

void GraphOverviewScene::zoomTo(const std::vector<ComponentId>& componentIds, bool doTransition)
void GraphOverviewScene::zoomTo(const std::vector<ComponentId>& componentIds, NamedBool<"doTransition"> doTransition)
{
Q_ASSERT(!componentIds.empty());

Expand Down Expand Up @@ -317,7 +317,7 @@ Transition& GraphOverviewScene::startTransitionFromComponentMode(ComponentId com
}

if(!focusComponentIds.empty())
zoomTo(focusComponentIds, false);
zoomTo(focusComponentIds, "doTransition"_no);

auto& transition = startTransition(duration, transitionType);

Expand Down
6 changes: 3 additions & 3 deletions source/app/rendering/graphoverviewscene.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<ComponentId>& componentIds, bool doTransition = true);
void zoomTo(const std::vector<ComponentId>& componentIds, NamedBool<"doTransition"> doTransition = "doTransition"_yes);

Transition& startTransitionFromComponentMode(ComponentId componentModeComponentId,
const std::vector<ComponentId>& focusComponentIds,
Expand Down
40 changes: 20 additions & 20 deletions source/app/rendering/graphrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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);
}
}

Expand All @@ -563,7 +563,7 @@ void GraphRenderer::moveFocusToComponent(ComponentId componentId)
if(componentId != _graphComponentScene->componentId())
rendererStartedTransition();

_graphComponentScene->setComponentId(componentId, true);
_graphComponentScene->setComponentId(componentId, "doTransition"_yes);
}
}

Expand Down Expand Up @@ -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<ComponentId>& focusComponentIds)
{
// If component mode has a queued transition nodeId, cancel the switch to overview
Expand All @@ -667,7 +667,7 @@ void GraphRenderer::finishTransitionToOverviewMode(bool doTransition,
setScene(_graphOverviewScene);
setInteractor(_graphOverviewInteractor);

_graphOverviewScene->resetView(false);
_graphOverviewScene->resetView("doTransition"_no);

if(doTransition)
{
Expand All @@ -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<ComponentId>& focusComponentIds)
{
executeOnRendererThread([this, doTransition, focusComponentIds]
Expand All @@ -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);
Expand All @@ -711,15 +711,15 @@ void GraphRenderer::finishTransitionToComponentMode(bool doTransition)
updateGPUData(When::Later);
}

void GraphRenderer::finishTransitionToComponentModeOnRendererThread(bool doTransition)
void GraphRenderer::finishTransitionToComponentModeOnRendererThread(NamedBool<"doTransition"> doTransition)
{
executeOnRendererThread([this, doTransition]
{
finishTransitionToComponentMode(doTransition);
}, u"GraphRenderer::finishTransitionToComponentMode"_s);
}

void GraphRenderer::switchToOverviewMode(bool doTransition, const std::vector<ComponentId>& focusComponentIds)
void GraphRenderer::switchToOverviewMode(NamedBool<"doTransition"> doTransition, const std::vector<ComponentId>& focusComponentIds)
{
// Refuse to switch to overview mode if there is nothing to display
if(_graphModel->graph().numComponents() <= 1)
Expand All @@ -744,13 +744,13 @@ void GraphRenderer::switchToOverviewMode(bool doTransition, const std::vector<Co
{
sceneFinishedTransition();
_transition.willBeImmediatelyReused();
finishTransitionToOverviewModeOnRendererThread(true, focusComponentIds);
finishTransitionToOverviewModeOnRendererThread("doTransition"_yes, focusComponentIds);
};

if(!_graphComponentScene->viewIsReset())
{
_graphComponentScene->startTransition().then(doPostViewResetTransition);
_graphComponentScene->resetView(false);
_graphComponentScene->resetView("doTransition"_no);
}
else if(_graphComponentScene->transitionActive())
{
Expand All @@ -759,15 +759,15 @@ void GraphRenderer::switchToOverviewMode(bool doTransition, const std::vector<Co
_transition.alternativeThen(doPostViewResetTransition);
}
else
finishTransitionToOverviewModeOnRendererThread(true, focusComponentIds);
finishTransitionToOverviewModeOnRendererThread("doTransition"_yes, focusComponentIds);
}
else
finishTransitionToOverviewMode(false, focusComponentIds);
finishTransitionToOverviewMode("doTransition"_no, focusComponentIds);

}, u"GraphRenderer::switchToOverviewMode"_s);
}

void GraphRenderer::switchToComponentMode(bool doTransition, ComponentId componentId, NodeId nodeId, float radius)
void GraphRenderer::switchToComponentMode(NamedBool<"doTransition"> doTransition, ComponentId componentId, NodeId nodeId, float radius)
{
doTransition = doTransition && mode() != GraphRenderer::Mode::Component;

Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
13 changes: 7 additions & 6 deletions source/app/rendering/graphrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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<ComponentId>& 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();
Expand Down Expand Up @@ -269,10 +270,10 @@ public slots:
void render() override;
void synchronize(QQuickFramebufferObject* item) override;

void finishTransitionToOverviewMode(bool doTransition, const std::vector<ComponentId>& focusComponentIds);
void finishTransitionToOverviewModeOnRendererThread(bool doTransition, const std::vector<ComponentId>& focusComponentIds);
void finishTransitionToComponentMode(bool doTransition);
void finishTransitionToComponentModeOnRendererThread(bool doTransition);
void finishTransitionToOverviewMode(NamedBool<"doTransition"> doTransition, const std::vector<ComponentId>& focusComponentIds);
void finishTransitionToOverviewModeOnRendererThread(NamedBool<"doTransition"> doTransition, const std::vector<ComponentId>& focusComponentIds);
void finishTransitionToComponentMode(NamedBool<"doTransition"> doTransition);
void finishTransitionToComponentModeOnRendererThread(NamedBool<"doTransition"> doTransition);

void setScene(Scene* scene);
void setInteractor(Interactor* interactor) { _interactor = interactor; }
Expand Down
Loading

0 comments on commit 7d34a3f

Please sign in to comment.