2011-03-06 19:50:44 -05:00
|
|
|
/*
|
|
|
|
* Paper.js
|
|
|
|
*
|
|
|
|
* This file is part of Paper.js, a JavaScript Vector Graphics Library,
|
|
|
|
* based on Scriptographer.org and designed to be largely API compatible.
|
2011-03-07 20:41:50 -05:00
|
|
|
* http://paperjs.org/
|
2011-03-06 19:50:44 -05:00
|
|
|
* http://scriptographer.org/
|
|
|
|
*
|
2011-03-07 20:41:50 -05:00
|
|
|
* Distributed under the MIT license. See LICENSE file for details.
|
|
|
|
*
|
2011-03-06 19:50:44 -05:00
|
|
|
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
|
|
|
|
* http://lehni.org/ & http://jonathanpuckey.com/
|
|
|
|
*
|
2011-03-07 20:41:50 -05:00
|
|
|
* All rights reserved.
|
2011-03-06 19:50:44 -05:00
|
|
|
*/
|
|
|
|
|
2011-05-26 07:04:47 -04:00
|
|
|
// TODO: Support midPoint? (initial tests didn't look nice)
|
2011-03-04 08:34:31 -05:00
|
|
|
var GradientStop = this.GradientStop = Base.extend({
|
2011-05-25 18:55:44 -04:00
|
|
|
/** @lends GradientStop# */
|
|
|
|
|
2011-02-19 16:50:37 -05:00
|
|
|
beans: true,
|
|
|
|
|
2011-05-25 18:55:44 -04:00
|
|
|
/**
|
|
|
|
* Creates a GradientStop object.
|
|
|
|
*
|
|
|
|
* @param {Color} [color=new RGBColor(0, 0, 0)] the color of the stop
|
|
|
|
* @param {number} [rampPoint=0] the position of the stop on the gradient
|
|
|
|
* ramp {@default 0}
|
|
|
|
* @constructs GradientStop
|
|
|
|
*
|
|
|
|
* @class The GradientStop object.
|
|
|
|
*/
|
2011-05-19 15:51:09 -04:00
|
|
|
initialize: function(arg0, arg1) {
|
|
|
|
if (arg1 === undefined && Array.isArray(arg0)) {
|
|
|
|
// [color, rampPoint]
|
|
|
|
this.setColor(arg0[0]);
|
|
|
|
this.setRampPoint(arg0[1]);
|
|
|
|
} else if (arg0.color) {
|
|
|
|
// stop
|
|
|
|
this.setColor(arg0.color);
|
|
|
|
this.setRampPoint(arg0.rampPoint);
|
|
|
|
} else {
|
|
|
|
// color [, rampPoint]
|
|
|
|
this.setColor(arg0);
|
|
|
|
this.setRampPoint(arg1);
|
|
|
|
}
|
2011-02-19 16:50:37 -05:00
|
|
|
},
|
2011-03-03 17:45:17 -05:00
|
|
|
|
2011-05-25 18:55:44 -04:00
|
|
|
/**
|
|
|
|
* @return {GradientColor} a copy of the gradient-stop
|
|
|
|
*/
|
2011-05-19 17:02:26 -04:00
|
|
|
clone: function() {
|
|
|
|
return new GradientStop(this._color.clone(), this._rampPoint);
|
|
|
|
},
|
|
|
|
|
2011-05-25 18:55:44 -04:00
|
|
|
/**
|
|
|
|
* The ramp-point of the gradient stop as a value between 0 and 1.
|
|
|
|
*
|
2011-05-27 14:15:15 -04:00
|
|
|
* @type Number
|
2011-05-25 18:55:44 -04:00
|
|
|
* @bean
|
|
|
|
*/
|
2011-02-19 16:50:37 -05:00
|
|
|
getRampPoint: function() {
|
|
|
|
return this._rampPoint;
|
|
|
|
},
|
2011-03-03 17:45:17 -05:00
|
|
|
|
2011-02-19 16:50:37 -05:00
|
|
|
setRampPoint: function(rampPoint) {
|
2011-05-19 15:51:09 -04:00
|
|
|
this._defaultRamp = rampPoint == null;
|
2011-05-18 04:38:20 -04:00
|
|
|
this._rampPoint = rampPoint || 0;
|
2011-02-19 16:50:37 -05:00
|
|
|
},
|
2011-03-03 17:45:17 -05:00
|
|
|
|
2011-05-25 18:55:44 -04:00
|
|
|
/**
|
|
|
|
* The color of the gradient stop.
|
|
|
|
*
|
|
|
|
* @type Color
|
|
|
|
* @bean
|
|
|
|
*/
|
2011-02-19 16:50:37 -05:00
|
|
|
getColor: function() {
|
|
|
|
return this._color;
|
|
|
|
},
|
2011-03-03 17:45:17 -05:00
|
|
|
|
2011-03-08 12:17:36 -05:00
|
|
|
setColor: function(color) {
|
2011-02-19 16:50:37 -05:00
|
|
|
this._color = Color.read(arguments);
|
2011-05-05 15:28:28 -04:00
|
|
|
},
|
2011-05-18 04:40:03 -04:00
|
|
|
|
2011-05-05 15:28:28 -04:00
|
|
|
equals: function(stop) {
|
2011-05-18 04:40:03 -04:00
|
|
|
return stop == this || stop instanceof GradientStop
|
|
|
|
&& this._color.equals(stop._color)
|
2011-05-18 05:04:46 -04:00
|
|
|
&& this._rampPoint == stop._rampPoint;
|
2011-02-19 16:50:37 -05:00
|
|
|
}
|
2011-03-03 11:32:55 -05:00
|
|
|
});
|