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 |
28 // NOTE: The 'Set' functions overwrite the previously set transformation | 26 // NOTE: The 'Set' functions overwrite the previously set transformation |
29 // parameters. The 'Concat' functions apply a transformation (e.g. rotation, | 27 // parameters. The 'Concat' functions apply a transformation (e.g. rotation, |
30 // scale, translate) on top of the existing transforms, instead of overwriting | 28 // scale, translate) on top of the existing transforms, instead of overwriting |
31 // them. | 29 // them. |
32 | 30 |
(...skipping 17 matching lines...) Expand all Loading... |
50 // Applies rotation on the current transformation. | 48 // Applies rotation on the current transformation. |
51 void ConcatRotate(float degree); | 49 void ConcatRotate(float degree); |
52 | 50 |
53 // Applies scaling on current transform. | 51 // Applies scaling on current transform. |
54 void ConcatScale(float x, float y); | 52 void ConcatScale(float x, float y); |
55 | 53 |
56 // Applies translation on current transform. | 54 // Applies translation on current transform. |
57 void ConcatTranslate(float x, float y); | 55 void ConcatTranslate(float x, float y); |
58 | 56 |
59 // Applies a transformation on the current transformation | 57 // Applies a transformation on the current transformation |
60 // (i.e. 'this = this * transform;'). Returns true if the result can be | 58 // (i.e. 'this = this * transform;'). |
61 // represented. | 59 void PreconcatTransform(const Transform& transform); |
62 bool PreconcatTransform(const Transform& transform); | |
63 | 60 |
64 // Applies a transformation on the current transformation | 61 // Applies a transformation on the current transformation |
65 // (i.e. 'this = transform * this;'). Returns true if the result can be | 62 // (i.e. 'this = transform * this;'). |
66 // represented. | 63 void ConcatTransform(const Transform& transform); |
67 bool ConcatTransform(const Transform& transform); | |
68 | 64 |
69 // Does the transformation change anything? | 65 // Does the transformation change anything? |
70 bool HasChange() const; | 66 bool HasChange() const; |
71 | 67 |
72 // Applies the transformation on the point. Returns true if the point is | 68 // Applies the transformation on the point. Returns true if the point is |
73 // transformed successfully. | 69 // transformed successfully. |
74 bool TransformPoint(gfx::Point* point); | 70 bool TransformPoint(gfx::Point3f& point) const; |
75 | 71 |
76 // Applies the reverse transformation on the point. Returns true if the point | 72 // Applies the transformation on the point. Returns true if the point is |
77 // is transformed successfully. | 73 // transformed successfully. Rounds the result to the nearest point. |
78 bool TransformPointReverse(gfx::Point* point); | 74 bool TransformPoint(gfx::Point& point) const; |
| 75 |
| 76 // Applies the reverse transformation on the point. Returns true if the |
| 77 // transformation can be inverted. |
| 78 bool TransformPointReverse(gfx::Point3f& point) const; |
| 79 |
| 80 // Applies the reverse transformation on the point. Returns true if the |
| 81 // transformation can be inverted. Rounds the result to the nearest point. |
| 82 bool TransformPointReverse(gfx::Point& point) const; |
79 | 83 |
80 // Applies transformation on the rectangle. Returns true if the rectangle is | 84 // Applies transformation on the rectangle. Returns true if the rectangle is |
81 // transformed successfully. | 85 // transformed successfully. |
82 bool TransformRect(gfx::Rect* rect); | 86 bool TransformRect(gfx::Rect* rect) const; |
83 | 87 |
84 // Applies the reverse transformation on the rectangle. Returns true if the | 88 // Applies the reverse transformation on the rectangle. Returns true if the |
85 // rectangle is transformed successfully. | 89 // rectangle is transformed successfully. |
86 bool TransformRectReverse(gfx::Rect* rect); | 90 bool TransformRectReverse(gfx::Rect* rect) const; |
87 | 91 |
88 // Returns the underlying matrix. | 92 // Returns the underlying matrix. |
89 const SkMatrix& matrix() const { return matrix_; } | 93 const SkMatrix44& matrix() const { return matrix_; } |
90 | 94 |
91 private: | 95 private: |
92 SkMatrix matrix_; | 96 void TransformPointInternal(const SkMatrix44& xform, |
| 97 gfx::Point& point) const; |
| 98 |
| 99 void TransformPointInternal(const SkMatrix44& xform, |
| 100 gfx::Point3f& point) const; |
| 101 |
| 102 SkMatrix44 matrix_; |
93 | 103 |
94 // copy/assign are allowed. | 104 // copy/assign are allowed. |
95 }; | 105 }; |
96 | 106 |
97 } // namespace ui | 107 }// namespace ui |
98 | 108 |
99 #endif // UI_GFX_TRANSFORM_H_ | 109 #endif // UI_GFX_TRANSFORM_H_ |
OLD | NEW |