Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: ui/gfx/interpolated_transform.h

Issue 11145005: Migrate ui::Transform to gfx::Transform (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Hopefully should work this time Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/gfx/canvas.cc ('k') | ui/gfx/interpolated_transform.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 15 matching lines...) Expand all
26 class UI_EXPORT InterpolatedTransform { 26 class UI_EXPORT InterpolatedTransform {
27 public: 27 public:
28 InterpolatedTransform(); 28 InterpolatedTransform();
29 // The interpolated transform varies only when t in (start_time, end_time). 29 // The interpolated transform varies only when t in (start_time, end_time).
30 // If t <= start_time, Interpolate(t) will return the initial transform, and 30 // If t <= start_time, Interpolate(t) will return the initial transform, and
31 // if t >= end_time, Interpolate(t) will return the final transform. 31 // if t >= end_time, Interpolate(t) will return the final transform.
32 InterpolatedTransform(float start_time, float end_time); 32 InterpolatedTransform(float start_time, float end_time);
33 virtual ~InterpolatedTransform(); 33 virtual ~InterpolatedTransform();
34 34
35 // Returns the interpolated transform at time t. Note: not virtual. 35 // Returns the interpolated transform at time t. Note: not virtual.
36 ui::Transform Interpolate(float t) const; 36 gfx::Transform Interpolate(float t) const;
37 37
38 // The Intepolate ultimately returns the product of our transform at time t 38 // 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). 39 // and our child's transform at time t (if we have one).
40 // 40 //
41 // This function takes ownership of the passed InterpolatedTransform. 41 // This function takes ownership of the passed InterpolatedTransform.
42 void SetChild(InterpolatedTransform* child); 42 void SetChild(InterpolatedTransform* child);
43 43
44 // If the interpolated transform is reversed, Interpolate(t) will return 44 // If the interpolated transform is reversed, Interpolate(t) will return
45 // Interpolate(1 - t) 45 // Interpolate(1 - t)
46 void SetReversed(bool reversed) { reversed_ = reversed; } 46 void SetReversed(bool reversed) { reversed_ = reversed; }
47 bool Reversed() const { return reversed_; } 47 bool Reversed() const { return reversed_; }
48 48
49 static bool FactorTRS(const ui::Transform& transform, 49 static bool FactorTRS(const gfx::Transform& transform,
50 gfx::Point* translation, 50 gfx::Point* translation,
51 float* rotation, 51 float* rotation,
52 gfx::Point3f* scale); 52 gfx::Point3f* scale);
53 53
54 protected: 54 protected:
55 // Calculates the interpolated transform without considering our child. 55 // Calculates the interpolated transform without considering our child.
56 virtual ui::Transform InterpolateButDoNotCompose(float t) const = 0; 56 virtual gfx::Transform InterpolateButDoNotCompose(float t) const = 0;
57 57
58 // If time in (start_time_, end_time_], this function linearly interpolates 58 // If time in (start_time_, end_time_], this function linearly interpolates
59 // between start_value and end_value. More precisely it returns 59 // between start_value and end_value. More precisely it returns
60 // (1 - t) * start_value + t * end_value where 60 // (1 - t) * start_value + t * end_value where
61 // t = (start_time_ - time) / (end_time_ - start_time_). 61 // t = (start_time_ - time) / (end_time_ - start_time_).
62 // If time < start_time_ it returns start_value, and if time >= end_time_ 62 // If time < start_time_ it returns start_value, and if time >= end_time_
63 // it returns end_value. 63 // it returns end_value.
64 float ValueBetween(float time, float start_value, float end_value) const; 64 float ValueBetween(float time, float start_value, float end_value) const;
65 65
66 float start_time() const { return start_time_; } 66 float start_time() const { return start_time_; }
(...skipping 23 matching lines...) Expand all
90 class UI_EXPORT InterpolatedRotation : public InterpolatedTransform { 90 class UI_EXPORT InterpolatedRotation : public InterpolatedTransform {
91 public: 91 public:
92 InterpolatedRotation(float start_degrees, float end_degrees); 92 InterpolatedRotation(float start_degrees, float end_degrees);
93 InterpolatedRotation(float start_degrees, 93 InterpolatedRotation(float start_degrees,
94 float end_degrees, 94 float end_degrees,
95 float start_time, 95 float start_time,
96 float end_time); 96 float end_time);
97 virtual ~InterpolatedRotation(); 97 virtual ~InterpolatedRotation();
98 98
99 protected: 99 protected:
100 virtual ui::Transform InterpolateButDoNotCompose(float t) const OVERRIDE; 100 virtual gfx::Transform InterpolateButDoNotCompose(float t) const OVERRIDE;
101 101
102 private: 102 private:
103 const float start_degrees_; 103 const float start_degrees_;
104 const float end_degrees_; 104 const float end_degrees_;
105 105
106 DISALLOW_COPY_AND_ASSIGN(InterpolatedRotation); 106 DISALLOW_COPY_AND_ASSIGN(InterpolatedRotation);
107 }; 107 };
108 108
109 /////////////////////////////////////////////////////////////////////////////// 109 ///////////////////////////////////////////////////////////////////////////////
110 // class InterpolatedAxisAngleRotation 110 // class InterpolatedAxisAngleRotation
111 // 111 //
112 // Represents an animated rotation. 112 // Represents an animated rotation.
113 // 113 //
114 /////////////////////////////////////////////////////////////////////////////// 114 ///////////////////////////////////////////////////////////////////////////////
115 class UI_EXPORT InterpolatedAxisAngleRotation : public InterpolatedTransform { 115 class UI_EXPORT InterpolatedAxisAngleRotation : public InterpolatedTransform {
116 public: 116 public:
117 InterpolatedAxisAngleRotation(gfx::Point3f axis, 117 InterpolatedAxisAngleRotation(gfx::Point3f axis,
118 float start_degrees, 118 float start_degrees,
119 float end_degrees); 119 float end_degrees);
120 InterpolatedAxisAngleRotation(gfx::Point3f axis, 120 InterpolatedAxisAngleRotation(gfx::Point3f axis,
121 float start_degrees, 121 float start_degrees,
122 float end_degrees, 122 float end_degrees,
123 float start_time, 123 float start_time,
124 float end_time); 124 float end_time);
125 virtual ~InterpolatedAxisAngleRotation(); 125 virtual ~InterpolatedAxisAngleRotation();
126 126
127 protected: 127 protected:
128 virtual ui::Transform InterpolateButDoNotCompose(float t) const OVERRIDE; 128 virtual gfx::Transform InterpolateButDoNotCompose(float t) const OVERRIDE;
129 129
130 private: 130 private:
131 gfx::Point3f axis_; 131 gfx::Point3f axis_;
132 const float start_degrees_; 132 const float start_degrees_;
133 const float end_degrees_; 133 const float end_degrees_;
134 134
135 DISALLOW_COPY_AND_ASSIGN(InterpolatedAxisAngleRotation); 135 DISALLOW_COPY_AND_ASSIGN(InterpolatedAxisAngleRotation);
136 }; 136 };
137 137
138 /////////////////////////////////////////////////////////////////////////////// 138 ///////////////////////////////////////////////////////////////////////////////
139 // class InterpolatedScale 139 // class InterpolatedScale
140 // 140 //
141 // Represents an animated scale. 141 // Represents an animated scale.
142 // 142 //
143 /////////////////////////////////////////////////////////////////////////////// 143 ///////////////////////////////////////////////////////////////////////////////
144 class UI_EXPORT InterpolatedScale : public InterpolatedTransform { 144 class UI_EXPORT InterpolatedScale : public InterpolatedTransform {
145 public: 145 public:
146 InterpolatedScale(float start_scale, float end_scale); 146 InterpolatedScale(float start_scale, float end_scale);
147 InterpolatedScale(float start_scale, float end_scale, 147 InterpolatedScale(float start_scale, float end_scale,
148 float start_time, float end_time); 148 float start_time, float end_time);
149 InterpolatedScale(const gfx::Point3f& start_scale, 149 InterpolatedScale(const gfx::Point3f& start_scale,
150 const gfx::Point3f& end_scale); 150 const gfx::Point3f& end_scale);
151 InterpolatedScale(const gfx::Point3f& start_scale, 151 InterpolatedScale(const gfx::Point3f& start_scale,
152 const gfx::Point3f& end_scale, 152 const gfx::Point3f& end_scale,
153 float start_time, 153 float start_time,
154 float end_time); 154 float end_time);
155 virtual ~InterpolatedScale(); 155 virtual ~InterpolatedScale();
156 156
157 protected: 157 protected:
158 virtual ui::Transform InterpolateButDoNotCompose(float t) const OVERRIDE; 158 virtual gfx::Transform InterpolateButDoNotCompose(float t) const OVERRIDE;
159 159
160 private: 160 private:
161 const gfx::Point3f start_scale_; 161 const gfx::Point3f start_scale_;
162 const gfx::Point3f end_scale_; 162 const gfx::Point3f end_scale_;
163 163
164 DISALLOW_COPY_AND_ASSIGN(InterpolatedScale); 164 DISALLOW_COPY_AND_ASSIGN(InterpolatedScale);
165 }; 165 };
166 166
167 class UI_EXPORT InterpolatedTranslation : public InterpolatedTransform { 167 class UI_EXPORT InterpolatedTranslation : public InterpolatedTransform {
168 public: 168 public:
169 InterpolatedTranslation(const gfx::Point& start_pos, 169 InterpolatedTranslation(const gfx::Point& start_pos,
170 const gfx::Point& end_pos); 170 const gfx::Point& end_pos);
171 InterpolatedTranslation(const gfx::Point& start_pos, 171 InterpolatedTranslation(const gfx::Point& start_pos,
172 const gfx::Point& end_pos, 172 const gfx::Point& end_pos,
173 float start_time, 173 float start_time,
174 float end_time); 174 float end_time);
175 virtual ~InterpolatedTranslation(); 175 virtual ~InterpolatedTranslation();
176 176
177 protected: 177 protected:
178 virtual ui::Transform InterpolateButDoNotCompose(float t) const OVERRIDE; 178 virtual gfx::Transform InterpolateButDoNotCompose(float t) const OVERRIDE;
179 179
180 private: 180 private:
181 const gfx::Point start_pos_; 181 const gfx::Point start_pos_;
182 const gfx::Point end_pos_; 182 const gfx::Point end_pos_;
183 183
184 DISALLOW_COPY_AND_ASSIGN(InterpolatedTranslation); 184 DISALLOW_COPY_AND_ASSIGN(InterpolatedTranslation);
185 }; 185 };
186 186
187 /////////////////////////////////////////////////////////////////////////////// 187 ///////////////////////////////////////////////////////////////////////////////
188 // class InterpolatedConstantTransform 188 // class InterpolatedConstantTransform
189 // 189 //
190 // Represents a transform that is constant over time. This is only useful when 190 // Represents a transform that is constant over time. This is only useful when
191 // composed with other interpolated transforms. 191 // composed with other interpolated transforms.
192 // 192 //
193 // See InterpolatedTransformAboutPivot for an example of its usage. 193 // See InterpolatedTransformAboutPivot for an example of its usage.
194 // 194 //
195 /////////////////////////////////////////////////////////////////////////////// 195 ///////////////////////////////////////////////////////////////////////////////
196 class UI_EXPORT InterpolatedConstantTransform : public InterpolatedTransform { 196 class UI_EXPORT InterpolatedConstantTransform : public InterpolatedTransform {
197 public: 197 public:
198 InterpolatedConstantTransform(const ui::Transform& transform); 198 InterpolatedConstantTransform(const gfx::Transform& transform);
199 virtual ~InterpolatedConstantTransform(); 199 virtual ~InterpolatedConstantTransform();
200 200
201 protected: 201 protected:
202 virtual ui::Transform InterpolateButDoNotCompose(float t) const OVERRIDE; 202 virtual gfx::Transform InterpolateButDoNotCompose(float t) const OVERRIDE;
203 203
204 private: 204 private:
205 const ui::Transform transform_; 205 const gfx::Transform transform_;
206 206
207 DISALLOW_COPY_AND_ASSIGN(InterpolatedConstantTransform); 207 DISALLOW_COPY_AND_ASSIGN(InterpolatedConstantTransform);
208 }; 208 };
209 209
210 /////////////////////////////////////////////////////////////////////////////// 210 ///////////////////////////////////////////////////////////////////////////////
211 // class InterpolatedTransformAboutPivot 211 // class InterpolatedTransformAboutPivot
212 // 212 //
213 // Represents an animated transform with a transformed origin. Essentially, 213 // Represents an animated transform with a transformed origin. Essentially,
214 // at each time, t, the interpolated transform is created by composing 214 // at each time, t, the interpolated transform is created by composing
215 // P * T * P^-1 where P is a constant transform to the new origin. 215 // P * T * P^-1 where P is a constant transform to the new origin.
216 // 216 //
217 /////////////////////////////////////////////////////////////////////////////// 217 ///////////////////////////////////////////////////////////////////////////////
218 class UI_EXPORT InterpolatedTransformAboutPivot : public InterpolatedTransform { 218 class UI_EXPORT InterpolatedTransformAboutPivot : public InterpolatedTransform {
219 public: 219 public:
220 // Takes ownership of the passed transform. 220 // Takes ownership of the passed transform.
221 InterpolatedTransformAboutPivot(const gfx::Point& pivot, 221 InterpolatedTransformAboutPivot(const gfx::Point& pivot,
222 InterpolatedTransform* transform); 222 InterpolatedTransform* transform);
223 223
224 // Takes ownership of the passed transform. 224 // Takes ownership of the passed transform.
225 InterpolatedTransformAboutPivot(const gfx::Point& pivot, 225 InterpolatedTransformAboutPivot(const gfx::Point& pivot,
226 InterpolatedTransform* transform, 226 InterpolatedTransform* transform,
227 float start_time, 227 float start_time,
228 float end_time); 228 float end_time);
229 virtual ~InterpolatedTransformAboutPivot(); 229 virtual ~InterpolatedTransformAboutPivot();
230 230
231 protected: 231 protected:
232 virtual Transform InterpolateButDoNotCompose(float t) const OVERRIDE; 232 virtual gfx::Transform InterpolateButDoNotCompose(float t) const OVERRIDE;
233 233
234 private: 234 private:
235 void Init(const gfx::Point& pivot, InterpolatedTransform* transform); 235 void Init(const gfx::Point& pivot, InterpolatedTransform* transform);
236 236
237 scoped_ptr<InterpolatedTransform> transform_; 237 scoped_ptr<InterpolatedTransform> transform_;
238 238
239 DISALLOW_COPY_AND_ASSIGN(InterpolatedTransformAboutPivot); 239 DISALLOW_COPY_AND_ASSIGN(InterpolatedTransformAboutPivot);
240 }; 240 };
241 241
242 class UI_EXPORT InterpolatedTRSTransform : public InterpolatedTransform { 242 class UI_EXPORT InterpolatedTRSTransform : public InterpolatedTransform {
243 public: 243 public:
244 InterpolatedTRSTransform(const Transform& start_transform, 244 InterpolatedTRSTransform(const gfx::Transform& start_transform,
245 const Transform& end_transform); 245 const gfx::Transform& end_transform);
246 246
247 InterpolatedTRSTransform(const Transform& start_transform, 247 InterpolatedTRSTransform(const gfx::Transform& start_transform,
248 const Transform& end_transform, 248 const gfx::Transform& end_transform,
249 float start_time, 249 float start_time,
250 float end_time); 250 float end_time);
251 251
252 virtual ~InterpolatedTRSTransform(); 252 virtual ~InterpolatedTRSTransform();
253 253
254 protected: 254 protected:
255 virtual Transform InterpolateButDoNotCompose(float t) const OVERRIDE; 255 virtual gfx::Transform InterpolateButDoNotCompose(float t) const OVERRIDE;
256 256
257 private: 257 private:
258 void Init(const ui::Transform& start_transform, 258 void Init(const gfx::Transform& start_transform,
259 const ui::Transform& end_transform); 259 const gfx::Transform& end_transform);
260 260
261 scoped_ptr<InterpolatedTransform> transform_; 261 scoped_ptr<InterpolatedTransform> transform_;
262 }; 262 };
263 263
264 } // namespace ui 264 } // namespace ui
265 265
266 #endif // UI_GFX_INTERPOLATED_TRANSFORM_H_ 266 #endif // UI_GFX_INTERPOLATED_TRANSFORM_H_
OLDNEW
« no previous file with comments | « ui/gfx/canvas.cc ('k') | ui/gfx/interpolated_transform.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698