pointerEvents.d.ts 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import type { Nullable } from "../types";
  2. import { Vector2 } from "../Maths/math.vector";
  3. import type { PickingInfo } from "../Collisions/pickingInfo";
  4. import type { IMouseEvent } from "./deviceInputEvents";
  5. import type { InputManager } from "../Inputs/scene.inputManager";
  6. import type { Ray } from "../Culling/ray";
  7. /**
  8. * Gather the list of pointer event types as constants.
  9. */
  10. export declare class PointerEventTypes {
  11. /**
  12. * The pointerdown event is fired when a pointer becomes active. For mouse, it is fired when the device transitions from no buttons depressed to at least one button depressed. For touch, it is fired when physical contact is made with the digitizer. For pen, it is fired when the stylus makes physical contact with the digitizer.
  13. */
  14. static readonly POINTERDOWN = 1;
  15. /**
  16. * The pointerup event is fired when a pointer is no longer active.
  17. */
  18. static readonly POINTERUP = 2;
  19. /**
  20. * The pointermove event is fired when a pointer changes coordinates.
  21. */
  22. static readonly POINTERMOVE = 4;
  23. /**
  24. * The pointerwheel event is fired when a mouse wheel has been rotated.
  25. */
  26. static readonly POINTERWHEEL = 8;
  27. /**
  28. * The pointerpick event is fired when a mesh or sprite has been picked by the pointer.
  29. */
  30. static readonly POINTERPICK = 16;
  31. /**
  32. * The pointertap event is fired when a the object has been touched and released without drag.
  33. */
  34. static readonly POINTERTAP = 32;
  35. /**
  36. * The pointerdoubletap event is fired when a the object has been touched and released twice without drag.
  37. */
  38. static readonly POINTERDOUBLETAP = 64;
  39. }
  40. /**
  41. * Base class of pointer info types.
  42. */
  43. export declare class PointerInfoBase {
  44. /**
  45. * Defines the type of event (PointerEventTypes)
  46. */
  47. type: number;
  48. /**
  49. * Defines the related dom event
  50. */
  51. event: IMouseEvent;
  52. /**
  53. * Instantiates the base class of pointers info.
  54. * @param type Defines the type of event (PointerEventTypes)
  55. * @param event Defines the related dom event
  56. */
  57. constructor(
  58. /**
  59. * Defines the type of event (PointerEventTypes)
  60. */
  61. type: number,
  62. /**
  63. * Defines the related dom event
  64. */
  65. event: IMouseEvent);
  66. }
  67. /**
  68. * This class is used to store pointer related info for the onPrePointerObservable event.
  69. * Set the skipOnPointerObservable property to true if you want the engine to stop any process after this event is triggered, even not calling onPointerObservable
  70. */
  71. export declare class PointerInfoPre extends PointerInfoBase {
  72. /**
  73. * Ray from a pointer if available (eg. 6dof controller)
  74. */
  75. ray: Nullable<Ray>;
  76. /**
  77. * Defines picking info coming from a near interaction (proximity instead of ray-based picking)
  78. */
  79. nearInteractionPickingInfo: Nullable<PickingInfo>;
  80. /**
  81. * The original picking info that was used to trigger the pointer event
  82. */
  83. originalPickingInfo: Nullable<PickingInfo>;
  84. /**
  85. * Defines the local position of the pointer on the canvas.
  86. */
  87. localPosition: Vector2;
  88. /**
  89. * Defines whether the engine should skip the next OnPointerObservable associated to this pre.
  90. */
  91. skipOnPointerObservable: boolean;
  92. /**
  93. * Instantiates a PointerInfoPre to store pointer related info to the onPrePointerObservable event.
  94. * @param type Defines the type of event (PointerEventTypes)
  95. * @param event Defines the related dom event
  96. * @param localX Defines the local x coordinates of the pointer when the event occured
  97. * @param localY Defines the local y coordinates of the pointer when the event occured
  98. */
  99. constructor(type: number, event: IMouseEvent, localX: number, localY: number);
  100. }
  101. /**
  102. * This type contains all the data related to a pointer event in Babylon.js.
  103. * The event member is an instance of PointerEvent for all types except PointerWheel and is of type MouseWheelEvent when type equals PointerWheel. The different event types can be found in the PointerEventTypes class.
  104. */
  105. export declare class PointerInfo extends PointerInfoBase {
  106. private _pickInfo;
  107. private _inputManager;
  108. /**
  109. * Defines the picking info associated with this PointerInfo object (if applicable)
  110. */
  111. get pickInfo(): Nullable<PickingInfo>;
  112. /**
  113. * Instantiates a PointerInfo to store pointer related info to the onPointerObservable event.
  114. * @param type Defines the type of event (PointerEventTypes)
  115. * @param event Defines the related dom event
  116. * @param pickInfo Defines the picking info associated to the info (if any)
  117. * @param inputManager Defines the InputManager to use if there is no pickInfo
  118. */
  119. constructor(type: number, event: IMouseEvent, pickInfo: Nullable<PickingInfo>, inputManager?: Nullable<InputManager>);
  120. /**
  121. * Generates the picking info if needed
  122. */
  123. /** @internal */
  124. _generatePickInfo(): void;
  125. }
  126. /**
  127. * Data relating to a touch event on the screen.
  128. */
  129. export interface PointerTouch {
  130. /**
  131. * X coordinate of touch.
  132. */
  133. x: number;
  134. /**
  135. * Y coordinate of touch.
  136. */
  137. y: number;
  138. /**
  139. * Id of touch. Unique for each finger.
  140. */
  141. pointerId: number;
  142. /**
  143. * Event type passed from DOM.
  144. */
  145. type: any;
  146. }