mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-05 20:32:00 -05:00
Implement Item#onMouseEnter / #onMouseLeave.
This commit is contained in:
parent
c0e6d5b2ee
commit
b3bf57c8e9
2 changed files with 23 additions and 15 deletions
|
@ -74,28 +74,18 @@ var CanvasView = View.extend(/** @lends CanvasView# */{
|
|||
tolerance: 0
|
||||
};
|
||||
|
||||
function callEvent(item, event, bubble) {
|
||||
var called = false;
|
||||
while (item) {
|
||||
called = item.fire(event.type, event) || called;
|
||||
if (called && (!bubble || event._stopped))
|
||||
break;
|
||||
item = item.getParent();
|
||||
}
|
||||
return called;
|
||||
}
|
||||
|
||||
function handleEvent(view, type, event, point) {
|
||||
if (view._eventCounters[type]) {
|
||||
var hit = view._project.hitTest(point, hitOptions);
|
||||
if (hit && hit.item) {
|
||||
callEvent(hit.item, new MouseEvent(type, point,
|
||||
hit.item, event), false);
|
||||
return hit;
|
||||
new MouseEvent(type, point, hit.item, event)._call();
|
||||
return hit.item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var overItem = null;
|
||||
|
||||
return {
|
||||
_onMouseDown: function(event, point) {
|
||||
handleEvent(this, 'mousedown', event, point);
|
||||
|
@ -106,7 +96,12 @@ var CanvasView = View.extend(/** @lends CanvasView# */{
|
|||
},
|
||||
|
||||
_onMouseMove: function(event, point) {
|
||||
handleEvent(this, 'mousemove', event, point);
|
||||
var item = handleEvent(this, 'mousemove', event, point);
|
||||
if (item != overItem) {
|
||||
new MouseEvent('mouseleave', point, overItem, event)._call();
|
||||
overItem = item;
|
||||
new MouseEvent('mouseenter', point, item, event)._call();
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
|
|
@ -36,5 +36,18 @@ var MouseEvent = this.MouseEvent = Event.extend(/** @lends MouseEvent# */{
|
|||
+ ', target: ' + this.target
|
||||
+ ', modifiers: ' + this.getModifiers()
|
||||
+ ' }';
|
||||
},
|
||||
|
||||
// TODO: Move to Event perhaps?
|
||||
_call: function(bubble) {
|
||||
var item = this.target,
|
||||
called = false;
|
||||
while (item) {
|
||||
called = item.fire(this.type, this) || called;
|
||||
if (called && (!bubble || this._stopped))
|
||||
break;
|
||||
item = item.getParent();
|
||||
}
|
||||
return called;
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue