use of com.kotcrab.vis.ui.widget.VisWindow in project HyperLap2D by rednblackgames.
the class GraphContainer method drawShapeConnections.
private void drawShapeConnections(float parentAlpha) {
float x = getX();
float y = getY();
Vector2 from = PolygonUtils.vector2Pool.obtain();
Vector2 to = PolygonUtils.vector2Pool.obtain();
// Connections
for (GraphConnection graphConnection : graphConnections) {
NodeConnector fromNode = getNodeInfo(graphConnection.getNodeFrom(), graphConnection.getFieldFrom(), tmpNodeInfo1);
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(), tmpNodeInfo2);
Window toWindow = boxWindows.get(toNode.getNodeId());
GraphBoxInputConnector<T> input = getGraphBoxById(toNode.getNodeId()).getInputs().get(toNode.getFieldId());
calculateConnection(to, toWindow, input);
boolean error = validationResult.getErrorConnections().contains(graphConnection);
from.add(x, y);
to.add(x, y);
float xDiff = Math.min(150, Math.abs(from.x - to.x));
shapeDrawerColor.set(error ? INVALID_CONNECTOR_COLOR : LINE_COLOR);
shapeDrawerColor.a *= parentAlpha;
shapeDrawer.setColor(shapeDrawerColor);
Vector2 center1 = PolygonUtils.vector2Pool.obtain();
center1.set(from.x + xDiff, from.y);
Vector2 center2 = PolygonUtils.vector2Pool.obtain();
center2.set(to.x - xDiff, to.y);
Array<Vector2> path = PolygonUtils.getCurvedLine(from, to, center1, center2, 50);
shapeDrawer.path(path, LINE_WEIGHT, JoinType.NONE, true);
PolygonUtils.vector2Pool.freeAll(path);
PolygonUtils.vector2Pool.free(center1);
PolygonUtils.vector2Pool.free(center2);
}
Sandbox sandbox = Sandbox.getInstance();
UIStage uiStage = sandbox.getUIStage();
if (drawingFromConnector != null) {
GraphBox<T> drawingFromNode = getGraphBoxById(drawingFromConnector.getNodeId());
Window fromWindow = getBoxWindow(drawingFromConnector.getNodeId());
if (drawingFromNode.isInputField(drawingFromConnector.getFieldId())) {
GraphBoxInputConnector<T> input = drawingFromNode.getInputs().get(drawingFromConnector.getFieldId());
calculateConnection(from, fromWindow, input);
shapeDrawerColor.set(LINE_COLOR);
shapeDrawerColor.a *= parentAlpha;
shapeDrawer.setColor(shapeDrawerColor);
shapeDrawer.line(x + from.x, y + from.y, sandbox.getInputX() - parentWindow.getX(), uiStage.getHeight() - sandbox.getInputY() - parentWindow.getY(), LINE_WEIGHT);
} else {
GraphBoxOutputConnector<T> output = drawingFromNode.getOutputs().get(drawingFromConnector.getFieldId());
calculateConnection(from, fromWindow, output);
shapeDrawerColor.set(LINE_COLOR);
shapeDrawerColor.a *= parentAlpha;
shapeDrawer.setColor(shapeDrawerColor);
shapeDrawer.line(x + from.x, y + from.y, sandbox.getInputX() - parentWindow.getX(), uiStage.getHeight() - sandbox.getInputY() - parentWindow.getY(), LINE_WEIGHT);
}
}
// Pins
for (Map.Entry<String, VisWindow> windowEntry : boxWindows.entrySet()) {
String nodeId = windowEntry.getKey();
Window window = windowEntry.getValue();
GraphBox<T> graphBox = graphBoxes.get(nodeId);
for (GraphNodeInput<T> 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);
shapeDrawerColor.set(VALID_CONNECTOR_COLOR);
shapeDrawerColor.a *= parentAlpha;
shapeDrawer.setColor(shapeDrawerColor);
shapeDrawer.line(from, to);
shapeDrawer.circle(from.x, from.y, CONNECTOR_RADIUS);
}
}
for (GraphBoxOutputConnector<T> connector : graphBox.getOutputs().values()) {
calculateConnector(from, to, window, connector);
from.add(x, y);
to.add(x, y);
shapeDrawerColor.set(VALID_CONNECTOR_COLOR);
shapeDrawerColor.a *= parentAlpha;
shapeDrawer.setColor(shapeDrawerColor);
shapeDrawer.line(from, to);
shapeDrawer.circle(from.x, from.y, CONNECTOR_RADIUS);
}
}
for (Map.Entry<String, VisWindow> windowEntry : boxWindows.entrySet()) {
String nodeId = windowEntry.getKey();
Window window = windowEntry.getValue();
GraphBox<T> graphBox = graphBoxes.get(nodeId);
for (GraphNodeInput<T> 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;
}
}
shapeDrawerColor.set(isErrorous ? INVALID_CONNECTOR_COLOR : VALID_CONNECTOR_COLOR);
shapeDrawerColor.a *= parentAlpha;
shapeDrawer.setColor(shapeDrawerColor);
shapeDrawer.line(from, to);
shapeDrawer.filledCircle(from.x, from.y, CONNECTOR_RADIUS);
}
}
}
PolygonUtils.vector2Pool.free(from);
PolygonUtils.vector2Pool.free(to);
}
use of com.kotcrab.vis.ui.widget.VisWindow in project gdx-graph by MarcinSc.
the class GraphContainer method addGraphBox.
public void addGraphBox(final GraphBox graphBox, String windowTitle, boolean closeable, float x, float y) {
graphBoxes.put(graphBox.getId(), graphBox);
VisWindow window = new VisWindow(windowTitle, false) {
@Override
protected void positionChanged() {
graphWindowMoved(this, graphBox.getId());
}
@Override
protected void close() {
removeGraphBox(graphBox);
windowPositions.remove(this);
super.close();
}
@Override
public void toFront() {
super.toFront();
String nodeId = graphBox.getId();
if (Gdx.input.isKeyPressed(Input.Keys.SHIFT_LEFT)) {
if (selectedNodes.contains(nodeId))
removeFromSelection(nodeId);
else
addToSelection(nodeId);
} else {
setSelection(nodeId);
}
}
};
window.setKeepWithinStage(false);
if (closeable) {
window.addCloseButton();
}
window.add(graphBox.getActor()).grow().row();
windowPositions.put(window, new Vector2(x, y));
window.setPosition(x, y);
addActor(window);
window.setSize(Math.max(150, window.getPrefWidth()), window.getPrefHeight());
boxWindows.put(graphBox.getId(), window);
fire(new GraphChangedEvent(true, false));
}
use of com.kotcrab.vis.ui.widget.VisWindow in project gdx-graph by MarcinSc.
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();
VisWindow window = windowEntry.getValue();
GraphBox graphBox = graphBoxes.get(nodeId);
float windowX = window.getX();
float windowY = window.getY();
for (GraphBoxInputConnector connector : graphBox.getInputs().values()) {
switch(connector.getSide()) {
case Left:
from.set(windowX - CONNECTOR_LENGTH, 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 connector : graphBox.getOutputs().values()) {
switch(connector.getSide()) {
case Right:
from.set(windowX + window.getWidth() + CONNECTOR_LENGTH, 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());
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);
Shape shape;
if (output.getSide() == GraphBoxOutputConnector.Side.Right) {
shape = basicStroke.createStrokedShape(new CubicCurve2D.Float(from.x, from.y, ((from.x + to.x) / 2), from.y, ((from.x + to.x) / 2), to.y, to.x, to.y));
} else {
shape = basicStroke.createStrokedShape(new CubicCurve2D.Float(from.x, from.y, from.x, ((from.y + to.y) / 2), to.x, ((from.y + to.y) / 2), 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 updateCanvas.
private void updateCanvas(boolean adjustPosition) {
if (!navigating) {
float minX = Float.MAX_VALUE;
float minY = Float.MAX_VALUE;
float maxX = Float.MIN_VALUE;
float maxY = Float.MIN_VALUE;
Collection<VisWindow> children = boxWindows.values();
if (children.size() == 0) {
minX = 0;
minY = 0;
maxX = 0;
maxY = 0;
} else {
for (Actor child : children) {
float childX = child.getX();
float childY = child.getY();
float childWidth = child.getWidth();
float childHeight = child.getHeight();
minX = Math.min(minX, childX);
minY = Math.min(minY, childY);
maxX = Math.max(maxX, childX + childWidth);
maxY = Math.max(maxY, childY + childHeight);
}
}
minX -= CANVAS_GAP;
minY -= CANVAS_GAP;
maxX += CANVAS_GAP;
maxY += CANVAS_GAP;
canvasWidth = maxX - minX;
canvasHeight = maxY - minY;
if (adjustPosition) {
canvasX = -minX;
canvasY = -minY;
}
}
}
use of com.kotcrab.vis.ui.widget.VisWindow in project HyperLap2D by rednblackgames.
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);
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