pixi.js
Version:
<p align="center"> <a href="https://pixijs.com" target="_blank" rel="noopener noreferrer"> <img height="150" src="https://files.pixijs.download/branding/pixijs-logo-transparent-dark.svg?v=1" alt="PixiJS logo"> </a> </p> <br/> <p align="center">
1 lines • 10.4 kB
Source Map (JSON)
{"version":3,"file":"FederatedMouseEvent.mjs","sources":["../../src/events/FederatedMouseEvent.ts"],"sourcesContent":["import { Point } from '../maths/point/Point';\nimport { FederatedEvent } from './FederatedEvent';\n\nimport type { PointData } from '../maths/point/PointData';\nimport type { Container } from '../scene/container/Container';\nimport type { PixiTouch } from './FederatedEvent';\n\n/**\n * A specialized event class for mouse interactions in PixiJS applications.\n * Extends {@link FederatedEvent} to provide mouse-specific properties and methods\n * while maintaining compatibility with the DOM MouseEvent interface.\n *\n * Key features:\n * - Tracks mouse button states\n * - Provides modifier key states\n * - Supports coordinate systems (client, screen, global)\n * - Enables precise position tracking\n * @example\n * ```ts\n * // Basic mouse event handling\n * sprite.on('mousemove', (event: FederatedMouseEvent) => {\n * // Get coordinates in different spaces\n * console.log('Global position:', event.global.x, event.global.y);\n * console.log('Client position:', event.client.x, event.client.y);\n * console.log('Screen position:', event.screen.x, event.screen.y);\n *\n * // Check button and modifier states\n * if (event.buttons === 1 && event.ctrlKey) {\n * console.log('Left click + Control key');\n * }\n *\n * // Get local coordinates relative to any container\n * const localPos = event.getLocalPosition(container);\n * console.log('Local position:', localPos.x, localPos.y);\n * });\n *\n * // Handle mouse button states\n * sprite.on('mousedown', (event: FederatedMouseEvent) => {\n * console.log('Mouse button:', event.button); // 0=left, 1=middle, 2=right\n * console.log('Active buttons:', event.buttons);\n * });\n * ```\n * @category events\n * @see {@link FederatedEvent} For base event functionality\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent} DOM MouseEvent Interface\n * @standard\n */\nexport class FederatedMouseEvent extends FederatedEvent<\nMouseEvent | PointerEvent | PixiTouch\n> implements MouseEvent\n{\n /** Whether the \"alt\" key was pressed when this mouse event occurred. */\n public altKey: boolean;\n\n /** The specific button that was pressed in this mouse event. */\n public button: number;\n\n /** The button depressed when this event occurred. */\n public buttons: number;\n\n /** Whether the \"control\" key was pressed when this mouse event occurred. */\n public ctrlKey: boolean;\n\n /** Whether the \"meta\" key was pressed when this mouse event occurred. */\n public metaKey: boolean;\n\n /** This is currently not implemented in the Federated Events API. */\n public relatedTarget: EventTarget;\n\n /** Whether the \"shift\" key was pressed when this mouse event occurred. */\n public shiftKey: boolean;\n\n /** The coordinates of the mouse event relative to the canvas. */\n public client: Point = new Point();\n\n /** @readonly */\n public get clientX(): number { return this.client.x; }\n\n /** @readonly */\n public get clientY(): number { return this.client.y; }\n\n /**\n * Alias for {@link FederatedMouseEvent.clientX this.clientX}.\n * @readonly\n */\n get x(): number { return this.clientX; }\n\n /**\n * Alias for {@link FederatedMouseEvent.clientY this.clientY}.\n * @readonly\n */\n get y(): number { return this.clientY; }\n\n /** This is the number of clicks that occurs in 200ms/click of each other. */\n public detail: number;\n\n /** The movement in this pointer relative to the last `mousemove` event. */\n public movement: Point = new Point();\n\n /** @readonly */\n get movementX(): number { return this.movement.x; }\n\n /** @readonly */\n get movementY(): number { return this.movement.y; }\n\n /** The offset of the pointer coordinates w.r.t. target Container in world space. This is not supported at the moment. */\n public offset: Point = new Point();\n\n /** @readonly */\n get offsetX(): number { return this.offset.x; }\n\n /** @readonly */\n get offsetY(): number { return this.offset.y; }\n\n /** The pointer coordinates in world space. */\n public global: Point = new Point();\n\n /** @readonly */\n get globalX(): number { return this.global.x; }\n\n /** @readonly */\n get globalY(): number { return this.global.y; }\n\n /**\n * The pointer coordinates in the renderer's {@link AbstractRenderer.screen screen}. This has slightly\n * different semantics than native PointerEvent screenX/screenY.\n */\n public screen: Point = new Point();\n\n /**\n * The pointer coordinates in the renderer's screen. Alias for `screen.x`.\n * @readonly\n */\n get screenX(): number { return this.screen.x; }\n\n /**\n * The pointer coordinates in the renderer's screen. Alias for `screen.y`.\n * @readonly\n */\n get screenY(): number { return this.screen.y; }\n\n /**\n * Converts global coordinates into container-local coordinates.\n *\n * This method transforms coordinates from world space to a container's local space,\n * useful for precise positioning and hit testing.\n * @param container - The Container to get local coordinates for\n * @param point - Optional Point object to store the result. If not provided, a new Point will be created\n * @param globalPos - Optional custom global coordinates. If not provided, the event's global position is used\n * @returns The local coordinates as a Point object\n * @example\n * ```ts\n * // Basic usage - get local coordinates relative to a container\n * sprite.on('pointermove', (event: FederatedMouseEvent) => {\n * // Get position relative to the sprite\n * const localPos = event.getLocalPosition(sprite);\n * console.log('Local position:', localPos.x, localPos.y);\n * });\n * // Using custom global coordinates\n * const customGlobal = new Point(100, 100);\n * sprite.on('pointermove', (event: FederatedMouseEvent) => {\n * // Transform custom coordinates\n * const localPos = event.getLocalPosition(sprite, undefined, customGlobal);\n * console.log('Custom local position:', localPos.x, localPos.y);\n * });\n * ```\n * @see {@link Container.worldTransform} For the transformation matrix\n * @see {@link Point} For the point class used to store coordinates\n */\n public getLocalPosition<P extends PointData = Point>(container: Container, point?: P, globalPos?: PointData): P\n {\n return container.worldTransform.applyInverse<P>(globalPos || this.global, point);\n }\n\n /**\n * Whether the modifier key was pressed when this event natively occurred.\n * @param key - The modifier key.\n */\n public getModifierState(key: string): boolean\n {\n return 'getModifierState' in this.nativeEvent && this.nativeEvent.getModifierState(key);\n }\n\n /**\n * Not supported.\n * @param _typeArg\n * @param _canBubbleArg\n * @param _cancelableArg\n * @param _viewArg\n * @param _detailArg\n * @param _screenXArg\n * @param _screenYArg\n * @param _clientXArg\n * @param _clientYArg\n * @param _ctrlKeyArg\n * @param _altKeyArg\n * @param _shiftKeyArg\n * @param _metaKeyArg\n * @param _buttonArg\n * @param _relatedTargetArg\n * @deprecated since 7.0.0\n * @ignore\n */\n // eslint-disable-next-line max-params\n public initMouseEvent(\n _typeArg: string,\n _canBubbleArg: boolean,\n _cancelableArg: boolean,\n _viewArg: Window,\n _detailArg: number,\n _screenXArg: number,\n _screenYArg: number,\n _clientXArg: number,\n _clientYArg: number,\n _ctrlKeyArg: boolean,\n _altKeyArg: boolean,\n _shiftKeyArg: boolean,\n _metaKeyArg: boolean,\n _buttonArg: number,\n _relatedTargetArg: EventTarget\n ): void\n {\n throw new Error('Method not implemented.');\n }\n}\n"],"names":[],"mappings":";;;;AA+CO,MAAM,4BAA4B,cAGzC,CAAA;AAAA,EAHO,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CAAA,CAAA;AA0BH;AAAA,IAAO,IAAA,CAAA,MAAA,GAAgB,IAAI,KAAM,EAAA,CAAA;AAwBjC;AAAA,IAAO,IAAA,CAAA,QAAA,GAAkB,IAAI,KAAM,EAAA,CAAA;AASnC;AAAA,IAAO,IAAA,CAAA,MAAA,GAAgB,IAAI,KAAM,EAAA,CAAA;AASjC;AAAA,IAAO,IAAA,CAAA,MAAA,GAAgB,IAAI,KAAM,EAAA,CAAA;AAYjC;AAAA;AAAA;AAAA;AAAA,IAAO,IAAA,CAAA,MAAA,GAAgB,IAAI,KAAM,EAAA,CAAA;AAAA,GAAA;AAAA;AAAA,EAnDjC,IAAW,OAAkB,GAAA;AAAE,IAAA,OAAO,KAAK,MAAO,CAAA,CAAA,CAAA;AAAA,GAAG;AAAA;AAAA,EAGrD,IAAW,OAAkB,GAAA;AAAE,IAAA,OAAO,KAAK,MAAO,CAAA,CAAA,CAAA;AAAA,GAAG;AAAA;AAAA;AAAA;AAAA;AAAA,EAMrD,IAAI,CAAY,GAAA;AAAE,IAAA,OAAO,IAAK,CAAA,OAAA,CAAA;AAAA,GAAS;AAAA;AAAA;AAAA;AAAA;AAAA,EAMvC,IAAI,CAAY,GAAA;AAAE,IAAA,OAAO,IAAK,CAAA,OAAA,CAAA;AAAA,GAAS;AAAA;AAAA,EASvC,IAAI,SAAoB,GAAA;AAAE,IAAA,OAAO,KAAK,QAAS,CAAA,CAAA,CAAA;AAAA,GAAG;AAAA;AAAA,EAGlD,IAAI,SAAoB,GAAA;AAAE,IAAA,OAAO,KAAK,QAAS,CA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