Class 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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe back (fourth) mouse button.static final intThe forward (fifth) mouse button.static final intThe middle mouse button (often the scroll wheel click).static final intNo button is associated with this event (for example a hover or a plain touch).static final intThe primary (usually left) mouse button, or a plain touch/stylus contact.static final intThe secondary (usually right) mouse button or stylus barrel button.static final intButton mask bit for the back button.static final intButton mask bit for the forward button.static final intButton mask bit for the middle button.static final intButton mask bit for the primary button.static final intButton mask bit for the secondary button.static final intModifier mask bit indicating the alt/option key was held.static final intModifier mask bit indicating the control key was held.static final intModifier mask bit indicating the meta/command/windows key was held.static final intModifier mask bit indicating the shift key was held.static final intThe interaction came from the eraser end of a stylus.static final intThe interaction came from a mouse or trackpad.static final intThe interaction came from a stylus or pen (Apple Pencil, S-Pen, Surface Pen and similar).static final intThe interaction came from a finger on a touch screen.static final intThe pointing device could not be determined. -
Constructor Summary
ConstructorsConstructorDescriptionPointerEvent(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. -
Method Summary
Modifier and TypeMethodDescriptionintThe button that triggered this event, one of theBUTTON_*constants.intA bitmask of all buttons currently held down, built from theMASK_*constants.floatThe normalized size of the contact area between0.0and1.0, or0when not reported.intA bitmask of the keyboard modifiers held during this event, built from theMODIFIER_*constants.intThe kind of pointing device that produced this event, one of theTYPE_*constants.floatThe normalized pressure applied by the pointer between0.0and1.0.floatgetTiltX()The stylus tilt across the x axis in degrees, or0when not reported.floatgetTiltY()The stylus tilt across the y axis in degrees, or0when not reported.intgetX()The x position of the pointer in display pixels.intgetY()The y position of the pointer in display pixels.booleanTrue if the alt/option key was held during this event.booleanTrue if the control key was held during this event.booleanisEraser()True if this event came from the eraser end of a stylus.booleanTrue if the pointer is hovering above the surface without making contact.booleanTrue if the meta/command/windows key was held during this event.booleanTrue if the triggering button is the middle button.booleanisMouse()True if this event came from a mouse or trackpad.booleanTrue if the triggering button is the primary (left) button.booleanTrue if the triggering button is the secondary (right) button or stylus barrel button.booleanTrue if the shift key was held during this event.booleanisStylus()True if this event came from a stylus or the eraser end of a stylus.booleanisTouch()True if this event came from a finger on a touch screen.toString()Returns a string representation of the object.
-
Field Details
-
TYPE_UNKNOWN
public static final int TYPE_UNKNOWNThe pointing device could not be determined.- See Also:
-
TYPE_TOUCH
public static final int TYPE_TOUCHThe interaction came from a finger on a touch screen.- See Also:
-
TYPE_MOUSE
public static final int TYPE_MOUSEThe interaction came from a mouse or trackpad.- See Also:
-
TYPE_STYLUS
public static final int TYPE_STYLUSThe interaction came from a stylus or pen (Apple Pencil, S-Pen, Surface Pen and similar).- See Also:
-
TYPE_ERASER
public static final int TYPE_ERASERThe interaction came from the eraser end of a stylus.- See Also:
-
BUTTON_NONE
public static final int BUTTON_NONENo button is associated with this event (for example a hover or a plain touch).- See Also:
-
BUTTON_PRIMARY
public static final int BUTTON_PRIMARYThe primary (usually left) mouse button, or a plain touch/stylus contact.- See Also:
-
BUTTON_SECONDARY
public static final int BUTTON_SECONDARYThe secondary (usually right) mouse button or stylus barrel button.- See Also:
-
BUTTON_MIDDLE
public static final int BUTTON_MIDDLEThe middle mouse button (often the scroll wheel click).- See Also:
-
BUTTON_BACK
public static final int BUTTON_BACKThe back (fourth) mouse button.- See Also:
-
BUTTON_FORWARD
public static final int BUTTON_FORWARDThe forward (fifth) mouse button.- See Also:
-
MASK_PRIMARY
public static final int MASK_PRIMARYButton mask bit for the primary button.- See Also:
-
MASK_SECONDARY
public static final int MASK_SECONDARYButton mask bit for the secondary button.- See Also:
-
MASK_MIDDLE
public static final int MASK_MIDDLEButton mask bit for the middle button.- See Also:
-
MASK_BACK
public static final int MASK_BACKButton mask bit for the back button.- See Also:
-
MASK_FORWARD
public static final int MASK_FORWARDButton mask bit for the forward button.- See Also:
-
MODIFIER_SHIFT
public static final int MODIFIER_SHIFTModifier mask bit indicating the shift key was held.- See Also:
-
MODIFIER_CONTROL
public static final int MODIFIER_CONTROLModifier mask bit indicating the control key was held.- See Also:
-
MODIFIER_ALT
public static final int MODIFIER_ALTModifier mask bit indicating the alt/option key was held.- See Also:
-
MODIFIER_META
public static final int MODIFIER_METAModifier mask bit indicating the meta/command/windows key was held.- See Also:
-
-
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
-
x: the x position of the pointer in display pixels -
y: the y position of the pointer in display pixels -
button: one of theBUTTON_*constants describing the triggering button -
buttonMask: bitmask of theMASK_*constants describing all currently held buttons -
pointerType: one of theTYPE_*constants describing the pointing device -
pressure: normalized pressure between0.0and1.0, defaulting to1.0 -
tiltX: stylus tilt across the x axis in degrees,0when not available -
tiltY: stylus tilt across the y axis in degrees,0when not available -
contactSize: normalized size of the contact area between0.0and1.0 -
modifiers: bitmask of theMODIFIER_*constants describing held keyboard modifiers -
hovering: 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 theBUTTON_*constants. Defaults toBUTTON_PRIMARYfor plain touch interactions andBUTTON_NONEfor hover events. -
getButtonMask
public int getButtonMask()A bitmask of all buttons currently held down, built from theMASK_*constants. -
getPointerType
public int getPointerType()The kind of pointing device that produced this event, one of theTYPE_*constants. -
getPressure
public float getPressure()The normalized pressure applied by the pointer between0.0and1.0. Ports that do not report pressure return1.0so that pressure aware code keeps working. -
getTiltX
public float getTiltX()The stylus tilt across the x axis in degrees, or0when not reported. -
getTiltY
public float getTiltY()The stylus tilt across the y axis in degrees, or0when not reported. -
getContactSize
public float getContactSize()The normalized size of the contact area between0.0and1.0, or0when not reported. -
getModifiers
public int getModifiers()A bitmask of the keyboard modifiers held during this event, built from theMODIFIER_*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
Description copied from class:ObjectReturns 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())
-