use of com.willwinder.ugs.nbp.designer.gui.MouseEntityEvent in project Universal-G-Code-Sender by winder.
the class CreateEllipseControl method onEvent.
@Override
public void onEvent(EntityEvent entityEvent) {
if (entityEvent instanceof MouseEntityEvent) {
MouseEntityEvent mouseEntityEvent = (MouseEntityEvent) entityEvent;
startPosition = mouseEntityEvent.getStartMousePosition();
endPosition = mouseEntityEvent.getCurrentMousePosition();
if (mouseEntityEvent.getType() == EventType.MOUSE_PRESSED) {
isPressed = true;
} else if (mouseEntityEvent.getType() == EventType.MOUSE_DRAGGED) {
isPressed = true;
} else if (mouseEntityEvent.getType() == EventType.MOUSE_RELEASED) {
isPressed = false;
createEntity();
}
}
}
use of com.willwinder.ugs.nbp.designer.gui.MouseEntityEvent in project Universal-G-Code-Sender by winder.
the class CreateRectangleControl method onEvent.
@Override
public void onEvent(EntityEvent entityEvent) {
if (entityEvent instanceof MouseEntityEvent) {
MouseEntityEvent mouseEntityEvent = (MouseEntityEvent) entityEvent;
startPosition = mouseEntityEvent.getStartMousePosition();
endPosition = mouseEntityEvent.getCurrentMousePosition();
if (mouseEntityEvent.getType() == EventType.MOUSE_PRESSED) {
isPressed = true;
} else if (mouseEntityEvent.getType() == EventType.MOUSE_DRAGGED) {
isPressed = true;
} else if (mouseEntityEvent.getType() == EventType.MOUSE_RELEASED) {
isPressed = false;
createEntity();
}
}
}
use of com.willwinder.ugs.nbp.designer.gui.MouseEntityEvent in project Universal-G-Code-Sender by winder.
the class MoveControl method onEvent.
@Override
public void onEvent(EntityEvent entityEvent) {
if (entityEvent instanceof MouseEntityEvent && entityEvent.getTarget() == this) {
MouseEntityEvent mouseShapeEvent = (MouseEntityEvent) entityEvent;
Point2D mousePosition = mouseShapeEvent.getCurrentMousePosition();
Entity target = getSelectionManager();
if (mouseShapeEvent.getType() == EventType.MOUSE_PRESSED) {
startPosition = target.getPosition();
startOffset = new Point2D.Double(mousePosition.getX() - target.getPosition().getX(), mousePosition.getY() - target.getPosition().getY());
} else if (mouseShapeEvent.getType() == EventType.MOUSE_DRAGGED) {
Point2D deltaMovement = new Point2D.Double(mousePosition.getX() - target.getPosition().getX() - startOffset.getX(), mousePosition.getY() - target.getPosition().getY() - startOffset.getY());
if (mouseShapeEvent.isAltPressed()) {
Point2D newPosition = new Point2D.Double(Utils.roundToDecimals(target.getPosition().getX() + deltaMovement.getX(), 1), Utils.roundToDecimals(target.getPosition().getY() + deltaMovement.getY(), 1));
target.setPosition(newPosition);
} else {
Point2D newPosition = new Point2D.Double(Math.round(target.getPosition().getX() + deltaMovement.getX()), Math.round(target.getPosition().getY() + deltaMovement.getY()));
target.setPosition(newPosition);
}
} else if (mouseShapeEvent.getType() == EventType.MOUSE_RELEASED && startPosition != null) {
Point2D deltaMovementTotal = new Point2D.Double(target.getPosition().getX() - startPosition.getX(), target.getPosition().getY() - startPosition.getY());
addUndoAction(deltaMovementTotal, target);
startPosition = null;
startOffset = null;
} else if (mouseShapeEvent.getType() == EventType.MOUSE_IN) {
isHovered = true;
} else if (mouseShapeEvent.getType() == EventType.MOUSE_OUT) {
isHovered = false;
}
}
}
use of com.willwinder.ugs.nbp.designer.gui.MouseEntityEvent in project Universal-G-Code-Sender by winder.
the class ResizeControl method onEvent.
@Override
public void onEvent(EntityEvent entityEvent) {
if (entityEvent instanceof MouseEntityEvent && entityEvent.getTarget() == this) {
MouseEntityEvent mouseShapeEvent = (MouseEntityEvent) entityEvent;
Point2D mousePosition = mouseShapeEvent.getCurrentMousePosition();
if (mouseShapeEvent.getType() == EventType.MOUSE_PRESSED) {
startOffset = new Point2D.Double(mousePosition.getX() - getPosition().getX(), mousePosition.getY() - getPosition().getY());
} else if (mouseShapeEvent.getType() == EventType.MOUSE_DRAGGED) {
performScaling(mousePosition);
} else if (mouseShapeEvent.getType() == EventType.MOUSE_RELEASED) {
Entity target = getSelectionManager();
LOGGER.info("Stopped moving " + target.getPosition());
} else if (mouseShapeEvent.getType() == EventType.MOUSE_IN) {
isHovered = true;
} else if (mouseShapeEvent.getType() == EventType.MOUSE_OUT) {
isHovered = false;
}
}
}
use of com.willwinder.ugs.nbp.designer.gui.MouseEntityEvent in project Universal-G-Code-Sender by winder.
the class RotationControl method onEvent.
@Override
public void onEvent(EntityEvent entityEvent) {
if (entityEvent instanceof MouseEntityEvent && entityEvent.getTarget() == this) {
MouseEntityEvent mouseShapeEvent = (MouseEntityEvent) entityEvent;
Point2D mousePosition = mouseShapeEvent.getCurrentMousePosition();
Entity target = getSelectionManager();
if (mouseShapeEvent.getType() == EventType.MOUSE_PRESSED) {
startPosition = mousePosition;
startRotation = target.getRotation();
center = target.getCenter();
} else if (mouseShapeEvent.getType() == EventType.MOUSE_DRAGGED) {
int decimals = 0;
if (mouseShapeEvent.isAltPressed()) {
decimals = 1;
}
double deltaAngle = Utils.calcRotationAngleInDegrees(target.getCenter(), startPosition) - Utils.calcRotationAngleInDegrees(target.getCenter(), mousePosition);
// Adjust the delta angle to achieve some rounding
double fractionToRound = deltaAngle + target.getRotation() - Utils.roundToDecimals(deltaAngle + target.getRotation(), decimals);
deltaAngle = deltaAngle - fractionToRound;
target.rotate(center, deltaAngle);
startPosition = mousePosition;
} else if (mouseShapeEvent.getType() == EventType.MOUSE_RELEASED) {
double totalRotation = (startRotation + target.getRotation());
addUndoAction(center, totalRotation, target);
} else if (mouseShapeEvent.getType() == EventType.MOUSE_IN) {
isHovered = true;
} else if (mouseShapeEvent.getType() == EventType.MOUSE_OUT) {
isHovered = false;
}
}
}
Aggregations