Class 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.

    • 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.