| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "ui/gfx/animation/tween.h" | 5 #include "ui/gfx/animation/tween.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 | 8 |
| 9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
| 10 #include <float.h> | 10 #include <float.h> |
| 11 #endif | 11 #endif |
| 12 | 12 |
| 13 #include <algorithm> | 13 #include <algorithm> |
| 14 | 14 |
| 15 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "ui/gfx/geometry/cubic_bezier.h" |
| 17 #include "ui/gfx/safe_integer_conversions.h" | 18 #include "ui/gfx/safe_integer_conversions.h" |
| 18 | 19 |
| 19 namespace gfx { | 20 namespace gfx { |
| 20 | 21 |
| 21 // static | 22 // static |
| 22 double Tween::CalculateValue(Tween::Type type, double state) { | 23 double Tween::CalculateValue(Tween::Type type, double state) { |
| 23 DCHECK_GE(state, 0); | 24 DCHECK_GE(state, 0); |
| 24 DCHECK_LE(state, 1); | 25 DCHECK_LE(state, 1); |
| 25 | 26 |
| 26 switch (type) { | 27 switch (type) { |
| 27 case EASE_IN: | 28 case EASE_IN: |
| 28 return pow(state, 2); | 29 return pow(state, 2); |
| 29 | 30 |
| 30 case EASE_IN_2: | 31 case EASE_IN_2: |
| 31 return pow(state, 4); | 32 return pow(state, 4); |
| 32 | 33 |
| 34 case EASE_IN_BEZIER: |
| 35 return gfx::CubicBezier(.4, 0, 1, .2).Solve(state); |
| 36 |
| 33 case EASE_IN_OUT: | 37 case EASE_IN_OUT: |
| 34 if (state < 0.5) | 38 if (state < 0.5) |
| 35 return pow(state * 2, 2) / 2.0; | 39 return pow(state * 2, 2) / 2.0; |
| 36 return 1.0 - (pow((state - 1.0) * 2, 2) / 2.0); | 40 return 1.0 - (pow((state - 1.0) * 2, 2) / 2.0); |
| 37 | 41 |
| 38 case FAST_IN_OUT: | 42 case FAST_IN_OUT: |
| 39 return (pow(state - 0.5, 3) + 0.125) / 0.25; | 43 return (pow(state - 0.5, 3) + 0.125) / 0.25; |
| 40 | 44 |
| 41 case LINEAR: | 45 case LINEAR: |
| 42 return state; | 46 return state; |
| 43 | 47 |
| 44 case EASE_OUT_SNAP: | 48 case EASE_OUT_SNAP: |
| 45 state = 0.95 * (1.0 - pow(1.0 - state, 2)); | 49 state = 0.95 * (1.0 - pow(1.0 - state, 2)); |
| 46 return state; | 50 return state; |
| 47 | 51 |
| 48 case EASE_OUT: | 52 case EASE_OUT: |
| 49 return 1.0 - pow(1.0 - state, 2); | 53 return 1.0 - pow(1.0 - state, 2); |
| 50 | 54 |
| 55 case EASE_OUT_BEZIER: |
| 56 return gfx::CubicBezier(.4, 0, .2, 1).Solve(state); |
| 57 |
| 51 case SMOOTH_IN_OUT: | 58 case SMOOTH_IN_OUT: |
| 52 return sin(state); | 59 return sin(state); |
| 53 | 60 |
| 54 case ZERO: | 61 case ZERO: |
| 55 return 0; | 62 return 0; |
| 56 } | 63 } |
| 57 | 64 |
| 58 NOTREACHED(); | 65 NOTREACHED(); |
| 59 return state; | 66 return state; |
| 60 } | 67 } |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 if (value <= 0.0) | 171 if (value <= 0.0) |
| 165 return start_transform; | 172 return start_transform; |
| 166 | 173 |
| 167 gfx::Transform to_return = end_transform; | 174 gfx::Transform to_return = end_transform; |
| 168 to_return.Blend(start_transform, value); | 175 to_return.Blend(start_transform, value); |
| 169 | 176 |
| 170 return to_return; | 177 return to_return; |
| 171 } | 178 } |
| 172 | 179 |
| 173 } // namespace gfx | 180 } // namespace gfx |
| OLD | NEW |