Chromium Code Reviews| 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 "base/basictypes.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "third_party/skia/include/core/SkMatrix.h" | 11 #include "third_party/skia/experimental/SkMatrix44.h" |
| 12 | 12 |
| 13 namespace gfx { | 13 namespace gfx { |
| 14 class Point; | 14 class Point; |
| 15 class Rect; | 15 class Rect; |
| 16 } | 16 } |
| 17 | 17 |
| 18 namespace ui { | 18 namespace ui { |
| 19 | 19 |
| 20 // 3x3 transformation matrix. Transform is cheap and explicitly allows | 20 // 4x4 transformation matrix. Transform is cheap and explicitly allows |
| 21 // copy/assign. | 21 // copy/assign. |
| 22 // TODO: make this a 4x4. | |
| 23 class Transform { | 22 class Transform { |
| 24 public: | 23 public: |
| 25 Transform(); | 24 Transform(); |
| 26 ~Transform(); | 25 ~Transform(); |
| 27 | 26 |
| 28 // NOTE: The 'Set' functions overwrite the previously set transformation | 27 // NOTE: The 'Set' functions overwrite the previously set transformation |
| 29 // parameters. The 'Concat' functions apply a transformation (e.g. rotation, | 28 // parameters. The 'Concat' functions apply a transformation (e.g. rotation, |
| 30 // scale, translate) on top of the existing transforms, instead of overwriting | 29 // scale, translate) on top of the existing transforms, instead of overwriting |
| 31 // them. | 30 // them. |
| 32 | 31 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 50 // Applies rotation on the current transformation. | 49 // Applies rotation on the current transformation. |
| 51 void ConcatRotate(float degree); | 50 void ConcatRotate(float degree); |
| 52 | 51 |
| 53 // Applies scaling on current transform. | 52 // Applies scaling on current transform. |
| 54 void ConcatScale(float x, float y); | 53 void ConcatScale(float x, float y); |
| 55 | 54 |
| 56 // Applies translation on current transform. | 55 // Applies translation on current transform. |
| 57 void ConcatTranslate(float x, float y); | 56 void ConcatTranslate(float x, float y); |
| 58 | 57 |
| 59 // Applies a transformation on the current transformation | 58 // Applies a transformation on the current transformation |
| 60 // (i.e. 'this = this * transform;'). Returns true if the result can be | 59 // (i.e. 'this = this * transform;'). |
| 61 // represented. | 60 void PreconcatTransform(const Transform& transform); |
| 62 bool PreconcatTransform(const Transform& transform); | |
| 63 | 61 |
| 64 // Applies a transformation on the current transformation | 62 // Applies a transformation on the current transformation |
| 65 // (i.e. 'this = transform * this;'). Returns true if the result can be | 63 // (i.e. 'this = transform * this;'). |
| 66 // represented. | 64 void ConcatTransform(const Transform& transform); |
| 67 bool ConcatTransform(const Transform& transform); | |
| 68 | 65 |
| 69 // Does the transformation change anything? | 66 // Does the transformation change anything? |
| 70 bool HasChange() const; | 67 bool HasChange() const; |
| 71 | 68 |
| 72 // Applies the transformation on the point. Returns true if the point is | 69 // Applies the transformation on the point. Returns true if the point is |
| 73 // transformed successfully. | 70 // transformed successfully. |
| 74 bool TransformPoint(gfx::Point* point); | 71 void TransformPoint(gfx::Point* point); |
| 75 | 72 |
| 76 // Applies the reverse transformation on the point. Returns true if the point | 73 // Applies the reverse transformation on the point. Returns true if the |
| 77 // is transformed successfully. | 74 // transformation can be inverted |
| 78 bool TransformPointReverse(gfx::Point* point); | 75 bool TransformPointReverse(gfx::Point* point); |
| 79 | 76 |
| 80 // Applies transformation on the rectangle. Returns true if the rectangle is | 77 // Applies transformation on the rectangle. Returns true if the rectangle is |
| 81 // transformed successfully. | 78 // transformed successfully. |
| 82 bool TransformRect(gfx::Rect* rect); | 79 bool TransformRect(gfx::Rect* rect); |
| 83 | 80 |
| 84 // Applies the reverse transformation on the rectangle. Returns true if the | 81 // Applies the reverse transformation on the rectangle. Returns true if the |
| 85 // rectangle is transformed successfully. | 82 // rectangle is transformed successfully. |
| 86 bool TransformRectReverse(gfx::Rect* rect); | 83 bool TransformRectReverse(gfx::Rect* rect); |
| 87 | 84 |
| 88 // Returns the underlying matrix. | 85 // Returns the underlying matrix. |
| 89 const SkMatrix& matrix() const { return matrix_; } | 86 const SkMatrix44& matrix() const { return matrix_; } |
| 90 | 87 |
| 91 private: | 88 private: |
| 92 SkMatrix matrix_; | 89 void TransformPointInternal(const SkMatrix44& xform, gfx::Point* point); |
| 90 bool ComputeInverse(); | |
| 91 SkMatrix44 matrix_; | |
|
sky
2011/06/09 17:20:29
newline between 90 and 91.
| |
| 92 SkMatrix44 inverse_; | |
| 93 bool hasInverse_; | |
| 93 | 94 |
| 94 // copy/assign are allowed. | 95 // copy/assign are allowed. |
| 95 }; | 96 }; |
| 96 | 97 |
| 97 } // namespace ui | 98 } // namespace ui |
| 98 | 99 |
| 99 #endif // UI_GFX_TRANSFORM_H_ | 100 #endif // UI_GFX_TRANSFORM_H_ |
| OLD | NEW |