use of com.kotcrab.vis.ui.widget.VisWindow in project HyperLap2D by rednblackgames.
the class GraphContainer method recreateClickableShapes.
private void recreateClickableShapes() {
connectionNodeMap.clear();
connections.clear();
Vector2 from = new Vector2();
for (Map.Entry<String, VisWindow> windowEntry : boxWindows.entrySet()) {
String nodeId = windowEntry.getKey();
Window window = windowEntry.getValue();
GraphBox<T> graphBox = graphBoxes.get(nodeId);
float windowX = window.getX();
float windowY = window.getY() + 14;
for (GraphBoxInputConnector<T> connector : graphBox.getInputs().values()) {
switch(connector.getSide()) {
case Left:
from.set(windowX - CONNECTOR_LENGTH + 7, windowY + connector.getOffset());
break;
case Top:
from.set(windowX + connector.getOffset(), windowY + window.getHeight() + CONNECTOR_LENGTH);
break;
}
Rectangle2D rectangle = new Rectangle2D.Float(from.x - CONNECTOR_RADIUS, from.y - CONNECTOR_RADIUS, CONNECTOR_RADIUS * 2, CONNECTOR_RADIUS * 2);
connectionNodeMap.put(new NodeConnector(nodeId, connector.getFieldId()), rectangle);
}
for (GraphBoxOutputConnector<T> connector : graphBox.getOutputs().values()) {
switch(connector.getSide()) {
case Right:
from.set(windowX + window.getWidth() + CONNECTOR_LENGTH - 7, windowY + connector.getOffset());
break;
case Bottom:
from.set(windowX + connector.getOffset(), windowY - CONNECTOR_LENGTH);
break;
}
Rectangle2D rectangle = new Rectangle2D.Float(from.x - CONNECTOR_RADIUS, from.y - CONNECTOR_RADIUS, CONNECTOR_RADIUS * 2, CONNECTOR_RADIUS * 2);
connectionNodeMap.put(new NodeConnector(nodeId, connector.getFieldId()), rectangle);
}
}
BasicStroke basicStroke = new BasicStroke(7);
Vector2 to = new Vector2();
for (GraphConnection graphConnection : graphConnections) {
NodeConnector fromNode = getNodeInfo(graphConnection.getNodeFrom(), graphConnection.getFieldFrom());
Window fromWindow = boxWindows.get(fromNode.getNodeId());
GraphBoxOutputConnector<T> output = getGraphBoxById(fromNode.getNodeId()).getOutputs().get(fromNode.getFieldId());
calculateConnection(from, fromWindow, output);
NodeConnector toNode = getNodeInfo(graphConnection.getNodeTo(), graphConnection.getFieldTo());
Window toWindow = boxWindows.get(toNode.getNodeId());
GraphBoxInputConnector<T> input = getGraphBoxById(toNode.getNodeId()).getInputs().get(toNode.getFieldId());
calculateConnection(to, toWindow, input);
Shape shape = basicStroke.createStrokedShape(new Line2D.Float(from.x, from.y, to.x, to.y));
connections.put(graphConnection, shape);
}
}
use of com.kotcrab.vis.ui.widget.VisWindow in project gdx-graph by MarcinSc.
the class GraphContainer method containedInWindow.
private boolean containedInWindow(float x, float y) {
for (VisWindow window : boxWindows.values()) {
float x1 = window.getX();
float y1 = window.getY();
float width = window.getWidth();
float height = window.getHeight();
// If window contains it - return
if (x >= x1 && x < x1 + width && y >= y1 && y < y1 + height)
return true;
}
return false;
}
use of com.kotcrab.vis.ui.widget.VisWindow in project gdx-graph by MarcinSc.
the class GraphContainer method drawConnections.
private void drawConnections() {
float x = getX();
float y = getY();
Vector2 from = new Vector2();
Vector2 to = new Vector2();
shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
shapeRenderer.setColor(LINE_COLOR);
for (Map.Entry<String, VisWindow> windowEntry : boxWindows.entrySet()) {
String nodeId = windowEntry.getKey();
VisWindow window = windowEntry.getValue();
GraphBox graphBox = graphBoxes.get(nodeId);
for (GraphNodeInput connector : graphBox.getConfiguration().getNodeInputs().values()) {
if (!connector.isRequired()) {
String fieldId = connector.getFieldId();
calculateConnector(from, to, window, graphBox.getInputs().get(fieldId));
from.add(x, y);
to.add(x, y);
shapeRenderer.line(from, to);
shapeRenderer.circle(from.x, from.y, CONNECTOR_RADIUS);
}
}
for (GraphBoxOutputConnector connector : graphBox.getOutputs().values()) {
calculateConnector(from, to, window, connector);
from.add(x, y);
to.add(x, y);
shapeRenderer.line(from, to);
shapeRenderer.circle(from.x, from.y, CONNECTOR_RADIUS);
}
}
for (GraphConnection graphConnection : graphConnections) {
NodeConnector fromNode = getNodeInfo(graphConnection.getNodeFrom(), graphConnection.getFieldFrom());
VisWindow fromWindow = boxWindows.get(fromNode.getNodeId());
GraphBoxOutputConnector output = getGraphBoxById(fromNode.getNodeId()).getOutputs().get(fromNode.getFieldId());
calculateConnection(from, fromWindow, output);
NodeConnector toNode = getNodeInfo(graphConnection.getNodeTo(), graphConnection.getFieldTo());
VisWindow toWindow = boxWindows.get(toNode.getNodeId());
GraphBoxInputConnector input = getGraphBoxById(toNode.getNodeId()).getInputs().get(toNode.getFieldId());
calculateConnection(to, toWindow, input);
boolean error = validationResult.getErrorConnections().contains(graphConnection);
shapeRenderer.setColor(error ? INVALID_CONNECTOR_COLOR : VALID_CONNECTOR_COLOR);
from.add(x, y);
to.add(x, y);
if (output.getSide() == GraphBoxOutputConnector.Side.Right) {
shapeRenderer.curve(from.x, from.y, ((from.x + to.x) / 2), from.y, ((from.x + to.x) / 2), to.y, to.x, to.y, 100);
} else {
shapeRenderer.curve(from.x, from.y, from.x, ((from.y + to.y) / 2), to.x, ((from.y + to.y) / 2), to.x, to.y, 100);
}
}
if (drawingFromConnector != null) {
shapeRenderer.setColor(LINE_COLOR);
GraphBox drawingFromNode = getGraphBoxById(drawingFromConnector.getNodeId());
VisWindow fromWindow = getBoxWindow(drawingFromConnector.getNodeId());
if (drawingFromNode.getConfiguration().getNodeInputs().containsKey(drawingFromConnector.getFieldId())) {
GraphBoxInputConnector input = drawingFromNode.getInputs().get(drawingFromConnector.getFieldId());
calculateConnection(from, fromWindow, input);
Vector2 mouseLocation = getStage().getViewport().unproject(new Vector2(Gdx.input.getX(), Gdx.input.getY()));
if (input.getSide() == GraphBoxInputConnector.Side.Left) {
shapeRenderer.curve(x + from.x, y + from.y, ((x + from.x + mouseLocation.x) / 2), y + from.y, ((x + from.x + mouseLocation.x) / 2), mouseLocation.y, mouseLocation.x, mouseLocation.y, 100);
} else {
shapeRenderer.curve(x + from.x, y + from.y, x + from.x, ((y + from.y + mouseLocation.y) / 2), mouseLocation.x, ((y + from.y + mouseLocation.y) / 2), mouseLocation.x, mouseLocation.y, 100);
}
} else {
GraphBoxOutputConnector output = drawingFromNode.getOutputs().get(drawingFromConnector.getFieldId());
calculateConnection(from, fromWindow, output);
Vector2 mouseLocation = getStage().getViewport().unproject(new Vector2(Gdx.input.getX(), Gdx.input.getY()));
if (output.getSide() == GraphBoxOutputConnector.Side.Right) {
shapeRenderer.curve(x + from.x, y + from.y, ((x + from.x + mouseLocation.x) / 2), y + from.y, ((x + from.x + mouseLocation.x) / 2), mouseLocation.y, mouseLocation.x, mouseLocation.y, 100);
} else {
shapeRenderer.curve(x + from.x, y + from.y, x + from.x, ((y + from.y + mouseLocation.y) / 2), mouseLocation.x, ((y + from.y + mouseLocation.y) / 2), mouseLocation.x, mouseLocation.y, 100);
}
}
}
shapeRenderer.set(ShapeRenderer.ShapeType.Filled);
for (Map.Entry<String, VisWindow> windowEntry : boxWindows.entrySet()) {
String nodeId = windowEntry.getKey();
VisWindow window = windowEntry.getValue();
GraphBox graphBox = graphBoxes.get(nodeId);
for (GraphNodeInput connector : graphBox.getConfiguration().getNodeInputs().values()) {
if (connector.isRequired()) {
String fieldId = connector.getFieldId();
calculateConnector(from, to, window, graphBox.getInputs().get(fieldId));
from.add(x, y);
to.add(x, y);
boolean isErrorous = false;
for (NodeConnector errorConnector : validationResult.getErrorConnectors()) {
if (errorConnector.getNodeId().equals(nodeId) && errorConnector.getFieldId().equals(connector.getFieldId())) {
isErrorous = true;
break;
}
}
shapeRenderer.setColor(isErrorous ? INVALID_CONNECTOR_COLOR : VALID_CONNECTOR_COLOR);
shapeRenderer.line(from, to);
shapeRenderer.circle(from.x, from.y, CONNECTOR_RADIUS);
}
}
}
shapeRenderer.end();
}
use of com.kotcrab.vis.ui.widget.VisWindow in project gdx-graph by MarcinSc.
the class GraphContainer method updateNodeGroups.
private void updateNodeGroups() {
for (Map.Entry<NodeGroupImpl, Rectangle> nodeGroupEntry : nodeGroups.entrySet()) {
float minX = Float.MAX_VALUE;
float minY = Float.MAX_VALUE;
float maxX = -Float.MAX_VALUE;
float maxY = -Float.MAX_VALUE;
NodeGroupImpl nodeGroupImpl = nodeGroupEntry.getKey();
for (String nodeId : nodeGroupImpl.getNodeIds()) {
VisWindow window = boxWindows.get(nodeId);
if (window == null)
throw new IllegalStateException("Unable to find node with id: " + nodeId);
float windowX = window.getX();
float windowY = window.getY();
float windowWidth = window.getWidth();
float windowHeight = window.getHeight();
minX = Math.min(minX, windowX);
minY = Math.min(minY, windowY);
maxX = Math.max(maxX, windowX + windowWidth);
maxY = Math.max(maxY, windowY + windowHeight);
}
minX -= GROUP_GAP;
minY -= GROUP_GAP;
maxX += GROUP_GAP;
maxY += GROUP_GAP + GROUP_LABEL_HEIGHT;
nodeGroupEntry.getValue().set(minX, minY, maxX - minX, maxY - minY);
}
}
Aggregations