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 #ifndef UI_GFX_INTERPOLATED_TRANSFORM_H_ | 5 #ifndef UI_GFX_INTERPOLATED_TRANSFORM_H_ |
6 #define UI_GFX_INTERPOLATED_TRANSFORM_H_ | 6 #define UI_GFX_INTERPOLATED_TRANSFORM_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "ui/gfx/point.h" | 11 #include "ui/gfx/point.h" |
| 12 #include "ui/gfx/point3.h" |
12 #include "ui/gfx/transform.h" | 13 #include "ui/gfx/transform.h" |
13 | 14 |
14 namespace ui { | 15 namespace ui { |
15 | 16 |
16 /////////////////////////////////////////////////////////////////////////////// | 17 /////////////////////////////////////////////////////////////////////////////// |
17 // class InterpolatedTransform | 18 // class InterpolatedTransform |
18 // | 19 // |
19 // Abstract base class for transforms that animate over time. These | 20 // Abstract base class for transforms that animate over time. These |
20 // interpolated transforms can be combined to allow for more sophisticated | 21 // interpolated transforms can be combined to allow for more sophisticated |
21 // animations. For example, you might combine a rotation of 90 degrees between | 22 // animations. For example, you might combine a rotation of 90 degrees between |
(...skipping 12 matching lines...) Expand all Loading... |
34 | 35 |
35 // Returns the interpolated transform at time t. Note: not virtual. | 36 // Returns the interpolated transform at time t. Note: not virtual. |
36 ui::Transform Interpolate(float t) const; | 37 ui::Transform Interpolate(float t) const; |
37 | 38 |
38 // The Intepolate ultimately returns the product of our transform at time t | 39 // The Intepolate ultimately returns the product of our transform at time t |
39 // and our child's transform at time t (if we have one). | 40 // and our child's transform at time t (if we have one). |
40 // | 41 // |
41 // This function takes ownership of the passed InterpolatedTransform. | 42 // This function takes ownership of the passed InterpolatedTransform. |
42 void SetChild(InterpolatedTransform* child); | 43 void SetChild(InterpolatedTransform* child); |
43 | 44 |
| 45 static bool FactorTRS(const ui::Transform& transform, |
| 46 gfx::Point* translation, |
| 47 float* rotation, |
| 48 gfx::Point3f* scale); |
| 49 |
44 protected: | 50 protected: |
45 // Calculates the interpolated transform without considering our child. | 51 // Calculates the interpolated transform without considering our child. |
46 virtual ui::Transform InterpolateButDoNotCompose(float t) const = 0; | 52 virtual ui::Transform InterpolateButDoNotCompose(float t) const = 0; |
47 | 53 |
48 // If time in (start_time_, end_time_], this function linearly interpolates | 54 // If time in (start_time_, end_time_], this function linearly interpolates |
49 // between start_value and end_value. More precisely it returns | 55 // between start_value and end_value. More precisely it returns |
50 // (1 - t) * start_value + t * end_value where | 56 // (1 - t) * start_value + t * end_value where |
51 // t = (start_time_ - time) / (end_time_ - start_time_). | 57 // t = (start_time_ - time) / (end_time_ - start_time_). |
52 // If time < start_time_ it returns start_value, and if time >= end_time_ | 58 // If time < start_time_ it returns start_value, and if time >= end_time_ |
53 // it returns end_value. | 59 // it returns end_value. |
54 float ValueBetween(float time, float start_value, float end_value) const; | 60 float ValueBetween(float time, float start_value, float end_value) const; |
55 | 61 |
| 62 float start_time() const { return start_time_; } |
| 63 float end_time() const { return end_time_; } |
| 64 |
56 private: | 65 private: |
57 const float start_time_; | 66 const float start_time_; |
58 const float end_time_; | 67 const float end_time_; |
59 | 68 |
60 // The child transform. If you consider an interpolated transform as a | 69 // The child transform. If you consider an interpolated transform as a |
61 // function of t. If, without a child, we are f(t), and our child is | 70 // function of t. If, without a child, we are f(t), and our child is |
62 // g(t), then with a child we become f'(t) = f(t) * g(t). Using a child | 71 // g(t), then with a child we become f'(t) = f(t) * g(t). Using a child |
63 // transform, we can chain collections of transforms together. | 72 // transform, we can chain collections of transforms together. |
64 scoped_ptr<InterpolatedTransform> child_; | 73 scoped_ptr<InterpolatedTransform> child_; |
65 | 74 |
(...skipping 27 matching lines...) Expand all Loading... |
93 | 102 |
94 /////////////////////////////////////////////////////////////////////////////// | 103 /////////////////////////////////////////////////////////////////////////////// |
95 // class InterpolatedScale | 104 // class InterpolatedScale |
96 // | 105 // |
97 // Represents an animated scale. | 106 // Represents an animated scale. |
98 // | 107 // |
99 /////////////////////////////////////////////////////////////////////////////// | 108 /////////////////////////////////////////////////////////////////////////////// |
100 class UI_EXPORT InterpolatedScale : public InterpolatedTransform { | 109 class UI_EXPORT InterpolatedScale : public InterpolatedTransform { |
101 public: | 110 public: |
102 InterpolatedScale(float start_scale, float end_scale); | 111 InterpolatedScale(float start_scale, float end_scale); |
103 InterpolatedScale(float start_scale, | 112 InterpolatedScale(float start_scale, float end_scale, |
104 float end_scale, | 113 float start_time, float end_time); |
| 114 InterpolatedScale(const gfx::Point3f& start_scale, |
| 115 const gfx::Point3f& end_scale); |
| 116 InterpolatedScale(const gfx::Point3f& start_scale, |
| 117 const gfx::Point3f& end_scale, |
105 float start_time, | 118 float start_time, |
106 float end_time); | 119 float end_time); |
107 virtual ~InterpolatedScale(); | 120 virtual ~InterpolatedScale(); |
108 | 121 |
109 protected: | 122 protected: |
110 virtual ui::Transform InterpolateButDoNotCompose(float t) const OVERRIDE; | 123 virtual ui::Transform InterpolateButDoNotCompose(float t) const OVERRIDE; |
111 | 124 |
112 private: | 125 private: |
113 const float start_scale_; | 126 const gfx::Point3f start_scale_; |
114 const float end_scale_; | 127 const gfx::Point3f end_scale_; |
115 | 128 |
116 DISALLOW_COPY_AND_ASSIGN(InterpolatedScale); | 129 DISALLOW_COPY_AND_ASSIGN(InterpolatedScale); |
117 }; | 130 }; |
118 | 131 |
119 class UI_EXPORT InterpolatedTranslation : public InterpolatedTransform { | 132 class UI_EXPORT InterpolatedTranslation : public InterpolatedTransform { |
120 public: | 133 public: |
121 InterpolatedTranslation(const gfx::Point& start_pos, | 134 InterpolatedTranslation(const gfx::Point& start_pos, |
122 const gfx::Point& end_pos); | 135 const gfx::Point& end_pos); |
123 InterpolatedTranslation(const gfx::Point& start_pos, | 136 InterpolatedTranslation(const gfx::Point& start_pos, |
124 const gfx::Point& end_pos, | 137 const gfx::Point& end_pos, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 InterpolatedTransform* transform); | 187 InterpolatedTransform* transform); |
175 | 188 |
176 // Takes ownership of the passed transform. | 189 // Takes ownership of the passed transform. |
177 InterpolatedTransformAboutPivot(const gfx::Point& pivot, | 190 InterpolatedTransformAboutPivot(const gfx::Point& pivot, |
178 InterpolatedTransform* transform, | 191 InterpolatedTransform* transform, |
179 float start_time, | 192 float start_time, |
180 float end_time); | 193 float end_time); |
181 virtual ~InterpolatedTransformAboutPivot(); | 194 virtual ~InterpolatedTransformAboutPivot(); |
182 | 195 |
183 protected: | 196 protected: |
184 virtual ui::Transform InterpolateButDoNotCompose(float t) const OVERRIDE; | 197 virtual Transform InterpolateButDoNotCompose(float t) const OVERRIDE; |
185 | 198 |
186 private: | 199 private: |
187 void Init(const gfx::Point& pivot, InterpolatedTransform* transform); | 200 void Init(const gfx::Point& pivot, InterpolatedTransform* transform); |
188 | 201 |
189 scoped_ptr<InterpolatedTransform> transform_; | 202 scoped_ptr<InterpolatedTransform> transform_; |
190 | 203 |
191 DISALLOW_COPY_AND_ASSIGN(InterpolatedTransformAboutPivot); | 204 DISALLOW_COPY_AND_ASSIGN(InterpolatedTransformAboutPivot); |
192 }; | 205 }; |
193 | 206 |
| 207 class UI_EXPORT InterpolatedTRSTransform : public InterpolatedTransform { |
| 208 public: |
| 209 InterpolatedTRSTransform(const Transform& start_transform, |
| 210 const Transform& end_transform); |
| 211 |
| 212 InterpolatedTRSTransform(const Transform& start_transform, |
| 213 const Transform& end_transform, |
| 214 float start_time, |
| 215 float end_time); |
| 216 |
| 217 virtual ~InterpolatedTRSTransform(); |
| 218 |
| 219 protected: |
| 220 virtual Transform InterpolateButDoNotCompose(float t) const OVERRIDE; |
| 221 |
| 222 private: |
| 223 void Init(const ui::Transform& start_transform, |
| 224 const ui::Transform& end_transform); |
| 225 |
| 226 scoped_ptr<InterpolatedTransform> transform_; |
| 227 }; |
| 228 |
194 } // namespace ui | 229 } // namespace ui |
195 | 230 |
196 #endif // UI_GFX_INTERPOLATED_TRANSFORM_H_ | 231 #endif // UI_GFX_INTERPOLATED_TRANSFORM_H_ |
OLD | NEW |