2011-03-04 08:34:31 -05:00
|
|
|
var GradientColor = this.GradientColor = Color.extend({
|
2011-02-19 16:50:37 -05:00
|
|
|
beans: true,
|
|
|
|
|
|
|
|
initialize: function(gradient, origin, destination, hilite) {
|
|
|
|
this.gradient = gradient || new Gradient();
|
2011-02-19 16:52:00 -05:00
|
|
|
this.origin = origin;
|
|
|
|
this.destination = destination;
|
2011-02-20 21:32:39 -05:00
|
|
|
if (hilite)
|
2011-02-19 16:52:00 -05:00
|
|
|
this.hilite = hilite;
|
2011-02-19 16:50:37 -05:00
|
|
|
},
|
2011-03-03 17:45:17 -05:00
|
|
|
|
2011-02-19 16:50:37 -05:00
|
|
|
getOrigin: function() {
|
|
|
|
return this._origin;
|
|
|
|
},
|
2011-03-03 17:45:17 -05:00
|
|
|
|
2011-02-19 16:50:37 -05:00
|
|
|
setOrigin: function() {
|
|
|
|
this._origin = Point.read(arguments);
|
2011-02-20 21:32:39 -05:00
|
|
|
if (this._destination)
|
2011-02-19 16:50:37 -05:00
|
|
|
this._radius = this._destination.getDistance(this._origin);
|
|
|
|
},
|
2011-03-03 17:45:17 -05:00
|
|
|
|
2011-02-19 16:50:37 -05:00
|
|
|
getDestination: function() {
|
|
|
|
return this._destination;
|
|
|
|
},
|
2011-03-03 17:45:17 -05:00
|
|
|
|
2011-02-19 16:50:37 -05:00
|
|
|
setDestination: function() {
|
|
|
|
this._destination = Point.read(arguments);
|
|
|
|
this._radius = this._destination.getDistance(this._origin);
|
|
|
|
},
|
2011-03-03 17:45:17 -05:00
|
|
|
|
2011-02-19 16:50:37 -05:00
|
|
|
getHilite: function() {
|
|
|
|
return this._hilite;
|
|
|
|
},
|
2011-03-03 17:45:17 -05:00
|
|
|
|
2011-02-19 16:50:37 -05:00
|
|
|
setHilite: function() {
|
|
|
|
var hilite = Point.read(arguments);
|
|
|
|
var vector = hilite.subtract(this.origin);
|
2011-02-20 21:32:39 -05:00
|
|
|
if (vector.length > this._radius) {
|
2011-03-03 17:45:17 -05:00
|
|
|
this._hilite = this.origin.add(vector.normalize(
|
|
|
|
this._radius - 0.1));
|
2011-02-19 16:50:37 -05:00
|
|
|
} else {
|
|
|
|
this._hilite = hilite;
|
|
|
|
}
|
|
|
|
},
|
2011-03-03 17:45:17 -05:00
|
|
|
|
2011-02-19 16:50:37 -05:00
|
|
|
getCanvasStyle: function(ctx) {
|
|
|
|
var gradient;
|
2011-02-20 21:32:39 -05:00
|
|
|
if (this.gradient.type == 'linear') {
|
2011-02-19 16:50:37 -05:00
|
|
|
gradient = ctx.createLinearGradient(this.origin.x, this.origin.y,
|
|
|
|
this.destination.x, this.destination.y);
|
|
|
|
} else {
|
|
|
|
var origin = this.hilite || this.origin;
|
|
|
|
gradient = ctx.createRadialGradient(origin.x, origin.y,
|
|
|
|
0, this.origin.x, this.origin.y, this._radius);
|
|
|
|
}
|
2011-02-20 21:32:39 -05:00
|
|
|
for (var i = 0, l = this.gradient.stops.length; i < l; i++) {
|
2011-02-19 16:50:37 -05:00
|
|
|
var stop = this.gradient.stops[i];
|
2011-03-03 12:36:53 -05:00
|
|
|
gradient.addColorStop(stop.rampPoint, stop.color.toCssString());
|
2011-02-19 16:50:37 -05:00
|
|
|
}
|
|
|
|
return gradient;
|
|
|
|
}
|
2011-03-03 11:32:55 -05:00
|
|
|
});
|