Allow implicit Gradient declaration in Color object literals.

This commit is contained in:
Jürg Lehni 2013-04-09 09:27:46 -07:00
parent 0d125e1a12
commit 9d0b9dc4c6
2 changed files with 18 additions and 4 deletions
examples/JSON
src/color

View file

@ -8,7 +8,9 @@
<script type="text/paperscript" canvas="canvas1">
var path = new Path.Circle(view.center, view.bounds.height * 0.4);
path.fillColor = {
gradient: [['yellow', 'red', 'black'], true],
// gradient: [['yellow', 'red', 'black'], true],
stops: ['yellow', 'red', 'black'],
radial: true,
origin: path.position,
destination: path.bounds.rightCenter
}

View file

@ -504,7 +504,7 @@ var Color = this.Color = Base.extend(new function() {
? 'lightness' in arg
? 'hsl'
: 'hsb'
: 'gradient' in arg
: 'gradient' in arg || 'stops' in arg
? 'gradient'
: 'gray' in arg
? 'gray'
@ -513,8 +513,20 @@ var Color = this.Color = Base.extend(new function() {
var properties = types[type];
parse = parsers[type];
this._components = components = [];
for (var i = 0, l = properties.length; i < l; i++)
components[i] = parse[i].call(this, arg[properties[i]]);
for (var i = 0, l = properties.length; i < l; i++) {
var value = arg[properties[i]];
// Allow implicit definition of gradients through
// stops / radial properties. Conversion happens
// here on the fly:
if (value == null && i === 0 && type === 'gradient'
&& 'stops' in arg) {
value = {
stops: arg.stops,
radial: arg.radial
};
}
components[i] = parse[i].call(this, value);
}
alpha = arg.alpha;
}
}