diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-05 03:43:55 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-05 03:43:55 +0000 |
commit | 4ce7e15da651c6221720e33dc8c500830d4b6b8a (patch) | |
tree | 376ef1d7e7951dae3376e65f4edee9e7367adc89 /app/slide_animation.cc | |
parent | 5ee3ca64cdf2d00f82a1bc36f36e8ab5e520b4de (diff) | |
download | chromium_src-4ce7e15da651c6221720e33dc8c500830d4b6b8a.zip chromium_src-4ce7e15da651c6221720e33dc8c500830d4b6b8a.tar.gz chromium_src-4ce7e15da651c6221720e33dc8c500830d4b6b8a.tar.bz2 |
Refactors animation to allow for cleaner subclassing. I'm doing this
for creating a different animation subclass (which you'll see
shortly).
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/1961001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46433 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app/slide_animation.cc')
-rw-r--r-- | app/slide_animation.cc | 35 |
1 files changed, 6 insertions, 29 deletions
diff --git a/app/slide_animation.cc b/app/slide_animation.cc index ca468d2..c79e3ec 100644 --- a/app/slide_animation.cc +++ b/app/slide_animation.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -13,9 +13,9 @@ static const int kDefaultFramerateHz = 50; static const int kDefaultDurationMs = 120; SlideAnimation::SlideAnimation(AnimationDelegate* target) - : Animation(kDefaultFramerateHz, target), + : LinearAnimation(kDefaultFramerateHz, target), target_(target), - tween_type_(EASE_OUT), + tween_type_(Tween::EASE_OUT), showing_(false), value_start_(0), value_end_(0), @@ -84,36 +84,13 @@ void SlideAnimation::AnimateToState(double state) { if (state > 1.0) state = 1.0; - // Make our animation ease-out. - switch (tween_type_) { - case EASE_IN: - state = pow(state, 2); - break; - case EASE_IN_OUT: - if (state < 0.5) - state = pow(state * 2, 2) / 2.0; - else - state = 1.0 - (pow((state - 1.0) * 2, 2) / 2.0); - break; - case FAST_IN_OUT: - state = (pow(state - 0.5, 3) + 0.125) / 0.25; - break; - case NONE: - // state remains linear. - break; - case EASE_OUT_SNAP: - state = 0.95 * (1.0 - pow(1.0 - state, 2)); - break; - case EASE_OUT: - default: - state = 1.0 - pow(1.0 - state, 2); - break; - } + state = Tween::CalculateValue(tween_type_, state); value_current_ = value_start_ + (value_end_ - value_start_) * state; // Implement snapping. - if (tween_type_ == EASE_OUT_SNAP && fabs(value_current_ - value_end_) <= 0.06) + if (tween_type_ == Tween::EASE_OUT_SNAP && + fabs(value_current_ - value_end_) <= 0.06) value_current_ = value_end_; // Correct for any overshoot (while state may be capped at 1.0, let's not |