UNPKG

@createjs/easeljs

Version:

The Easel JavaScript library provides a full, hierarchical display list, a core interaction model, and helper classes to make working with the HTML5 Canvas element much easier. Part of the CreateJS suite of libraries.

157 lines (139 loc) 5.98 kB
/** * @license MouseEvent * Visit http://createjs.com/ for documentation, updates and examples. * * Copyright (c) 2017 gskinner.com, inc. * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, * copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following * conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. */ import { Event } from "@createjs/core"; /** * Passed as the parameter to all mouse/pointer/touch related events. For a listing of mouse events and their properties, * see the {@link easeljs.DisplayObject} and {@link easeljs.Stage} event listings. * @memberof easeljs * @extends core.Event * @param {String} type The event type. * @param {Boolean} bubbles Indicates whether the event will bubble through the display list. * @param {Boolean} cancelable Indicates whether the default behaviour of this event can be cancelled. * @param {Number} stageX The normalized x position relative to the stage. * @param {Number} stageY The normalized y position relative to the stage. * @param {easeljs.MouseEvent} nativeEvent The native DOM event related to this mouse event. * @param {Number} pointerID The unique id for the pointer. * @param {Boolean} primary Indicates whether this is the primary pointer in a multitouch environment. * @param {Number} rawX The raw x position relative to the stage. * @param {Number} rawY The raw y position relative to the stage. * @param {easeljs.DisplayObject} relatedTarget The secondary target for the event. */ export default class MouseEvent extends Event { constructor (type, bubbles, cancelable, stageX, stageY, nativeEvent, pointerID, primary, rawX, rawY, relatedTarget) { super(type, bubbles, cancelable); // public properties: /** * The normalized x position on the stage. This will always be within the range 0 to stage width. * @type {Number} */ this.stageX = stageX; /** * The normalized y position on the stage. This will always be within the range 0 to stage height. * @type {Number} */ this.stageY = stageY; /** * The raw x position relative to the stage. Normally this will be the same as the stageX value, unless * stage.mouseMoveOutside is true and the pointer is outside of the stage bounds. * @type {Number} */ this.rawX = (rawX==null)?stageX:rawX; /** * The raw y position relative to the stage. Normally this will be the same as the stageY value, unless * stage.mouseMoveOutside is true and the pointer is outside of the stage bounds. * @type {Number} */ this.rawY = (rawY==null)?stageY:rawY; /** * The native MouseEvent generated by the browser. The properties and API for this * event may differ between browsers. This property will be null if the * EaselJS property was not directly generated from a native MouseEvent. * @type {HTMLMouseEvent} */ this.nativeEvent = nativeEvent; /** * The unique id for the pointer (touch point or cursor). This will be either -1 for the mouse, or the system * supplied id value. * @type {Number} */ this.pointerID = pointerID; /** * Indicates whether this is the primary pointer in a multitouch environment. This will always be true for the mouse. * For touch pointers, the first pointer in the current stack will be considered the primary pointer. * @type {Boolean} */ this.primary = !!primary; /** * The secondary target for the event, if applicable. This is used for mouseout/rollout * events to indicate the object that the mouse entered from, mouseover/rollover for the object the mouse exited, * and stagemousedown/stagemouseup events for the object that was the under the cursor, if any. * * Only valid interaction targets will be returned (ie. objects with mouse listeners or a cursor set). * @type {easeljs.DisplayObject} */ this.relatedTarget = relatedTarget; } /** * Returns the x position of the mouse in the local coordinate system of the current target (ie. the dispatcher). * @type {Number} * @readonly */ get localX () { return this.currentTarget.globalToLocal(this.rawX, this.rawY).x; } /** * Returns the y position of the mouse in the local coordinate system of the current target (ie. the dispatcher). * @type {Number} * @readonly */ get localY () { return this.currentTarget.globalToLocal(this.rawX, this.rawY).y; } /** * Indicates whether the event was generated by a touch input (versus a mouse input). * @type {Boolean} * @readonly */ get isTouch () { return this.pointerID !== -1; } /** * Returns a clone of the MouseEvent instance. * @return {easeljs.MouseEvent} a clone of the MouseEvent instance. */ clone () { return new MouseEvent(this.type, this.bubbles, this.cancelable, this.stageX, this.stageY, this.nativeEvent, this.pointerID, this.primary, this.rawX, this.rawY); } /** * Returns a string representation of this object. * @return {String} a string representation of the instance. */ toString () { return `[${this.constructor.name} (type=${this.type} stageX=${this.stageX} stageY=${this.stageY})]`; } }