mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-23 07:49:48 -05:00
Implement _changed() mechanism in Color, by having Colors know which items they are defining styles for, through an internal _owners list.
This commit is contained in:
parent
af0e5a07b7
commit
3a232b305e
3 changed files with 32 additions and 2 deletions
|
@ -270,7 +270,7 @@ var Color = this.Color = Base.extend(new function() {
|
||||||
? ((value % 360) + 360) % 360
|
? ((value % 360) + 360) % 360
|
||||||
// All other values are 0..1
|
// All other values are 0..1
|
||||||
: Math.min(Math.max(value, 0), 1);
|
: Math.min(Math.max(value, 0), 1);
|
||||||
this._cssString = null;
|
this._changed();
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
}, src);
|
}, src);
|
||||||
|
@ -306,6 +306,27 @@ var Color = this.Color = Base.extend(new function() {
|
||||||
}, {
|
}, {
|
||||||
/** @lends Color# */
|
/** @lends Color# */
|
||||||
|
|
||||||
|
_changed: function() {
|
||||||
|
this._cssString = null;
|
||||||
|
for (var i = 0, l = this._owners && this._owners.length; i < l; i++)
|
||||||
|
this._owners[i]._changed(Change.STYLE);
|
||||||
|
},
|
||||||
|
|
||||||
|
_addOwner: function(item) {
|
||||||
|
if (!this._owners)
|
||||||
|
this._owners = [];
|
||||||
|
this._owners.push(item);
|
||||||
|
},
|
||||||
|
|
||||||
|
_removeOwner: function(item) {
|
||||||
|
var index = this._owners ? this._owners.indexOf(item) : -1;
|
||||||
|
if (index != -1) {
|
||||||
|
this._owners.splice(index, 1);
|
||||||
|
if (this._owners.length == 0)
|
||||||
|
delete this._owners;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the type of the color as a string.
|
* Returns the type of the color as a string.
|
||||||
*
|
*
|
||||||
|
@ -357,7 +378,7 @@ var Color = this.Color = Base.extend(new function() {
|
||||||
|
|
||||||
setAlpha: function(alpha) {
|
setAlpha: function(alpha) {
|
||||||
this._alpha = alpha == null ? null : Math.min(Math.max(alpha, 0), 1);
|
this._alpha = alpha == null ? null : Math.min(Math.max(alpha, 0), 1);
|
||||||
this._cssString = null;
|
this._changed();
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -136,6 +136,7 @@ var GradientColor = this.GradientColor = Color.extend({
|
||||||
this._origin = origin;
|
this._origin = origin;
|
||||||
if (this._destination)
|
if (this._destination)
|
||||||
this._radius = this._destination.getDistance(this._origin);
|
this._radius = this._destination.getDistance(this._origin);
|
||||||
|
this._changed();
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -175,6 +176,7 @@ var GradientColor = this.GradientColor = Color.extend({
|
||||||
destination = Point.read(arguments).clone();
|
destination = Point.read(arguments).clone();
|
||||||
this._destination = destination;
|
this._destination = destination;
|
||||||
this._radius = this._destination.getDistance(this._origin);
|
this._radius = this._destination.getDistance(this._origin);
|
||||||
|
this._changed();
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -218,6 +220,7 @@ var GradientColor = this.GradientColor = Color.extend({
|
||||||
} else {
|
} else {
|
||||||
this._hilite = hilite;
|
this._hilite = hilite;
|
||||||
}
|
}
|
||||||
|
this._changed();
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -104,6 +104,12 @@ var PathStyle = this.PathStyle = Base.extend(new function() {
|
||||||
var old = this['_' + key];
|
var old = this['_' + key];
|
||||||
if (old != value && !(old && old.equals && old.equals(value))) {
|
if (old != value && !(old && old.equals && old.equals(value))) {
|
||||||
this['_' + key] = value;
|
this['_' + key] = value;
|
||||||
|
if (isColor) {
|
||||||
|
if (old)
|
||||||
|
old._removeOwner(this._item);
|
||||||
|
if (value)
|
||||||
|
value._addOwner(this._item);
|
||||||
|
}
|
||||||
if (this._item) {
|
if (this._item) {
|
||||||
this._item._changed(Change.STYLE
|
this._item._changed(Change.STYLE
|
||||||
| (strokeFlags[key] ? Change.STROKE : 0));
|
| (strokeFlags[key] ? Change.STROKE : 0));
|
||||||
|
|
Loading…
Reference in a new issue