mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-05 20:32:00 -05:00
Implement Item#onMouseUp events and work on #onMouseMove.
This commit is contained in:
parent
57bd659023
commit
8efc7ce7cd
2 changed files with 34 additions and 19 deletions
|
@ -65,17 +65,16 @@ var CanvasView = View.extend(/** @lends CanvasView# */{
|
|||
ctx.restore();
|
||||
this._redrawNeeded = false;
|
||||
return true;
|
||||
},
|
||||
}
|
||||
}, new function() { // Item based mouse handling:
|
||||
|
||||
// Item based mouse handling:
|
||||
|
||||
_hitOptions: {
|
||||
var hitOptions = {
|
||||
fill: true,
|
||||
stroke: true,
|
||||
tolerance: 0
|
||||
},
|
||||
};
|
||||
|
||||
_callEvent: function(item, event, bubble) {
|
||||
function callEvent(item, event, bubble) {
|
||||
var called = false;
|
||||
while (item) {
|
||||
called = item.fire(event.type, event) || called;
|
||||
|
@ -84,17 +83,32 @@ var CanvasView = View.extend(/** @lends CanvasView# */{
|
|||
item = item.getParent();
|
||||
}
|
||||
return called;
|
||||
},
|
||||
}
|
||||
|
||||
_onMouseDown: function(event, point) {
|
||||
if (this._eventCounters.mousedown) {
|
||||
var hit = this._project.hitTest(point, this._hitOptions);
|
||||
function handleEvent(view, type, event, point) {
|
||||
if (view._eventCounters[type]) {
|
||||
var hit = view._project.hitTest(point, hitOptions);
|
||||
if (hit && hit.item) {
|
||||
this._callEvent(hit.item, new MouseEvent('mousedown', point,
|
||||
callEvent(hit.item, new MouseEvent(type, point,
|
||||
hit.item, event), false);
|
||||
return hit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
_onMouseDown: function(event, point) {
|
||||
handleEvent(this, 'mousedown', event, point);
|
||||
},
|
||||
|
||||
_onMouseUp: function(event, point) {
|
||||
handleEvent(this, 'mouseup', event, point);
|
||||
},
|
||||
|
||||
_onMouseMove: function(event, point) {
|
||||
handleEvent(this, 'mousemove', event, point);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
/*#*/ if (options.server) {
|
||||
|
|
|
@ -495,15 +495,16 @@ var View = this.View = Base.extend(Callback, /** @lends View# */{
|
|||
var view = View._focused;
|
||||
if (!view || !dragging)
|
||||
return;
|
||||
dragging = false;
|
||||
var point = viewToProject(view, event);
|
||||
curPoint = null;
|
||||
if (tool) {
|
||||
if (tool._onHandleEvent('mouseup', viewToProject(view, event),
|
||||
event)) {
|
||||
view.draw(true);
|
||||
DomEvent.stop(event);
|
||||
}
|
||||
}
|
||||
dragging = false;
|
||||
if (view._onMouseUp)
|
||||
view._onMouseUp(event, point);
|
||||
// Cancel DOM-event if it was handled by our tool
|
||||
if (tool && tool._onHandleEvent('mouseup', point, event))
|
||||
DomEvent.stop(event);
|
||||
// See mousedown() for an explanation of why we can always call this.
|
||||
view.draw(true);
|
||||
}
|
||||
|
||||
function selectstart(event) {
|
||||
|
|
Loading…
Reference in a new issue