Class MotionEvent

java.lang.Object
icyllis.modernui.view.InputEvent
icyllis.modernui.view.MotionEvent

public final class MotionEvent extends InputEvent
Object that indicates movement events (mouse, touchpad etc.). Modified for desktop application, such as multiple pointers are disabled.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Constant for getActionMasked(): A button has been pressed.
    static final int
    Constant for getActionMasked(): A button has been released.
    static final int
    Constant for getActionMasked(): The current gesture has been aborted.
    static final int
    Constant for getActionMasked(): A pressed gesture has started, the motion contains the initial starting location.
    static final int
    Constant for getActionMasked(): The pointer is not down but has entered the boundaries of a window or view.
    static final int
    Constant for getActionMasked(): The pointer is not down but has exited the boundaries of a window or view.
    static final int
    Constant for getActionMasked(): A change happened but the pointer is not down (unlike ACTION_MOVE).
    static final int
    Bit mask of the parts of the action code that are the action itself.
    static final int
    Constant for getActionMasked(): A change has happened during a press gesture (between ACTION_DOWN and ACTION_UP).
    static final int
    Constant for getActionMasked(): A movement has happened outside the normal bounds of the UI element.
    static final int
    Constant for getActionMasked(): A non-primary pointer has gone down.
    static final int
    Bits in the action code that represent a pointer index, used with ACTION_POINTER_DOWN and ACTION_POINTER_UP.
    static final int
    Bit shift for the action bits holding the pointer index as defined by ACTION_POINTER_INDEX_MASK.
    static final int
    Constant for getActionMasked(): A non-primary pointer has gone up.
    static final int
    Constant for getActionMasked(): The motion event contains relative vertical and/or horizontal scroll offsets.
    static final int
    Constant for getActionMasked(): A pressed gesture has finished, the motion contains the final release location as well as any intermediate points since the last down or move event.
    static final int
    Axis constant: Horizontal Scroll axis of a motion event.
    static final int
    Axis constant: Vertical Scroll axis of a motion event.
    static final int
    Axis constant: X axis of a motion event.
    static final int
    Axis constant: Y axis of a motion event.
    static final int
    Button constant: Back button pressed (mouse back button).
    static final int
    Button constant: Forward button pressed (mouse forward button).
    static final int
    Button constant: Primary button (left mouse button).
    static final int
    Button constant: Secondary button (right mouse button).
    static final int
    Button constant: Tertiary button (middle mouse button).
    static final int
    This private flag is only set on ACTION_HOVER_MOVE events and indicates that this event will be immediately followed by a ACTION_HOVER_EXIT.
    static final int
    Private flag that indicates when the system has detected that this motion event may be inconsistent with respect to the sequence of previously delivered motion events, such as when a pointer move event is sent but the pointer is not down.
    static final int
    An invalid pointer id.
    static final int
    Tool type constant: Unknown tool type.
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    actionToString(int action)
    Returns a string that represents the symbolic name of the specified unmasked action such as "ACTION_DOWN", "ACTION_POINTER_DOWN(3)" or an equivalent numeric constant such as "35" if unknown.
    static String
    buttonStateToString(int buttonState)
    Returns a string that represents the symbolic name of the specified combined button state flags such as "0", "BUTTON_PRIMARY", "BUTTON_PRIMARY|BUTTON_SECONDARY" or an equivalent numeric constant such as "0x10000000" if unknown.
    void
    Marks the input event as being canceled.
    Create a new MotionEvent, copying from this one.
    int
    Return the kind of action being performed.
    int
    Gets which button has been modified during a press or release action.
    int
    Return the masked action being performed, without pointer index information.
    float
    getAxisValue(int axis)
    Gets the value associated with the specified axis for the first pointer index (may be an arbitrary pointer identifier).
    int
    Gets the state of all buttons that are pressed such as a mouse, use an AND operation to get the state of a button.
    long
    Get the time in milliseconds that this event object is created in the GLFW time base
    long
    Get the precise time in nanoseconds that this event object is created in the GLFW time base
    int
    Returns the state of the modifier keys that were in effect when the event was generated.
    int
    The number of pointers of data contained in this event.
    int
    getPointerId(int pointerIndex)
    Return the pointer identifier associated with a particular pointer data index in this event.
    float
    Returns the original raw X coordinate of this event.
    float
    Returns the original raw Y coordinate of this event.
    int
    getToolType(int pointerIndex)
    Gets the tool type of a pointer for the given pointer index.
    float
    getX(int) for the first pointer index (may be an arbitrary pointer identifier).
    float
    getY(int) for the first pointer index (may be an arbitrary pointer identifier).
    boolean
    hasModifiers(int modifiers)
    Returns true if only the specified modifiers keys are pressed.
    boolean
    Returns the pressed state of the ALT key.
    boolean
    isButtonPressed(int button)
    Checks if a mouse button (or combination of buttons) is pressed.
    boolean
    Returns the locked state of the CAPS LOCK key.
    boolean
    Returns the pressed state of the CTRL key.
    boolean
     
    boolean
    Returns the locked state of the NUM LOCK key.
    boolean
    Returns the pressed state of the SHIFT key.
    boolean
    Returns the pressed state of the SUPER key (a.k.a.
    boolean
    Returns true if this motion event is a touch event.
    obtain(long eventTime, int action, float x, float y, int modifiers)
     
    obtain(long eventTime, int action, int actionButton, float x, float y, int modifiers, int buttonState, int flags)
    Create a new MotionEvent, filling in a subset of the basic motion values.
    void
    offsetLocation(float deltaX, float deltaY)
    Adjust this event's location.
    void
    Recycles the event.
    void
    setAction(int action)
    Sets this event's action.
    void
    setAxisValue(int axis, float value)
    Sets the value associated with the specified axis.
    void
    setHoverExitPending(boolean hoverExitPending)
     
    void
    setLocation(float x, float y)
    Set this event's location.
     
    void
    transform(Matrix matrix)
    Applies a transformation matrix to all of the points in the event.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • INVALID_POINTER_ID

      public static final int INVALID_POINTER_ID
      An invalid pointer id.

      This value (-1) can be used as a placeholder to indicate that a pointer id has not been assigned or is not available.
      It cannot appear as a pointer id inside a MotionEvent.

      See Also:
    • ACTION_MASK

      public static final int ACTION_MASK
      Bit mask of the parts of the action code that are the action itself.
      See Also:
    • ACTION_DOWN

      public static final int ACTION_DOWN
      Constant for getActionMasked(): A pressed gesture has started, the motion contains the initial starting location.

      This is also a good time to check the button state to distinguish secondary and tertiary button clicks and handle them appropriately. Use getButtonState() to retrieve the button state.

      See Also:
    • ACTION_UP

      public static final int ACTION_UP
      Constant for getActionMasked(): A pressed gesture has finished, the motion contains the final release location as well as any intermediate points since the last down or move event.
      See Also:
    • ACTION_MOVE

      public static final int ACTION_MOVE
      Constant for getActionMasked(): A change has happened during a press gesture (between ACTION_DOWN and ACTION_UP). The motion contains the most recent point, as well as any intermediate points since the last down or move event.
      See Also:
    • ACTION_CANCEL

      public static final int ACTION_CANCEL
      Constant for getActionMasked(): The current gesture has been aborted. You will not receive any more points in it. You should treat this as an up event, but not perform any action that you normally would.
      See Also:
    • ACTION_OUTSIDE

      public static final int ACTION_OUTSIDE
      Constant for getActionMasked(): A movement has happened outside the normal bounds of the UI element. This does not provide a full gesture, but only the initial location of the movement/touch.

      Note: Because the location of any event will be outside the bounds of the view hierarchy, it will not get dispatched to any children of a ViewGroup by default. Therefore, movements with ACTION_OUTSIDE should be handled in either the root View.

      See Also:
    • ACTION_POINTER_DOWN

      public static final int ACTION_POINTER_DOWN
      Constant for getActionMasked(): A non-primary pointer has gone down.

      Use getActionIndex() to retrieve the index of the pointer that changed.

      The index is encoded in the ACTION_POINTER_INDEX_MASK bits of the unmasked action returned by getAction().

      See Also:
    • ACTION_POINTER_UP

      public static final int ACTION_POINTER_UP
      Constant for getActionMasked(): A non-primary pointer has gone up.

      Use getActionIndex() to retrieve the index of the pointer that changed.

      The index is encoded in the ACTION_POINTER_INDEX_MASK bits of the unmasked action returned by getAction().

      See Also:
    • ACTION_HOVER_MOVE

      public static final int ACTION_HOVER_MOVE
      Constant for getActionMasked(): A change happened but the pointer is not down (unlike ACTION_MOVE). The motion contains the most recent point, as well as any intermediate points since the last hover move event.

      This action is always delivered to the window or view under the pointer.

      This action is not a touch event so it is delivered to View.onGenericMotionEvent(MotionEvent) rather than View.onTouchEvent(MotionEvent).

      See Also:
    • ACTION_SCROLL

      public static final int ACTION_SCROLL
      Constant for getActionMasked(): The motion event contains relative vertical and/or horizontal scroll offsets. Use getAxisValue(int) to retrieve the information from AXIS_VSCROLL and AXIS_HSCROLL. The pointer may or may not be down when this event is dispatched.

      This action is always delivered to the window or view under the pointer, which may not be the window or view currently touched.

      This action is not a touch event so it is delivered to View.onGenericMotionEvent(MotionEvent) rather than View.onTouchEvent(MotionEvent).

      See Also:
    • ACTION_HOVER_ENTER

      public static final int ACTION_HOVER_ENTER
      Constant for getActionMasked(): The pointer is not down but has entered the boundaries of a window or view.

      This action is always delivered to the window or view under the pointer.

      This action is not a touch event so it is delivered to View.onGenericMotionEvent(MotionEvent) rather than View.onTouchEvent(MotionEvent).

      See Also:
    • ACTION_HOVER_EXIT

      public static final int ACTION_HOVER_EXIT
      Constant for getActionMasked(): The pointer is not down but has exited the boundaries of a window or view.

      This action is always delivered to the window or view that was previously under the pointer.

      This action is not a touch event so it is delivered to View.onGenericMotionEvent(MotionEvent) rather than View.onTouchEvent(MotionEvent).

      See Also:
    • ACTION_BUTTON_PRESS

      public static final int ACTION_BUTTON_PRESS
      Constant for getActionMasked(): A button has been pressed.

      Use getActionButton() to get which button was pressed.

      This action is not a touch event so it is delivered to View.onGenericMotionEvent(MotionEvent) rather than View.onTouchEvent(MotionEvent).

      See Also:
    • ACTION_BUTTON_RELEASE

      public static final int ACTION_BUTTON_RELEASE
      Constant for getActionMasked(): A button has been released.

      Use getActionButton() to get which button was released.

      This action is not a touch event so it is delivered to View.onGenericMotionEvent(MotionEvent) rather than View.onTouchEvent(MotionEvent).

      See Also:
    • ACTION_POINTER_INDEX_MASK

      public static final int ACTION_POINTER_INDEX_MASK
      Bits in the action code that represent a pointer index, used with ACTION_POINTER_DOWN and ACTION_POINTER_UP. Shifting down by ACTION_POINTER_INDEX_SHIFT provides the actual pointer index where the data for the pointer going up or down can be found; you can get its identifier with getPointerId(int) and the actual data with getX(int) etc.
      See Also:
    • ACTION_POINTER_INDEX_SHIFT

      public static final int ACTION_POINTER_INDEX_SHIFT
      Bit shift for the action bits holding the pointer index as defined by ACTION_POINTER_INDEX_MASK.
      See Also:
    • FLAG_HOVER_EXIT_PENDING

      @Internal public static final int FLAG_HOVER_EXIT_PENDING
      This private flag is only set on ACTION_HOVER_MOVE events and indicates that this event will be immediately followed by a ACTION_HOVER_EXIT. It is used to prevent generating redundant ACTION_HOVER_ENTER events.
      See Also:
    • FLAG_TAINTED

      @Internal public static final int FLAG_TAINTED
      Private flag that indicates when the system has detected that this motion event may be inconsistent with respect to the sequence of previously delivered motion events, such as when a pointer move event is sent but the pointer is not down.
      See Also:
    • BUTTON_PRIMARY

      public static final int BUTTON_PRIMARY
      Button constant: Primary button (left mouse button).

      This button constant is not set in response to simple touches with a finger or stylus tip.
      The user must actually push a button.

      See Also:
    • BUTTON_SECONDARY

      public static final int BUTTON_SECONDARY
      Button constant: Secondary button (right mouse button).
      See Also:
    • BUTTON_TERTIARY

      public static final int BUTTON_TERTIARY
      Button constant: Tertiary button (middle mouse button).
      See Also:
    • BUTTON_BACK

      public static final int BUTTON_BACK
      Button constant: Back button pressed (mouse back button).
      See Also:
    • BUTTON_FORWARD

      public static final int BUTTON_FORWARD
      Button constant: Forward button pressed (mouse forward button).
      See Also:
    • TOOL_TYPE_UNKNOWN

      public static final int TOOL_TYPE_UNKNOWN
      Tool type constant: Unknown tool type. This constant is used when the tool type is not known or is not relevant, such as for a trackball or other non-pointing device.
      See Also:
    • AXIS_X

      public static final int AXIS_X
      Axis constant: X axis of a motion event.

      • For a touch screen, reports the absolute X screen position of the center of the touch contact area. The units are display pixels.
      • For a touch pad, reports the absolute X surface position of the center of the touch contact area.
      • For a mouse, reports the absolute X screen position of the mouse pointer. The units are display pixels.
      • For a trackball, reports the relative horizontal displacement of the trackball. The value is normalized to a range from -1.0 (left) to 1.0 (right).
      • For a joystick, reports the absolute X position of the joystick. The value is normalized to a range from -1.0 (left) to 1.0 (right).

      See Also:
    • AXIS_Y

      public static final int AXIS_Y
      Axis constant: Y axis of a motion event.

      • For a touch screen, reports the absolute Y screen position of the center of the touch contact area. The units are display pixels.
      • For a touch pad, reports the absolute Y surface position of the center of the touch contact area.
      • For a mouse, reports the absolute Y screen position of the mouse pointer. The units are display pixels.
      • For a trackball, reports the relative vertical displacement of the trackball. The value is normalized to a range from -1.0 (up) to 1.0 (down).
      • For a joystick, reports the absolute Y position of the joystick. The value is normalized to a range from -1.0 (up or far) to 1.0 (down or near).

      See Also:
    • AXIS_VSCROLL

      public static final int AXIS_VSCROLL
      Axis constant: Vertical Scroll axis of a motion event.

      • For a mouse, reports the relative movement of the vertical scroll wheel. The value is normalized to a range from -1.0 (down) to 1.0 (up).

      This axis should be used to scroll views vertically.

      See Also:
    • AXIS_HSCROLL

      public static final int AXIS_HSCROLL
      Axis constant: Horizontal Scroll axis of a motion event.

      • For a mouse, reports the relative movement of the horizontal scroll wheel. The value is normalized to a range from -1.0 (left) to 1.0 (right).

      This axis should be used to scroll views horizontally.

      See Also:
  • Method Details

    • obtain

      @NonNull public static MotionEvent obtain(long eventTime, int action, float x, float y, int modifiers)
    • obtain

      @NonNull public static MotionEvent obtain(long eventTime, int action, int actionButton, float x, float y, int modifiers, int buttonState, int flags)
      Create a new MotionEvent, filling in a subset of the basic motion values.
      Parameters:
      eventTime - The time (in ns) when this specific event was generated. This must be obtained from Core.timeNanos().
      action - The kind of action being performed, such as ACTION_DOWN.
      actionButton - The button of press or release action, such as BUTTON_PRIMARY
      x - The X coordinate of this event.
      y - The Y coordinate of this event.
      modifiers - The modifier keys that were in effect when the event was generated.
      buttonState - The state of buttons that are pressed.
      flags - The motion event flags.
    • recycle

      public void recycle()
      Recycles the event. This object should not be ever used after recycling.

      This method should only be called by system.

      Specified by:
      recycle in class InputEvent
    • getAction

      public int getAction()
      Return the kind of action being performed. Consider using getActionMasked() and getActionIndex() to retrieve the separate masked action and pointer index.
      Returns:
      The action, such as ACTION_DOWN or the combination of ACTION_POINTER_DOWN with a shifted pointer index.
    • getActionMasked

      public int getActionMasked()
      Return the masked action being performed, without pointer index information. Use getActionIndex() to return the index associated with pointer actions.
      Returns:
      The action, such as ACTION_DOWN or ACTION_POINTER_DOWN.
    • isTouchEvent

      public boolean isTouchEvent()
      Returns true if this motion event is a touch event.

      Specifically excludes pointer events with action ACTION_HOVER_MOVE, ACTION_HOVER_ENTER, ACTION_HOVER_EXIT, ACTION_SCROLL, ACTION_BUTTON_PRESS or ACTION_BUTTON_RELEASE, because they are not actually touch events (the pointer is not down).

      Returns:
      true if this motion event is a touch event.
    • setAction

      public void setAction(int action)
      Sets this event's action.
    • getButtonState

      public int getButtonState()
      Gets the state of all buttons that are pressed such as a mouse, use an AND operation to get the state of a button.
      Returns:
      The button state.
      See Also:
    • isButtonPressed

      public boolean isButtonPressed(int button)
      Checks if a mouse button (or combination of buttons) is pressed.
      Parameters:
      button - Button (or combination of buttons).
      Returns:
      true if specified buttons are pressed.
      See Also:
    • getPointerCount

      public int getPointerCount()
      The number of pointers of data contained in this event. Always >= 1.
    • getPointerId

      public int getPointerId(int pointerIndex)
      Return the pointer identifier associated with a particular pointer data index in this event. The identifier tells you the actual pointer number associated with the data, accounting for individual pointers going up and down since the start of the current gesture.
      Parameters:
      pointerIndex - Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
    • getToolType

      public int getToolType(int pointerIndex)
      Gets the tool type of a pointer for the given pointer index. The tool type indicates the type of tool used to make contact such as a finger or stylus, if known.
      Parameters:
      pointerIndex - Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
      Returns:
      The tool type of the pointer.
      See Also:
    • isHoverExitPending

      public boolean isHoverExitPending()
    • setHoverExitPending

      public void setHoverExitPending(boolean hoverExitPending)
    • copy

      @NonNull public MotionEvent copy()
      Create a new MotionEvent, copying from this one.
      Specified by:
      copy in class InputEvent
      Returns:
      A deep copy of the event.
    • getEventTime

      public long getEventTime()
      Description copied from class: InputEvent
      Get the time in milliseconds that this event object is created in the GLFW time base
      Specified by:
      getEventTime in class InputEvent
      Returns:
      the time this event occurred
    • getEventTimeNano

      public long getEventTimeNano()
      Description copied from class: InputEvent
      Get the precise time in nanoseconds that this event object is created in the GLFW time base
      Specified by:
      getEventTimeNano in class InputEvent
      Returns:
      the time this event occurred
    • cancel

      public void cancel()
      Description copied from class: InputEvent
      Marks the input event as being canceled.
      Specified by:
      cancel in class InputEvent
    • setAxisValue

      public void setAxisValue(int axis, float value)
      Sets the value associated with the specified axis.
      Parameters:
      axis - The axis identifier for the axis value to assign.
      value - The value to set.
    • getAxisValue

      public float getAxisValue(int axis)
      Gets the value associated with the specified axis for the first pointer index (may be an arbitrary pointer identifier).
      Parameters:
      axis - The axis identifier for the axis value to retrieve.
      Returns:
      The value associated with the axis, or 0 if none.
    • getX

      public float getX()
      getX(int) for the first pointer index (may be an arbitrary pointer identifier).
      See Also:
    • getY

      public float getY()
      getY(int) for the first pointer index (may be an arbitrary pointer identifier).
      See Also:
    • getRawX

      public float getRawX()
      Returns the original raw X coordinate of this event. For touch events on the screen, this is the original location of the event on the screen, before it had been adjusted for the containing window and views.
      See Also:
    • getRawY

      public float getRawY()
      Returns the original raw Y coordinate of this event. For touch events on the screen, this is the original location of the event on the screen, before it had been adjusted for the containing window and views.
      See Also:
    • getActionButton

      public int getActionButton()
      Gets which button has been modified during a press or release action.

      For actions other than ACTION_BUTTON_PRESS and ACTION_BUTTON_RELEASE the returned value is undefined.

      See Also:
    • offsetLocation

      public void offsetLocation(float deltaX, float deltaY)
      Adjust this event's location.
      Parameters:
      deltaX - Amount to add to the current X coordinate of the event.
      deltaY - Amount to add to the current Y coordinate of the event.
    • setLocation

      public void setLocation(float x, float y)
      Set this event's location. Applies offsetLocation(float, float) with a delta from the current location to the given new location.
      Parameters:
      x - New absolute X location.
      y - New absolute Y location.
    • transform

      public void transform(@NonNull Matrix matrix)
      Applies a transformation matrix to all of the points in the event.
      Parameters:
      matrix - The transformation matrix to apply.
    • getModifiers

      public int getModifiers()
      Returns the state of the modifier keys that were in effect when the event was generated. This is the same values as those returned by KeyEvent.getModifiers().
      Returns:
      an integer in which each bit set to 1 represents a pressed modifier key
      See Also:
    • hasModifiers

      public boolean hasModifiers(int modifiers)
      Returns true if only the specified modifiers keys are pressed. Returns false if a different combination of modifier keys are pressed.

      If the specified modifier mask includes non-directional modifiers, such as GLFW.GLFW_MOD_SHIFT, then this method ensures that the modifier is pressed on either side.

      Parameters:
      modifiers - The modifier keys to check. May be a combination of modifier keys. May be 0 to ensure that no modifier keys are pressed.
      Returns:
      true if only the specified modifier keys are pressed.
    • isShiftPressed

      public boolean isShiftPressed()
      Returns the pressed state of the SHIFT key.
      Returns:
      true if the SHIFT key is pressed, false otherwise
    • isCtrlPressed

      public boolean isCtrlPressed()
      Returns the pressed state of the CTRL key. If it's running on OSX, returns the pressed state of the SUPER key.
      Returns:
      true if the CTRL key is pressed, false otherwise
    • isAltPressed

      public boolean isAltPressed()
      Returns the pressed state of the ALT key.
      Returns:
      true if the ALT key is pressed, false otherwise
    • isSuperPressed

      public boolean isSuperPressed()
      Returns the pressed state of the SUPER key (a.k.a. META or WIN key).
      Returns:
      true if the SUPER key is pressed, false otherwise
    • isCapsLockOn

      public boolean isCapsLockOn()
      Returns the locked state of the CAPS LOCK key.
      Returns:
      true if the CAPS LOCK key is on, false otherwise
    • isNumLockOn

      public boolean isNumLockOn()
      Returns the locked state of the NUM LOCK key.
      Returns:
      true if the NUM LOCK key is on, false otherwise
    • toString

      @NonNull public String toString()
      Overrides:
      toString in class Object
    • actionToString

      @NonNull public static String actionToString(int action)
      Returns a string that represents the symbolic name of the specified unmasked action such as "ACTION_DOWN", "ACTION_POINTER_DOWN(3)" or an equivalent numeric constant such as "35" if unknown.
      Parameters:
      action - The unmasked action.
      Returns:
      The symbolic name of the specified action.
      See Also:
    • buttonStateToString

      public static String buttonStateToString(int buttonState)
      Returns a string that represents the symbolic name of the specified combined button state flags such as "0", "BUTTON_PRIMARY", "BUTTON_PRIMARY|BUTTON_SECONDARY" or an equivalent numeric constant such as "0x10000000" if unknown.
      Parameters:
      buttonState - The button state.
      Returns:
      The symbolic name of the specified combined button state flags.