Skip to content

Commit

Permalink
fix scrolling when holding SHIFT in 3D view
Browse files Browse the repository at this point in the history
  • Loading branch information
cmhulbert committed Jan 13, 2021
1 parent 07f061b commit 2818cae
Showing 1 changed file with 42 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,53 +86,52 @@ 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;
double scrollFactor;

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();
}
if (event.isShiftDown()) {
/* If SHIFT is held down, Java interprets the scroll wheel as a horizontal scroll.
* Check for the X delta instead of Y*/
scroll = event.getDeltaX();
if (event.isControlDown()) {
scrollFactor = scroll > 0 ? 1.01 : 1 / 1.01;
} else {
scrollFactor = scroll > 0 ? 2.05 : 1 / 2.05;
}
} else {
scroll = event.getDeltaY();
scrollFactor = scroll > 0 ? 1.05 : 1 / 1.05;
}

if (Math.abs(scroll) > 0) {
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 2818cae

Please sign in to comment.