1 goog.provide('lime.animation.ScaleBy');
  2 
  3 
  4 goog.require('goog.math.Vec2');
  5 goog.require('lime.Sprite');
  6 goog.require('lime.animation.Animation');
  7 
  8 /**
  9  * Scale by a factor
 10  * Also accepts one or two numbers
 11  * @param {goog.math.Vec2} factor Factor to scale.
 12  * @constructor
 13  * @extends lime.animation.Animation
 14  */
 15 lime.animation.ScaleBy = function(factor) {
 16     lime.animation.Animation.call(this);
 17 
 18     if (arguments.length == 1 && goog.isNumber(factor)) {
 19         this.factor_ = new goog.math.Vec2(factor, factor);
 20     }
 21     else if (arguments.length == 2) {
 22         this.factor_ = new goog.math.Vec2(arguments[0], arguments[1]);
 23     }
 24     else this.factor_ = factor;
 25 
 26 
 27 };
 28 goog.inherits(lime.animation.ScaleBy, lime.animation.Animation);
 29 
 30 /**
 31  * @inheritDoc
 32  */
 33 lime.animation.ScaleBy.prototype.scope = 'scale';
 34 
 35 /**
 36  * @inheritDoc
 37  * @see lime.animation.Animation#makeTargetProp
 38  */
 39 lime.animation.ScaleBy.prototype.makeTargetProp = function(target) {
 40     var scale = target.getScale(),
 41         delta = new goog.math.Vec2(scale.x * this.factor_.x - scale.x,
 42                                   scale.y * this.factor_.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.ScaleBy.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.ScaleBy.prototype.clearTransition = function(target) {
 74     if (this.useTransitions()) {
 75         target.clearTransition(lime.Transition.SCALE);
 76         target.setDirty(lime.Dirty.SCALE);
 77     }
 78 };
 79 
 80 /**
 81  * @inheritDoc
 82  * @see lime.animation.Animation#reverse
 83  */
 84 lime.animation.ScaleBy.prototype.reverse = function() {
 85     var f = this.factor_.clone();
 86     f.x = 1 / f.x;
 87     f.y = 1 / f.y;
 88 
 89     return new lime.animation.ScaleBy(f).cloneParam(this);
 90 };
 91