Skip to content

Commit

Permalink
Merge pull request #144 from saalfeldlab/fix-shift-scroll-issues
Browse files Browse the repository at this point in the history
Fix shift scroll issues
  • Loading branch information
hanslovsky authored Oct 15, 2018
2 parents a7133d4 + 68e2323 commit 928bba5
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.janelia.saalfeldlab.paintera.control;

import javafx.scene.input.ScrollEvent;

public class ControlUtils {

/**
*
* @param e event
* @return {@code e.getDeltaX()} if {@code e.getDeltaX() > e.getDeltaY()}, {@code e.getDeltaY()} otherwise.
*/
public static double getBiggestScroll(ScrollEvent e)
{
return getArgMaxWithRespectToAbs(e.getDeltaX(), e.getDeltaY());
}

private static double getArgMaxWithRespectToAbs(double v1, double v2)
{
return Math.abs(Math.abs(v1)) > Math.abs(v2) ? v1 : v2;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,17 @@ public Consumer<ViewerPanelFX> getOnEnter()

iars.add(EventFX.SCROLL(
"translate along normal",
e -> scrollDefault.scroll(-e.getDeltaY()),
e -> scrollDefault.scroll(-ControlUtils.getBiggestScroll(e)),
event -> keyTracker.noKeysActive()
));
iars.add(EventFX.SCROLL(
"translate along normal fast",
e -> scrollFast.scroll(-e.getDeltaY()),
e -> scrollFast.scroll(-ControlUtils.getBiggestScroll(e)),
event -> keyTracker.areOnlyTheseKeysDown(KeyCode.SHIFT)
));
iars.add(EventFX.SCROLL(
"translate along normal slow",
e -> scrollSlow.scroll(-e.getDeltaY()),
e -> scrollSlow.scroll(-ControlUtils.getBiggestScroll(e)),
event -> keyTracker.areOnlyTheseKeysDown(KeyCode.CONTROL)
));

Expand Down Expand Up @@ -219,7 +219,7 @@ public Consumer<ViewerPanelFX> getOnEnter()
final Zoom zoom = new Zoom(zoomSpeed::get, manager, viewerTransform, manager);
iars.add(EventFX.SCROLL(
"zoom",
event -> zoom.zoomCenteredAt(-event.getDeltaY(), event.getX(), event.getY()),
event -> zoom.zoomCenteredAt(-ControlUtils.getBiggestScroll(event), event.getX(), event.getY()),
event -> keyTracker.areOnlyTheseKeysDown(KeyCode.META) ||
keyTracker.areOnlyTheseKeysDown(KeyCode.CONTROL, KeyCode.SHIFT)
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public Consumer<ViewerPanelFX> getOnEnter()
));
iars.add(EventFX.SCROLL(
"change brush depth",
event -> paint2D.changeBrushDepth(event.getDeltaY()),
event -> paint2D.changeBrushDepth(-ControlUtils.getBiggestScroll(event)),
event -> keyTracker.areOnlyTheseKeysDown(
KeyCode.SPACE,
KeyCode.SHIFT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ public Zoom(

public void zoomCenteredAt(final double delta, final double x, final double y)
{

if (delta == 0.0)
{
return;
}

final AffineTransform3D global = new AffineTransform3D();
synchronized (lock)
{
Expand Down

0 comments on commit 928bba5

Please sign in to comment.