Skip to content

Commit

Permalink
get largest scroll axis, since shift+scroll now returns X
Browse files Browse the repository at this point in the history
  • Loading branch information
cmhulbert committed Jan 13, 2021
1 parent 07f061b commit a3bc181
Showing 1 changed file with 37 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import org.janelia.saalfeldlab.fx.event.MouseDragFX;
import org.janelia.saalfeldlab.fx.util.InvokeOnJavaFXApplicationThread;
import org.janelia.saalfeldlab.paintera.control.ControlUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -86,53 +87,49 @@ public void setInitialTransformToInterval(final Interval interval)
InvokeOnJavaFXApplicationThread.invoke(() -> this.setAffine(initialTransform));
}

private void addCommands()
{
viewer.addEventHandler(ScrollEvent.SCROLL, event -> {
private void addCommands() {

final double scroll = event.getDeltaY();
double scrollFactor = scroll > 0 ? 1.05 : 1 / 1.05;
viewer.addEventHandler(ScrollEvent.SCROLL, event -> {

if (event.isShiftDown())
{
if (event.isControlDown())
{
scrollFactor = scroll > 0 ? 1.01 : 1 / 1.01;
}
else
{
scrollFactor = scroll > 0 ? 2.05 : 1 / 2.05;
}
}

if (Math.abs(event.getDeltaY()) > Math.abs(event.getDeltaX()))
{
final Affine target = affine.clone();
target.prependScale(scrollFactor, scrollFactor, scrollFactor);
InvokeOnJavaFXApplicationThread.invoke(() -> this.setAffine(target));
final double scroll = ControlUtils.getBiggestScroll(event);
if ( scroll == 0) {
event.consume();
return;
}

event.consume();
}
});

viewer.addEventHandler(KeyEvent.KEY_PRESSED, event -> {
if (event.getCode().equals(KeyCode.Z) && event.isShiftDown())
{
InvokeOnJavaFXApplicationThread.invoke(() -> this.setAffine(initialTransform));
event.consume();
}
});
double scrollFactor = scroll > 0 ? 1.05 : 1 / 1.05;

viewer.addEventHandler(KeyEvent.KEY_PRESSED, event -> {
if (event.getCode().equals(KeyCode.P) && event.isControlDown())
{
InvokeOnJavaFXApplicationThread.invoke(() -> {
saveAsPng();
});
event.consume();
}
if (event.isShiftDown()) {
if (event.isControlDown()) {
scrollFactor = scroll > 0 ? 1.01 : 1 / 1.01;
} else {
scrollFactor = scroll > 0 ? 2.05 : 1 / 2.05;
}
}
final Affine target = affine.clone();
target.prependScale(scrollFactor, scrollFactor, scrollFactor);
InvokeOnJavaFXApplicationThread.invoke(() -> this.setAffine(target));
event.consume();
});

viewer.addEventHandler(KeyEvent.KEY_PRESSED, event -> {
if (event.getCode().equals(KeyCode.Z) && event.isShiftDown()) {
InvokeOnJavaFXApplicationThread.invoke(() -> this.setAffine(initialTransform));
event.consume();
}
});

viewer.addEventHandler(KeyEvent.KEY_PRESSED, event -> {
if (event.getCode().equals(KeyCode.P) && event.isControlDown()) {
InvokeOnJavaFXApplicationThread.invoke(() -> {
saveAsPng();
});
}
event.consume();
}
});
}

private class Rotate extends MouseDragFX
{
Expand Down

0 comments on commit a3bc181

Please sign in to comment.