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

Update GraphViewer code

parent f8c2146c
Branches
Tags
No related merge requests found
......@@ -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();
......
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment