OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef APP_SLIDE_ANIMATION_H_ | 5 #ifndef APP_SLIDE_ANIMATION_H_ |
6 #define APP_SLIDE_ANIMATION_H_ | 6 #define APP_SLIDE_ANIMATION_H_ |
7 | 7 |
8 #include "app/animation.h" | 8 #include "app/linear_animation.h" |
| 9 #include "app/tween.h" |
9 | 10 |
10 // Slide Animation | 11 // Slide Animation |
11 // | 12 // |
12 // Used for reversible animations and as a general helper class. Typical usage: | 13 // Used for reversible animations and as a general helper class. Typical usage: |
13 // | 14 // |
14 // #include "app/slide_animation.h" | 15 // #include "app/slide_animation.h" |
15 // | 16 // |
16 // class MyClass : public AnimationDelegate { | 17 // class MyClass : public AnimationDelegate { |
17 // public: | 18 // public: |
18 // MyClass() { | 19 // MyClass() { |
19 // animation_.reset(new SlideAnimation(this)); | 20 // animation_.reset(new SlideAnimation(this)); |
20 // animation_->SetSlideDuration(500); | 21 // animation_->SetSlideDuration(500); |
21 // } | 22 // } |
22 // void OnMouseOver() { | 23 // void OnMouseOver() { |
23 // animation_->Show(); | 24 // animation_->Show(); |
24 // } | 25 // } |
25 // void OnMouseOut() { | 26 // void OnMouseOut() { |
26 // animation_->Hide(); | 27 // animation_->Hide(); |
27 // } | 28 // } |
28 // void AnimationProgressed(const Animation* animation) { | 29 // void AnimationProgressed(const Animation* animation) { |
29 // if (animation == animation_.get()) { | 30 // if (animation == animation_.get()) { |
30 // Layout(); | 31 // Layout(); |
31 // SchedulePaint(); | 32 // SchedulePaint(); |
32 // } else if (animation == other_animation_.get()) { | 33 // } else if (animation == other_animation_.get()) { |
33 // ... | 34 // ... |
34 // } | 35 // } |
35 // } | 36 // } |
36 // void Layout() { | 37 // void Layout() { |
37 // if (animation_->IsAnimating()) { | 38 // if (animation_->is_animating()) { |
38 // hover_image_.SetOpacity(animation_->GetCurrentValue()); | 39 // hover_image_.SetOpacity(animation_->GetCurrentValue()); |
39 // } | 40 // } |
40 // } | 41 // } |
41 // private: | 42 // private: |
42 // scoped_ptr<SlideAnimation> animation_; | 43 // scoped_ptr<SlideAnimation> animation_; |
43 // } | 44 // } |
44 class SlideAnimation : public Animation { | 45 class SlideAnimation : public LinearAnimation { |
45 public: | 46 public: |
46 enum TweenType { | |
47 NONE, // Linear. | |
48 EASE_OUT, // Fast in, slow out (default). | |
49 EASE_IN, // Slow in, fast out. | |
50 EASE_IN_OUT, // Slow in and out, fast in the middle. | |
51 FAST_IN_OUT, // Fast in and out, slow in the middle. | |
52 EASE_OUT_SNAP, // Fast in, slow out, snap to final value. | |
53 }; | |
54 | |
55 explicit SlideAnimation(AnimationDelegate* target); | 47 explicit SlideAnimation(AnimationDelegate* target); |
56 virtual ~SlideAnimation(); | 48 virtual ~SlideAnimation(); |
57 | 49 |
58 // Set the animation back to the 0 state. | 50 // Set the animation back to the 0 state. |
59 virtual void Reset(); | 51 virtual void Reset(); |
60 virtual void Reset(double value); | 52 virtual void Reset(double value); |
61 | 53 |
62 // Begin a showing animation or reverse a hiding animation in progress. | 54 // Begin a showing animation or reverse a hiding animation in progress. |
63 virtual void Show(); | 55 virtual void Show(); |
64 | 56 |
65 // Begin a hiding animation or reverse a showing animation in progress. | 57 // Begin a hiding animation or reverse a showing animation in progress. |
66 virtual void Hide(); | 58 virtual void Hide(); |
67 | 59 |
68 // Sets the time a slide will take. Note that this isn't actually | 60 // Sets the time a slide will take. Note that this isn't actually |
69 // the amount of time an animation will take as the current value of | 61 // the amount of time an animation will take as the current value of |
70 // the slide is considered. | 62 // the slide is considered. |
71 virtual void SetSlideDuration(int duration) { slide_duration_ = duration; } | 63 virtual void SetSlideDuration(int duration) { slide_duration_ = duration; } |
72 int GetSlideDuration() const { return slide_duration_; } | 64 int GetSlideDuration() const { return slide_duration_; } |
73 void SetTweenType(TweenType tween_type) { tween_type_ = tween_type; } | 65 void SetTweenType(Tween::Type tween_type) { tween_type_ = tween_type; } |
74 | 66 |
75 double GetCurrentValue() const { return value_current_; } | 67 double GetCurrentValue() const { return value_current_; } |
76 bool IsShowing() const { return showing_; } | 68 bool IsShowing() const { return showing_; } |
77 bool IsClosing() const { return !showing_ && value_end_ < value_current_; } | 69 bool IsClosing() const { return !showing_ && value_end_ < value_current_; } |
78 | 70 |
79 private: | 71 private: |
80 // Overridden from Animation. | 72 // Overridden from Animation. |
81 void AnimateToState(double state); | 73 void AnimateToState(double state); |
82 | 74 |
83 AnimationDelegate* target_; | 75 AnimationDelegate* target_; |
84 | 76 |
85 TweenType tween_type_; | 77 Tween::Type tween_type_; |
86 | 78 |
87 // Used to determine which way the animation is going. | 79 // Used to determine which way the animation is going. |
88 bool showing_; | 80 bool showing_; |
89 | 81 |
90 // Animation values. These are a layer on top of Animation::state_ to | 82 // Animation values. These are a layer on top of Animation::state_ to |
91 // provide the reversability. | 83 // provide the reversability. |
92 double value_start_; | 84 double value_start_; |
93 double value_end_; | 85 double value_end_; |
94 double value_current_; | 86 double value_current_; |
95 | 87 |
96 // How long a hover in/out animation will last for. This defaults to | 88 // How long a hover in/out animation will last for. This defaults to |
97 // kHoverFadeDurationMS, but can be overridden with SetDuration. | 89 // kHoverFadeDurationMS, but can be overridden with SetDuration. |
98 int slide_duration_; | 90 int slide_duration_; |
99 | 91 |
100 DISALLOW_COPY_AND_ASSIGN(SlideAnimation); | 92 DISALLOW_COPY_AND_ASSIGN(SlideAnimation); |
101 }; | 93 }; |
102 | 94 |
103 #endif // APP_SLIDE_ANIMATION_H_ | 95 #endif // APP_SLIDE_ANIMATION_H_ |
OLD | NEW |