Skip to content
Snippets Groups Projects
Commit 21d604fc authored by Josh Siegle's avatar Josh Siegle
Browse files

Update GraphViewer code

parent f8c2146c
No related branches found
No related tags found
No related merge requests found
...@@ -66,14 +66,45 @@ void GraphViewer::removeAllNodes() ...@@ -66,14 +66,45 @@ void GraphViewer::removeAllNodes()
void GraphViewer::updateNodeLocations() void GraphViewer::updateNodeLocations()
{ {
// set the initial locations
for (int i = 0; i < availableNodes.size(); i++) for (int i = 0; i < availableNodes.size(); i++)
{ {
availableNodes[i]->updateBoundaries(); availableNodes[i]->updateBoundaries();
} }
// perform checks
//checkLayout(); // not helpful...yet
repaint(); 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 GraphViewer::indexOfEditor(GenericEditor* editor)
{ {
int index = -1; int index = -1;
...@@ -221,6 +252,22 @@ int GraphNode::getLevel() ...@@ -221,6 +252,22 @@ int GraphNode::getLevel()
return level; 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) void GraphNode::mouseEnter(const MouseEvent& m)
{ {
...@@ -261,6 +308,11 @@ GenericEditor* GraphNode::getDest() ...@@ -261,6 +308,11 @@ GenericEditor* GraphNode::getDest()
return editor->getDestEditor(); return editor->getDestEditor();
} }
GenericEditor* GraphNode::getSource()
{
return editor->getSourceEditor();
}
Array<GenericEditor*> GraphNode::getConnectedEditors() Array<GenericEditor*> GraphNode::getConnectedEditors()
{ {
return editor->getConnectedEditors(); return editor->getConnectedEditors();
......
...@@ -58,6 +58,7 @@ public: ...@@ -58,6 +58,7 @@ public:
Point<float> getCenterPoint(); Point<float> getCenterPoint();
GenericEditor* getDest(); GenericEditor* getDest();
GenericEditor* getSource();
Array<GenericEditor*> getConnectedEditors(); Array<GenericEditor*> getConnectedEditors();
void switchIO(int path); void switchIO(int path);
...@@ -67,6 +68,9 @@ public: ...@@ -67,6 +68,9 @@ public:
const String getName(); const String getName();
int getLevel(); int getLevel();
void setLevel(int);
int getHorzShift();
void setHorzShift(int);
private: private:
...@@ -100,6 +104,7 @@ public: ...@@ -100,6 +104,7 @@ public:
private: private:
void connectNodes(int, int, Graphics&); void connectNodes(int, int, Graphics&);
void checkLayout();
void updateNodeLocations(); void updateNodeLocations();
int indexOfEditor(GenericEditor* editor); int indexOfEditor(GenericEditor* editor);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment