From 2ee381bb98d3192dce21f24a41459add9d85e84d Mon Sep 17 00:00:00 2001 From: aschain Date: Fri, 26 Mar 2021 12:21:17 -0400 Subject: [PATCH 1/2] When drawing ROIs, alt and shift together now perform AND instead of OR like shift alone --- ij/gui/ImageCanvas.java | 5 +++-- ij/gui/Roi.java | 10 +++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) 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..e2dce4a56 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(); @@ -1656,8 +1658,10 @@ void subtractPoints() { makeOval(), makePolygon() and makeSelection() macro functions. */ public void update(boolean add, boolean subtract) { if (previousRoi==null) return; + IJ.log("Update: "+add+" "+subtract); if (add) { previousRoi.modState = ADD_TO_ROI; + if(subtract) previousRoi.modState = KEEP_WITHIN_ROI; modifyRoi(); } else if (subtract) { previousRoi.modState = SUBTRACT_FROM_ROI; From 88d620c1399bb1301def869814fddc5a9869b418 Mon Sep 17 00:00:00 2001 From: A Schain Date: Mon, 29 Mar 2021 23:31:13 -0400 Subject: [PATCH 2/2] Update Roi.java --- ij/gui/Roi.java | 1 - 1 file changed, 1 deletion(-) diff --git a/ij/gui/Roi.java b/ij/gui/Roi.java index e2dce4a56..4bf0bb278 100644 --- a/ij/gui/Roi.java +++ b/ij/gui/Roi.java @@ -1658,7 +1658,6 @@ void subtractPoints() { makeOval(), makePolygon() and makeSelection() macro functions. */ public void update(boolean add, boolean subtract) { if (previousRoi==null) return; - IJ.log("Update: "+add+" "+subtract); if (add) { previousRoi.modState = ADD_TO_ROI; if(subtract) previousRoi.modState = KEEP_WITHIN_ROI;