Implement onActivate() onDeactivate() handlers on Tool, and remove onSelect() / onDeselect() which never worked.

This commit is contained in:
Jürg Lehni 2012-11-07 01:02:09 -08:00
parent e9a9066d7f
commit 01342fa073
4 changed files with 12 additions and 8 deletions

View file

@ -23,7 +23,7 @@
*
* @private
*/
var PaperScopeItem = Base.extend(/** @lends PaperScopeItem# */{
var PaperScopeItem = Base.extend(Callback, /** @lends PaperScopeItem# */{
/**
* Creates a PaperScopeItem object.
@ -41,7 +41,11 @@ var PaperScopeItem = Base.extend(/** @lends PaperScopeItem# */{
activate: function() {
if (!this._scope)
return false;
var prev = this._scope[this._reference];
if (prev && prev != this)
prev.fire('deactivate');
this._scope[this._reference] = this;
this.fire('activate', prev);
return true;
},

View file

@ -165,7 +165,7 @@ var PaperScript = this.PaperScript = new function() {
// Within this, use a function scope, so local variables to not try
// and set themselves on the scope object.
(function() {
var onEditOptions, onSelect, onDeselect, onReselect,
var onActivate, onDeactivate, onEditOptions,
onMouseDown, onMouseUp, onMouseDrag, onMouseMove,
onKeyDown, onKeyUp, onFrame, onResize;
res = eval(compile(code));

View file

@ -56,9 +56,9 @@ var paper = new function() {
/*#*/ } // options.stats
/*#*/ include('core/Base.js');
/*#*/ include('core/Callback.js');
/*#*/ include('core/PaperScope.js');
/*#*/ include('core/PaperScopeItem.js');
/*#*/ include('core/Callback.js');
// Include Paper classes, which are later injected into PaperScope by setting
// them on the 'this' object, e.g.:

View file

@ -46,10 +46,10 @@
* path.add(event.point);
* }
*/
var Tool = this.Tool = PaperScopeItem.extend(Callback, /** @lends Tool# */{
var Tool = this.Tool = PaperScopeItem.extend(/** @lends Tool# */{
_list: 'tools',
_reference: '_tool', // PaperScope has accessor for #tool
_events: [ 'onEditOptions', 'onSelect', 'onDeselect', 'onReselect',
_events: [ 'onActivate', 'onDeactivate', 'onEditOptions',
'onMouseDown', 'onMouseUp', 'onMouseDrag', 'onMouseMove',
'onKeyDown', 'onKeyUp' ],
@ -272,9 +272,9 @@ var Tool = this.Tool = PaperScopeItem.extend(Callback, /** @lends Tool# */{
needsChange, matchMaxDistance) {
if (!start) {
if (minDistance != null || maxDistance != null) {
var minDist = minDistance != null ? minDistance : 0;
var vector = pt.subtract(this._point);
var distance = vector.getLength();
var minDist = minDistance != null ? minDistance : 0,
vector = pt.subtract(this._point),
distance = vector.getLength();
if (distance < minDist)
return false;
// Produce a new point on the way to pt if pt is further away