blob: 1482fb7e9c85c1e1b4996e0ae1ba33e5caa2d09e [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
[email protected]80248e32011-07-08 15:31:119#include "third_party/skia/include/utils/SkMatrix44.h"
[email protected]b9b1e7a42011-05-17 15:29:5110
[email protected]36df22b2011-02-24 21:47:5611namespace gfx {
[email protected]36df22b2011-02-24 21:47:5612class Rect;
[email protected]80248e32011-07-08 15:31:1113class Point;
14class Point3f;
[email protected]36df22b2011-02-24 21:47:5615}
16
17namespace ui {
18
[email protected]80248e32011-07-08 15:31:1119// 4x4 transformation matrix. Transform is cheap and explicitly allows
[email protected]b9b1e7a42011-05-17 15:29:5120// copy/assign.
[email protected]36df22b2011-02-24 21:47:5621class Transform {
22 public:
[email protected]b9b1e7a42011-05-17 15:29:5123 Transform();
24 ~Transform();
[email protected]36df22b2011-02-24 21:47:5625
[email protected]80248e32011-07-08 15:31:1126 bool operator==(const Transform& rhs) const;
27 bool operator!=(const Transform& rhs) const;
28
[email protected]598080082011-04-14 19:36:3329 // NOTE: The 'Set' functions overwrite the previously set transformation
30 // parameters. The 'Concat' functions apply a transformation (e.g. rotation,
31 // scale, translate) on top of the existing transforms, instead of overwriting
32 // them.
33
34 // 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
36 // with the 'Set' functions.
37
38 // Sets the rotation of the transformation.
[email protected]b9b1e7a42011-05-17 15:29:5139 void SetRotate(float degree);
[email protected]36df22b2011-02-24 21:47:5640
[email protected]598080082011-04-14 19:36:3341 // Sets the scaling parameters.
[email protected]b9b1e7a42011-05-17 15:29:5142 void SetScaleX(float x);
43 void SetScaleY(float y);
44 void SetScale(float x, float y);
[email protected]36df22b2011-02-24 21:47:5645
[email protected]598080082011-04-14 19:36:3346 // Sets the translation parameters.
[email protected]b9b1e7a42011-05-17 15:29:5147 void SetTranslateX(float x);
48 void SetTranslateY(float y);
49 void SetTranslate(float x, float y);
[email protected]36df22b2011-02-24 21:47:5650
[email protected]598080082011-04-14 19:36:3351 // Applies rotation on the current transformation.
[email protected]b9b1e7a42011-05-17 15:29:5152 void ConcatRotate(float degree);
[email protected]36df22b2011-02-24 21:47:5653
[email protected]598080082011-04-14 19:36:3354 // Applies scaling on current transform.
[email protected]b9b1e7a42011-05-17 15:29:5155 void ConcatScale(float x, float y);
[email protected]36df22b2011-02-24 21:47:5656
[email protected]598080082011-04-14 19:36:3357 // Applies translation on current transform.
[email protected]b9b1e7a42011-05-17 15:29:5158 void ConcatTranslate(float x, float y);
59
60 // Applies a transformation on the current transformation
[email protected]80248e32011-07-08 15:31:1161 // (i.e. 'this = this * transform;').
62 void PreconcatTransform(const Transform& transform);
[email protected]36df22b2011-02-24 21:47:5663
[email protected]598080082011-04-14 19:36:3364 // Applies a transformation on the current transformation
[email protected]80248e32011-07-08 15:31:1165 // (i.e. 'this = transform * this;').
66 void ConcatTransform(const Transform& transform);
[email protected]36df22b2011-02-24 21:47:5667
68 // Does the transformation change anything?
[email protected]b9b1e7a42011-05-17 15:29:5169 bool HasChange() const;
[email protected]36df22b2011-02-24 21:47:5670
[email protected]598080082011-04-14 19:36:3371 // Applies the transformation on the point. Returns true if the point is
72 // transformed successfully.
[email protected]80248e32011-07-08 15:31:1173 void TransformPoint(gfx::Point3f& point) const;
[email protected]36df22b2011-02-24 21:47:5674
[email protected]80248e32011-07-08 15:31:1175 // Applies the transformation on the point. Returns true if the point is
76 // transformed successfully. Rounds the result to the nearest point.
77 void TransformPoint(gfx::Point& point) const;
[email protected]36df22b2011-02-24 21:47:5678
[email protected]80248e32011-07-08 15:31:1179 // Applies the reverse transformation on the point. Returns true if the
80 // transformation can be inverted.
81 bool TransformPointReverse(gfx::Point3f& point) const;
[email protected]463eb0e2011-05-10 03:11:0482
[email protected]80248e32011-07-08 15:31:1183 // Applies the reverse transformation on the point. Returns true if the
84 // transformation can be inverted. Rounds the result to the nearest point.
85 bool TransformPointReverse(gfx::Point& point) const;
86
87 // Applies transformation on the rectangle. Returns true if the transformed
88 // rectangle was axis aligned. If it returns false, rect will be the
89 // smallest axis aligned bounding box containg the transformed rect.
90 void TransformRect(gfx::Rect* rect) const;
91
92 // Applies the reverse transformation on the rectangle. Returns true if
93 // the transformed rectangle was axis aligned. If it returns false,
94 // rect will be the smallest axis aligned bounding box containg the
95 // transformed rect.
[email protected]3d19a532011-06-17 17:19:5096 bool TransformRectReverse(gfx::Rect* rect) const;
[email protected]277c7b72011-06-06 15:23:0997
[email protected]b9b1e7a42011-05-17 15:29:5198 // Returns the underlying matrix.
[email protected]80248e32011-07-08 15:31:1199 const SkMatrix44& matrix() const { return matrix_; }
100 SkMatrix44& matrix() { return matrix_; }
[email protected]b9b1e7a42011-05-17 15:29:51101
102 private:
[email protected]80248e32011-07-08 15:31:11103 void TransformPointInternal(const SkMatrix44& xform,
104 gfx::Point& point) const;
105
106 void TransformPointInternal(const SkMatrix44& xform,
107 gfx::Point3f& point) const;
108
109 SkMatrix44 matrix_;
[email protected]b9b1e7a42011-05-17 15:29:51110
111 // copy/assign are allowed.
[email protected]36df22b2011-02-24 21:47:56112};
113
[email protected]80248e32011-07-08 15:31:11114}// namespace ui
[email protected]36df22b2011-02-24 21:47:56115
116#endif // UI_GFX_TRANSFORM_H_