mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-06-06 02:04:20 -04:00
Implement onActivate() onDeactivate() handlers on Tool, and remove onSelect() / onDeselect() which never worked.
This commit is contained in:
parent
e9a9066d7f
commit
01342fa073
4 changed files with 12 additions and 8 deletions
|
@ -23,7 +23,7 @@
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
var PaperScopeItem = Base.extend(/** @lends PaperScopeItem# */{
|
var PaperScopeItem = Base.extend(Callback, /** @lends PaperScopeItem# */{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a PaperScopeItem object.
|
* Creates a PaperScopeItem object.
|
||||||
|
@ -41,7 +41,11 @@ var PaperScopeItem = Base.extend(/** @lends PaperScopeItem# */{
|
||||||
activate: function() {
|
activate: function() {
|
||||||
if (!this._scope)
|
if (!this._scope)
|
||||||
return false;
|
return false;
|
||||||
|
var prev = this._scope[this._reference];
|
||||||
|
if (prev && prev != this)
|
||||||
|
prev.fire('deactivate');
|
||||||
this._scope[this._reference] = this;
|
this._scope[this._reference] = this;
|
||||||
|
this.fire('activate', prev);
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -165,7 +165,7 @@ var PaperScript = this.PaperScript = new function() {
|
||||||
// Within this, use a function scope, so local variables to not try
|
// Within this, use a function scope, so local variables to not try
|
||||||
// and set themselves on the scope object.
|
// and set themselves on the scope object.
|
||||||
(function() {
|
(function() {
|
||||||
var onEditOptions, onSelect, onDeselect, onReselect,
|
var onActivate, onDeactivate, onEditOptions,
|
||||||
onMouseDown, onMouseUp, onMouseDrag, onMouseMove,
|
onMouseDown, onMouseUp, onMouseDrag, onMouseMove,
|
||||||
onKeyDown, onKeyUp, onFrame, onResize;
|
onKeyDown, onKeyUp, onFrame, onResize;
|
||||||
res = eval(compile(code));
|
res = eval(compile(code));
|
||||||
|
|
|
@ -56,9 +56,9 @@ var paper = new function() {
|
||||||
/*#*/ } // options.stats
|
/*#*/ } // options.stats
|
||||||
|
|
||||||
/*#*/ include('core/Base.js');
|
/*#*/ include('core/Base.js');
|
||||||
|
/*#*/ include('core/Callback.js');
|
||||||
/*#*/ include('core/PaperScope.js');
|
/*#*/ include('core/PaperScope.js');
|
||||||
/*#*/ include('core/PaperScopeItem.js');
|
/*#*/ include('core/PaperScopeItem.js');
|
||||||
/*#*/ include('core/Callback.js');
|
|
||||||
|
|
||||||
// Include Paper classes, which are later injected into PaperScope by setting
|
// Include Paper classes, which are later injected into PaperScope by setting
|
||||||
// them on the 'this' object, e.g.:
|
// them on the 'this' object, e.g.:
|
||||||
|
|
|
@ -46,10 +46,10 @@
|
||||||
* path.add(event.point);
|
* path.add(event.point);
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
var Tool = this.Tool = PaperScopeItem.extend(Callback, /** @lends Tool# */{
|
var Tool = this.Tool = PaperScopeItem.extend(/** @lends Tool# */{
|
||||||
_list: 'tools',
|
_list: 'tools',
|
||||||
_reference: '_tool', // PaperScope has accessor for #tool
|
_reference: '_tool', // PaperScope has accessor for #tool
|
||||||
_events: [ 'onEditOptions', 'onSelect', 'onDeselect', 'onReselect',
|
_events: [ 'onActivate', 'onDeactivate', 'onEditOptions',
|
||||||
'onMouseDown', 'onMouseUp', 'onMouseDrag', 'onMouseMove',
|
'onMouseDown', 'onMouseUp', 'onMouseDrag', 'onMouseMove',
|
||||||
'onKeyDown', 'onKeyUp' ],
|
'onKeyDown', 'onKeyUp' ],
|
||||||
|
|
||||||
|
@ -272,9 +272,9 @@ var Tool = this.Tool = PaperScopeItem.extend(Callback, /** @lends Tool# */{
|
||||||
needsChange, matchMaxDistance) {
|
needsChange, matchMaxDistance) {
|
||||||
if (!start) {
|
if (!start) {
|
||||||
if (minDistance != null || maxDistance != null) {
|
if (minDistance != null || maxDistance != null) {
|
||||||
var minDist = minDistance != null ? minDistance : 0;
|
var minDist = minDistance != null ? minDistance : 0,
|
||||||
var vector = pt.subtract(this._point);
|
vector = pt.subtract(this._point),
|
||||||
var distance = vector.getLength();
|
distance = vector.getLength();
|
||||||
if (distance < minDist)
|
if (distance < minDist)
|
||||||
return false;
|
return false;
|
||||||
// Produce a new point on the way to pt if pt is further away
|
// Produce a new point on the way to pt if pt is further away
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue