mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2024-12-29 09:22:22 -05:00
parent
b5c753f23d
commit
bc5a361470
2 changed files with 28 additions and 45 deletions
|
@ -712,7 +712,11 @@ var Color = Base.extend(new function() {
|
||||||
_changed: function() {
|
_changed: function() {
|
||||||
this._canvasStyle = null;
|
this._canvasStyle = null;
|
||||||
if (this._owner) {
|
if (this._owner) {
|
||||||
this._owner[this._setter](this);
|
if (this._setter) {
|
||||||
|
this._owner[this._setter](this);
|
||||||
|
} else {
|
||||||
|
this._owner._changed(/*#=*/Change.STYLE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -1390,30 +1394,3 @@ new function() {
|
||||||
*/
|
*/
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
|
||||||
* @name LinkedColor
|
|
||||||
*
|
|
||||||
* @class An internal version of Color that notifies its owner of each change
|
|
||||||
* through setting itself again on the setter that corresponds to the getter
|
|
||||||
* that produced this LinkedColor. This is used to solve group color update
|
|
||||||
* problem (#1152) with the same principle used in LinkedPoint.
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
var LinkedColor = Color.extend({
|
|
||||||
// Make sure LinkedColor is displayed as Color in debugger.
|
|
||||||
initialize: function Color(color, item, setter) {
|
|
||||||
// Rely on real constructor for instantiation.
|
|
||||||
paper.Color.apply(this, [color]);
|
|
||||||
// Store references.
|
|
||||||
this._item = item;
|
|
||||||
this._setter = setter;
|
|
||||||
},
|
|
||||||
|
|
||||||
// Rely on Color#_changed() method to detect changes.
|
|
||||||
_changed: function(){
|
|
||||||
// Update owner color by calling setter.
|
|
||||||
this._item[this._setter](this);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
|
@ -187,7 +187,10 @@ var Style = Base.extend(new function() {
|
||||||
if (value && value.constructor === Color) {
|
if (value && value.constructor === Color) {
|
||||||
// NOTE: If value is not a Color, it is only
|
// NOTE: If value is not a Color, it is only
|
||||||
// converted and cloned in the getter further down.
|
// converted and cloned in the getter further down.
|
||||||
value = Color._setOwner(value, owner, set);
|
value = Color._setOwner(value, owner,
|
||||||
|
// Only provide a color-setter if the style
|
||||||
|
// is to be applied to the children:
|
||||||
|
applyToChildren && set);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// NOTE: We do not convert the values to Colors in the
|
// NOTE: We do not convert the values to Colors in the
|
||||||
|
@ -204,12 +207,24 @@ var Style = Base.extend(new function() {
|
||||||
fields[get] = function(_dontMerge) {
|
fields[get] = function(_dontMerge) {
|
||||||
var owner = this._owner,
|
var owner = this._owner,
|
||||||
children = owner && owner._children,
|
children = owner && owner._children,
|
||||||
|
applyToChildren = children && children.length > 0
|
||||||
|
&& !(owner instanceof CompoundPath),
|
||||||
value;
|
value;
|
||||||
// If the owner has children, walk through all of them and see if
|
// If the owner has children, walk through all of them and see if
|
||||||
// they all have the same style.
|
// they all have the same style.
|
||||||
// If true is passed for _dontMerge, don't merge children styles
|
// If true is passed for _dontMerge, don't merge children styles.
|
||||||
if (key in this._defaults && (!children || !children.length
|
if (applyToChildren && !_dontMerge) {
|
||||||
|| _dontMerge || owner instanceof CompoundPath)) {
|
for (var i = 0, l = children.length; i < l; i++) {
|
||||||
|
var childValue = children[i]._style[get]();
|
||||||
|
if (!i) {
|
||||||
|
value = childValue;
|
||||||
|
} else if (!Base.equals(value, childValue)) {
|
||||||
|
// If there is another child with a different
|
||||||
|
// style, the style is not defined:
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (key in this._defaults) {
|
||||||
var value = this._values[key];
|
var value = this._values[key];
|
||||||
if (value === undefined) {
|
if (value === undefined) {
|
||||||
value = this._defaults[key];
|
value = this._defaults[key];
|
||||||
|
@ -226,22 +241,13 @@ var Style = Base.extend(new function() {
|
||||||
{ readNull: true, clone: true });
|
{ readNull: true, clone: true });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (children) {
|
|
||||||
for (var i = 0, l = children.length; i < l; i++) {
|
|
||||||
var childValue = children[i]._style[get]();
|
|
||||||
if (!i) {
|
|
||||||
value = childValue;
|
|
||||||
} else if (!Base.equals(value, childValue)) {
|
|
||||||
// If there is another child with a different
|
|
||||||
// style, the style is not defined:
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (value && isColor) {
|
if (value && isColor) {
|
||||||
// Color._setOwner() may clone the color if it already has a
|
// Color._setOwner() may clone the color if it already has a
|
||||||
// different owner (e.g. resulting from `childValue` above):
|
// different owner (e.g. resulting from `childValue` above).
|
||||||
value = Color._setOwner(value, owner, set);
|
// Only provide a color-setter if the style is to be applied to
|
||||||
|
// the children:
|
||||||
|
value = Color._setOwner(value, owner, applyToChildren && set);
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue