UNPKG

@sky-foundry/two.js

Version:

A renderer agnostic two-dimensional drawing api for the web.

107 lines (67 loc) 2.09 kB
(function(Two) { var _ = Two.Utils; var LinearGradient = Two.LinearGradient = function(x1, y1, x2, y2, stops) { Two.Gradient.call(this, stops); this._renderer.type = 'linear-gradient'; var flagEndPoints = _.bind(LinearGradient.FlagEndPoints, this); this.left = new Two.Vector().bind(Two.Events.change, flagEndPoints); this.right = new Two.Vector().bind(Two.Events.change, flagEndPoints); if (_.isNumber(x1)) { this.left.x = x1; } if (_.isNumber(y1)) { this.left.y = y1; } if (_.isNumber(x2)) { this.right.x = x2; } if (_.isNumber(y2)) { this.right.y = y2; } }; _.extend(LinearGradient, { Stop: Two.Gradient.Stop, MakeObservable: function(object) { Two.Gradient.MakeObservable(object); }, FlagEndPoints: function() { this._flagEndPoints = true; } }); _.extend(LinearGradient.prototype, Two.Gradient.prototype, { _flagEndPoints: false, constructor: LinearGradient, clone: function(parent) { var stops = _.map(this.stops, function(stop) { return stop.clone(); }); var clone = new LinearGradient(this.left._x, this.left._y, this.right._x, this.right._y, stops); _.each(Two.Gradient.Properties, function(k) { clone[k] = this[k]; }, this); if (parent) { parent.add(clone); } return clone; }, toObject: function() { var result = Two.Gradient.prototype.toObject.call(this); result.left = this.left.toObject(); result.right = this.right.toObject(); return result; }, _update: function() { if (this._flagEndPoints || this._flagSpread || this._flagStops) { this.trigger(Two.Events.change); } return this; }, flagReset: function() { this._flagEndPoints = false; Two.Gradient.prototype.flagReset.call(this); return this; } }); LinearGradient.MakeObservable(LinearGradient.prototype); })((typeof global !== 'undefined' ? global : (this || window)).Two);