[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 | |
| 9 | namespace gfx { |
| 10 | class Point; |
| 11 | class Rect; |
| 12 | } |
| 13 | |
| 14 | namespace ui { |
| 15 | |
| 16 | // Transformation interface. |
| 17 | // Classes implement this interface to apply transformations (e.g. rotation, |
| 18 | // scaling etc.) on UI components. |
| 19 | class Transform { |
| 20 | public: |
[email protected] | a2aa155 | 2011-02-25 04:00:16 | [diff] [blame] | 21 | virtual ~Transform() {} |
| 22 | |
[email protected] | 59808008 | 2011-04-14 19:36:33 | [diff] [blame] | 23 | // Creates an object that implements this interface (e.g. using skia |
[email protected] | 36df22b | 2011-02-24 21:47:56 | [diff] [blame] | 24 | // transformation matrices). |
| 25 | static Transform* Create(); |
| 26 | |
[email protected] | 59808008 | 2011-04-14 19:36:33 | [diff] [blame] | 27 | // NOTE: The 'Set' functions overwrite the previously set transformation |
| 28 | // parameters. The 'Concat' functions apply a transformation (e.g. rotation, |
| 29 | // scale, translate) on top of the existing transforms, instead of overwriting |
| 30 | // them. |
| 31 | |
| 32 | // NOTE: The order of the 'Set' function calls do not matter. However, the |
| 33 | // order of the 'Concat' function calls do matter, especially when combined |
| 34 | // with the 'Set' functions. |
| 35 | |
| 36 | // Sets the rotation of the transformation. |
[email protected] | 36df22b | 2011-02-24 21:47:56 | [diff] [blame] | 37 | virtual void SetRotate(float degree) = 0; |
| 38 | |
[email protected] | 59808008 | 2011-04-14 19:36:33 | [diff] [blame] | 39 | // Sets the scaling parameters. |
[email protected] | 36df22b | 2011-02-24 21:47:56 | [diff] [blame] | 40 | virtual void SetScaleX(float x) = 0; |
| 41 | virtual void SetScaleY(float y) = 0; |
| 42 | virtual void SetScale(float x, float y) = 0; |
| 43 | |
[email protected] | 59808008 | 2011-04-14 19:36:33 | [diff] [blame] | 44 | // Sets the translation parameters. |
[email protected] | 36df22b | 2011-02-24 21:47:56 | [diff] [blame] | 45 | virtual void SetTranslateX(float x) = 0; |
| 46 | virtual void SetTranslateY(float y) = 0; |
| 47 | virtual void SetTranslate(float x, float y) = 0; |
| 48 | |
[email protected] | 59808008 | 2011-04-14 19:36:33 | [diff] [blame] | 49 | // Applies rotation on the current transformation. |
[email protected] | 36df22b | 2011-02-24 21:47:56 | [diff] [blame] | 50 | virtual void ConcatRotate(float degree) = 0; |
| 51 | |
[email protected] | 59808008 | 2011-04-14 19:36:33 | [diff] [blame] | 52 | // Applies scaling on current transform. |
[email protected] | 36df22b | 2011-02-24 21:47:56 | [diff] [blame] | 53 | virtual void ConcatScale(float x, float y) = 0; |
| 54 | |
[email protected] | 59808008 | 2011-04-14 19:36:33 | [diff] [blame] | 55 | // Applies translation on current transform. |
[email protected] | 36df22b | 2011-02-24 21:47:56 | [diff] [blame] | 56 | virtual void ConcatTranslate(float x, float y) = 0; |
| 57 | |
[email protected] | 59808008 | 2011-04-14 19:36:33 | [diff] [blame] | 58 | // Applies a transformation on the current transformation |
| 59 | // (i.e. 'this = this * transform;'). Returns true if the result can be |
| 60 | // represented. |
[email protected] | 36df22b | 2011-02-24 21:47:56 | [diff] [blame] | 61 | virtual bool ConcatTransform(const Transform& transform) = 0; |
| 62 | |
| 63 | // Does the transformation change anything? |
| 64 | virtual bool HasChange() const = 0; |
| 65 | |
[email protected] | 59808008 | 2011-04-14 19:36:33 | [diff] [blame] | 66 | // Applies the transformation on the point. Returns true if the point is |
| 67 | // transformed successfully. |
[email protected] | 36df22b | 2011-02-24 21:47:56 | [diff] [blame] | 68 | virtual bool TransformPoint(gfx::Point* point) = 0; |
| 69 | |
[email protected] | 59808008 | 2011-04-14 19:36:33 | [diff] [blame] | 70 | // Applies the reverse transformation on the point. Returns true if the point |
| 71 | // is transformed successfully. |
[email protected] | 36df22b | 2011-02-24 21:47:56 | [diff] [blame] | 72 | virtual bool TransformPointReverse(gfx::Point* point) = 0; |
| 73 | |
[email protected] | 59808008 | 2011-04-14 19:36:33 | [diff] [blame] | 74 | // Applies transformation on the rectangle. Returns true of the rectangle is |
| 75 | // transformed successfully. |
[email protected] | 36df22b | 2011-02-24 21:47:56 | [diff] [blame] | 76 | virtual bool TransformRect(gfx::Rect* rect) = 0; |
[email protected] | 463eb0e | 2011-05-10 03:11:04 | [diff] [blame^] | 77 | |
| 78 | // operator=. |
| 79 | virtual void Copy(const Transform& transform) = 0; |
[email protected] | 36df22b | 2011-02-24 21:47:56 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | } // namespace ui |
| 83 | |
| 84 | #endif // UI_GFX_TRANSFORM_H_ |