Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ROI -AND- operation when holding down shift and alt #115

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions ij/gui/ImageCanvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 6 additions & 3 deletions ij/gui/Roi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down