mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-05 20:32:00 -05:00
Clean up mouse handling code.
This commit is contained in:
parent
31c06b4a61
commit
7ca22cd260
1 changed files with 8 additions and 16 deletions
|
@ -282,9 +282,7 @@ var View = this.View = Base.extend(Callback, /** @lends View# */{
|
||||||
this._element.height = size.height;
|
this._element.height = size.height;
|
||||||
// Update _viewSize but don't notify of change.
|
// Update _viewSize but don't notify of change.
|
||||||
this._viewSize.set(size.width, size.height, true);
|
this._viewSize.set(size.width, size.height, true);
|
||||||
// Force recalculation
|
this._bounds = null; // Force recalculation
|
||||||
this._bounds = null;
|
|
||||||
this._redrawNeeded = true;
|
|
||||||
// Call onResize handler on any size change
|
// Call onResize handler on any size change
|
||||||
this.fire('resize', {
|
this.fire('resize', {
|
||||||
size: size,
|
size: size,
|
||||||
|
@ -571,7 +569,6 @@ var View = this.View = Base.extend(Callback, /** @lends View# */{
|
||||||
// Injection scope for mouse events on the browser
|
// Injection scope for mouse events on the browser
|
||||||
/*#*/ if (options.browser) {
|
/*#*/ if (options.browser) {
|
||||||
var tool,
|
var tool,
|
||||||
curPoint,
|
|
||||||
prevFocus,
|
prevFocus,
|
||||||
tempFocus,
|
tempFocus,
|
||||||
dragging = false;
|
dragging = false;
|
||||||
|
@ -603,15 +600,15 @@ var View = this.View = Base.extend(Callback, /** @lends View# */{
|
||||||
function mousedown(event) {
|
function mousedown(event) {
|
||||||
// Get the view from the event, and store a reference to the view that
|
// Get the view from the event, and store a reference to the view that
|
||||||
// should receive keyboard input.
|
// should receive keyboard input.
|
||||||
var view = View._focused = getView(event);
|
var view = View._focused = getView(event),
|
||||||
curPoint = viewToProject(view, event);
|
point = viewToProject(view, event);
|
||||||
dragging = true;
|
dragging = true;
|
||||||
// Always first call the view's mouse handlers, as required by
|
// Always first call the view's mouse handlers, as required by
|
||||||
// CanvasView, and then handle the active tool, if any.
|
// CanvasView, and then handle the active tool, if any.
|
||||||
if (view._onMouseDown)
|
if (view._onMouseDown)
|
||||||
view._onMouseDown(event, curPoint);
|
view._onMouseDown(event, point);
|
||||||
if (tool = view._scope._tool)
|
if (tool = view._scope._tool)
|
||||||
tool._onHandleEvent('mousedown', curPoint, event);
|
tool._onHandleEvent('mousedown', point, event);
|
||||||
// In the end we always call draw(), but pass checkRedraw = true, so we
|
// In the end we always call draw(), but pass checkRedraw = true, so we
|
||||||
// only redraw the view if anything has changed in the above calls.
|
// only redraw the view if anything has changed in the above calls.
|
||||||
view.draw(true);
|
view.draw(true);
|
||||||
|
@ -640,15 +637,10 @@ var View = this.View = Base.extend(Callback, /** @lends View# */{
|
||||||
if (view._onMouseMove)
|
if (view._onMouseMove)
|
||||||
view._onMouseMove(event, point);
|
view._onMouseMove(event, point);
|
||||||
if (tool = view._scope._tool) {
|
if (tool = view._scope._tool) {
|
||||||
var onlyMove = !!(!tool.onMouseDrag && tool.onMouseMove);
|
// If there's no onMouseDrag, fire onMouseMove while dragging too.
|
||||||
if (dragging && !onlyMove) {
|
if (tool._onHandleEvent(dragging && tool.responds('mousedrag')
|
||||||
if ((curPoint = point || curPoint)
|
? 'mousedrag' : 'mousemove', point, event))
|
||||||
&& tool._onHandleEvent('mousedrag', curPoint, event))
|
|
||||||
DomEvent.stop(event);
|
|
||||||
} else if ((!dragging || onlyMove)
|
|
||||||
&& tool._onHandleEvent('mousemove', point, event)) {
|
|
||||||
DomEvent.stop(event);
|
DomEvent.stop(event);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
view.draw(true);
|
view.draw(true);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue