blob: 233df689abf057b4c1765aeffafac8a9ef0f6b81 [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_
[email protected]36df22b2011-02-24 21:47:567
[email protected]80248e32011-07-08 15:31:118#include "third_party/skia/include/utils/SkMatrix44.h"
[email protected]507bad52011-08-06 04:51:079#include "ui/base/ui_export.h"
[email protected]b9b1e7a42011-05-17 15:29:5110
[email protected]36df22b2011-02-24 21:47:5611namespace gfx {
[email protected]0f0453e2012-10-14 18:15:3512
[email protected]79fbdab02012-11-14 07:28:1113class RectF;
[email protected]80248e32011-07-08 15:31:1114class Point;
[email protected]2771b1c2012-10-31 05:15:4315class Point3F;
[email protected]36df22b2011-02-24 21:47:5616
[email protected]80248e32011-07-08 15:31:1117// 4x4 transformation matrix. Transform is cheap and explicitly allows
[email protected]b9b1e7a42011-05-17 15:29:5118// copy/assign.
[email protected]507bad52011-08-06 04:51:0719class UI_EXPORT Transform {
[email protected]36df22b2011-02-24 21:47:5620 public:
[email protected]b9b1e7a42011-05-17 15:29:5121 Transform();
22 ~Transform();
[email protected]36df22b2011-02-24 21:47:5623
[email protected]80248e32011-07-08 15:31:1124 bool operator==(const Transform& rhs) const;
25 bool operator!=(const Transform& rhs) const;
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]b9b1e7a42011-05-17 15:29:5137 void SetRotate(float degree);
[email protected]36df22b2011-02-24 21:47:5638
[email protected]3c2196b22012-03-17 03:42:2539 // Sets the rotation of the transform (about a vector).
[email protected]2771b1c2012-10-31 05:15:4340 void SetRotateAbout(const Point3F& point, float degree);
[email protected]3c2196b22012-03-17 03:42:2541
[email protected]598080082011-04-14 19:36:3342 // Sets the scaling parameters.
[email protected]b9b1e7a42011-05-17 15:29:5143 void SetScaleX(float x);
44 void SetScaleY(float y);
45 void SetScale(float x, float y);
[email protected]36df22b2011-02-24 21:47:5646
[email protected]598080082011-04-14 19:36:3347 // Sets the translation parameters.
[email protected]b9b1e7a42011-05-17 15:29:5148 void SetTranslateX(float x);
49 void SetTranslateY(float y);
50 void SetTranslate(float x, float y);
[email protected]36df22b2011-02-24 21:47:5651
[email protected]9dc5f9d2012-05-14 19:28:0152 // Creates a perspective matrix.
53 // Based on the 'perspective' operation from
54 // http://www.w3.org/TR/css3-3d-transforms/#transform-functions
55 void SetPerspectiveDepth(float depth);
56
[email protected]3c2196b22012-03-17 03:42:2557 // Applies a rotation on the current transformation.
[email protected]b9b1e7a42011-05-17 15:29:5158 void ConcatRotate(float degree);
[email protected]36df22b2011-02-24 21:47:5659
[email protected]3c2196b22012-03-17 03:42:2560 // Applies an axis-angle rotation on the current transformation.
[email protected]2771b1c2012-10-31 05:15:4361 void ConcatRotateAbout(const Point3F& point, float degree);
[email protected]3c2196b22012-03-17 03:42:2562
[email protected]598080082011-04-14 19:36:3363 // Applies scaling on current transform.
[email protected]b9b1e7a42011-05-17 15:29:5164 void ConcatScale(float x, float y);
[email protected]36df22b2011-02-24 21:47:5665
[email protected]598080082011-04-14 19:36:3366 // Applies translation on current transform.
[email protected]b9b1e7a42011-05-17 15:29:5167 void ConcatTranslate(float x, float y);
68
[email protected]2b36aeb2012-10-30 04:53:0969 // Applies a perspective on current transform.
70 void ConcatPerspectiveDepth(float depth);
71
[email protected]b9b1e7a42011-05-17 15:29:5172 // 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]2771b1c2012-10-31 05:15:4388 void TransformPoint(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.
[email protected]0f0453e2012-10-14 18:15:3592 void TransformPoint(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.
[email protected]2771b1c2012-10-31 05:15:4396 bool TransformPointReverse(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.
[email protected]0f0453e2012-10-14 18:15:35100 bool TransformPointReverse(Point& point) const;
[email protected]80248e32011-07-08 15:31:11101
102 // Applies transformation on the rectangle. Returns true if the transformed
103 // rectangle was axis aligned. If it returns false, rect will be the
[email protected]91f4c792012-06-06 02:21:19104 // smallest axis aligned bounding box containing the transformed rect.
[email protected]79fbdab02012-11-14 07:28:11105 void TransformRect(RectF* rect) const;
[email protected]80248e32011-07-08 15:31:11106
107 // Applies the reverse transformation on the rectangle. Returns true if
108 // the transformed rectangle was axis aligned. If it returns false,
[email protected]91f4c792012-06-06 02:21:19109 // rect will be the smallest axis aligned bounding box containing the
[email protected]80248e32011-07-08 15:31:11110 // transformed rect.
[email protected]79fbdab02012-11-14 07:28:11111 bool TransformRectReverse(RectF* 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,
[email protected]0f0453e2012-10-14 18:15:35119 Point& point) const;
[email protected]80248e32011-07-08 15:31:11120
121 void TransformPointInternal(const SkMatrix44& xform,
[email protected]2771b1c2012-10-31 05:15:43122 Point3F& point) const;
[email protected]80248e32011-07-08 15:31:11123
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]0f0453e2012-10-14 18:15:35129} // namespace gfx
[email protected]36df22b2011-02-24 21:47:56130
131#endif // UI_GFX_TRANSFORM_H_