Newer
Older
AlgebraicDataflowArchitectureModel / GameEngine / src / main / java / gameEngine / entites / editorComponents / Connection.java
package gameEngine.entites.editorComponents;

import gameEngine.entites.editorComponents.PortView;
import gameEngine.views.LineRenderer;
import gameEngine.views.Sprite;
import gameEngine.views.Window;
import org.joml.Vector3f;

public class Connection {
    private final PortView portA;
    private final PortView portB;
    private final LineRenderer lineRenderer;
    private final Sprite removeButtonSprite;

    public Connection(PortView inPort, PortView outPort) {
        this.portA = inPort;
        this.portB = outPort;
        this.lineRenderer = new LineRenderer(Window.resourcePath + "Line.png");
        this.removeButtonSprite = new Sprite(Window.resourcePath + "RemoveButton.png");
    }

    public void render() {
        Vector3f posA = portA.getPosition();
        Vector3f posB = portB.getPosition();

        lineRenderer.updateLine(portA.getPosition(), portB.getPosition(), 3);
        lineRenderer.render();

        Vector3f buttonPosition = lineRenderer.calculatePosition(posA, posB);
        removeButtonSprite.setPosition(buttonPosition.x+2, buttonPosition.y+2);
        removeButtonSprite.setScale(1,1,1);
        removeButtonSprite.update();
    }

    public boolean isRemoveButtonClicked(float mouseX, float mouseY) {
        return removeButtonSprite.isMouseOver(mouseX, mouseY);
    }

    public PortView getPortA() {
        return portA;
    }

    public PortView getPortB() {
        return portB;
    }
}