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

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

Powered by Google App Engine
This is Rietveld 408576698