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_TRANSFORM_H_ | 5 #ifndef UI_GFX_TRANSFORM_H_ |
6 #define UI_GFX_TRANSFORM_H_ | 6 #define UI_GFX_TRANSFORM_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "third_party/skia/include/utils/SkMatrix44.h" |
10 #include "base/compiler_specific.h" | |
11 #include "third_party/skia/include/core/SkMatrix.h" | |
12 | 10 |
13 namespace gfx { | 11 namespace gfx { |
| 12 class Rect; |
14 class Point; | 13 class Point; |
15 class Rect; | 14 class Point3f; |
16 } | 15 } |
17 | 16 |
18 namespace ui { | 17 namespace ui { |
19 | 18 |
20 // 3x3 transformation matrix. Transform is cheap and explicitly allows | 19 // 4x4 transformation matrix. Transform is cheap and explicitly allows |
21 // copy/assign. | 20 // copy/assign. |
22 // TODO: make this a 4x4. | |
23 class Transform { | 21 class Transform { |
24 public: | 22 public: |
25 Transform(); | 23 Transform(); |
26 ~Transform(); | 24 ~Transform(); |
27 | 25 |
| 26 bool operator==(const Transform& rhs) const; |
| 27 bool operator!=(const Transform& rhs) const; |
| 28 |
28 // NOTE: The 'Set' functions overwrite the previously set transformation | 29 // NOTE: The 'Set' functions overwrite the previously set transformation |
29 // parameters. The 'Concat' functions apply a transformation (e.g. rotation, | 30 // parameters. The 'Concat' functions apply a transformation (e.g. rotation, |
30 // scale, translate) on top of the existing transforms, instead of overwriting | 31 // scale, translate) on top of the existing transforms, instead of overwriting |
31 // them. | 32 // them. |
32 | 33 |
33 // NOTE: The order of the 'Set' function calls do not matter. However, the | 34 // 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 // order of the 'Concat' function calls do matter, especially when combined |
35 // with the 'Set' functions. | 36 // with the 'Set' functions. |
36 | 37 |
37 // Sets the rotation of the transformation. | 38 // Sets the rotation of the transformation. |
(...skipping 12 matching lines...) Expand all Loading... |
50 // Applies rotation on the current transformation. | 51 // Applies rotation on the current transformation. |
51 void ConcatRotate(float degree); | 52 void ConcatRotate(float degree); |
52 | 53 |
53 // Applies scaling on current transform. | 54 // Applies scaling on current transform. |
54 void ConcatScale(float x, float y); | 55 void ConcatScale(float x, float y); |
55 | 56 |
56 // Applies translation on current transform. | 57 // Applies translation on current transform. |
57 void ConcatTranslate(float x, float y); | 58 void ConcatTranslate(float x, float y); |
58 | 59 |
59 // Applies a transformation on the current transformation | 60 // Applies a transformation on the current transformation |
60 // (i.e. 'this = this * transform;'). Returns true if the result can be | 61 // (i.e. 'this = this * transform;'). |
61 // represented. | 62 void PreconcatTransform(const Transform& transform); |
62 bool PreconcatTransform(const Transform& transform); | |
63 | 63 |
64 // Applies a transformation on the current transformation | 64 // Applies a transformation on the current transformation |
65 // (i.e. 'this = transform * this;'). Returns true if the result can be | 65 // (i.e. 'this = transform * this;'). |
66 // represented. | 66 void ConcatTransform(const Transform& transform); |
67 bool ConcatTransform(const Transform& transform); | |
68 | 67 |
69 // Does the transformation change anything? | 68 // Does the transformation change anything? |
70 bool HasChange() const; | 69 bool HasChange() const; |
71 | 70 |
72 // Applies the transformation on the point. Returns true if the point is | 71 // Applies the transformation on the point. Returns true if the point is |
73 // transformed successfully. | 72 // transformed successfully. |
74 bool TransformPoint(gfx::Point* point) const; | 73 void TransformPoint(gfx::Point3f& point) const; |
75 | 74 |
76 // Applies the reverse transformation on the point. Returns true if the point | 75 // Applies the transformation on the point. Returns true if the point is |
77 // is transformed successfully. | 76 // transformed successfully. Rounds the result to the nearest point. |
78 bool TransformPointReverse(gfx::Point* point) const; | 77 void TransformPoint(gfx::Point& point) const; |
79 | 78 |
80 // Applies transformation on the rectangle. Returns true if the rectangle is | 79 // Applies the reverse transformation on the point. Returns true if the |
81 // transformed successfully. | 80 // transformation can be inverted. |
82 bool TransformRect(gfx::Rect* rect) const; | 81 bool TransformPointReverse(gfx::Point3f& point) const; |
83 | 82 |
84 // Applies the reverse transformation on the rectangle. Returns true if the | 83 // Applies the reverse transformation on the point. Returns true if the |
85 // rectangle is transformed successfully. | 84 // transformation can be inverted. Rounds the result to the nearest point. |
| 85 bool TransformPointReverse(gfx::Point& point) const; |
| 86 |
| 87 // Applies transformation on the rectangle. Returns true if the transformed |
| 88 // rectangle was axis aligned. If it returns false, rect will be the |
| 89 // smallest axis aligned bounding box containg the transformed rect. |
| 90 void TransformRect(gfx::Rect* rect) const; |
| 91 |
| 92 // Applies the reverse transformation on the rectangle. Returns true if |
| 93 // the transformed rectangle was axis aligned. If it returns false, |
| 94 // rect will be the smallest axis aligned bounding box containg the |
| 95 // transformed rect. |
86 bool TransformRectReverse(gfx::Rect* rect) const; | 96 bool TransformRectReverse(gfx::Rect* rect) const; |
87 | 97 |
88 // Returns the underlying matrix. | 98 // Returns the underlying matrix. |
89 const SkMatrix& matrix() const { return matrix_; } | 99 const SkMatrix44& matrix() const { return matrix_; } |
90 SkMatrix& matrix() { return matrix_; } | 100 SkMatrix44& matrix() { return matrix_; } |
91 | 101 |
92 private: | 102 private: |
93 SkMatrix matrix_; | 103 void TransformPointInternal(const SkMatrix44& xform, |
| 104 gfx::Point& point) const; |
| 105 |
| 106 void TransformPointInternal(const SkMatrix44& xform, |
| 107 gfx::Point3f& point) const; |
| 108 |
| 109 SkMatrix44 matrix_; |
94 | 110 |
95 // copy/assign are allowed. | 111 // copy/assign are allowed. |
96 }; | 112 }; |
97 | 113 |
98 } // namespace ui | 114 }// namespace ui |
99 | 115 |
100 #endif // UI_GFX_TRANSFORM_H_ | 116 #endif // UI_GFX_TRANSFORM_H_ |
OLD | NEW |