mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-07 13:22:07 -05:00
Fix Color cloning by adding clone function and using it in Color#initialize.
This commit is contained in:
parent
0a86c2b34e
commit
024e8eb19b
1 changed files with 14 additions and 3 deletions
|
@ -158,10 +158,11 @@ var Color = this.Color = Base.extend(new function() {
|
||||||
} else {
|
} else {
|
||||||
// Called on a subclass instance. Return the converted
|
// Called on a subclass instance. Return the converted
|
||||||
// color.
|
// color.
|
||||||
var color = Color.read(arguments, 0, 1);
|
var color = arg._colorType ? arg
|
||||||
return this._colorType
|
: Color.read(arguments, 0, 1);
|
||||||
|
return (this._colorType !== color._colorType)
|
||||||
? color.convert(this._colorType)
|
? color.convert(this._colorType)
|
||||||
: color;
|
: color.clone();
|
||||||
}
|
}
|
||||||
} else if (typeof arg === 'string') {
|
} else if (typeof arg === 'string') {
|
||||||
var rgbColor = arg.match(/^#[0-9a-f]{3,6}$/i)
|
var rgbColor = arg.match(/^#[0-9a-f]{3,6}$/i)
|
||||||
|
@ -196,6 +197,16 @@ var Color = this.Color = Base.extend(new function() {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
clone: function(color) {
|
||||||
|
var copy = new this.constructor(),
|
||||||
|
components = this._components;
|
||||||
|
for (var i = 0, l = components.length; i < l; i++) {
|
||||||
|
var key = '_' + components[i];
|
||||||
|
copy[key] = this[key];
|
||||||
|
}
|
||||||
|
return copy;
|
||||||
|
},
|
||||||
|
|
||||||
convert: function(type) {
|
convert: function(type) {
|
||||||
return this._colorType == type
|
return this._colorType == type
|
||||||
? this
|
? this
|
||||||
|
|
Loading…
Reference in a new issue