Implement Item#onMouseUp events and work on #onMouseMove.

This commit is contained in:
Jürg Lehni 2011-11-16 22:41:22 +01:00
parent 57bd659023
commit 8efc7ce7cd
2 changed files with 34 additions and 19 deletions

View file

@ -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;
}
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;
}
}
}
return {
_onMouseDown: function(event, point) {
handleEvent(this, 'mousedown', event, point);
}, },
_onMouseDown: function(event, point) { _onMouseUp: function(event, point) {
if (this._eventCounters.mousedown) { handleEvent(this, 'mouseup', event, point);
var hit = this._project.hitTest(point, this._hitOptions); },
if (hit && hit.item) {
this._callEvent(hit.item, new MouseEvent('mousedown', point, _onMouseMove: function(event, point) {
hit.item, event), false); handleEvent(this, 'mousemove', event, point);
}
}
} }
};
}); });
/*#*/ if (options.server) { /*#*/ if (options.server) {

View file

@ -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
if (tool && tool._onHandleEvent('mouseup', point, event))
DomEvent.stop(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) {