mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-09 06:12:34 -05:00
Reuse the Tool mousedrag handlign logic for mousemove
This commit is contained in:
parent
f193acf31b
commit
5060a18263
1 changed files with 24 additions and 22 deletions
|
@ -354,30 +354,12 @@ var Tool = PaperScopeItem.extend(/** @lends Tool# */{
|
||||||
// Update global reference to this scope.
|
// Update global reference to this scope.
|
||||||
paper = this._scope;
|
paper = this._scope;
|
||||||
// Now handle event callbacks
|
// Now handle event callbacks
|
||||||
var called = false;
|
var called = false, drag = false;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'mousedown':
|
case 'mousedown':
|
||||||
this._updateEvent(type, point, null, null, true, false, false);
|
this._updateEvent(type, point, null, null, true, false, false);
|
||||||
called = this._fireEvent(type, event);
|
called = this._fireEvent(type, event);
|
||||||
break;
|
break;
|
||||||
case 'mousedrag':
|
|
||||||
// In order for idleInterval drag events to work, we need to not
|
|
||||||
// check the first call for a change of position. Subsequent calls
|
|
||||||
// required by min/maxDistance functionality will require it,
|
|
||||||
// otherwise this might loop endlessly.
|
|
||||||
var needsChange = false,
|
|
||||||
// If the mouse is moving faster than maxDistance, do not produce
|
|
||||||
// events for what is left after the first event is generated in
|
|
||||||
// case it is shorter than maxDistance, as this would produce weird
|
|
||||||
// results. matchMaxDistance controls this.
|
|
||||||
matchMaxDistance = false;
|
|
||||||
while (this._updateEvent(type, point, this.minDistance,
|
|
||||||
this.maxDistance, false, needsChange, matchMaxDistance)) {
|
|
||||||
called = this._fireEvent(type, event) || called;
|
|
||||||
needsChange = true;
|
|
||||||
matchMaxDistance = true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'mouseup':
|
case 'mouseup':
|
||||||
// If the last mouse drag happened in a different place, call mouse
|
// If the last mouse drag happened in a different place, call mouse
|
||||||
// drag first, then mouse up.
|
// drag first, then mouse up.
|
||||||
|
@ -393,12 +375,32 @@ var Tool = PaperScopeItem.extend(/** @lends Tool# */{
|
||||||
this._updateEvent(type, point, null, null, true, false, false);
|
this._updateEvent(type, point, null, null, true, false, false);
|
||||||
this._firstMove = true;
|
this._firstMove = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'mousedrag':
|
||||||
|
drag = true;
|
||||||
|
// Fall through to share event handling
|
||||||
case 'mousemove':
|
case 'mousemove':
|
||||||
while (this._updateEvent(type, point, this.minDistance,
|
var source = !drag && this._firstMove;
|
||||||
this.maxDistance, this._firstMove, true, false)) {
|
// In order for idleInterval drag events to work, we need to not
|
||||||
|
// check the first call for a change of position. Subsequent calls
|
||||||
|
// required by min/maxDistance functionality will require it,
|
||||||
|
// otherwise this might loop endlessly.
|
||||||
|
var needsChange = !drag;
|
||||||
|
// If the mouse is moving faster than maxDistance, do not produce
|
||||||
|
// events for what is left after the first event is generated in
|
||||||
|
// case it is shorter than maxDistance, as this would produce weird
|
||||||
|
// results. matchMaxDistance controls this.
|
||||||
|
var matchMaxDistance = false;
|
||||||
|
while (this._updateEvent(type, point, this.minDistance, this.maxDistance,
|
||||||
|
source, needsChange, matchMaxDistance)) {
|
||||||
called = this._fireEvent(type, event) || called;
|
called = this._fireEvent(type, event) || called;
|
||||||
|
if (drag) {
|
||||||
|
needsChange = true;
|
||||||
|
matchMaxDistance = true;
|
||||||
|
} else {
|
||||||
this._firstMove = false;
|
this._firstMove = false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Prevent default if mouse event was handled.
|
// Prevent default if mouse event was handled.
|
||||||
|
|
Loading…
Reference in a new issue