Skip to content

Commit

Permalink
Fixing an issue where moving a selection using the RotateTool would p…
Browse files Browse the repository at this point in the history
…revent subsequent rotation
  • Loading branch information
defano committed Feb 11, 2017
1 parent 82118c8 commit 676d0a4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
15 changes: 5 additions & 10 deletions src/main/java/com/defano/jmonet/tools/RotateTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,8 @@ public RotateTool() {
@Override
public void mousePressed(MouseEvent e, Point imageLocation) {

// User clicked outside the selection after making a rotation change
if (isDirty() && !selectionBounds.contains(e.getPoint())) {
rotating = false;
super.mousePressed(e, imageLocation);
}

// User clicked inside drag handle
else if (hasSelection() && dragHandle.contains(imageLocation)) {
if (hasSelection() && dragHandle.contains(imageLocation)) {
rotating = true;

if (centerpoint == null) {
Expand All @@ -53,7 +47,7 @@ else if (hasSelection() && dragHandle.contains(imageLocation)) {
}
}

// None of the above; delegate to superclass
// User did not click inside a drag handle; delegate to superclass
else {
rotating = false;
super.mousePressed(e, imageLocation);
Expand All @@ -63,7 +57,7 @@ else if (hasSelection() && dragHandle.contains(imageLocation)) {
@Override
public void mouseDragged(MouseEvent e, Point imageLocation) {

if (rotating && originalSelectionBounds != null) {
if (rotating) {
setDirty(); // Mutating the selected image

// Calculate the rotation angle
Expand Down Expand Up @@ -108,7 +102,8 @@ protected void addSelectionPoint(Point initialPoint, Point newPoint, boolean isS

@Override
public void completeSelection(Point finalPoint) {
// Nothing to do
originalImage = square(getSelectedImage());
originalSelectionBounds = getSelectionOutline();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ public void createSelection(Rectangle bounds) {
}

addSelectionPoint(bounds.getLocation(), new Point(bounds.x + bounds.width, bounds.y + bounds.height), false);
completeSelection(new Point(bounds.x + bounds.width, bounds.y + bounds.height));
getSelectionFromCanvas();
completeSelection(new Point(bounds.x + bounds.width, bounds.y + bounds.height));
}

public void createSelection(BufferedImage image, Point location) {
Expand All @@ -107,12 +107,13 @@ public void createSelection(BufferedImage image, Point location) {
g.dispose();

addSelectionPoint(location.getLocation(), new Point(location.x + image.getWidth(), location.y + image.getHeight()), false);
completeSelection(new Point(location.x + image.getWidth(), location.y + image.getHeight()));
selectedImage.set(image);

selectionChange = new ChangeSet(getCanvas().getScratchImage(), AlphaComposite.getInstance(AlphaComposite.DST_OUT, 1.0f));
getCanvas().commit(selectionChange);
dirty = true;

completeSelection(new Point(location.x + image.getWidth(), location.y + image.getHeight()));
}

@Override
Expand Down Expand Up @@ -170,8 +171,8 @@ public void mouseDragged(MouseEvent e, Point imageLocation) {
public void mouseReleased(MouseEvent e, Point imageLocation) {
// User released mouse after defining a selection
if (!hasSelection() && hasSelectionBounds()) {
completeSelection(imageLocation);
getSelectionFromCanvas();
completeSelection(imageLocation);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ protected BufferedImage getOriginalImage() {
protected void drawSelectionOutline() {
super.drawSelectionOutline();

if (hasSelection()) {
if (hasSelection() && transformBounds != null) {

// Render drag handles on selection bounds
Graphics2D g = (Graphics2D) getCanvas().getScratchImage().getGraphics();
Expand Down

0 comments on commit 676d0a4

Please sign in to comment.