| 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 #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 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "ui/gfx/point.h" | 10 #include "ui/gfx/point.h" |
| 11 #include "ui/gfx/point3_f.h" | 11 #include "ui/gfx/point3_f.h" |
| 12 #include "ui/gfx/transform.h" | 12 #include "ui/gfx/transform.h" |
| 13 #include "ui/gfx/transform_util.h" | 13 #include "ui/gfx/transform_util.h" |
| 14 #include "ui/gfx/vector3d_f.h" | 14 #include "ui/gfx/vector3d_f.h" |
| 15 | 15 |
| 16 namespace ui { | 16 namespace ui { |
| 17 | 17 |
| 18 /////////////////////////////////////////////////////////////////////////////// | 18 /////////////////////////////////////////////////////////////////////////////// |
| 19 // class InterpolatedTransform | 19 // class InterpolatedTransform |
| 20 // | 20 // |
| 21 // Abstract base class for transforms that animate over time. These | 21 // Abstract base class for transforms that animate over time. These |
| 22 // interpolated transforms can be combined to allow for more sophisticated | 22 // interpolated transforms can be combined to allow for more sophisticated |
| 23 // animations. For example, you might combine a rotation of 90 degrees between | 23 // animations. For example, you might combine a rotation of 90 degrees between |
| 24 // times 0 and 1, with a scale from 1 to 0.3 between times 0 and 0.25 and a | 24 // times 0 and 1, with a scale from 1 to 0.3 between times 0 and 0.25 and a |
| 25 // scale from 0.3 to 1 from between times 0.75 and 1. | 25 // scale from 0.3 to 1 from between times 0.75 and 1. |
| 26 // | 26 // |
| 27 /////////////////////////////////////////////////////////////////////////////// | 27 /////////////////////////////////////////////////////////////////////////////// |
| 28 class UI_EXPORT InterpolatedTransform { | 28 class GFX_EXPORT InterpolatedTransform { |
| 29 public: | 29 public: |
| 30 InterpolatedTransform(); | 30 InterpolatedTransform(); |
| 31 // The interpolated transform varies only when t in (start_time, end_time). | 31 // The interpolated transform varies only when t in (start_time, end_time). |
| 32 // If t <= start_time, Interpolate(t) will return the initial transform, and | 32 // If t <= start_time, Interpolate(t) will return the initial transform, and |
| 33 // if t >= end_time, Interpolate(t) will return the final transform. | 33 // if t >= end_time, Interpolate(t) will return the final transform. |
| 34 InterpolatedTransform(float start_time, float end_time); | 34 InterpolatedTransform(float start_time, float end_time); |
| 35 virtual ~InterpolatedTransform(); | 35 virtual ~InterpolatedTransform(); |
| 36 | 36 |
| 37 // Returns the interpolated transform at time t. Note: not virtual. | 37 // Returns the interpolated transform at time t. Note: not virtual. |
| 38 gfx::Transform Interpolate(float t) const; | 38 gfx::Transform Interpolate(float t) const; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 | 77 |
| 78 DISALLOW_COPY_AND_ASSIGN(InterpolatedTransform); | 78 DISALLOW_COPY_AND_ASSIGN(InterpolatedTransform); |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 /////////////////////////////////////////////////////////////////////////////// | 81 /////////////////////////////////////////////////////////////////////////////// |
| 82 // class InterpolatedRotation | 82 // class InterpolatedRotation |
| 83 // | 83 // |
| 84 // Represents an animated rotation. | 84 // Represents an animated rotation. |
| 85 // | 85 // |
| 86 /////////////////////////////////////////////////////////////////////////////// | 86 /////////////////////////////////////////////////////////////////////////////// |
| 87 class UI_EXPORT InterpolatedRotation : public InterpolatedTransform { | 87 class GFX_EXPORT InterpolatedRotation : public InterpolatedTransform { |
| 88 public: | 88 public: |
| 89 InterpolatedRotation(float start_degrees, float end_degrees); | 89 InterpolatedRotation(float start_degrees, float end_degrees); |
| 90 InterpolatedRotation(float start_degrees, | 90 InterpolatedRotation(float start_degrees, |
| 91 float end_degrees, | 91 float end_degrees, |
| 92 float start_time, | 92 float start_time, |
| 93 float end_time); | 93 float end_time); |
| 94 virtual ~InterpolatedRotation(); | 94 virtual ~InterpolatedRotation(); |
| 95 | 95 |
| 96 protected: | 96 protected: |
| 97 virtual gfx::Transform InterpolateButDoNotCompose(float t) const OVERRIDE; | 97 virtual gfx::Transform InterpolateButDoNotCompose(float t) const OVERRIDE; |
| 98 | 98 |
| 99 private: | 99 private: |
| 100 const float start_degrees_; | 100 const float start_degrees_; |
| 101 const float end_degrees_; | 101 const float end_degrees_; |
| 102 | 102 |
| 103 DISALLOW_COPY_AND_ASSIGN(InterpolatedRotation); | 103 DISALLOW_COPY_AND_ASSIGN(InterpolatedRotation); |
| 104 }; | 104 }; |
| 105 | 105 |
| 106 /////////////////////////////////////////////////////////////////////////////// | 106 /////////////////////////////////////////////////////////////////////////////// |
| 107 // class InterpolatedAxisAngleRotation | 107 // class InterpolatedAxisAngleRotation |
| 108 // | 108 // |
| 109 // Represents an animated rotation. | 109 // Represents an animated rotation. |
| 110 // | 110 // |
| 111 /////////////////////////////////////////////////////////////////////////////// | 111 /////////////////////////////////////////////////////////////////////////////// |
| 112 class UI_EXPORT InterpolatedAxisAngleRotation : public InterpolatedTransform { | 112 class GFX_EXPORT InterpolatedAxisAngleRotation : public InterpolatedTransform { |
| 113 public: | 113 public: |
| 114 InterpolatedAxisAngleRotation(const gfx::Vector3dF& axis, | 114 InterpolatedAxisAngleRotation(const gfx::Vector3dF& axis, |
| 115 float start_degrees, | 115 float start_degrees, |
| 116 float end_degrees); | 116 float end_degrees); |
| 117 InterpolatedAxisAngleRotation(const gfx::Vector3dF& axis, | 117 InterpolatedAxisAngleRotation(const gfx::Vector3dF& axis, |
| 118 float start_degrees, | 118 float start_degrees, |
| 119 float end_degrees, | 119 float end_degrees, |
| 120 float start_time, | 120 float start_time, |
| 121 float end_time); | 121 float end_time); |
| 122 virtual ~InterpolatedAxisAngleRotation(); | 122 virtual ~InterpolatedAxisAngleRotation(); |
| 123 | 123 |
| 124 protected: | 124 protected: |
| 125 virtual gfx::Transform InterpolateButDoNotCompose(float t) const OVERRIDE; | 125 virtual gfx::Transform InterpolateButDoNotCompose(float t) const OVERRIDE; |
| 126 | 126 |
| 127 private: | 127 private: |
| 128 gfx::Vector3dF axis_; | 128 gfx::Vector3dF axis_; |
| 129 const float start_degrees_; | 129 const float start_degrees_; |
| 130 const float end_degrees_; | 130 const float end_degrees_; |
| 131 | 131 |
| 132 DISALLOW_COPY_AND_ASSIGN(InterpolatedAxisAngleRotation); | 132 DISALLOW_COPY_AND_ASSIGN(InterpolatedAxisAngleRotation); |
| 133 }; | 133 }; |
| 134 | 134 |
| 135 /////////////////////////////////////////////////////////////////////////////// | 135 /////////////////////////////////////////////////////////////////////////////// |
| 136 // class InterpolatedScale | 136 // class InterpolatedScale |
| 137 // | 137 // |
| 138 // Represents an animated scale. | 138 // Represents an animated scale. |
| 139 // | 139 // |
| 140 /////////////////////////////////////////////////////////////////////////////// | 140 /////////////////////////////////////////////////////////////////////////////// |
| 141 class UI_EXPORT InterpolatedScale : public InterpolatedTransform { | 141 class GFX_EXPORT InterpolatedScale : public InterpolatedTransform { |
| 142 public: | 142 public: |
| 143 InterpolatedScale(float start_scale, float end_scale); | 143 InterpolatedScale(float start_scale, float end_scale); |
| 144 InterpolatedScale(float start_scale, float end_scale, | 144 InterpolatedScale(float start_scale, float end_scale, |
| 145 float start_time, float end_time); | 145 float start_time, float end_time); |
| 146 InterpolatedScale(const gfx::Point3F& start_scale, | 146 InterpolatedScale(const gfx::Point3F& start_scale, |
| 147 const gfx::Point3F& end_scale); | 147 const gfx::Point3F& end_scale); |
| 148 InterpolatedScale(const gfx::Point3F& start_scale, | 148 InterpolatedScale(const gfx::Point3F& start_scale, |
| 149 const gfx::Point3F& end_scale, | 149 const gfx::Point3F& end_scale, |
| 150 float start_time, | 150 float start_time, |
| 151 float end_time); | 151 float end_time); |
| 152 virtual ~InterpolatedScale(); | 152 virtual ~InterpolatedScale(); |
| 153 | 153 |
| 154 protected: | 154 protected: |
| 155 virtual gfx::Transform InterpolateButDoNotCompose(float t) const OVERRIDE; | 155 virtual gfx::Transform InterpolateButDoNotCompose(float t) const OVERRIDE; |
| 156 | 156 |
| 157 private: | 157 private: |
| 158 const gfx::Point3F start_scale_; | 158 const gfx::Point3F start_scale_; |
| 159 const gfx::Point3F end_scale_; | 159 const gfx::Point3F end_scale_; |
| 160 | 160 |
| 161 DISALLOW_COPY_AND_ASSIGN(InterpolatedScale); | 161 DISALLOW_COPY_AND_ASSIGN(InterpolatedScale); |
| 162 }; | 162 }; |
| 163 | 163 |
| 164 class UI_EXPORT InterpolatedTranslation : public InterpolatedTransform { | 164 class GFX_EXPORT InterpolatedTranslation : public InterpolatedTransform { |
| 165 public: | 165 public: |
| 166 InterpolatedTranslation(const gfx::Point& start_pos, | 166 InterpolatedTranslation(const gfx::Point& start_pos, |
| 167 const gfx::Point& end_pos); | 167 const gfx::Point& end_pos); |
| 168 InterpolatedTranslation(const gfx::Point& start_pos, | 168 InterpolatedTranslation(const gfx::Point& start_pos, |
| 169 const gfx::Point& end_pos, | 169 const gfx::Point& end_pos, |
| 170 float start_time, | 170 float start_time, |
| 171 float end_time); | 171 float end_time); |
| 172 virtual ~InterpolatedTranslation(); | 172 virtual ~InterpolatedTranslation(); |
| 173 | 173 |
| 174 protected: | 174 protected: |
| 175 virtual gfx::Transform InterpolateButDoNotCompose(float t) const OVERRIDE; | 175 virtual gfx::Transform InterpolateButDoNotCompose(float t) const OVERRIDE; |
| 176 | 176 |
| 177 private: | 177 private: |
| 178 const gfx::Point start_pos_; | 178 const gfx::Point start_pos_; |
| 179 const gfx::Point end_pos_; | 179 const gfx::Point end_pos_; |
| 180 | 180 |
| 181 DISALLOW_COPY_AND_ASSIGN(InterpolatedTranslation); | 181 DISALLOW_COPY_AND_ASSIGN(InterpolatedTranslation); |
| 182 }; | 182 }; |
| 183 | 183 |
| 184 /////////////////////////////////////////////////////////////////////////////// | 184 /////////////////////////////////////////////////////////////////////////////// |
| 185 // class InterpolatedConstantTransform | 185 // class InterpolatedConstantTransform |
| 186 // | 186 // |
| 187 // Represents a transform that is constant over time. This is only useful when | 187 // Represents a transform that is constant over time. This is only useful when |
| 188 // composed with other interpolated transforms. | 188 // composed with other interpolated transforms. |
| 189 // | 189 // |
| 190 // See InterpolatedTransformAboutPivot for an example of its usage. | 190 // See InterpolatedTransformAboutPivot for an example of its usage. |
| 191 // | 191 // |
| 192 /////////////////////////////////////////////////////////////////////////////// | 192 /////////////////////////////////////////////////////////////////////////////// |
| 193 class UI_EXPORT InterpolatedConstantTransform : public InterpolatedTransform { | 193 class GFX_EXPORT InterpolatedConstantTransform : public InterpolatedTransform { |
| 194 public: | 194 public: |
| 195 explicit InterpolatedConstantTransform(const gfx::Transform& transform); | 195 explicit InterpolatedConstantTransform(const gfx::Transform& transform); |
| 196 virtual ~InterpolatedConstantTransform(); | 196 virtual ~InterpolatedConstantTransform(); |
| 197 | 197 |
| 198 protected: | 198 protected: |
| 199 virtual gfx::Transform InterpolateButDoNotCompose(float t) const OVERRIDE; | 199 virtual gfx::Transform InterpolateButDoNotCompose(float t) const OVERRIDE; |
| 200 | 200 |
| 201 private: | 201 private: |
| 202 const gfx::Transform transform_; | 202 const gfx::Transform transform_; |
| 203 | 203 |
| 204 DISALLOW_COPY_AND_ASSIGN(InterpolatedConstantTransform); | 204 DISALLOW_COPY_AND_ASSIGN(InterpolatedConstantTransform); |
| 205 }; | 205 }; |
| 206 | 206 |
| 207 /////////////////////////////////////////////////////////////////////////////// | 207 /////////////////////////////////////////////////////////////////////////////// |
| 208 // class InterpolatedTransformAboutPivot | 208 // class InterpolatedTransformAboutPivot |
| 209 // | 209 // |
| 210 // Represents an animated transform with a transformed origin. Essentially, | 210 // Represents an animated transform with a transformed origin. Essentially, |
| 211 // at each time, t, the interpolated transform is created by composing | 211 // at each time, t, the interpolated transform is created by composing |
| 212 // P * T * P^-1 where P is a constant transform to the new origin. | 212 // P * T * P^-1 where P is a constant transform to the new origin. |
| 213 // | 213 // |
| 214 /////////////////////////////////////////////////////////////////////////////// | 214 /////////////////////////////////////////////////////////////////////////////// |
| 215 class UI_EXPORT InterpolatedTransformAboutPivot : public InterpolatedTransform { | 215 class GFX_EXPORT InterpolatedTransformAboutPivot |
| 216 : public InterpolatedTransform { |
| 216 public: | 217 public: |
| 217 // Takes ownership of the passed transform. | 218 // Takes ownership of the passed transform. |
| 218 InterpolatedTransformAboutPivot(const gfx::Point& pivot, | 219 InterpolatedTransformAboutPivot(const gfx::Point& pivot, |
| 219 InterpolatedTransform* transform); | 220 InterpolatedTransform* transform); |
| 220 | 221 |
| 221 // Takes ownership of the passed transform. | 222 // Takes ownership of the passed transform. |
| 222 InterpolatedTransformAboutPivot(const gfx::Point& pivot, | 223 InterpolatedTransformAboutPivot(const gfx::Point& pivot, |
| 223 InterpolatedTransform* transform, | 224 InterpolatedTransform* transform, |
| 224 float start_time, | 225 float start_time, |
| 225 float end_time); | 226 float end_time); |
| 226 virtual ~InterpolatedTransformAboutPivot(); | 227 virtual ~InterpolatedTransformAboutPivot(); |
| 227 | 228 |
| 228 protected: | 229 protected: |
| 229 virtual gfx::Transform InterpolateButDoNotCompose(float t) const OVERRIDE; | 230 virtual gfx::Transform InterpolateButDoNotCompose(float t) const OVERRIDE; |
| 230 | 231 |
| 231 private: | 232 private: |
| 232 void Init(const gfx::Point& pivot, InterpolatedTransform* transform); | 233 void Init(const gfx::Point& pivot, InterpolatedTransform* transform); |
| 233 | 234 |
| 234 scoped_ptr<InterpolatedTransform> transform_; | 235 scoped_ptr<InterpolatedTransform> transform_; |
| 235 | 236 |
| 236 DISALLOW_COPY_AND_ASSIGN(InterpolatedTransformAboutPivot); | 237 DISALLOW_COPY_AND_ASSIGN(InterpolatedTransformAboutPivot); |
| 237 }; | 238 }; |
| 238 | 239 |
| 239 class UI_EXPORT InterpolatedMatrixTransform : public InterpolatedTransform { | 240 class GFX_EXPORT InterpolatedMatrixTransform : public InterpolatedTransform { |
| 240 public: | 241 public: |
| 241 InterpolatedMatrixTransform(const gfx::Transform& start_transform, | 242 InterpolatedMatrixTransform(const gfx::Transform& start_transform, |
| 242 const gfx::Transform& end_transform); | 243 const gfx::Transform& end_transform); |
| 243 | 244 |
| 244 InterpolatedMatrixTransform(const gfx::Transform& start_transform, | 245 InterpolatedMatrixTransform(const gfx::Transform& start_transform, |
| 245 const gfx::Transform& end_transform, | 246 const gfx::Transform& end_transform, |
| 246 float start_time, | 247 float start_time, |
| 247 float end_time); | 248 float end_time); |
| 248 | 249 |
| 249 virtual ~InterpolatedMatrixTransform(); | 250 virtual ~InterpolatedMatrixTransform(); |
| 250 | 251 |
| 251 protected: | 252 protected: |
| 252 virtual gfx::Transform InterpolateButDoNotCompose(float t) const OVERRIDE; | 253 virtual gfx::Transform InterpolateButDoNotCompose(float t) const OVERRIDE; |
| 253 | 254 |
| 254 private: | 255 private: |
| 255 void Init(const gfx::Transform& start_transform, | 256 void Init(const gfx::Transform& start_transform, |
| 256 const gfx::Transform& end_transform); | 257 const gfx::Transform& end_transform); |
| 257 | 258 |
| 258 gfx::DecomposedTransform start_decomp_; | 259 gfx::DecomposedTransform start_decomp_; |
| 259 gfx::DecomposedTransform end_decomp_; | 260 gfx::DecomposedTransform end_decomp_; |
| 260 }; | 261 }; |
| 261 | 262 |
| 262 } // namespace ui | 263 } // namespace ui |
| 263 | 264 |
| 264 #endif // UI_GFX_INTERPOLATED_TRANSFORM_H_ | 265 #endif // UI_GFX_INTERPOLATED_TRANSFORM_H_ |
| OLD | NEW |