1 goog.provide('lime.animation.ScaleTo');
  2 
  3 
  4 goog.require('goog.math.Vec2');
  5 goog.require('lime.Sprite');
  6 goog.require('lime.animation.Animation');
  7 
  8 /**
  9  * Scale to a given factor
 10  * Also accepts one or two numbers
 11  * @param {goog.math.Vec2} scale Target value.
 12  * @constructor
 13  * @extends lime.animation.Animation
 14  */
 15 lime.animation.ScaleTo = function(scale) {
 16     lime.animation.Animation.call(this);
 17 
 18     if (arguments.length == 1 && goog.isNumber(scale)) {
 19         this.scale_ = new goog.math.Vec2(scale, scale);
 20     }
 21     else if (arguments.length == 2) {
 22         this.scale_ = new goog.math.Vec2(arguments[0], arguments[1]);
 23     }
 24     else this.scale_ = scale;
 25 
 26 
 27 };
 28 goog.inherits(lime.animation.ScaleTo, lime.animation.Animation);
 29 
 30 /**
 31  * @inheritDoc
 32  */
 33 lime.animation.ScaleTo.prototype.scope = 'scale';
 34 
 35 /**
 36  * @inheritDoc
 37  * @see lime.animation.Animation#makeTargetProp
 38  */
 39 lime.animation.ScaleTo.prototype.makeTargetProp = function(target) {
 40     var scale = target.getScale(),
 41         delta = new goog.math.Vec2(this.scale_.x - scale.x,
 42                                   this.scale_.y - scale.y);
 43 
 44     if (this.useTransitions()) {
 45         target.addTransition(lime.Transition.SCALE,
 46             new goog.math.Vec2(scale.x + delta.x, scale.y + delta.y),
 47             this.duration_, this.getEasing());
 48         target.setDirty(lime.Dirty.SCALE);
 49     }
 50 
 51     return {startScale: scale,
 52             delta: delta};
 53 };
 54 
 55 /**
 56  * @inheritDoc
 57  * @see lime.animation.Animation#update
 58  */
 59 lime.animation.ScaleTo.prototype.update = function(t, target) {
 60     if (this.status_ == 0) return;
 61     var prop = this.getTargetProp(target);
 62 
 63     target.setScale(
 64         prop.startScale.x + prop.delta.x * t,
 65         prop.startScale.y + prop.delta.y * t
 66     );
 67 };
 68 
 69 /**
 70  * @inheritDoc
 71  * @see lime.animation.Animation#clearTransition
 72  */
 73 lime.animation.ScaleTo.prototype.clearTransition = function(target) {
 74     if (this.useTransitions()) {
 75         target.clearTransition(lime.Transition.SCALE);
 76         target.setDirty(lime.Dirty.SCALE);
 77     }
 78 };
 79 
 80