org.gicentre.utils.move

## Class ZoomPan30

- java.lang.Object
- - org.gicentre.utils.move.ZoomPan30

-     public class ZoomPan30
      extends java.lang.Object

  Class to allow interactive zooming and panning of the Processing display. This is the Processing 3.x implementation that uses Processing 3's event handling model. This should not be created directly, but instead it will be created at runtime by the `ZoomPan` class if it detects Processing 3.x core libraries. Despite this, the class has to remain public so that it can be registered by Processing's event handling model.
  Version:
    3.4, 5th February 2016.
  Author:
    Jo Wood and Aidan Slingsby, giCentre, City University London.

- - ### Method Summary

    All Methods Instance Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addZoomPanListener(ZoomPanListener zoomPanListener)` Adds a listener to be informed when some zooming or panning has finished.
    `void` | `allowPanButton(boolean allowPan)` Determines whether or not panning is permitted via a button press.
    `void` | `allowZoomButton(boolean allowZoom)` Determines whether or not zooming via a button press is permitted.
    `processing.core.PVector` | `getCoordToDisp(processing.core.PVector p)` Transforms the given point from coordinate to display space.
    `processing.core.PVector` | `getDispToCoord(processing.core.PVector p)` Transforms the given point from display to coordinate space.
    `processing.core.PVector` | `getMouseCoord()` Reports the current mouse position in coordinate space.
    `processing.core.PVector` | `getPanOffset()` Reports the current pan offset.
    `ZoomPan.ZoomPanDirection` | `getZoomPanDirection()` Reports the zoom/zan behaviour type.
    `ZoomPanState` | `getZoomPanState()` Provides a copy (cloned snapshot) of the current ZoomPanState.
    `double` | `getZoomScale()` Reports the current zoom scale.
    `double` | `getZoomScaleX()` Reports the current zoom scale in X.
    `double` | `getZoomScaleY()` Reports the current zoom scale in Y.
    `boolean` | `isMouseCaptured()` Reports whether a mouse event has been captured by the zoomer.
    `boolean` | `isPanning()` Reports whether display is currently being panned (ie mouse is being dragged with pan key/button pressed).
    `boolean` | `isZooming()` Reports whether display is currently being zoomed (i.e.
    `void` | `mouseEvent(processing.event.MouseEvent e)` Updates zoom and pan transformation according to mouse activity.
    `boolean` | `removeZoomPanListener(ZoomPanListener zoomPanListener)` Removes the given listener from those to be informed when zooming/panning has finished.
    `void` | `reset()` Resets the display to unzoomed and unpanned position.
    `void` | `setMaxZoomScale(double maxZoomScale)` Sets the maximum permitted zoom scale (i.e.
    `void` | `setMaxZoomScaleX(double maxZoomScaleX)` Sets the maximum permitted zoom scale in X(i.e.
    `void` | `setMaxZoomScaleY(double maxZoomScaleY)` Sets the maximum permitted zoom scale in Y(i.e.
    `void` | `setMinZoomScale(double minZoomScale)` Sets the minimum permitted zoom scale (i.e.
    `void` | `setMinZoomScaleX(double minZoomScaleX)` Sets the minimum permitted zoom scale in X (i.e.
    `void` | `setMinZoomScaleY(double minZoomScaleY)` Sets the minimum permitted zoom scale in Y(i.e.
    `void` | `setMouseMask(int mouseMask)` Sets the key that must be pressed before mouse actions are active.
    `void` | `setPanOffset(float panX, float panY)` Sets a new pan offset.
    `void` | `setZoomMouseButton(int zoomMouseButton)` Sets mouse button for zooming.
    `void` | `setZoomPanDirection(ZoomPan.ZoomPanDirection zoomPanDirection)` Sets the zooming/panning direction
    `void` | `setZoomScale(double zoomScale)` Sets a new zoom scale.
    `void` | `setZoomScale(double zoomScaleX, double zoomScaleY)` Sets a new zoom scale for X and Y.
    `void` | `setZoomScaleX(double zoomScaleX)` Sets a new zoom scale in X.
    `void` | `setZoomScaleY(double zoomScaleY)` Sets a new zoom scale.
    `void` | `text(java.lang.String textToDisplay, float xPos, float yPos)` Deprecated. Should no longer be required as Processing bug fixed in 3.0.
    `void` | `transform()` Performs the zooming/panning transformation.
    `void` | `transform(processing.core.PGraphics offScreenBuffer)` Performs the zooming/panning transformation in the given graphics context.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### transform

          public void transform()

      Performs the zooming/panning transformation. This method should be called in the draw() method before any drawing that is to be zoomed or panned.

    - #### transform

          public void transform(processing.core.PGraphics offScreenBuffer)

      Performs the zooming/panning transformation in the given graphics context. This version of transform() can be used for transforming off-screen buffers that were not provided to the constructor. Can be useful when a sketch temporarily creates an off-screen buffer that needs to be zoomed and panned in the same way as the main PApplet.
      Parameters:
        `offScreenBuffer` - Graphics context in which to apply the zoom/pan transformation.

    - #### reset

          public void reset()

      Resets the display to unzoomed and unpanned position.

    - #### addZoomPanListener

          public void addZoomPanListener(ZoomPanListener zoomPanListener)

      Adds a listener to be informed when some zooming or panning has finished.
      Parameters:
        `zoomPanListener` - Listener to be informed when some zooming or panning has finished.

    - #### removeZoomPanListener

          public boolean removeZoomPanListener(ZoomPanListener zoomPanListener)

      Removes the given listener from those to be informed when zooming/panning has finished.
      Parameters:
        `zoomPanListener` - Listener to remove.
      Returns:
        True if listener found and removed.

    - #### setMouseMask

          public void setMouseMask(int mouseMask)

      Sets the key that must be pressed before mouse actions are active. By default, no key is needed for the mouse to be active. Specifying a value allows normal mouse actions to be intercepted without zooming or panning. To set the mouse mask to no key, specify a mouseMask value of 0. Mouse actions can be disabled entirely by setting the mouseMask to a negative value.
      Parameters:
        `mouseMask` - Keyboard modifier required to activate mouse actions. Valid values are `CONTROL`, `SHIFT`, `ALT`, `0` and `-1`.

    - #### getMouseCoord

          public processing.core.PVector getMouseCoord()

      Reports the current mouse position in coordinate space. This method should be used in preference to `mouseX` and `mouseY` if the current display has been zoomed or panned.
      Returns:
        Coordinates of current mouse position accounting for any zooming or panning.

    - #### getZoomScale

          public double getZoomScale()

      Reports the current zoom scale. Can be used for drawing objects that maintain their size when zooming.
      Returns:
        Current zoom scale.

    - #### getZoomScaleX

          public double getZoomScaleX()

      Reports the current zoom scale in X. Can be used for drawing objects that maintain their size when zooming.
      Returns:
        Current zoom scale.

    - #### getZoomScaleY

          public double getZoomScaleY()

      Reports the current zoom scale in Y. Can be used for drawing objects that maintain their size when zooming.
      Returns:
        Current zoom scale.

    - #### setZoomScale

          public void setZoomScale(double zoomScale)

      Sets a new zoom scale. Can be used for programmatic control of zoomer, such as eased interpolated zooming.
      Parameters:
        `zoomScale` - New zoom scale. A value of 1 indicates no zooming, values above 0 and below 1 will shrink the display; values above 1 will enlarge the display. Values less than or equal to 0 will be ignored.

    - #### setZoomScale

          public void setZoomScale(double zoomScaleX,
                                   double zoomScaleY)

      Sets a new zoom scale for X and Y. Can be used for programmatic control of zoomer, such as eased interpolated zooming.
      Parameters:
        `zoomScaleX` - New horizontal zoom scale. A value of 1 indicates no zooming, values above 0 and below 1 will shrink the display; values above 1 will enlarge the display. Values less than or equal to 0 will be ignored.
        `zoomScaleY` - New vertical zoom scale. A value of 1 indicates no zooming, values above 0 and below 1 will shrink the display; values above 1 will enlarge the display. Values less than or equal to 0 will be ignored.

    - #### setZoomScaleX

          public void setZoomScaleX(double zoomScaleX)

      Sets a new zoom scale in X. Can be used for programmatic control of zoomer, such as eased interpolated zooming.
      Parameters:
        `zoomScaleX` - New horizontal zoom scale. A value of 1 indicates no zooming, values above 0 and below 1 will shrink the display; values above 1 will enlarge the display. Values less than or equal to 0 will be ignored.

    - #### setZoomScaleY

          public void setZoomScaleY(double zoomScaleY)

      Sets a new zoom scale. Can be used for programmatic control of zoomer, such as eased interpolated zooming.
      Parameters:
        `zoomScaleY` - New vertical zoom scale. A value of 1 indicates no zooming, values above 0 and below 1 will shrink the display; values above 1 will enlarge the display. Values less than or equal to 0 will be ignored.

    - #### setZoomPanDirection

          public void setZoomPanDirection(ZoomPan.ZoomPanDirection zoomPanDirection)

      Sets the zooming/panning direction
      Parameters:
        `zoomPanDirection` - Direction of available zoom-pan transformations.

    - #### getZoomPanDirection

          public ZoomPan.ZoomPanDirection getZoomPanDirection()

      Reports the zoom/zan behaviour type.
      Returns:
        Reports the available zoom/pan options.

    - #### getPanOffset

          public processing.core.PVector getPanOffset()

      Reports the current pan offset. Useful when wishing to use an interpolated panning between this current value and some new pan offset.
      Returns:
        Current pan offset. Negative coordinates indicate an offset to the left or upwards, positive values to the right or downward.

    - #### setPanOffset

          public void setPanOffset(float panX,
                                   float panY)

      Sets a new pan offset. Can be used for programmatic control of panning, such as eased interpolated zooming and panning.
      Parameters:
        `panX` - X coordinate of new pan offset. A value of 0 indicates no translation of the display on the horizontal axis; a negative value indicates a translation to the left; a positive value indicates translation to the right.
        `panY` - Y coordinate of new pan offset. A value of 0 indicates no translation of the display on the vertical axis; a negative value indicates a translation upwards; a positive value indicates translation downwards.

    - #### isZooming

          public boolean isZooming()

      Reports whether display is currently being zoomed (i.e. mouse is being dragged with zoom key/button pressed).
      Returns:
        True if display is being actively zoomed.

    - #### isPanning

          public boolean isPanning()

      Reports whether display is currently being panned (ie mouse is being dragged with pan key/button pressed).
      Returns:
        True if display is being actively panned.

    - #### isMouseCaptured

          public boolean isMouseCaptured()

      Reports whether a mouse event has been captured by the zoomer. This allows zoom and pan events to be separated from other mouse actions. Usually only useful if the zoomer uses some mouse mask.
      Returns:
        True if mouse event has been captured by the zoomer.

    - #### allowZoomButton

          public void allowZoomButton(boolean allowZoom)

      Determines whether or not zooming via a button press is permitted. By default zooming is enabled with the appropriate mouse button, but can be disabled by setting allowZoom to false. Note that the scroll wheel will zoom whether or not the zoom button is activated.
      Parameters:
        `allowZoom` - Zooming permitted via mouse button press if true.

    - #### allowPanButton

          public void allowPanButton(boolean allowPan)

      Determines whether or not panning is permitted via a button press. By default panning is enabled with the appropriate mouse button, but can be disabled by setting allowPan to false.
      Parameters:
        `allowPan` - Panning permitted via mouse button press if true.

    - #### mouseEvent

          public void mouseEvent(processing.event.MouseEvent e)

      Updates zoom and pan transformation according to mouse activity.
      Parameters:
        `e` - Mouse event.

    - #### setMinZoomScale

          public void setMinZoomScale(double minZoomScale)

      Sets the minimum permitted zoom scale (i.e. how far zoomed out a view is allowed to be). If the current zoom level is smaller than the new minimum, the zoom scale will be set to the new minimum value. A value above zero but less than one means that the view will be smaller than its natural size. A value greater than one means the view will be larger than its natural size.
      Parameters:
        `minZoomScale` - Minimum permitted zoom scale.

    - #### setMinZoomScaleX

          public void setMinZoomScaleX(double minZoomScaleX)

      Sets the minimum permitted zoom scale in X (i.e. how far zoomed out a view is allowed to be). If the current zoom level is smaller than the new minimum, the zoom scale will be set to the new minimum value. A value above zero but less than one means that the view will be smaller than its natural size. A value greater than one means the view will be larger than its natural size.
      Parameters:
        `minZoomScaleX` - Minimum horizontal zoom scale.

    - #### setMinZoomScaleY

          public void setMinZoomScaleY(double minZoomScaleY)

      Sets the minimum permitted zoom scale in Y(i.e. how far zoomed out a view is allowed to be). If the current zoom level is smaller than the new minimum, the zoom scale will be set to the new minimum value. A value above zero but less than one means that the view will be smaller than its natural size. A value greater than one means the view will be larger than its natural size.
      Parameters:
        `minZoomScaleY` - Minimum vertical zoom scale.

    - #### setMaxZoomScale

          public void setMaxZoomScale(double maxZoomScale)

      Sets the maximum permitted zoom scale (i.e. how far zoomed in a view is allowed to be). If the current zoom level is larger than the new maximum, the zoom scale will be set to the new maximum value. A value above zero but less than one means that the view will be smaller than its natural size. A value greater than one means the view will be larger than its natural size.
      Parameters:
        `maxZoomScale` - Maximum permitted zoom scale.

    - #### setMaxZoomScaleX

          public void setMaxZoomScaleX(double maxZoomScaleX)

      Sets the maximum permitted zoom scale in X(i.e. how far zoomed in a view is allowed to be). If the current zoom level is larger than the new maximum, the zoom scale will be set to the new maximum value. A value above zero but less than one means that the view will be smaller than its natural size. A value greater than one means the view will be larger than its natural size.
      Parameters:
        `maxZoomScaleX` - Maximum horizontal zoom scale.

    - #### setMaxZoomScaleY

          public void setMaxZoomScaleY(double maxZoomScaleY)

      Sets the maximum permitted zoom scale in Y(i.e. how far zoomed in a view is allowed to be). If the current zoom level is larger than the new maximum, the zoom scale will be set to the new maximum value. A value above zero but less than one means that the view will be smaller than its natural size. A value greater than one means the view will be larger than its natural size.
      Parameters:
        `maxZoomScaleY` - Maximum vertical zoom scale.

    - #### getDispToCoord

          public processing.core.PVector getDispToCoord(processing.core.PVector p)

      Transforms the given point from display to coordinate space. Display space is that which has been subjected to zooming and panning. Coordinate space is the original space into which objects have been placed before zooming and panning. For most drawing operations you should not need to use this method. It is available for those operations that do not draw directly, but need to know the transformation between coordinate and screen space.
      Parameters:
        `p` - 2D point in zoomed display space.
      Returns:
        Location of point in original coordinate space.

    - #### getCoordToDisp

          public processing.core.PVector getCoordToDisp(processing.core.PVector p)

      Transforms the given point from coordinate to display space. Display space is that which has been subjected to zooming and panning. Coordinate space is the original space into which objects have been placed before zooming and panning. For most drawing operations you should not need to use this method. It is available for those operations that do not draw directly, but need to know the transformation between coordinate and screen space.
      Parameters:
        `p` - 2D point in original coordinate space.
      Returns:
        Location of point in zoomed display space.

    - #### setZoomMouseButton

          public void setZoomMouseButton(int zoomMouseButton)

      Sets mouse button for zooming. If this is set to either LEFT or RIGHT, the other button (RIGHT or LEFT) will be set for panning.
      Parameters:
        `zoomMouseButton` - Zoom mouse button (must be either PConstants.LEFT or PConstants.RIGHT

    - #### text

          @Deprecated
          public void text(java.lang.String textToDisplay,
                                       float xPos,
                                       float yPos)

      Deprecated. Should no longer be required as Processing bug fixed in 3.0.
      Replacement for Processing's `text()` method for faster and more accurate placement of characters in Java2D mode when a zoomed font is to be displayed. This method is not necessary when text is not subject to scaling via zooming, nor is is necessary in `P2D`, `P3D` or `OpenGL` modes.
      Parameters:
        `textToDisplay` - Text to be displayed.
        `xPos` - x-position of the the text to display in original unzoomed screen coordinates.
        `yPos` - y-position of the the text to display in original unzoomed screen coordinates.

    - #### getZoomPanState

          public ZoomPanState getZoomPanState()

      Provides a copy (cloned snapshot) of the current ZoomPanState. You can assume that this will not change its state.
      Returns:
        Copy of the current zoomPanState.