mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-08 05:42:07 -05:00
Simplify installling of mouse handlers in View.
This commit is contained in:
parent
acbebc2aa4
commit
c85f0326c3
1 changed files with 31 additions and 35 deletions
|
@ -161,7 +161,6 @@ var View = this.View = Base.extend(Callback, /** @lends View# */{
|
||||||
if (this._id == null)
|
if (this._id == null)
|
||||||
this._canvas.setAttribute('id', this._id = 'canvas-' + View._id++);
|
this._canvas.setAttribute('id', this._id = 'canvas-' + View._id++);
|
||||||
// Install event handlers
|
// Install event handlers
|
||||||
this._handlers = this._createHandlers();
|
|
||||||
DomEvent.add(this._canvas, this._handlers);
|
DomEvent.add(this._canvas, this._handlers);
|
||||||
/*#*/ } // options.browser
|
/*#*/ } // options.browser
|
||||||
// Keep track of views internally
|
// Keep track of views internally
|
||||||
|
@ -196,7 +195,7 @@ var View = this.View = Base.extend(Callback, /** @lends View# */{
|
||||||
this._project.view = null;
|
this._project.view = null;
|
||||||
// Uninstall event handlers again for this view.
|
// Uninstall event handlers again for this view.
|
||||||
DomEvent.remove(this._canvas, this._handlers);
|
DomEvent.remove(this._canvas, this._handlers);
|
||||||
this._canvas = this._project = this._handlers = null;
|
this._canvas = this._project = null;
|
||||||
// Removing all onFrame handlers makes the _onFrameCallback handler stop
|
// Removing all onFrame handlers makes the _onFrameCallback handler stop
|
||||||
// automatically through its uninstall method.
|
// automatically through its uninstall method.
|
||||||
this.detach('frame');
|
this.detach('frame');
|
||||||
|
@ -476,6 +475,31 @@ var View = this.View = Base.extend(Callback, /** @lends View# */{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function mousedown(event) {
|
||||||
|
var view = View._viewsById[DomEvent.getTarget(event).getAttribute('id')];
|
||||||
|
// Tell the Key class which view should receive keyboard input.
|
||||||
|
View._focused = view;
|
||||||
|
curPoint = viewToProject(view, event);
|
||||||
|
dragging = true;
|
||||||
|
|
||||||
|
var update = false;
|
||||||
|
// TODO: Move this to CanvasView soon!
|
||||||
|
if (view._eventCounters.mousedown) {
|
||||||
|
var hit = view._project.hitTest(curPoint, hitOptions);
|
||||||
|
if (hit && hit.item) {
|
||||||
|
update = callEvent(hit.item, new MouseEvent('mousedown',
|
||||||
|
curPoint, hit.item, event), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tool = view._scope.tool)
|
||||||
|
update = tool.onHandleEvent('mousedown', curPoint, event)
|
||||||
|
|| update;
|
||||||
|
|
||||||
|
if (update)
|
||||||
|
view.draw(true);
|
||||||
|
}
|
||||||
|
|
||||||
function mousemove(event) {
|
function mousemove(event) {
|
||||||
var view;
|
var view;
|
||||||
if (!dragging) {
|
if (!dragging) {
|
||||||
|
@ -569,38 +593,10 @@ var View = this.View = Base.extend(Callback, /** @lends View# */{
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
_createHandlers: function() {
|
_handlers: {
|
||||||
var view = this;
|
|
||||||
|
|
||||||
function mousedown(event) {
|
|
||||||
// Tell the Key class which view should receive keyboard input.
|
|
||||||
View._focused = view;
|
|
||||||
curPoint = viewToProject(view, event);
|
|
||||||
dragging = true;
|
|
||||||
|
|
||||||
var update = false;
|
|
||||||
// TODO: Move this to CanvasView soon!
|
|
||||||
if (view._eventCounters.mousedown) {
|
|
||||||
var hit = view._project.hitTest(curPoint, hitOptions);
|
|
||||||
if (hit && hit.item) {
|
|
||||||
update = callEvent(hit.item, new MouseEvent('mousedown',
|
|
||||||
curPoint, hit.item, event), false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tool = view._scope.tool)
|
|
||||||
update = tool.onHandleEvent('mousedown', curPoint, event)
|
|
||||||
|| update;
|
|
||||||
|
|
||||||
if (update)
|
|
||||||
view.draw(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
mousedown: mousedown,
|
mousedown: mousedown,
|
||||||
touchstart: mousedown,
|
touchstart: mousedown,
|
||||||
selectstart: selectstart
|
selectstart: selectstart
|
||||||
};
|
|
||||||
},
|
},
|
||||||
|
|
||||||
statics: {
|
statics: {
|
||||||
|
|
Loading…
Reference in a new issue