Skip to content

Commit

Permalink
Some small designer fixes (#2467)
Browse files Browse the repository at this point in the history
- Select primitive after creation (Ellipse, Point, Rectangle) 
- Only perform a move (and event cascade) for a delta > 0. I.e. avoid move on click.
- Invalidate bounds after a change but before notification. I.e. avoid event handlers to use stale cached information.
  • Loading branch information
werckmeister committed Feb 16, 2024
1 parent dc2d8b1 commit eab6cbf
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 12 deletions.
Expand Up @@ -18,12 +18,13 @@ This file is part of Universal Gcode Sender (UGS).
*/
package com.willwinder.ugs.nbp.designer;

import static com.willwinder.ugs.nbp.designer.DesignerMain.PROPERTY_IS_STANDALONE;
import org.apache.commons.lang3.StringUtils;

import java.awt.geom.Point2D;
import java.text.ParseException;

import static com.willwinder.ugs.nbp.designer.DesignerMain.PROPERTY_IS_STANDALONE;

/**
* @author Joacim Breiler
*/
Expand Down
Expand Up @@ -179,8 +179,10 @@ public void setTransform(AffineTransform transform) {
@Override
public void move(Point2D deltaMovement) {
try {
transform.preConcatenate(AffineTransform.getTranslateInstance(deltaMovement.getX(), deltaMovement.getY()));
notifyEvent(new EntityEvent(this, EventType.MOVED));
if( deltaMovement.distance(new Point2D.Double(0d, 0d)) > 0) {
transform.preConcatenate(AffineTransform.getTranslateInstance(deltaMovement.getX(), deltaMovement.getY()));
notifyEvent(new EntityEvent(this, EventType.MOVED));
}
} catch (Exception e) {
throw new EntityException("Could not make inverse transform of point", e);
}
Expand Down
Expand Up @@ -70,6 +70,7 @@ public void rotate(double angle) {
groupRotation += angle;
Point2D center = getCenter();
getAllChildren().forEach(entity -> entity.rotate(center, angle));
invalidateBounds();
notifyEvent(new EntityEvent(this, EventType.ROTATED));
} catch (Exception e) {
throw new EntityException("Couldn't set the rotation", e);
Expand All @@ -81,8 +82,8 @@ public void rotate(Point2D center, double angle) {
try {
groupRotation += angle;
getAllChildren().forEach(entity -> entity.rotate(center, angle));
notifyEvent(new EntityEvent(this, EventType.ROTATED));
invalidateBounds();
notifyEvent(new EntityEvent(this, EventType.ROTATED));
} catch (Exception e) {
throw new EntityException("Couldn't set the rotation", e);
}
Expand Down Expand Up @@ -170,8 +171,8 @@ public void applyTransform(AffineTransform transform) {
public void move(Point2D deltaMovement) {
try {
applyTransform(AffineTransform.getTranslateInstance(deltaMovement.getX(), deltaMovement.getY()));
notifyEvent(new EntityEvent(this, EventType.MOVED));
invalidateBounds();
notifyEvent(new EntityEvent(this, EventType.MOVED));
} catch (Exception e) {
throw new EntityException("Could not make inverse transform of point", e);
}
Expand Down Expand Up @@ -328,14 +329,14 @@ public void scale(double sx, double sy) {
child.scale(sx, sy);
child.setPosition(new Point2D.Double(originalPosition.getX() + (relativePosition.getX() * sx), originalPosition.getY() + (relativePosition.getY() * sy)));
});
notifyEvent(new EntityEvent(this, EventType.RESIZED));
invalidateBounds();
notifyEvent(new EntityEvent(this, EventType.RESIZED));
}

@Override
public void onEvent(EntityEvent entityEvent) {
notifyEvent(entityEvent);
invalidateBounds();
notifyEvent(entityEvent);
}

@Override
Expand Down
Expand Up @@ -28,7 +28,7 @@ This file is part of Universal Gcode Sender (UGS).
import com.willwinder.ugs.nbp.designer.model.Size;
import com.willwinder.universalgcodesender.uielements.helpers.ThemeColors;

import java.awt.*;
import java.awt.Graphics2D;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Point2D;

Expand Down Expand Up @@ -95,6 +95,9 @@ private void createEntity() {
Ellipse ellipse = new Ellipse(startX, startY);
ellipse.setSize(new Size(endX - startX, endY - startY));
controller.addEntity(ellipse);

controller.setTool(Tool.SELECT);
controller.getSelectionManager().addSelection(ellipse);
}

@Override
Expand Down
Expand Up @@ -59,7 +59,11 @@ public void onEvent(EntityEvent entityEvent) {
if (entityEvent instanceof MouseEntityEvent) {
MouseEntityEvent mouseEntityEvent = (MouseEntityEvent) entityEvent;
if (mouseEntityEvent.getType() == EventType.MOUSE_PRESSED) {
controller.addEntity(new Point(mouseEntityEvent.getStartMousePosition().getX(), mouseEntityEvent.getStartMousePosition().getY()));

Point point = new Point(mouseEntityEvent.getStartMousePosition().getX(), mouseEntityEvent.getStartMousePosition().getY());
controller.addEntity(point);
controller.setTool(Tool.SELECT);
controller.getSelectionManager().addSelection(point);
}
}
}
Expand Down
Expand Up @@ -27,7 +27,7 @@ This file is part of Universal Gcode Sender (UGS).
import com.willwinder.ugs.nbp.designer.logic.Tool;
import com.willwinder.universalgcodesender.uielements.helpers.ThemeColors;

import java.awt.*;
import java.awt.Graphics2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;

Expand Down Expand Up @@ -95,6 +95,9 @@ private void createEntity() {
rectangle.setWidth(endX - startX);
rectangle.setHeight(endY - startY);
controller.addEntity(rectangle);

controller.setTool(Tool.SELECT);
controller.getSelectionManager().addSelection(rectangle);
}

@Override
Expand Down
Expand Up @@ -31,7 +31,9 @@ This file is part of Universal Gcode Sender (UGS).
import com.willwinder.ugs.nbp.designer.logic.Controller;
import com.willwinder.ugs.nbp.designer.logic.ControllerFactory;

import java.awt.*;
import java.awt.Cursor;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
Expand Down
Expand Up @@ -21,7 +21,6 @@ This file is part of Universal Gcode Sender (UGS).
import com.willwinder.ugs.nbp.designer.entities.Entity;

import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.Ellipse2D;

/**
Expand Down

0 comments on commit eab6cbf

Please sign in to comment.