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