1 goog.provide('lime.animation.ColorTo'); 2 3 4 goog.require('lime.Sprite'); 5 goog.require('lime.animation.Animation'); 6 7 /** 8 * Animation for changing element's fillcolor value 9 * @param {mixed...} args Color definition. 10 * @constructor 11 * @extends lime.animation.Animation 12 */ 13 lime.animation.ColorTo = function(args) { 14 lime.animation.Animation.call(this); 15 16 this.rgb_ = null; 17 18 var color = lime.fill.parse(goog.array.toArray(arguments)); 19 20 if (color instanceof lime.fill.Color) { 21 this.rgba_ = color.getRgba(); 22 } 23 }; 24 goog.inherits(lime.animation.ColorTo, lime.animation.Animation); 25 26 /** @inheritDoc */ 27 lime.animation.ColorTo.prototype.scope = 'color'; 28 29 /** @inheritDoc */ 30 lime.animation.ColorTo.prototype.makeTargetProp = function(target) { 31 var fill = target.getFill(), 32 oldrgb = fill instanceof lime.fill.Color ? target.getFill().getRgba() : [255,255,255,0]; 33 34 return {start: oldrgb, 35 delta: [this.rgba_[0] - oldrgb[0], this.rgba_[1] - oldrgb[1], 36 this.rgba_[2] - oldrgb[2], this.rgba_[3] - oldrgb[3]]}; 37 }; 38 39 /** @inheritDoc */ 40 lime.animation.ColorTo.prototype.update = function(t, target) { 41 if (this.status_ == 0) return; 42 43 var prop = this.getTargetProp(target); 44 if ('start' in prop) { 45 target.setFill( 46 Math.round(prop.start[0] + prop.delta[0] * t), 47 Math.round(prop.start[1] + prop.delta[1] * t), 48 Math.round(prop.start[2] + prop.delta[2] * t), 49 prop.start[3] + prop.delta[3] * t 50 ); 51 } 52 }; 53