blob: 893e4cde038eee9e2824b3be65f1175772f95859 [file] [log] [blame]
[email protected]3c2196b22012-03-17 03:42:251// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]36df22b2011-02-24 21:47:562// 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]507bad52011-08-06 04:51:0710#include "ui/base/ui_export.h"
[email protected]b9b1e7a42011-05-17 15:29:5111
[email protected]36df22b2011-02-24 21:47:5612namespace gfx {
[email protected]36df22b2011-02-24 21:47:5613class Rect;
[email protected]80248e32011-07-08 15:31:1114class Point;
15class Point3f;
[email protected]36df22b2011-02-24 21:47:5616}
17
18namespace ui {
19
[email protected]80248e32011-07-08 15:31:1120// 4x4 transformation matrix. Transform is cheap and explicitly allows
[email protected]b9b1e7a42011-05-17 15:29:5121// copy/assign.
[email protected]507bad52011-08-06 04:51:0722class UI_EXPORT Transform {
[email protected]36df22b2011-02-24 21:47:5623 public:
[email protected]b9b1e7a42011-05-17 15:29:5124 Transform();
25 ~Transform();
[email protected]36df22b2011-02-24 21:47:5626
[email protected]80248e32011-07-08 15:31:1127 bool operator==(const Transform& rhs) const;
28 bool operator!=(const Transform& rhs) const;
29
[email protected]598080082011-04-14 19:36:3330 // NOTE: The 'Set' functions overwrite the previously set transformation
31 // parameters. The 'Concat' functions apply a transformation (e.g. rotation,
32 // scale, translate) on top of the existing transforms, instead of overwriting
33 // them.
34
35 // NOTE: The order of the 'Set' function calls do not matter. However, the
36 // order of the 'Concat' function calls do matter, especially when combined
37 // with the 'Set' functions.
38
39 // Sets the rotation of the transformation.
[email protected]b9b1e7a42011-05-17 15:29:5140 void SetRotate(float degree);
[email protected]36df22b2011-02-24 21:47:5641
[email protected]3c2196b22012-03-17 03:42:2542 // Sets the rotation of the transform (about a vector).
43 void SetRotateAbout(const gfx::Point3f& point, float degree);
44
[email protected]598080082011-04-14 19:36:3345 // Sets the scaling parameters.
[email protected]b9b1e7a42011-05-17 15:29:5146 void SetScaleX(float x);
47 void SetScaleY(float y);
48 void SetScale(float x, float y);
[email protected]36df22b2011-02-24 21:47:5649
[email protected]598080082011-04-14 19:36:3350 // Sets the translation parameters.
[email protected]b9b1e7a42011-05-17 15:29:5151 void SetTranslateX(float x);
52 void SetTranslateY(float y);
53 void SetTranslate(float x, float y);
[email protected]36df22b2011-02-24 21:47:5654
[email protected]9dc5f9d2012-05-14 19:28:0155 // Creates a perspective matrix.
56 // Based on the 'perspective' operation from
57 // http://www.w3.org/TR/css3-3d-transforms/#transform-functions
58 void SetPerspectiveDepth(float depth);
59
[email protected]3c2196b22012-03-17 03:42:2560 // Applies a rotation on the current transformation.
[email protected]b9b1e7a42011-05-17 15:29:5161 void ConcatRotate(float degree);
[email protected]36df22b2011-02-24 21:47:5662
[email protected]3c2196b22012-03-17 03:42:2563 // Applies an axis-angle rotation on the current transformation.
64 void ConcatRotateAbout(const gfx::Point3f& point, float degree);
65
[email protected]598080082011-04-14 19:36:3366 // Applies scaling on current transform.
[email protected]b9b1e7a42011-05-17 15:29:5167 void ConcatScale(float x, float y);
[email protected]36df22b2011-02-24 21:47:5668
[email protected]598080082011-04-14 19:36:3369 // Applies translation on current transform.
[email protected]b9b1e7a42011-05-17 15:29:5170 void ConcatTranslate(float x, float y);
71
72 // Applies a transformation on the current transformation
[email protected]80248e32011-07-08 15:31:1173 // (i.e. 'this = this * transform;').
74 void PreconcatTransform(const Transform& transform);
[email protected]36df22b2011-02-24 21:47:5675
[email protected]598080082011-04-14 19:36:3376 // Applies a transformation on the current transformation
[email protected]80248e32011-07-08 15:31:1177 // (i.e. 'this = transform * this;').
78 void ConcatTransform(const Transform& transform);
[email protected]36df22b2011-02-24 21:47:5679
80 // Does the transformation change anything?
[email protected]b9b1e7a42011-05-17 15:29:5181 bool HasChange() const;
[email protected]36df22b2011-02-24 21:47:5682
[email protected]38919392011-10-24 22:26:2383 // Inverts the transform which is passed in. Returns true if successful.
84 bool GetInverse(Transform* transform) const;
85
[email protected]598080082011-04-14 19:36:3386 // Applies the transformation on the point. Returns true if the point is
87 // transformed successfully.
[email protected]80248e32011-07-08 15:31:1188 void TransformPoint(gfx::Point3f& point) const;
[email protected]36df22b2011-02-24 21:47:5689
[email protected]80248e32011-07-08 15:31:1190 // Applies the transformation on the point. Returns true if the point is
91 // transformed successfully. Rounds the result to the nearest point.
92 void TransformPoint(gfx::Point& point) const;
[email protected]36df22b2011-02-24 21:47:5693
[email protected]80248e32011-07-08 15:31:1194 // Applies the reverse transformation on the point. Returns true if the
95 // transformation can be inverted.
96 bool TransformPointReverse(gfx::Point3f& point) const;
[email protected]463eb0e2011-05-10 03:11:0497
[email protected]80248e32011-07-08 15:31:1198 // Applies the reverse transformation on the point. Returns true if the
99 // transformation can be inverted. Rounds the result to the nearest point.
100 bool TransformPointReverse(gfx::Point& point) const;
101
102 // Applies transformation on the rectangle. Returns true if the transformed
103 // rectangle was axis aligned. If it returns false, rect will be the
104 // smallest axis aligned bounding box containg the transformed rect.
105 void TransformRect(gfx::Rect* rect) const;
106
107 // Applies the reverse transformation on the rectangle. Returns true if
108 // the transformed rectangle was axis aligned. If it returns false,
109 // rect will be the smallest axis aligned bounding box containg the
110 // transformed rect.
[email protected]3d19a532011-06-17 17:19:50111 bool TransformRectReverse(gfx::Rect* rect) const;
[email protected]277c7b72011-06-06 15:23:09112
[email protected]b9b1e7a42011-05-17 15:29:51113 // Returns the underlying matrix.
[email protected]80248e32011-07-08 15:31:11114 const SkMatrix44& matrix() const { return matrix_; }
115 SkMatrix44& matrix() { return matrix_; }
[email protected]b9b1e7a42011-05-17 15:29:51116
117 private:
[email protected]80248e32011-07-08 15:31:11118 void TransformPointInternal(const SkMatrix44& xform,
119 gfx::Point& point) const;
120
121 void TransformPointInternal(const SkMatrix44& xform,
122 gfx::Point3f& point) const;
123
124 SkMatrix44 matrix_;
[email protected]b9b1e7a42011-05-17 15:29:51125
126 // copy/assign are allowed.
[email protected]36df22b2011-02-24 21:47:56127};
128
[email protected]80248e32011-07-08 15:31:11129}// namespace ui
[email protected]36df22b2011-02-24 21:47:56130
131#endif // UI_GFX_TRANSFORM_H_