mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-08 05:42:07 -05:00
Simplify ToolEvent#modifiers.
This commit is contained in:
parent
22bc08501e
commit
1e4ae9afb4
6 changed files with 27 additions and 54 deletions
|
@ -63,8 +63,6 @@ var sources = [
|
||||||
'src/tool/ToolEvent.js',
|
'src/tool/ToolEvent.js',
|
||||||
'src/tool/ToolHandler.js',
|
'src/tool/ToolHandler.js',
|
||||||
'src/tool/Tool.js',
|
'src/tool/Tool.js',
|
||||||
|
|
||||||
'src/ui/KeyModifiers.js',
|
|
||||||
|
|
||||||
'src/util/BlendMode.js',
|
'src/util/BlendMode.js',
|
||||||
'src/util/CanvasProvider.js',
|
'src/util/CanvasProvider.js',
|
||||||
|
|
|
@ -111,8 +111,6 @@ Base.inject({
|
||||||
//#include "tool/ToolHandler.js"
|
//#include "tool/ToolHandler.js"
|
||||||
//#include "tool/Tool.js"
|
//#include "tool/Tool.js"
|
||||||
|
|
||||||
//#include "ui/KeyModifiers.js"
|
|
||||||
|
|
||||||
//#include "util/BlendMode.js"
|
//#include "util/BlendMode.js"
|
||||||
//#include "util/CanvasProvider.js"
|
//#include "util/CanvasProvider.js"
|
||||||
//#include "util/Element.js"
|
//#include "util/Element.js"
|
||||||
|
|
|
@ -31,9 +31,8 @@ var Tool = this.Tool = ToolHandler.extend(new function() {
|
||||||
var dragging = false;
|
var dragging = false;
|
||||||
this.events = {
|
this.events = {
|
||||||
mousedown: function(event) {
|
mousedown: function(event) {
|
||||||
var modifiers = new KeyModifiers(event);
|
|
||||||
curPoint = viewToArtwork(event, that._document);
|
curPoint = viewToArtwork(event, that._document);
|
||||||
that.onHandleEvent('mouse-down', curPoint, modifiers);
|
that.onHandleEvent('mouse-down', curPoint, event);
|
||||||
if (that.onMouseDown)
|
if (that.onMouseDown)
|
||||||
that._document.redraw();
|
that._document.redraw();
|
||||||
if (that.eventInterval != null) {
|
if (that.eventInterval != null) {
|
||||||
|
@ -44,30 +43,28 @@ var Tool = this.Tool = ToolHandler.extend(new function() {
|
||||||
},
|
},
|
||||||
|
|
||||||
mousemove: function(event) {
|
mousemove: function(event) {
|
||||||
var modifiers = new KeyModifiers(event);
|
|
||||||
var point = event && viewToArtwork(event, that._document);
|
var point = event && viewToArtwork(event, that._document);
|
||||||
if (dragging) {
|
if (dragging) {
|
||||||
curPoint = point || curPoint;
|
curPoint = point || curPoint;
|
||||||
if (curPoint) {
|
if (curPoint) {
|
||||||
that.onHandleEvent('mouse-drag', curPoint, modifiers);
|
that.onHandleEvent('mouse-drag', curPoint, event);
|
||||||
if (that.onMouseDrag)
|
if (that.onMouseDrag)
|
||||||
that._document.redraw();
|
that._document.redraw();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
that.onHandleEvent('mouse-move', point, modifiers);
|
that.onHandleEvent('mouse-move', point, event);
|
||||||
if (that.onMouseMove)
|
if (that.onMouseMove)
|
||||||
that._document.redraw();
|
that._document.redraw();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
mouseup: function(event) {
|
mouseup: function(event) {
|
||||||
var modifiers = new KeyModifiers(event);
|
|
||||||
if (dragging) {
|
if (dragging) {
|
||||||
curPoint = null;
|
curPoint = null;
|
||||||
if (that.eventInterval != null)
|
if (that.eventInterval != null)
|
||||||
clearInterval(this.timer);
|
clearInterval(this.timer);
|
||||||
that.onHandleEvent('mouse-up',
|
that.onHandleEvent('mouse-up',
|
||||||
viewToArtwork(event, that._document), modifiers);
|
viewToArtwork(event, that._document), event);
|
||||||
if (that.onMouseUp)
|
if (that.onMouseUp)
|
||||||
that._document.redraw();
|
that._document.redraw();
|
||||||
dragging = false;
|
dragging = false;
|
||||||
|
|
|
@ -34,12 +34,12 @@
|
||||||
var ToolEvent = this.ToolEvent = Base.extend({
|
var ToolEvent = this.ToolEvent = Base.extend({
|
||||||
beans: true,
|
beans: true,
|
||||||
|
|
||||||
initialize: function(tool, type, modifiers) {
|
initialize: function(tool, type, event) {
|
||||||
this.modifiers = modifiers;
|
this.event = event;
|
||||||
this.tool = tool;
|
this.tool = tool;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
},
|
},
|
||||||
|
|
||||||
toString: function() {
|
toString: function() {
|
||||||
return '{ type: ' + this.type
|
return '{ type: ' + this.type
|
||||||
+ ', point: ' + this.point
|
+ ', point: ' + this.point
|
||||||
|
@ -189,6 +189,20 @@ var ToolEvent = this.ToolEvent = Base.extend({
|
||||||
this.tool.count = count;
|
this.tool.count = count;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
getModifiers: function() {
|
||||||
|
if (!this._modifiers) {
|
||||||
|
var event = this.event;
|
||||||
|
this._modifiers = {
|
||||||
|
shift: event.shiftKey,
|
||||||
|
control: event.ctrlKey,
|
||||||
|
alt: event.altKey,
|
||||||
|
command: event.metaKey
|
||||||
|
// TODO: capslock
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return this._modifiers;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: implement hitTest first
|
// TODO: implement hitTest first
|
||||||
|
|
|
@ -117,12 +117,12 @@ var ToolHandler = this.ToolHandler = Base.extend({
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
onHandleEvent: function(type, pt, modifiers) {
|
onHandleEvent: function(type, pt, event) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'mouse-down':
|
case 'mouse-down':
|
||||||
this.updateEvent(type, pt, null, null, true, false, false);
|
this.updateEvent(type, pt, null, null, true, false, false);
|
||||||
if (this.onMouseDown)
|
if (this.onMouseDown)
|
||||||
this.onMouseDown(new ToolEvent(this, type, modifiers));
|
this.onMouseDown(new ToolEvent(this, type, event));
|
||||||
break;
|
break;
|
||||||
case 'mouse-drag':
|
case 'mouse-drag':
|
||||||
// In order for idleInterval drag events to work, we need to
|
// In order for idleInterval drag events to work, we need to
|
||||||
|
@ -139,7 +139,7 @@ var ToolHandler = this.ToolHandler = Base.extend({
|
||||||
this.maxDistance, false, this.needsChange,
|
this.maxDistance, false, this.needsChange,
|
||||||
this.matchMaxDistance)) {
|
this.matchMaxDistance)) {
|
||||||
if (this.onMouseDrag)
|
if (this.onMouseDrag)
|
||||||
this.onMouseDrag(new ToolEvent(this, type, modifiers));
|
this.onMouseDrag(new ToolEvent(this, type, event));
|
||||||
this.needsChange = true;
|
this.needsChange = true;
|
||||||
this.matchMaxDistance = true;
|
this.matchMaxDistance = true;
|
||||||
}
|
}
|
||||||
|
@ -151,12 +151,12 @@ var ToolHandler = this.ToolHandler = Base.extend({
|
||||||
&& this.updateEvent('mouse-drag', pt, this.minDistance,
|
&& this.updateEvent('mouse-drag', pt, this.minDistance,
|
||||||
this.maxDistance, false, false, false)) {
|
this.maxDistance, false, false, false)) {
|
||||||
if (this.onMouseDrag)
|
if (this.onMouseDrag)
|
||||||
this.onMouseDrag(new ToolEvent(this, type, modifiers));
|
this.onMouseDrag(new ToolEvent(this, type, event));
|
||||||
}
|
}
|
||||||
this.updateEvent(type, pt, null, this.maxDistance, false,
|
this.updateEvent(type, pt, null, this.maxDistance, false,
|
||||||
false, false);
|
false, false);
|
||||||
if (this.onMouseUp)
|
if (this.onMouseUp)
|
||||||
this.onMouseUp(new ToolEvent(this, type, modifiers));
|
this.onMouseUp(new ToolEvent(this, type, event));
|
||||||
// Start with new values for TRACK_CURSOR
|
// Start with new values for TRACK_CURSOR
|
||||||
this.updateEvent(type, pt, null, null, true, false, false);
|
this.updateEvent(type, pt, null, null, true, false, false);
|
||||||
this.firstMove = true;
|
this.firstMove = true;
|
||||||
|
@ -165,7 +165,7 @@ var ToolHandler = this.ToolHandler = Base.extend({
|
||||||
while (this.updateEvent(type, pt, this.minDistance,
|
while (this.updateEvent(type, pt, this.minDistance,
|
||||||
this.maxDistance, this.firstMove, true, false)) {
|
this.maxDistance, this.firstMove, true, false)) {
|
||||||
if (this.onMouseMove)
|
if (this.onMouseMove)
|
||||||
this.onMouseMove(new ToolEvent(this, type, modifiers));
|
this.onMouseMove(new ToolEvent(this, type, event));
|
||||||
this.firstMove = false;
|
this.firstMove = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1,34 +0,0 @@
|
||||||
/*
|
|
||||||
* Paper.js
|
|
||||||
*
|
|
||||||
* This file is part of Paper.js, a JavaScript Vector Graphics Library,
|
|
||||||
* based on Scriptographer.org and designed to be largely API compatible.
|
|
||||||
* http://paperjs.org/
|
|
||||||
* http://scriptographer.org/
|
|
||||||
*
|
|
||||||
* Distributed under the MIT license. See LICENSE file for details.
|
|
||||||
*
|
|
||||||
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
|
|
||||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
|
||||||
*
|
|
||||||
* All rights reserved.
|
|
||||||
*/
|
|
||||||
|
|
||||||
var KeyModifiers = Base.extend({
|
|
||||||
initialize: function(event) {
|
|
||||||
this.event = event;
|
|
||||||
}
|
|
||||||
}, new function() {
|
|
||||||
var modifiers = {
|
|
||||||
shift: 'shiftKey',
|
|
||||||
control: 'ctrlKey',
|
|
||||||
alt: 'altKey',
|
|
||||||
command: 'metaKey'
|
|
||||||
};
|
|
||||||
|
|
||||||
return Base.each(modifiers, function(modifier, key) {
|
|
||||||
this['get' + Base.capitalize(key)] = function() {
|
|
||||||
return this.event[modifier];
|
|
||||||
};
|
|
||||||
}, { beans: true });
|
|
||||||
});
|
|
Loading…
Reference in a new issue