[email protected] | 36df22b | 2011-02-24 21:47:56 | [diff] [blame] | 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 | ||||
3 | // found in the LICENSE file. | ||||
4 | |||||
5 | #ifndef UI_GFX_TRANSFORM_H_ | ||||
6 | #define UI_GFX_TRANSFORM_H_ | ||||
7 | #pragma once | ||||
8 | |||||
[email protected] | b9b1e7a4 | 2011-05-17 15:29:51 | [diff] [blame^] | 9 | #include "base/basictypes.h" |
10 | #include "base/compiler_specific.h" | ||||
11 | #include "third_party/skia/include/core/SkMatrix.h" | ||||
12 | |||||
[email protected] | 36df22b | 2011-02-24 21:47:56 | [diff] [blame] | 13 | namespace gfx { |
14 | class Point; | ||||
15 | class Rect; | ||||
16 | } | ||||
17 | |||||
18 | namespace ui { | ||||
19 | |||||
[email protected] | b9b1e7a4 | 2011-05-17 15:29:51 | [diff] [blame^] | 20 | // 3x3 transformation matrix. Transform is cheap and explicitly allows |
21 | // copy/assign. | ||||
22 | // TODO: make this a 4x4. | ||||
[email protected] | 36df22b | 2011-02-24 21:47:56 | [diff] [blame] | 23 | class Transform { |
24 | public: | ||||
[email protected] | b9b1e7a4 | 2011-05-17 15:29:51 | [diff] [blame^] | 25 | Transform(); |
26 | ~Transform(); | ||||
[email protected] | 36df22b | 2011-02-24 21:47:56 | [diff] [blame] | 27 | |
[email protected] | 59808008 | 2011-04-14 19:36:33 | [diff] [blame] | 28 | // NOTE: The 'Set' functions overwrite the previously set transformation |
29 | // parameters. The 'Concat' functions apply a transformation (e.g. rotation, | ||||
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. | ||||
[email protected] | b9b1e7a4 | 2011-05-17 15:29:51 | [diff] [blame^] | 38 | void SetRotate(float degree); |
[email protected] | 36df22b | 2011-02-24 21:47:56 | [diff] [blame] | 39 | |
[email protected] | 59808008 | 2011-04-14 19:36:33 | [diff] [blame] | 40 | // Sets the scaling parameters. |
[email protected] | b9b1e7a4 | 2011-05-17 15:29:51 | [diff] [blame^] | 41 | void SetScaleX(float x); |
42 | void SetScaleY(float y); | ||||
43 | void SetScale(float x, float y); | ||||
[email protected] | 36df22b | 2011-02-24 21:47:56 | [diff] [blame] | 44 | |
[email protected] | 59808008 | 2011-04-14 19:36:33 | [diff] [blame] | 45 | // Sets the translation parameters. |
[email protected] | b9b1e7a4 | 2011-05-17 15:29:51 | [diff] [blame^] | 46 | void SetTranslateX(float x); |
47 | void SetTranslateY(float y); | ||||
48 | void SetTranslate(float x, float y); | ||||
[email protected] | 36df22b | 2011-02-24 21:47:56 | [diff] [blame] | 49 | |
[email protected] | 59808008 | 2011-04-14 19:36:33 | [diff] [blame] | 50 | // Applies rotation on the current transformation. |
[email protected] | b9b1e7a4 | 2011-05-17 15:29:51 | [diff] [blame^] | 51 | void ConcatRotate(float degree); |
[email protected] | 36df22b | 2011-02-24 21:47:56 | [diff] [blame] | 52 | |
[email protected] | 59808008 | 2011-04-14 19:36:33 | [diff] [blame] | 53 | // Applies scaling on current transform. |
[email protected] | b9b1e7a4 | 2011-05-17 15:29:51 | [diff] [blame^] | 54 | void ConcatScale(float x, float y); |
[email protected] | 36df22b | 2011-02-24 21:47:56 | [diff] [blame] | 55 | |
[email protected] | 59808008 | 2011-04-14 19:36:33 | [diff] [blame] | 56 | // Applies translation on current transform. |
[email protected] | b9b1e7a4 | 2011-05-17 15:29:51 | [diff] [blame^] | 57 | void ConcatTranslate(float x, float y); |
58 | |||||
59 | // Applies a transformation on the current transformation | ||||
60 | // (i.e. 'this = transform * this;'). Returns true if the result can be | ||||
61 | // represented. | ||||
62 | bool PreconcatTransform(const Transform& transform); | ||||
[email protected] | 36df22b | 2011-02-24 21:47:56 | [diff] [blame] | 63 | |
[email protected] | 59808008 | 2011-04-14 19:36:33 | [diff] [blame] | 64 | // Applies a transformation on the current transformation |
65 | // (i.e. 'this = this * transform;'). Returns true if the result can be | ||||
66 | // represented. | ||||
[email protected] | b9b1e7a4 | 2011-05-17 15:29:51 | [diff] [blame^] | 67 | bool ConcatTransform(const Transform& transform); |
[email protected] | 36df22b | 2011-02-24 21:47:56 | [diff] [blame] | 68 | |
69 | // Does the transformation change anything? | ||||
[email protected] | b9b1e7a4 | 2011-05-17 15:29:51 | [diff] [blame^] | 70 | bool HasChange() const; |
[email protected] | 36df22b | 2011-02-24 21:47:56 | [diff] [blame] | 71 | |
[email protected] | 59808008 | 2011-04-14 19:36:33 | [diff] [blame] | 72 | // Applies the transformation on the point. Returns true if the point is |
73 | // transformed successfully. | ||||
[email protected] | b9b1e7a4 | 2011-05-17 15:29:51 | [diff] [blame^] | 74 | bool TransformPoint(gfx::Point* point); |
[email protected] | 36df22b | 2011-02-24 21:47:56 | [diff] [blame] | 75 | |
[email protected] | 59808008 | 2011-04-14 19:36:33 | [diff] [blame] | 76 | // Applies the reverse transformation on the point. Returns true if the point |
77 | // is transformed successfully. | ||||
[email protected] | b9b1e7a4 | 2011-05-17 15:29:51 | [diff] [blame^] | 78 | bool TransformPointReverse(gfx::Point* point); |
[email protected] | 36df22b | 2011-02-24 21:47:56 | [diff] [blame] | 79 | |
[email protected] | 59808008 | 2011-04-14 19:36:33 | [diff] [blame] | 80 | // Applies transformation on the rectangle. Returns true of the rectangle is |
81 | // transformed successfully. | ||||
[email protected] | b9b1e7a4 | 2011-05-17 15:29:51 | [diff] [blame^] | 82 | bool TransformRect(gfx::Rect* rect); |
[email protected] | 463eb0e | 2011-05-10 03:11:04 | [diff] [blame] | 83 | |
[email protected] | b9b1e7a4 | 2011-05-17 15:29:51 | [diff] [blame^] | 84 | // Returns the underlying matrix. |
85 | const SkMatrix& matrix() const { return matrix_; } | ||||
86 | |||||
87 | private: | ||||
88 | SkMatrix matrix_; | ||||
89 | |||||
90 | // copy/assign are allowed. | ||||
[email protected] | 36df22b | 2011-02-24 21:47:56 | [diff] [blame] | 91 | }; |
92 | |||||
93 | } // namespace ui | ||||
94 | |||||
95 | #endif // UI_GFX_TRANSFORM_H_ |