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

View file

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

View file

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