Implement argument reading for Gradient objects.

This commit is contained in:
Jürg Lehni 2013-04-09 09:20:32 -07:00
parent b9532f6a1a
commit 26efbdb451
3 changed files with 14 additions and 9 deletions

View file

@ -7,11 +7,11 @@
<script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas1">
var path = new Path.Circle(view.center, view.bounds.height * 0.4);
var gradient = new Gradient(['yellow', 'red', 'black'], true);
var from = path.position;
var to = path.bounds.rightCenter;
var gradientColor = new Color(gradient, from, to);
path.fillColor = gradientColor;
path.fillColor = {
gradient: [['yellow', 'red', 'black'], true],
origin: path.position,
destination: path.bounds.rightCenter
}
path.strokeColor = 'black';
window._json = project.exportJson();
console.log(window._json);

View file

@ -226,6 +226,9 @@ var Color = this.Color = Base.extend(new function() {
parser = parsers[type][index] = name === 'gradient'
? function(value) {
var current = this._components[0];
value = Gradient.read(
Array.isArray(value) ? value : arguments,
0, 0, false, true); // readNull
if (current !== value) {
if (current)
current._removeOwner(this);

View file

@ -21,10 +21,12 @@ var Gradient = this.Gradient = Base.extend(/** @lends Gradient# */{
initialize: function(stops, radial) {
// Define this Gradient's unique id.
this._id = ++Base._uid;
this.setStops(stops || ['white', 'black']);
// Support old version of string type argument and new radial boolean.
this.setRadial(typeof radial === 'string' && radial === 'radial'
|| radial || false);
if (!stops || !this._set(stops)) {
this.setStops(stops || ['white', 'black']);
// Support old string type argument and new radial boolean.
this.setRadial(typeof radial === 'string' && radial === 'radial'
|| radial || false);
}
},
_serialize: function(options, dictionary) {