OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/base/animation/tween.h" | 5 #include "ui/base/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 "base/logging.h" | 13 #include "base/logging.h" |
14 #include "ui/gfx/rect.h" | 14 #include "ui/gfx/rect.h" |
| 15 #include "ui/gfx/interpolated_transform.h" |
15 | 16 |
16 namespace ui { | 17 namespace ui { |
17 | 18 |
18 // static | 19 // static |
19 double Tween::CalculateValue(Tween::Type type, double state) { | 20 double Tween::CalculateValue(Tween::Type type, double state) { |
20 DCHECK_GE(state, 0); | 21 DCHECK_GE(state, 0); |
21 DCHECK_LE(state, 1); | 22 DCHECK_LE(state, 1); |
22 | 23 |
23 switch (type) { | 24 switch (type) { |
24 case EASE_IN: | 25 case EASE_IN: |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 const gfx::Rect& start_bounds, | 77 const gfx::Rect& start_bounds, |
77 const gfx::Rect& target_bounds) { | 78 const gfx::Rect& target_bounds) { |
78 return gfx::Rect(ValueBetween(value, start_bounds.x(), target_bounds.x()), | 79 return gfx::Rect(ValueBetween(value, start_bounds.x(), target_bounds.x()), |
79 ValueBetween(value, start_bounds.y(), target_bounds.y()), | 80 ValueBetween(value, start_bounds.y(), target_bounds.y()), |
80 ValueBetween(value, start_bounds.width(), | 81 ValueBetween(value, start_bounds.width(), |
81 target_bounds.width()), | 82 target_bounds.width()), |
82 ValueBetween(value, start_bounds.height(), | 83 ValueBetween(value, start_bounds.height(), |
83 target_bounds.height())); | 84 target_bounds.height())); |
84 } | 85 } |
85 | 86 |
| 87 // static |
| 88 Transform Tween::ValueBetween(double value, |
| 89 const Transform& start_transform, |
| 90 const Transform& end_transform) { |
| 91 Transform to_return; |
| 92 gfx::Point start_translation, end_translation; |
| 93 float start_rotation, end_rotation; |
| 94 gfx::Point3f start_scale, end_scale; |
| 95 if (InterpolatedTransform::FactorTRS(start_transform, |
| 96 &start_translation, |
| 97 &start_rotation, |
| 98 &start_scale) && |
| 99 InterpolatedTransform::FactorTRS(end_transform, |
| 100 &end_translation, |
| 101 &end_rotation, |
| 102 &end_scale)) { |
| 103 to_return.SetScale(ValueBetween(value, start_scale.x(), end_scale.x()), |
| 104 ValueBetween(value, start_scale.y(), end_scale.y())); |
| 105 to_return.ConcatRotate(ValueBetween(value, start_rotation, end_rotation)); |
| 106 to_return.ConcatTranslate( |
| 107 ValueBetween(value, start_translation.x(), end_translation.x()), |
| 108 ValueBetween(value, start_translation.y(), end_translation.y())); |
| 109 } else { |
| 110 for (int row = 0; row < 4; ++row) { |
| 111 for (int col = 0; col < 4; ++col) { |
| 112 to_return.matrix().set(row, col, |
| 113 ValueBetween(value, |
| 114 start_transform.matrix().get(row, col), |
| 115 end_transform.matrix().get(row, col))); |
| 116 } |
| 117 } |
| 118 } |
| 119 |
| 120 return to_return; |
| 121 } |
| 122 |
86 } // namespace ui | 123 } // namespace ui |
OLD | NEW |