Package ej.microui.event.generator

## Class Pointer

- java.lang.Object
- - ej.microui.event.EventGenerator
  - - ej.microui.event.generator.Buttons
    - - ej.microui.event.generator.Pointer

-     public class Pointer
      extends Buttons

  A pointer event generator represents a pointing device that is usually associated to a group of physical buttons. It reports the position of a pointing device as an x, y position within an area called pointer area. The size of the pointer area is set when the pointer is constructed and cannot be modified. When a pointer is pre-configured within a system its area is normally set to be the area of the `Display` with which it is associated. The associated MicroUI event type is `EVENT_TYPE`.

  The pointer can be asked for the absolute position, expressed in terms of the pointer area with which it was constructed. It can also be asked for scaled co-ordinates (`getX()`, `getY()`). The scaled area is set using the `setScale(int, int)` method. By default there is no scaling (scaled area is the pointer area).

  It is also possible to specify, using `setOrigin(int, int)`, an offset to be applied to the co-ordinates returned by `getX()` and `getX()`. For example, if the origin is set to be `(20, 30)` then the x position returned will be the absolute x position - 20, and the y position will be the absolute y position - 30. By default there is no offset.

  If both scaling and origin adjustment are specified then the origin offset is first applied to the absolute position then the scaling is applied.

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `static int` | `DRAGGED` | Constant for "dragged" action.
    `static int` | `EVENT_TYPE` | The POINTER event type returned by `getEventType()`.
    `static int` | `MOVED` | Constant for "moved" action.

    - ### Fields inherited from class ej.microui.event.generator.Buttons

      `CLICKED, DOUBLE_CLICKED, LONG, PRESSED, RELEASED, REPEATED`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `Pointer​(int width, int height)` | Constructor with a specified area range (`width` and `height`) that does not support click, doubleClick nor elapsedTime for any of its buttons.
    `Pointer​(int nbButtons, int width, int height)` | Constructor with a specified area range (`width` and `height`) where elapsedTime, click and doubleClick features are supported and enabled for the first `nbButtons` (doubleClick feature is initialized with a 200ms delay).

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `int` | `getAbsoluteHeight()` |
    `int` | `getAbsoluteWidth()` |
    `int` | `getAbsoluteX()` | Returns the last available absolute x coordinate in pointer area
    `int` | `getAbsoluteY()` | Returns the last available absolute y coordinate in pointer area
    `int` | `getEventType()` | Gets the event type associated with the event generator
    `int` | `getHeight()` |
    `int` | `getWidth()` |
    `int` | `getX()` | Returns the last available x coordinate in scaled area (after applying any origin offset and the scale factor).
    `int` | `getY()` | Returns the last available y coordinate in scaled area (after applying any origin offset and the scale factor).
    `static boolean` | `isDragged​(int event)` | Tells if a pointer event is a drag event.
    `static boolean` | `isMoved​(int event)` | Tells if a pointer event is a move event.
    `void` | `move​(int x, int y)` | Stores the given position and sends a MicroUI Event to the Pointer's listener.
    `void` | `reset​(int x, int y)` | Stores the given position.
    `void` | `setOrigin​(int x0, int y0)` | Sets an origin offset.
    `void` | `setScale​(int areaWidth, int areaHeight)` | Sets a scaled area.

    - ### Methods inherited from class ej.microui.event.generator.Buttons

      `buildEvent, clickEnabled, doubleClickEnabled, elapsedTime, enableClick, enableDoubleClick, getAction, getButtonId, isClicked, isDoubleClicked, isLong, isPressed, isReleased, isRepeated, send, supportsExtendedFeatures`

    - ### Methods inherited from class ej.microui.event.EventGenerator

      `addToSystemPool, get, get, get, getEventHandler, getId, removeFromSystemPool, sendEvent, setEventHandler`

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

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

- - ### Field Detail

    - #### EVENT_TYPE

          public static final int EVENT_TYPE

      The POINTER event type returned by `getEventType()`.
      See Also:
        Constant Field Values

    - #### MOVED

          public static final int MOVED

      Constant for "moved" action.
      See Also:
        Constant Field Values

    - #### DRAGGED

          public static final int DRAGGED

      Constant for "dragged" action.
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### Pointer

          public Pointer​(int nbButtons,
                         int width,
                         int height)

      Constructor with a specified area range (`width` and `height`) where elapsedTime, click and doubleClick features are supported and enabled for the first `nbButtons` (doubleClick feature is initialized with a 200ms delay).
      Parameters:
        `nbButtons` - the number of buttons that support the extended features
        `width` - area width
        `height` - area height

    - #### Pointer

          public Pointer​(int width,
                         int height)

      Constructor with a specified area range (`width` and `height`) that does not support click, doubleClick nor elapsedTime for any of its buttons. The effect is identical to:
      `new Pointer(0, width, height)`.
      Parameters:
        `width` - area width
        `height` - area height

  - ### Method Detail

    - #### getAbsoluteWidth

          public int getAbsoluteWidth()

      Returns:
        pointer area width

    - #### getAbsoluteHeight

          public int getAbsoluteHeight()

      Returns:
        pointer area height

    - #### getEventType

          public int getEventType()

      Description copied from class: `EventGenerator`
      Gets the event type associated with the event generator
      Overrides:
        `getEventType` in class `Buttons`
      Returns:
        the event type

    - #### getX

          public int getX()

      Returns the last available x coordinate in scaled area (after applying any origin offset and the scale factor).
      Returns:
        last available x coordinate
      See Also:
        `getAbsoluteX()`

    - #### getY

          public int getY()

      Returns the last available y coordinate in scaled area (after applying any origin offset and the scale factor).
      Returns:
        last available y coordinate
      See Also:
        `getAbsoluteY()`

    - #### getAbsoluteX

          public int getAbsoluteX()

      Returns the last available absolute x coordinate in pointer area
      Returns:
        last available absolute x coordinate

    - #### getAbsoluteY

          public int getAbsoluteY()

      Returns the last available absolute y coordinate in pointer area
      Returns:
        last available absolute y coordinate

    - #### setScale

          public void setScale​(int areaWidth,
                               int areaHeight)

      Sets a scaled area. The x position returned by `getX()` is scaled so that it returns a value between 0 and areaWidth-1. The x position returned by `getY()` is scaled so that it returns a value between 0 and areaHeight-1.
      Parameters:
        `areaWidth` - the area width
        `areaHeight` - the area height

    - #### setOrigin

          public void setOrigin​(int x0,
                                int y0)

      Sets an origin offset. This offset is subtracted from the absolute position (before applying any scaling) when reporting x and y positions.
      Parameters:
        `x0` - the X coordinate of the new origin
        `y0` - the Y coordinate of the new origin

    - #### getWidth

          public int getWidth()

      Returns:
        the width of the scaled area
      See Also:
        `getX()`

    - #### getHeight

          public int getHeight()

      Returns:
        the height of the scaled area
      See Also:
        `getY()`

    - #### move

          public void move​(int x,
                           int y)

      Stores the given position and sends a MicroUI Event to the Pointer's listener. Coordinates are clipped to the pointer area.
      Parameters:
        `x` - the x coordinate
        `y` - the y coordinate

    - #### reset

          public void reset​(int x,
                            int y)

      Stores the given position. The Pointer's listener is not notified. Coordinates are clipped to the pointer area.
      Parameters:
        `x` - the x coordinate
        `y` - the y coordinate

    - #### isMoved

          public static boolean isMoved​(int event)

      Tells if a pointer event is a move event.
      Parameters:
        `event` - the pointer event.
      Returns:
        true if the pointer event is a move event.

    - #### isDragged

          public static boolean isDragged​(int event)

      Tells if a pointer event is a drag event.
      Parameters:
        `event` - the pointer event.
      Returns:
        true if the pointer event is a drag event.