package gameEngine.entites.gameComponents; import gameEngine.views.Sprite; import gameEngine.input.Input; import gameEngine.input.MouseInput; import org.joml.Vector3f; public class PortView { private Sprite sprite; private Vector3f position = new Vector3f(0,0,0); public PortView(boolean componentPort){ if(componentPort){ this.sprite = new Sprite("GameEngine/resources/PortA.png"); } else { this.sprite = new Sprite("GameEngine/resources/PortB.png"); } sprite.updateSpriteDimensions(); } public void update(Vector3f pos, Vector3f rot, Vector3f scale){ sprite.setPosition(pos); sprite.setRotation(rot); sprite.setScale(scale); sprite.update(); position.set(pos); } public void handleDragging(String portName) { float mouseX = MouseInput.getX(); float mouseY = MouseInput.getY(); if (Input.GetMouseButtonDown(0) && isMouseOver(mouseX, mouseY)) { System.out.println("Press:" + portName); } if (Input.GetMouseButtonUp(0) && isMouseOver(mouseX, mouseY)) { System.out.println("Release:" + portName); } } protected boolean isMouseOver(float mouseX, float mouseY) { float width = sprite.getDisplayedWidth(); float height = sprite.getDisplayedHeight(); return mouseX >= position.x && mouseX <= position.x + width && mouseY >= position.y && mouseY <= position.y + height; } public Vector3f getPosition() { return position; } }