mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Implement JSON serialization for Gradient and GradientColor.
This commit is contained in:
parent
e7bb334c6a
commit
366524d0a7
4 changed files with 19 additions and 2 deletions
|
@ -320,8 +320,8 @@ var Color = this.Color = Base.extend(new function() {
|
|||
* @ignore
|
||||
*/
|
||||
extend: function(src) {
|
||||
if (src._type) {
|
||||
var comps = components[src._type];
|
||||
var comps = components[src._type];
|
||||
if (comps) {
|
||||
// Automatically produce the _components field, adding alpha
|
||||
src._components = comps.concat(['alpha']);
|
||||
Base.each(comps, function(name) {
|
||||
|
|
|
@ -33,6 +33,11 @@ var Gradient = this.Gradient = Base.extend(/** @lends Gradient# */{
|
|||
this.type = type || 'linear';
|
||||
},
|
||||
|
||||
_serialize: function(dictionary) {
|
||||
return dictionary.get(this) || dictionary.set(this, Base.serialize(
|
||||
[this._type, this._stops, this.type], true, dictionary));
|
||||
},
|
||||
|
||||
/**
|
||||
* Called by various setters whenever a gradient value changes
|
||||
*/
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
* @class The GradientColor object.
|
||||
*/
|
||||
var GradientColor = this.GradientColor = Color.extend(/** @lends GradientColor# */{
|
||||
_type: 'gradientcolor',
|
||||
|
||||
/**
|
||||
* Creates a gradient color object.
|
||||
|
@ -97,6 +98,13 @@ var GradientColor = this.GradientColor = Color.extend(/** @lends GradientColor#
|
|||
this._hilite);
|
||||
},
|
||||
|
||||
_serialize: function(dictionary) {
|
||||
var values = [ this.gradient, this._origin, this._destination ];
|
||||
if (this._hilite)
|
||||
values.push(this._hilite);
|
||||
return Base.serialize(values, true, dictionary);
|
||||
},
|
||||
|
||||
/**
|
||||
* The origin point of the gradient.
|
||||
*
|
||||
|
|
|
@ -53,6 +53,10 @@ var GradientStop = this.GradientStop = Base.extend(/** @lends GradientStop# */{
|
|||
return new GradientStop(this._color.clone(), this._rampPoint);
|
||||
},
|
||||
|
||||
_serialize: function(dictionary) {
|
||||
return Base.serialize([this._color, this._rampPoint], false, dictionary);
|
||||
},
|
||||
|
||||
/**
|
||||
* Called by various setters whenever a value changes
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue