0

In most applications rotating wheel down descreases the size of scaled objects, while rotating wheel up increases sizes.

In piccolo2d default behavior is reversed:

private static void showWorldNode() {
        new PFrame() {

            @Override
            public void initialize() {

                getCanvas().getLayer().addChild(worldNode);

                PMouseWheelZoomEventHandler mouseWheelZoomEventHandler = new PMouseWheelZoomEventHandler();
                mouseWheelZoomEventHandler.zoomAboutMouse();
                getCanvas().addInputEventListener(mouseWheelZoomEventHandler);
            }

        };
    }

How to reverse to default?

Suzan Cioc
  • 29,281
  • 63
  • 213
  • 385

1 Answers1

1

You can provide a negative scale factor to reverse the behavior, for example:

mouseWheelZoomEventHandler.setScaleFactor(-0.1d);

PMouseWheelZoomEventHandler calculates the zoom value based on the scale factor and the value of MouseWheelEvent.getWheelRotation() which returns:

negative values if the mouse wheel was rotated up/away from the user, and positive values if the mouse wheel was rotated down/ towards the user

Here is the relevant code from PMouseWheelZoomEventHandler

double scale = 1.0d + event.getWheelRotation() * scaleFactor;
tenorsax
  • 21,123
  • 9
  • 60
  • 107
  • Strange, but while scale of `-0.1` worked, scale of `-1` is causing exception when rotating back. – Suzan Cioc May 23 '14 at 13:35
  • @SuzanCioc yes, according to the calculation of `scale` mentioned above, `scaleFactor = -1` results in `scale = 0`. `PAffineTransform` protects against zero division for calculation of inverse transform and it throws `PAffineTransformException`. – tenorsax May 23 '14 at 22:06