mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-07 13:22:07 -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();
|
ctx.restore();
|
||||||
this._redrawNeeded = false;
|
this._redrawNeeded = false;
|
||||||
return true;
|
return true;
|
||||||
},
|
}
|
||||||
|
}, new function() { // Item based mouse handling:
|
||||||
|
|
||||||
// Item based mouse handling:
|
var hitOptions = {
|
||||||
|
|
||||||
_hitOptions: {
|
|
||||||
fill: true,
|
fill: true,
|
||||||
stroke: true,
|
stroke: true,
|
||||||
tolerance: 0
|
tolerance: 0
|
||||||
},
|
};
|
||||||
|
|
||||||
_callEvent: function(item, event, bubble) {
|
function callEvent(item, event, bubble) {
|
||||||
var called = false;
|
var called = false;
|
||||||
while (item) {
|
while (item) {
|
||||||
called = item.fire(event.type, event) || called;
|
called = item.fire(event.type, event) || called;
|
||||||
|
@ -84,17 +83,32 @@ var CanvasView = View.extend(/** @lends CanvasView# */{
|
||||||
item = item.getParent();
|
item = item.getParent();
|
||||||
}
|
}
|
||||||
return called;
|
return called;
|
||||||
},
|
}
|
||||||
|
|
||||||
_onMouseDown: function(event, point) {
|
function handleEvent(view, type, event, point) {
|
||||||
if (this._eventCounters.mousedown) {
|
if (view._eventCounters[type]) {
|
||||||
var hit = this._project.hitTest(point, this._hitOptions);
|
var hit = view._project.hitTest(point, hitOptions);
|
||||||
if (hit && hit.item) {
|
if (hit && hit.item) {
|
||||||
this._callEvent(hit.item, new MouseEvent('mousedown', point,
|
callEvent(hit.item, new MouseEvent(type, point,
|
||||||
hit.item, event), false);
|
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) {
|
/*#*/ if (options.server) {
|
||||||
|
|
|
@ -495,15 +495,16 @@ var View = this.View = Base.extend(Callback, /** @lends View# */{
|
||||||
var view = View._focused;
|
var view = View._focused;
|
||||||
if (!view || !dragging)
|
if (!view || !dragging)
|
||||||
return;
|
return;
|
||||||
dragging = false;
|
var point = viewToProject(view, event);
|
||||||
curPoint = null;
|
curPoint = null;
|
||||||
if (tool) {
|
dragging = false;
|
||||||
if (tool._onHandleEvent('mouseup', viewToProject(view, event),
|
if (view._onMouseUp)
|
||||||
event)) {
|
view._onMouseUp(event, point);
|
||||||
view.draw(true);
|
// Cancel DOM-event if it was handled by our tool
|
||||||
DomEvent.stop(event);
|
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) {
|
function selectstart(event) {
|
||||||
|
|
Loading…
Reference in a new issue