OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 // Inspired by NSAnimation |
| 5 |
| 6 #ifndef APP_LINEAR_ANIMATION_H_ |
| 7 #define APP_LINEAR_ANIMATION_H_ |
| 8 |
| 9 #include "app/animation.h" |
| 10 #include "base/time.h" |
| 11 |
| 12 class AnimationDelegate; |
| 13 |
| 14 // Linear time bounded animation. As the animation progresses AnimateToState is |
| 15 // invoked. |
| 16 class LinearAnimation : public Animation { |
| 17 public: |
| 18 // Initializes everything except the duration. |
| 19 // |
| 20 // Caller must make sure to call SetDuration() if they use this |
| 21 // constructor; it is preferable to use the full one, but sometimes |
| 22 // duration can change between calls to Start() and we need to |
| 23 // expose this interface. |
| 24 LinearAnimation(int frame_rate, AnimationDelegate* delegate); |
| 25 |
| 26 // Initializes all fields. |
| 27 LinearAnimation(int duration, int frame_rate, AnimationDelegate* delegate); |
| 28 |
| 29 // Gets the value for the current state, according to the animation curve in |
| 30 // use. This class provides only for a linear relationship, however subclasses |
| 31 // can override this to provide others. |
| 32 virtual double GetCurrentValue() const; |
| 33 |
| 34 // Skip to the end of the current animation. |
| 35 void End(); |
| 36 |
| 37 // Changes the length of the animation. This resets the current |
| 38 // state of the animation to the beginning. |
| 39 void SetDuration(int duration); |
| 40 |
| 41 protected: |
| 42 // Called when the animation progresses. Subclasses override this to |
| 43 // efficiently update their state. |
| 44 virtual void AnimateToState(double state) = 0; |
| 45 |
| 46 // Invoked by the AnimationContainer when the animation is running to advance |
| 47 // the animation. Use |time_now| rather than Time::Now to avoid multiple |
| 48 // animations running at the same time diverging. |
| 49 virtual void Step(base::TimeTicks time_now); |
| 50 |
| 51 // Overriden to advance to the end (if End was invoked). |
| 52 virtual void AnimationStopped(); |
| 53 |
| 54 // Overriden to return true if state is not 1. |
| 55 virtual bool ShouldSendCanceledFromStop(); |
| 56 |
| 57 private: |
| 58 base::TimeDelta duration_; |
| 59 |
| 60 // Current state, on a scale from 0.0 to 1.0. |
| 61 double state_; |
| 62 |
| 63 // If true, we're in end. This is used to determine if the animation should |
| 64 // be advanced to the end from AnimationStopped. |
| 65 bool in_end_; |
| 66 |
| 67 DISALLOW_COPY_AND_ASSIGN(LinearAnimation); |
| 68 }; |
| 69 |
| 70 #endif // APP_LINEAR_ANIMATION_H_ |
OLD | NEW |