| OLD | NEW |
| 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 class Rect; | 13 class Rect; |
| 13 class Point; | 14 class Point; |
| 14 class Point3f; | 15 class Point3f; |
| 15 } | |
| 16 | |
| 17 namespace ui { | |
| 18 | 16 |
| 19 // 4x4 transformation matrix. Transform is cheap and explicitly allows | 17 // 4x4 transformation matrix. Transform is cheap and explicitly allows |
| 20 // copy/assign. | 18 // copy/assign. |
| 21 class UI_EXPORT Transform { | 19 class UI_EXPORT Transform { |
| 22 public: | 20 public: |
| 23 Transform(); | 21 Transform(); |
| 24 ~Transform(); | 22 ~Transform(); |
| 25 | 23 |
| 26 bool operator==(const Transform& rhs) const; | 24 bool operator==(const Transform& rhs) const; |
| 27 bool operator!=(const Transform& rhs) const; | 25 bool operator!=(const Transform& rhs) const; |
| 28 | 26 |
| 29 // NOTE: The 'Set' functions overwrite the previously set transformation | 27 // NOTE: The 'Set' functions overwrite the previously set transformation |
| 30 // parameters. The 'Concat' functions apply a transformation (e.g. rotation, | 28 // parameters. The 'Concat' functions apply a transformation (e.g. rotation, |
| 31 // scale, translate) on top of the existing transforms, instead of overwriting | 29 // scale, translate) on top of the existing transforms, instead of overwriting |
| 32 // them. | 30 // them. |
| 33 | 31 |
| 34 // NOTE: The order of the 'Set' function calls do not matter. However, the | 32 // NOTE: The order of the 'Set' function calls do not matter. However, the |
| 35 // order of the 'Concat' function calls do matter, especially when combined | 33 // order of the 'Concat' function calls do matter, especially when combined |
| 36 // with the 'Set' functions. | 34 // with the 'Set' functions. |
| 37 | 35 |
| 38 // Sets the rotation of the transformation. | 36 // Sets the rotation of the transformation. |
| 39 void SetRotate(float degree); | 37 void SetRotate(float degree); |
| 40 | 38 |
| 41 // Sets the rotation of the transform (about a vector). | 39 // Sets the rotation of the transform (about a vector). |
| 42 void SetRotateAbout(const gfx::Point3f& point, float degree); | 40 void SetRotateAbout(const Point3f& point, float degree); |
| 43 | 41 |
| 44 // Sets the scaling parameters. | 42 // Sets the scaling parameters. |
| 45 void SetScaleX(float x); | 43 void SetScaleX(float x); |
| 46 void SetScaleY(float y); | 44 void SetScaleY(float y); |
| 47 void SetScale(float x, float y); | 45 void SetScale(float x, float y); |
| 48 | 46 |
| 49 // Sets the translation parameters. | 47 // Sets the translation parameters. |
| 50 void SetTranslateX(float x); | 48 void SetTranslateX(float x); |
| 51 void SetTranslateY(float y); | 49 void SetTranslateY(float y); |
| 52 void SetTranslate(float x, float y); | 50 void SetTranslate(float x, float y); |
| 53 | 51 |
| 54 // Creates a perspective matrix. | 52 // Creates a perspective matrix. |
| 55 // Based on the 'perspective' operation from | 53 // Based on the 'perspective' operation from |
| 56 // http://www.w3.org/TR/css3-3d-transforms/#transform-functions | 54 // http://www.w3.org/TR/css3-3d-transforms/#transform-functions |
| 57 void SetPerspectiveDepth(float depth); | 55 void SetPerspectiveDepth(float depth); |
| 58 | 56 |
| 59 // Applies a rotation on the current transformation. | 57 // Applies a rotation on the current transformation. |
| 60 void ConcatRotate(float degree); | 58 void ConcatRotate(float degree); |
| 61 | 59 |
| 62 // Applies an axis-angle rotation on the current transformation. | 60 // Applies an axis-angle rotation on the current transformation. |
| 63 void ConcatRotateAbout(const gfx::Point3f& point, float degree); | 61 void ConcatRotateAbout(const Point3f& point, float degree); |
| 64 | 62 |
| 65 // Applies scaling on current transform. | 63 // Applies scaling on current transform. |
| 66 void ConcatScale(float x, float y); | 64 void ConcatScale(float x, float y); |
| 67 | 65 |
| 68 // Applies translation on current transform. | 66 // Applies translation on current transform. |
| 69 void ConcatTranslate(float x, float y); | 67 void ConcatTranslate(float x, float y); |
| 70 | 68 |
| 71 // Applies a transformation on the current transformation | 69 // Applies a transformation on the current transformation |
| 72 // (i.e. 'this = this * transform;'). | 70 // (i.e. 'this = this * transform;'). |
| 73 void PreconcatTransform(const Transform& transform); | 71 void PreconcatTransform(const Transform& transform); |
| 74 | 72 |
| 75 // Applies a transformation on the current transformation | 73 // Applies a transformation on the current transformation |
| 76 // (i.e. 'this = transform * this;'). | 74 // (i.e. 'this = transform * this;'). |
| 77 void ConcatTransform(const Transform& transform); | 75 void ConcatTransform(const Transform& transform); |
| 78 | 76 |
| 79 // Does the transformation change anything? | 77 // Does the transformation change anything? |
| 80 bool HasChange() const; | 78 bool HasChange() const; |
| 81 | 79 |
| 82 // Inverts the transform which is passed in. Returns true if successful. | 80 // Inverts the transform which is passed in. Returns true if successful. |
| 83 bool GetInverse(Transform* transform) const; | 81 bool GetInverse(Transform* transform) const; |
| 84 | 82 |
| 85 // Applies the transformation on the point. Returns true if the point is | 83 // Applies the transformation on the point. Returns true if the point is |
| 86 // transformed successfully. | 84 // transformed successfully. |
| 87 void TransformPoint(gfx::Point3f& point) const; | 85 void TransformPoint(Point3f& point) const; |
| 88 | 86 |
| 89 // Applies the transformation on the point. Returns true if the point is | 87 // Applies the transformation on the point. Returns true if the point is |
| 90 // transformed successfully. Rounds the result to the nearest point. | 88 // transformed successfully. Rounds the result to the nearest point. |
| 91 void TransformPoint(gfx::Point& point) const; | 89 void TransformPoint(Point& point) const; |
| 92 | 90 |
| 93 // Applies the reverse transformation on the point. Returns true if the | 91 // Applies the reverse transformation on the point. Returns true if the |
| 94 // transformation can be inverted. | 92 // transformation can be inverted. |
| 95 bool TransformPointReverse(gfx::Point3f& point) const; | 93 bool TransformPointReverse(Point3f& point) const; |
| 96 | 94 |
| 97 // Applies the reverse transformation on the point. Returns true if the | 95 // Applies the reverse transformation on the point. Returns true if the |
| 98 // transformation can be inverted. Rounds the result to the nearest point. | 96 // transformation can be inverted. Rounds the result to the nearest point. |
| 99 bool TransformPointReverse(gfx::Point& point) const; | 97 bool TransformPointReverse(Point& point) const; |
| 100 | 98 |
| 101 // Applies transformation on the rectangle. Returns true if the transformed | 99 // Applies transformation on the rectangle. Returns true if the transformed |
| 102 // rectangle was axis aligned. If it returns false, rect will be the | 100 // rectangle was axis aligned. If it returns false, rect will be the |
| 103 // smallest axis aligned bounding box containing the transformed rect. | 101 // smallest axis aligned bounding box containing the transformed rect. |
| 104 void TransformRect(gfx::Rect* rect) const; | 102 void TransformRect(Rect* rect) const; |
| 105 | 103 |
| 106 // Applies the reverse transformation on the rectangle. Returns true if | 104 // Applies the reverse transformation on the rectangle. Returns true if |
| 107 // the transformed rectangle was axis aligned. If it returns false, | 105 // the transformed rectangle was axis aligned. If it returns false, |
| 108 // rect will be the smallest axis aligned bounding box containing the | 106 // rect will be the smallest axis aligned bounding box containing the |
| 109 // transformed rect. | 107 // transformed rect. |
| 110 bool TransformRectReverse(gfx::Rect* rect) const; | 108 bool TransformRectReverse(Rect* rect) const; |
| 111 | 109 |
| 112 // Returns the underlying matrix. | 110 // Returns the underlying matrix. |
| 113 const SkMatrix44& matrix() const { return matrix_; } | 111 const SkMatrix44& matrix() const { return matrix_; } |
| 114 SkMatrix44& matrix() { return matrix_; } | 112 SkMatrix44& matrix() { return matrix_; } |
| 115 | 113 |
| 116 private: | 114 private: |
| 117 void TransformPointInternal(const SkMatrix44& xform, | 115 void TransformPointInternal(const SkMatrix44& xform, |
| 118 gfx::Point& point) const; | 116 Point& point) const; |
| 119 | 117 |
| 120 void TransformPointInternal(const SkMatrix44& xform, | 118 void TransformPointInternal(const SkMatrix44& xform, |
| 121 gfx::Point3f& point) const; | 119 Point3f& point) const; |
| 122 | 120 |
| 123 SkMatrix44 matrix_; | 121 SkMatrix44 matrix_; |
| 124 | 122 |
| 125 // copy/assign are allowed. | 123 // copy/assign are allowed. |
| 126 }; | 124 }; |
| 127 | 125 |
| 128 }// namespace ui | 126 } // namespace gfx |
| 129 | 127 |
| 130 #endif // UI_GFX_TRANSFORM_H_ | 128 #endif // UI_GFX_TRANSFORM_H_ |
| OLD | NEW |