mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
Add support for GradientColor object literal constructor.
And introduce getter / setter for #gradient.
This commit is contained in:
parent
1d1e6425fa
commit
b8ca30a4cd
1 changed files with 30 additions and 12 deletions
|
@ -85,29 +85,47 @@ var GradientColor = this.GradientColor = Color.extend(/** @lends GradientColor#
|
||||||
initialize: function(gradient, origin, destination, hilite) {
|
initialize: function(gradient, origin, destination, hilite) {
|
||||||
// Define this GradientColor's unique id.
|
// Define this GradientColor's unique id.
|
||||||
this._id = ++Base._uid;
|
this._id = ++Base._uid;
|
||||||
this.gradient = gradient || new LinearGradient();
|
// Try object literal constructor first
|
||||||
this.gradient._addOwner(this);
|
if (!this._set(gradient)) {
|
||||||
this.setOrigin(origin);
|
this.setGradient(gradient || new LinearGradient());
|
||||||
this.setDestination(destination);
|
this.setOrigin(origin);
|
||||||
if (hilite)
|
this.setDestination(destination);
|
||||||
this.setHilite(hilite);
|
if (hilite)
|
||||||
|
this.setHilite(hilite);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {GradientColor} a copy of the gradient color
|
* @return {GradientColor} a copy of the gradient color
|
||||||
*/
|
*/
|
||||||
clone: function() {
|
clone: function() {
|
||||||
return new GradientColor(this.gradient, this._origin, this._destination,
|
return new GradientColor(this._gradient, this._origin,
|
||||||
this._hilite);
|
this._destination, this._hilite);
|
||||||
},
|
},
|
||||||
|
|
||||||
_serialize: function(options, dictionary) {
|
_serialize: function(options, dictionary) {
|
||||||
var values = [ this.gradient, this._origin, this._destination ];
|
var values = [ this._gradient, this._origin, this._destination ];
|
||||||
if (this._hilite)
|
if (this._hilite)
|
||||||
values.push(this._hilite);
|
values.push(this._hilite);
|
||||||
return Base.serialize(values, options, true, dictionary);
|
return Base.serialize(values, options, true, dictionary);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The gradient object describing the type of gradient and the stops.
|
||||||
|
*
|
||||||
|
* @type Gradient
|
||||||
|
* @bean
|
||||||
|
*/
|
||||||
|
getGradient: function() {
|
||||||
|
return this._gradient;
|
||||||
|
},
|
||||||
|
|
||||||
|
setGradient: function(gradient) {
|
||||||
|
this._gradient = gradient;
|
||||||
|
gradient._addOwner(this);
|
||||||
|
this._changed();
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The origin point of the gradient.
|
* The origin point of the gradient.
|
||||||
*
|
*
|
||||||
|
@ -236,8 +254,8 @@ var GradientColor = this.GradientColor = Color.extend(/** @lends GradientColor#
|
||||||
|
|
||||||
toCanvasStyle: function(ctx) {
|
toCanvasStyle: function(ctx) {
|
||||||
var gradient,
|
var gradient,
|
||||||
stops = this.gradient._stops;
|
stops = this._gradient._stops;
|
||||||
if (this.gradient._type === 'LinearGradient') {
|
if (this._gradient._type === 'LinearGradient') {
|
||||||
gradient = ctx.createLinearGradient(this._origin.x, this._origin.y,
|
gradient = ctx.createLinearGradient(this._origin.x, this._origin.y,
|
||||||
this._destination.x, this._destination.y);
|
this._destination.x, this._destination.y);
|
||||||
} else {
|
} else {
|
||||||
|
@ -261,7 +279,7 @@ var GradientColor = this.GradientColor = Color.extend(/** @lends GradientColor#
|
||||||
*/
|
*/
|
||||||
equals: function(color) {
|
equals: function(color) {
|
||||||
return color == this || color && color._type === this._type
|
return color == this || color && color._type === this._type
|
||||||
&& this.gradient.equals(color.gradient)
|
&& this._gradient.equals(color._gradient)
|
||||||
&& this._origin.equals(color._origin)
|
&& this._origin.equals(color._origin)
|
||||||
&& this._destination.equals(color._destination);
|
&& this._destination.equals(color._destination);
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue