paper.js/src/event/MouseEvent.js

86 lines
2.4 KiB
JavaScript
Raw Normal View History

/*
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
2014-01-03 19:47:16 -05:00
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/
/**
* @name MouseEvent
*
2012-12-23 10:01:53 -05:00
* @class The MouseEvent object is received by the {@link Item}'s mouse event
* handlers {@link Item#onMouseDown}, {@link Item#onMouseDrag},
* {@link Item#onMouseMove}, {@link Item#onMouseUp}, {@link Item#onClick},
* {@link Item#onDoubleClick}, {@link Item#onMouseEnter} and
* {@link Item#onMouseLeave}. The MouseEvent object is the only parameter passed
* to these functions and contains information about the mouse event.
*
* @extends Event
*/
/* global MouseEvent: true */
var MouseEvent = Event.extend(/** @lends MouseEvent# */{
2014-08-16 13:24:54 -04:00
_class: 'MouseEvent',
2014-08-16 13:24:54 -04:00
initialize: function MouseEvent(type, event, point, target, delta) {
this.type = type;
this.event = event;
2014-08-16 13:24:54 -04:00
this.point = point;
this._target = target;
2014-08-16 13:24:54 -04:00
this.delta = delta;
},
2014-08-16 13:24:54 -04:00
/**
* The type of mouse event.
*
* @name MouseEvent#type
* @type String
* @values 'mousedown', 'mouseup', 'mousedrag', 'click', 'doubleclick',
* 'mousemove', 'mouseenter', mouseleave'
2014-08-16 13:24:54 -04:00
*/
2014-08-16 13:24:54 -04:00
/**
* The position of the mouse in project coordinates when the event was
* fired.
*
* @name MouseEvent#point
* @type Point
*/
2014-08-16 13:24:54 -04:00
// DOCS: document MouseEvent#target
/**
* @name MouseEvent#target
* @type Item
*/
getTarget: function() {
// #_target may be a hitTest() function, in which case we need to
// execute and override it the first time #target is requested.
var target = this._target;
if (typeof target === 'function')
target = this._target = target();
return target;
},
2014-08-16 13:24:54 -04:00
// DOCS: document MouseEvent#delta
/**
* @name MouseEvent#delta
* @type Point
*/
2014-08-16 13:24:54 -04:00
/**
* @return {String} a string representation of the mouse event
*/
toString: function() {
return "{ type: '" + this.type
+ "', point: " + this.point
+ ', target: ' + this.getTarget()
2014-08-16 13:24:54 -04:00
+ (this.delta ? ', delta: ' + this.delta : '')
+ ', modifiers: ' + this.getModifiers()
+ ' }';
}
});