From 21d604fc9b5aee8c3ec19a85db57c69ef5882016 Mon Sep 17 00:00:00 2001 From: Josh Siegle <jsiegle@mit.edu> Date: Sun, 12 Jan 2014 16:42:53 -0500 Subject: [PATCH] Update GraphViewer code --- Source/UI/GraphViewer.cpp | 52 +++++++++++++++++++++++++++++++++++++++ Source/UI/GraphViewer.h | 5 ++++ 2 files changed, 57 insertions(+) diff --git a/Source/UI/GraphViewer.cpp b/Source/UI/GraphViewer.cpp index 89d066f3f..ca7e52b11 100644 --- a/Source/UI/GraphViewer.cpp +++ b/Source/UI/GraphViewer.cpp @@ -66,14 +66,45 @@ void GraphViewer::removeAllNodes() void GraphViewer::updateNodeLocations() { + // set the initial locations for (int i = 0; i < availableNodes.size(); i++) { availableNodes[i]->updateBoundaries(); } + // perform checks + //checkLayout(); // not helpful...yet + repaint(); } +void GraphViewer::checkLayout() +{ + + for (int i = 0; i < availableNodes.size(); i++) + { + int sourceIndex = indexOfEditor(availableNodes[i]->getSource()); + + if (sourceIndex > -1) + { + if (availableNodes[i]->getHorzShift() < availableNodes[sourceIndex]->getHorzShift()) + { + availableNodes[i]->setHorzShift(availableNodes[sourceIndex]->getHorzShift()); + } + } + + int destIndex = indexOfEditor(availableNodes[i]->getDest()); + + if (destIndex > -1) + { + if (availableNodes[i]->getLevel() > availableNodes[destIndex]->getLevel()) + { + availableNodes[destIndex]->setLevel(availableNodes[i]->getLevel()+1); + } + } + } +} + int GraphViewer::indexOfEditor(GenericEditor* editor) { int index = -1; @@ -221,6 +252,22 @@ int GraphNode::getLevel() return level; } + +void GraphNode::setLevel(int level) +{ + setBounds(getX(), 20+getLevel()*40, getWidth(), getHeight()); + +} + +int GraphNode::getHorzShift() +{ + return gv->getHorizontalShift(this); +} + +void GraphNode::setHorzShift(int shift) +{ + setBounds(20+shift*140, getY(), getWidth(), getHeight()); +} void GraphNode::mouseEnter(const MouseEvent& m) { @@ -261,6 +308,11 @@ GenericEditor* GraphNode::getDest() return editor->getDestEditor(); } +GenericEditor* GraphNode::getSource() +{ + return editor->getSourceEditor(); +} + Array<GenericEditor*> GraphNode::getConnectedEditors() { return editor->getConnectedEditors(); diff --git a/Source/UI/GraphViewer.h b/Source/UI/GraphViewer.h index 9b0273130..1454631b6 100644 --- a/Source/UI/GraphViewer.h +++ b/Source/UI/GraphViewer.h @@ -58,6 +58,7 @@ public: Point<float> getCenterPoint(); GenericEditor* getDest(); + GenericEditor* getSource(); Array<GenericEditor*> getConnectedEditors(); void switchIO(int path); @@ -67,6 +68,9 @@ public: const String getName(); int getLevel(); + void setLevel(int); + int getHorzShift(); + void setHorzShift(int); private: @@ -100,6 +104,7 @@ public: private: void connectNodes(int, int, Graphics&); + void checkLayout(); void updateNodeLocations(); int indexOfEditor(GenericEditor* editor); -- GitLab