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

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

Issue 11418040: gfx::Transform API clean-up (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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 | Annotate | Revision Log
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_TRANSFORM_H_ 5 #ifndef UI_GFX_TRANSFORM_H_
6 #define UI_GFX_TRANSFORM_H_ 6 #define UI_GFX_TRANSFORM_H_
7 7
8 #include "third_party/skia/include/utils/SkMatrix44.h" 8 #include "third_party/skia/include/utils/SkMatrix44.h"
9 #include "ui/base/ui_export.h" 9 #include "ui/base/ui_export.h"
10 10
11 namespace gfx { 11 namespace gfx {
12 12
13 class RectF; 13 class RectF;
14 class Point; 14 class Point;
15 class Point3F; 15 class Point3F;
16 class Vector3dF;
16 17
17 // 4x4 transformation matrix. Transform is cheap and explicitly allows 18 // 4x4 transformation matrix. Transform is cheap and explicitly allows
18 // copy/assign. 19 // copy/assign.
19 class UI_EXPORT Transform { 20 class UI_EXPORT Transform {
20 public: 21 public:
21 Transform(); 22 Transform();
22 ~Transform(); 23 ~Transform();
23 24
24 bool operator==(const Transform& rhs) const; 25 bool operator==(const Transform& rhs) const;
25 bool operator!=(const Transform& rhs) const; 26 bool operator!=(const Transform& rhs) const;
26 27
27 // NOTE: The 'Set' functions overwrite the previously set transformation 28 // Resets this transform to the identity transform.
28 // parameters. The 'Concat' functions apply a transformation (e.g. rotation, 29 void MakeIdentity();
29 // scale, translate) on top of the existing transforms, instead of overwriting
30 // them.
31
32 // NOTE: The order of the 'Set' function calls do not matter. However, the
33 // order of the 'Concat' function calls do matter, especially when combined
34 // with the 'Set' functions.
35
36 // Sets the rotation of the transformation.
37 void SetRotate(double degree);
38
39 // Sets the rotation of the transform (about a vector).
40 void SetRotateAbout(const Point3F& point, double degree);
41
42 // Sets the scaling parameters.
43 void SetScaleX(double x);
44 void SetScaleY(double y);
45 void SetScaleZ(double z);
46 void SetScale(double x, double y);
47 void SetScale3d(double x, double y, double z);
48
49 // Sets the translation parameters.
50 void SetTranslateX(double x);
51 void SetTranslateY(double y);
52 void SetTranslateZ(double z);
53 void SetTranslate(double x, double y);
54 void SetTranslate3d(double x, double y, double z);
55
56 // Sets the skew parameters.
57 void SetSkewX(double angle);
58 void SetSkewY(double angle);
59
60 // Creates a perspective matrix.
61 // Based on the 'perspective' operation from
62 // http://www.w3.org/TR/css3-3d-transforms/#transform-functions
63 void SetPerspectiveDepth(double depth);
64
65 // Applies a rotation on the current transformation.
66 void ConcatRotate(double degree);
67
68 // Applies an axis-angle rotation on the current transformation.
69 void ConcatRotateAbout(const Point3F& point, double degree);
70
71 // Applies scaling on current transform.
72 void ConcatScale(double x, double y);
73 void ConcatScale3d(double x, double y, double z);
74
75 // Applies translation on current transform.
76 void ConcatTranslate(double x, double y);
77 void ConcatTranslate3d(double x, double y, double z);
78
79 // Applies a perspective on current transform.
80 void ConcatPerspectiveDepth(double depth);
81
82 // Applies a skew on the current transform.
83 void ConcatSkewX(double angle_x);
84 void ConcatSkewY(double angle_y);
85 30
86 // Applies the current transformation on a rotation and assigns the result 31 // Applies the current transformation on a rotation and assigns the result
87 // to |this|. 32 // to |this|.
88 void PreconcatRotate(double degree); 33 void Rotate(double degree);
89 34
90 // Applies the current transformation on an axis-angle rotation and assigns 35 // Applies the current transformation on an axis-angle rotation and assigns
91 // the result to |this|. 36 // the result to |this|.
92 void PreconcatRotateAbout(const Point3F& point, double degree); 37 void RotateAbout(const Vector3dF& point, double degree);
93 38
94 // Applies the current transformation on a scaling and assigns the result 39 // Applies the current transformation on a scaling and assigns the result
95 // to |this|. 40 // to |this|.
96 void PreconcatScale(double x, double y); 41 void Scale(double x, double y);
97 void PreconcatScale3d(double x, double y, double z); 42 void Scale3d(double x, double y, double z);
98 43
99 // Applies the current transformation on a translation and assigns the result 44 // Applies the current transformation on a translation and assigns the result
100 // to |this|. 45 // to |this|.
101 void PreconcatTranslate(double x, double y); 46 void Translate(double x, double y);
102 void PreconcatTranslate3d(double x, double y, double z); 47 void Translate3d(double x, double y, double z);
103 48
104 // Applies the current transformation on a skew and assigns the result 49 // Applies the current transformation on a skew and assigns the result
105 // to |this|. 50 // to |this|.
106 void PreconcatSkewX(double angle_x); 51 void SkewX(double angle_x);
107 void PreconcatSkewY(double angle_y); 52 void SkewY(double angle_y);
108 53
109 // Applies the current transformation on a perspective transform and assigns 54 // Applies the current transformation on a perspective transform and assigns
110 // the result to |this|. 55 // the result to |this|.
111 void PreconcatPerspectiveDepth(double depth); 56 void ApplyPerspectiveDepth(double depth);
112 57
113 // Applies a transformation on the current transformation 58 // Applies a transformation on the current transformation
114 // (i.e. 'this = this * transform;'). 59 // (i.e. 'this = this * transform;').
115 void PreconcatTransform(const Transform& transform); 60 void PreconcatTransform(const Transform& transform);
116 61
117 // Applies a transformation on the current transformation 62 // Applies a transformation on the current transformation
118 // (i.e. 'this = transform * this;'). 63 // (i.e. 'this = transform * this;').
119 void ConcatTransform(const Transform& transform); 64 void ConcatTransform(const Transform& transform);
120 65
121 // Does the transformation change anything? 66 // Does the transformation change anything?
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 // sets |this| to the reconstituted result. Returns false if either matrix 100 // sets |this| to the reconstituted result. Returns false if either matrix
156 // can't be decomposed. Uses routines described in this spec: 101 // can't be decomposed. Uses routines described in this spec:
157 // http://www.w3.org/TR/css3-3d-transforms/. 102 // http://www.w3.org/TR/css3-3d-transforms/.
158 // 103 //
159 // Note: this call is expensive since we need to decompose the transform. If 104 // Note: this call is expensive since we need to decompose the transform. If
160 // you're going to be calling this rapidly (e.g., in an animation) you should 105 // you're going to be calling this rapidly (e.g., in an animation) you should
161 // decompose once using gfx::DecomposeTransforms and reuse your 106 // decompose once using gfx::DecomposeTransforms and reuse your
162 // DecomposedTransform. 107 // DecomposedTransform.
163 bool Blend(const Transform& from, double progress); 108 bool Blend(const Transform& from, double progress);
164 109
110 // Returns |this| * |other|.
111 Transform operator*(const Transform& other) const;
112
113 // Sets |this| = |this| * |other|
114 Transform& operator*=(const Transform& other);
115
165 // Returns the underlying matrix. 116 // Returns the underlying matrix.
166 const SkMatrix44& matrix() const { return matrix_; } 117 const SkMatrix44& matrix() const { return matrix_; }
167 SkMatrix44& matrix() { return matrix_; } 118 SkMatrix44& matrix() { return matrix_; }
168 119
169 private: 120 private:
170 void TransformPointInternal(const SkMatrix44& xform, 121 void TransformPointInternal(const SkMatrix44& xform,
171 Point& point) const; 122 Point& point) const;
172 123
173 void TransformPointInternal(const SkMatrix44& xform, 124 void TransformPointInternal(const SkMatrix44& xform,
174 Point3F& point) const; 125 Point3F& point) const;
175 126
176 SkMatrix44 matrix_; 127 SkMatrix44 matrix_;
177 128
178 // copy/assign are allowed. 129 // copy/assign are allowed.
179 }; 130 };
180 131
181 } // namespace gfx 132 } // namespace gfx
182 133
183 #endif // UI_GFX_TRANSFORM_H_ 134 #endif // UI_GFX_TRANSFORM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698