diff --git a/ij/gui/ImageCanvas.java b/ij/gui/ImageCanvas.java index d5c619f0c..14cf47c0e 100644 --- a/ij/gui/ImageCanvas.java +++ b/ij/gui/ImageCanvas.java @@ -1447,9 +1447,10 @@ void setRoiModState(MouseEvent e, Roi roi, int handle) { int tool = Toolbar.getToolId(); if (tool>Toolbar.FREEROI && tool!=Toolbar.WAND && tool!=Toolbar.POINT) {roi.modState = Roi.NO_MODS; return;} - if (e.isShiftDown()) + if (e.isShiftDown()){ roi.modState = Roi.ADD_TO_ROI; - else if (e.isAltDown()) + if (e.isAltDown()) roi.modState = Roi.KEEP_WITHIN_ROI; + }else if (e.isAltDown()) roi.modState = Roi.SUBTRACT_FROM_ROI; else roi.modState = Roi.NO_MODS; diff --git a/ij/gui/Roi.java b/ij/gui/Roi.java index 076e6ad90..4bf0bb278 100644 --- a/ij/gui/Roi.java +++ b/ij/gui/Roi.java @@ -55,7 +55,7 @@ public class Roi extends Object implements Cloneable, java.io.Serializable, Iter public static final int FERET_ARRAY_POINTOFFSET = 8; // Where point coordinates start in Feret array private static final String NAMES_KEY = "group.names"; - static final int NO_MODS=0, ADD_TO_ROI=1, SUBTRACT_FROM_ROI=2; // modification states + static final int NO_MODS=0, ADD_TO_ROI=1, SUBTRACT_FROM_ROI=2, KEEP_WITHIN_ROI=3; // modification states int startX, startY, x, y, width, height; double startXD, startYD; @@ -1615,9 +1615,11 @@ void modifyRoi() { s2 = (ShapeRoi)this; else s2 = new ShapeRoi(this); - if (previousRoi.modState==ADD_TO_ROI) + if (previousRoi.modState==ADD_TO_ROI) { s1.or(s2); - else + }else if(previousRoi.modState==KEEP_WITHIN_ROI){ + s1.and(s2); + }else s1.not(s2); previousRoi.modState = NO_MODS; Roi roi2 = s1.trySimplify(); @@ -1658,6 +1660,7 @@ public void update(boolean add, boolean subtract) { if (previousRoi==null) return; if (add) { previousRoi.modState = ADD_TO_ROI; + if(subtract) previousRoi.modState = KEEP_WITHIN_ROI; modifyRoi(); } else if (subtract) { previousRoi.modState = SUBTRACT_FROM_ROI;