public final class PointerEvent
- Object
- PointerEvent
Immutable snapshot describing the rich detail of a pointer interaction that goes beyond the simple x/y coordinates carried by the legacy pointer callbacks.
A PointerEvent exposes which mouse button triggered the interaction, the kind of
pointing device used (finger, mouse, stylus or eraser), the pressure applied, stylus
tilt, the size of the contact area and the keyboard modifiers that were held down.
The snapshot is available in two ways:
- From an
ActionEventfired by a pointer listener viaActionEvent#getPointerEvent(). - By polling
com.codename1.ui.Display#getCurrentPointerEvent()(or the matchingcom.codename1.ui.CNconvenience method) while a pointer event is being dispatched.
Every value carries a safe default so code written against the rich API behaves predictably
on devices and ports that do not supply the extra detail. On such ports the button defaults to
BUTTON_PRIMARY, the pressure to 1.0, the type to TYPE_UNKNOWN and tilt/contact size to 0.
Fields
public static final int TYPE_UNKNOWN = 0 | The pointing device could not be determined. |
public static final int TYPE_TOUCH = 1 | The interaction came from a finger on a touch screen. |
public static final int TYPE_MOUSE = 2 | The interaction came from a mouse or trackpad. |
public static final int TYPE_STYLUS = 3 | The interaction came from a stylus or pen (Apple Pencil, S-Pen, Surface Pen and similar). |
public static final int TYPE_ERASER = 4 | The interaction came from the eraser end of a stylus. |
public static final int BUTTON_NONE = -1 | No button is associated with this event (for example a hover or a plain touch). |
public static final int BUTTON_PRIMARY = 0 | The primary (usually left) mouse button, or a plain touch/stylus contact. |
public static final int BUTTON_SECONDARY = 1 | The secondary (usually right) mouse button or stylus barrel button. |
public static final int BUTTON_MIDDLE = 2 | The middle mouse button (often the scroll wheel click). |
public static final int BUTTON_BACK = 3 | The back (fourth) mouse button. |
public static final int BUTTON_FORWARD = 4 | The forward (fifth) mouse button. |
public static final int MASK_PRIMARY = 1 | Button mask bit for the primary button. |
public static final int MASK_SECONDARY = 2 | Button mask bit for the secondary button. |
public static final int MASK_MIDDLE = 4 | Button mask bit for the middle button. |
public static final int MASK_BACK = 8 | Button mask bit for the back button. |
public static final int MASK_FORWARD = 16 | Button mask bit for the forward button. |
public static final int MODIFIER_SHIFT = 1 | Modifier mask bit indicating the shift key was held. |
public static final int MODIFIER_CONTROL = 2 | Modifier mask bit indicating the control key was held. |
public static final int MODIFIER_ALT = 4 | Modifier mask bit indicating the alt/option key was held. |
public static final int MODIFIER_META = 8 | Modifier mask bit indicating the meta/command/windows key was held. |
Constructors
public PointerEvent(int x, int y, int button, int buttonMask, int pointerType, float pressure, float tiltX, float tiltY, float contactSize, int modifiers, boolean hovering) | Creates a new immutable pointer event snapshot. |
Methods
public int getX() | The x position of the pointer in display pixels. |
public int getY() | The y position of the pointer in display pixels. |
public int getButton() | The button that triggered this event, one of the BUTTON_* constants. |
public int getButtonMask() | A bitmask of all buttons currently held down, built from the MASK_* constants. |
public int getPointerType() | The kind of pointing device that produced this event, one of the TYPE_* constants. |
public float getPressure() | The normalized pressure applied by the pointer between 0.0 and 1.0. |
public float getTiltX() | The stylus tilt across the x axis in degrees, or 0 when not reported. |
public float getTiltY() | The stylus tilt across the y axis in degrees, or 0 when not reported. |
public float getContactSize() | The normalized size of the contact area between 0.0 and 1.0, or 0 when not reported. |
public int getModifiers() | A bitmask of the keyboard modifiers held during this event, built from the MODIFIER_* constants. |
public boolean isHovering() | True if the pointer is hovering above the surface without making contact. |
public boolean isTouch() | True if this event came from a finger on a touch screen. |
public boolean isMouse() | True if this event came from a mouse or trackpad. |
public boolean isStylus() | True if this event came from a stylus or the eraser end of a stylus. |
public boolean isEraser() | True if this event came from the eraser end of a stylus. |
public boolean isPrimaryButton() | True if the triggering button is the primary (left) button. |
public boolean isSecondaryButton() | True if the triggering button is the secondary (right) button or stylus barrel button. |
public boolean isMiddleButton() | True if the triggering button is the middle button. |
public boolean isShiftDown() | True if the shift key was held during this event. |
public boolean isControlDown() | True if the control key was held during this event. |
public boolean isAltDown() | True if the alt/option key was held during this event. |
public boolean isMetaDown() | True if the meta/command/windows key was held during this event. |
public String toString() | Returns a string representation of the object. |
Inherited methods
Field details
TYPE_UNKNOWN
public static final int TYPE_UNKNOWN = 0The pointing device could not be determined.
TYPE_TOUCH
public static final int TYPE_TOUCH = 1The interaction came from a finger on a touch screen.
TYPE_MOUSE
public static final int TYPE_MOUSE = 2The interaction came from a mouse or trackpad.
TYPE_STYLUS
public static final int TYPE_STYLUS = 3The interaction came from a stylus or pen (Apple Pencil, S-Pen, Surface Pen and similar).
TYPE_ERASER
public static final int TYPE_ERASER = 4The interaction came from the eraser end of a stylus.
BUTTON_NONE
public static final int BUTTON_NONE = -1No button is associated with this event (for example a hover or a plain touch).
BUTTON_PRIMARY
public static final int BUTTON_PRIMARY = 0The primary (usually left) mouse button, or a plain touch/stylus contact.
BUTTON_SECONDARY
public static final int BUTTON_SECONDARY = 1The secondary (usually right) mouse button or stylus barrel button.
BUTTON_MIDDLE
public static final int BUTTON_MIDDLE = 2The middle mouse button (often the scroll wheel click).
BUTTON_BACK
public static final int BUTTON_BACK = 3The back (fourth) mouse button.
BUTTON_FORWARD
public static final int BUTTON_FORWARD = 4The forward (fifth) mouse button.
MASK_PRIMARY
public static final int MASK_PRIMARY = 1Button mask bit for the primary button.
MASK_SECONDARY
public static final int MASK_SECONDARY = 2Button mask bit for the secondary button.
MASK_MIDDLE
public static final int MASK_MIDDLE = 4Button mask bit for the middle button.
MASK_BACK
public static final int MASK_BACK = 8Button mask bit for the back button.
MASK_FORWARD
public static final int MASK_FORWARD = 16Button mask bit for the forward button.
MODIFIER_SHIFT
public static final int MODIFIER_SHIFT = 1Modifier mask bit indicating the shift key was held.
MODIFIER_CONTROL
public static final int MODIFIER_CONTROL = 2Modifier mask bit indicating the control key was held.
MODIFIER_ALT
public static final int MODIFIER_ALT = 4Modifier mask bit indicating the alt/option key was held.
MODIFIER_META
public static final int MODIFIER_META = 8Modifier mask bit indicating the meta/command/windows key was held.
Constructor details
PointerEvent
public PointerEvent(int x, int y, int button, int buttonMask, int pointerType, float pressure, float tiltX, float tiltY, float contactSize, int modifiers, boolean hovering)Creates a new immutable pointer event snapshot.
Parameters
xint- the x position of the pointer in display pixels
yint- the y position of the pointer in display pixels
buttonint- one of the
BUTTON_*constants describing the triggering button buttonMaskint- bitmask of the
MASK_*constants describing all currently held buttons pointerTypeint- one of the
TYPE_*constants describing the pointing device pressurefloat- normalized pressure between
0.0and1.0, defaulting to1.0 tiltXfloat- stylus tilt across the x axis in degrees,
0when not available tiltYfloat- stylus tilt across the y axis in degrees,
0when not available contactSizefloat- normalized size of the contact area between
0.0and1.0 modifiersint- bitmask of the
MODIFIER_*constants describing held keyboard modifiers hoveringboolean- true if the pointer is hovering above the surface without contact
Method details
getX
public int getX()The x position of the pointer in display pixels.
getY
public int getY()The y position of the pointer in display pixels.
getButton
public int getButton()The button that triggered this event, one of the
BUTTON_* constants. Defaults to
BUTTON_PRIMARY for plain touch interactions and BUTTON_NONE for hover events.getButtonMask
public int getButtonMask()A bitmask of all buttons currently held down, built from the
MASK_* constants.getPointerType
public int getPointerType()The kind of pointing device that produced this event, one of the
TYPE_* constants.getPressure
public float getPressure()The normalized pressure applied by the pointer between
0.0 and 1.0. Ports that do not
report pressure return 1.0 so that pressure aware code keeps working.getTiltX
public float getTiltX()The stylus tilt across the x axis in degrees, or
0 when not reported.getTiltY
public float getTiltY()The stylus tilt across the y axis in degrees, or
0 when not reported.getContactSize
public float getContactSize()The normalized size of the contact area between
0.0 and 1.0, or 0 when not reported.getModifiers
public int getModifiers()A bitmask of the keyboard modifiers held during this event, built from the
MODIFIER_* constants.isHovering
public boolean isHovering()True if the pointer is hovering above the surface without making contact.
isTouch
public boolean isTouch()True if this event came from a finger on a touch screen.
isMouse
public boolean isMouse()True if this event came from a mouse or trackpad.
isStylus
public boolean isStylus()True if this event came from a stylus or the eraser end of a stylus.
isEraser
public boolean isEraser()True if this event came from the eraser end of a stylus.
isPrimaryButton
public boolean isPrimaryButton()True if the triggering button is the primary (left) button.
isSecondaryButton
public boolean isSecondaryButton()True if the triggering button is the secondary (right) button or stylus barrel button.
isMiddleButton
public boolean isMiddleButton()True if the triggering button is the middle button.
isShiftDown
public boolean isShiftDown()True if the shift key was held during this event.
isControlDown
public boolean isControlDown()True if the control key was held during this event.
isAltDown
public boolean isAltDown()True if the alt/option key was held during this event.
isMetaDown
public boolean isMetaDown()True if the meta/command/windows key was held during this event.
toString
public String toString()Returns a string representation of the object. In general, the toString method returns a string that “textually represents” this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.
The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@’, and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:
getClass().getName() + ‘@’ + Integer.toHexString(hashCode())