blob: ce3fb67ed38ca11c7de11fc9a940d1fd8a66e780 [file] [log] [blame]
[email protected]36df22b2011-02-24 21:47:561// 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
9namespace gfx {
10class Point;
11class Rect;
12}
13
14namespace ui {
15
16// Transformation interface.
17// Classes implement this interface to apply transformations (e.g. rotation,
18// scaling etc.) on UI components.
19class Transform {
20 public:
[email protected]a2aa1552011-02-25 04:00:1621 virtual ~Transform() {}
22
[email protected]598080082011-04-14 19:36:3323 // Creates an object that implements this interface (e.g. using skia
[email protected]36df22b2011-02-24 21:47:5624 // transformation matrices).
25 static Transform* Create();
26
[email protected]598080082011-04-14 19:36:3327 // 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]36df22b2011-02-24 21:47:5637 virtual void SetRotate(float degree) = 0;
38
[email protected]598080082011-04-14 19:36:3339 // Sets the scaling parameters.
[email protected]36df22b2011-02-24 21:47:5640 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]598080082011-04-14 19:36:3344 // Sets the translation parameters.
[email protected]36df22b2011-02-24 21:47:5645 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]598080082011-04-14 19:36:3349 // Applies rotation on the current transformation.
[email protected]36df22b2011-02-24 21:47:5650 virtual void ConcatRotate(float degree) = 0;
51
[email protected]598080082011-04-14 19:36:3352 // Applies scaling on current transform.
[email protected]36df22b2011-02-24 21:47:5653 virtual void ConcatScale(float x, float y) = 0;
54
[email protected]598080082011-04-14 19:36:3355 // Applies translation on current transform.
[email protected]36df22b2011-02-24 21:47:5656 virtual void ConcatTranslate(float x, float y) = 0;
57
[email protected]598080082011-04-14 19:36:3358 // Applies a transformation on the current transformation
59 // (i.e. 'this = this * transform;'). Returns true if the result can be
60 // represented.
[email protected]36df22b2011-02-24 21:47:5661 virtual bool ConcatTransform(const Transform& transform) = 0;
62
63 // Does the transformation change anything?
64 virtual bool HasChange() const = 0;
65
[email protected]598080082011-04-14 19:36:3366 // Applies the transformation on the point. Returns true if the point is
67 // transformed successfully.
[email protected]36df22b2011-02-24 21:47:5668 virtual bool TransformPoint(gfx::Point* point) = 0;
69
[email protected]598080082011-04-14 19:36:3370 // Applies the reverse transformation on the point. Returns true if the point
71 // is transformed successfully.
[email protected]36df22b2011-02-24 21:47:5672 virtual bool TransformPointReverse(gfx::Point* point) = 0;
73
[email protected]598080082011-04-14 19:36:3374 // Applies transformation on the rectangle. Returns true of the rectangle is
75 // transformed successfully.
[email protected]36df22b2011-02-24 21:47:5676 virtual bool TransformRect(gfx::Rect* rect) = 0;
[email protected]463eb0e2011-05-10 03:11:0477
78 // operator=.
79 virtual void Copy(const Transform& transform) = 0;
[email protected]36df22b2011-02-24 21:47:5680};
81
82} // namespace ui
83
84#endif // UI_GFX_TRANSFORM_H_