diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-05 04:52:11 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-05 04:52:11 +0000 |
commit | 220705c2b06962462e471b28ad85c76c0f9c3080 (patch) | |
tree | cfc44266116bbf2acc3a4fae32625c4481c8243e /app/slide_animation.h | |
parent | 1b8d02f181d089ee670f2ba72089c3722f679d5f (diff) | |
download | chromium_src-220705c2b06962462e471b28ad85c76c0f9c3080.zip chromium_src-220705c2b06962462e471b28ad85c76c0f9c3080.tar.gz chromium_src-220705c2b06962462e471b28ad85c76c0f9c3080.tar.bz2 |
Move *Animation to app/
http://crbug.com/11387
Review URL: http://codereview.chromium.org/109001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15275 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app/slide_animation.h')
-rw-r--r-- | app/slide_animation.h | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/app/slide_animation.h b/app/slide_animation.h new file mode 100644 index 0000000..4bbcd2e --- /dev/null +++ b/app/slide_animation.h @@ -0,0 +1,102 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef APP_SLIDE_ANIMATION_H_ +#define APP_SLIDE_ANIMATION_H_ + +#include "app/animation.h" + +// Slide Animation +// +// Used for reversible animations and as a general helper class. Typical usage: +// +// #include "app/slide_animation.h" +// +// class MyClass : public AnimationDelegate { +// public: +// MyClass() { +// animation_.reset(new SlideAnimation(this)); +// animation_->SetSlideDuration(500); +// } +// void OnMouseOver() { +// animation_->Show(); +// } +// void OnMouseOut() { +// animation_->Hide(); +// } +// void AnimationProgressed(const Animation* animation) { +// if (animation == animation_.get()) { +// Layout(); +// SchedulePaint(); +// } else if (animation == other_animation_.get()) { +// ... +// } +// } +// void Layout() { +// if (animation_->IsAnimating()) { +// hover_image_.SetOpacity(animation_->GetCurrentValue()); +// } +// } +// private: +// scoped_ptr<SlideAnimation> animation_; +// } +class SlideAnimation : public Animation { + public: + explicit SlideAnimation(AnimationDelegate* target); + virtual ~SlideAnimation(); + + enum TweenType { + NONE, // Default linear. + EASE_OUT, // Fast in, slow out. + EASE_IN, // Slow in, fast out. + EASE_IN_OUT, // Slow in and out, fast in the middle. + FAST_IN_OUT, // Fast in and out, slow in the middle. + EASE_OUT_SNAP, // Fast in, slow out, snap to final value. + }; + + // Set the animation back to the 0 state. + virtual void Reset(); + virtual void Reset(double value); + + // Begin a showing animation or reverse a hiding animation in progress. + virtual void Show(); + + // Begin a hiding animation or reverse a showing animation in progress. + virtual void Hide(); + + // Sets the time a slide will take. Note that this isn't actually + // the amount of time an animation will take as the current value of + // the slide is considered. + virtual void SetSlideDuration(int duration) { slide_duration_ = duration; } + int GetSlideDuration() const { return slide_duration_; } + void SetTweenType(TweenType tween_type) { tween_type_ = tween_type; } + + double GetCurrentValue() const { return value_current_; } + bool IsShowing() const { return showing_; } + + private: + // Overridden from Animation. + void AnimateToState(double state); + + AnimationDelegate* target_; + + TweenType tween_type_; + + // Used to determine which way the animation is going. + bool showing_; + + // Animation values. These are a layer on top of Animation::state_ to + // provide the reversability. + double value_start_; + double value_end_; + double value_current_; + + // How long a hover in/out animation will last for. This defaults to + // kHoverFadeDurationMS, but can be overridden with SetDuration. + int slide_duration_; + + DISALLOW_COPY_AND_ASSIGN(SlideAnimation); +}; + +#endif // APP_SLIDE_ANIMATION_H_ |