blob: 52d15cfb22fe54a4208e76828df69ac2f0078e12 [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]45127922012-11-17 12:24:498#include "base/compiler_specific.h"
[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]0f0453e2012-10-14 18:15:3513
[email protected]79fbdab02012-11-14 07:28:1114class RectF;
[email protected]80248e32011-07-08 15:31:1115class Point;
[email protected]2771b1c2012-10-31 05:15:4316class Point3F;
[email protected]f7c321eb2012-11-26 20:13:0817class Vector3dF;
[email protected]36df22b2011-02-24 21:47:5618
[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]507bad52011-08-06 04:51:0721class UI_EXPORT Transform {
[email protected]36df22b2011-02-24 21:47:5622 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]f7c321eb2012-11-26 20:13:0829 // Resets this transform to the identity transform.
30 void MakeIdentity();
[email protected]2fcafa02012-11-15 01:12:5531
32 // Applies the current transformation on a rotation and assigns the result
33 // to |this|.
[email protected]f7c321eb2012-11-26 20:13:0834 void Rotate(double degree);
[email protected]2fcafa02012-11-15 01:12:5535
36 // Applies the current transformation on an axis-angle rotation and assigns
37 // the result to |this|.
[email protected]f7c321eb2012-11-26 20:13:0838 void RotateAbout(const Vector3dF& point, double degree);
[email protected]2fcafa02012-11-15 01:12:5539
40 // Applies the current transformation on a scaling and assigns the result
41 // to |this|.
[email protected]f7c321eb2012-11-26 20:13:0842 void Scale(double x, double y);
43 void Scale3d(double x, double y, double z);
[email protected]2fcafa02012-11-15 01:12:5544
45 // Applies the current transformation on a translation and assigns the result
46 // to |this|.
[email protected]f7c321eb2012-11-26 20:13:0847 void Translate(double x, double y);
48 void Translate3d(double x, double y, double z);
[email protected]2fcafa02012-11-15 01:12:5549
50 // Applies the current transformation on a skew and assigns the result
51 // to |this|.
[email protected]f7c321eb2012-11-26 20:13:0852 void SkewX(double angle_x);
53 void SkewY(double angle_y);
[email protected]2fcafa02012-11-15 01:12:5554
55 // Applies the current transformation on a perspective transform and assigns
56 // the result to |this|.
[email protected]f7c321eb2012-11-26 20:13:0857 void ApplyPerspectiveDepth(double depth);
[email protected]2fcafa02012-11-15 01:12:5558
[email protected]b9b1e7a42011-05-17 15:29:5159 // Applies a transformation on the current transformation
[email protected]80248e32011-07-08 15:31:1160 // (i.e. 'this = this * transform;').
61 void PreconcatTransform(const Transform& transform);
[email protected]36df22b2011-02-24 21:47:5662
[email protected]598080082011-04-14 19:36:3363 // Applies a transformation on the current transformation
[email protected]80248e32011-07-08 15:31:1164 // (i.e. 'this = transform * this;').
65 void ConcatTransform(const Transform& transform);
[email protected]36df22b2011-02-24 21:47:5666
[email protected]45127922012-11-17 12:24:4967 // Returns true if this is the identity matrix.
68 bool IsIdentity() const;
69
70 // Returns true if this transform is non-singular.
71 bool IsInvertible() const;
[email protected]36df22b2011-02-24 21:47:5672
[email protected]38919392011-10-24 22:26:2373 // Inverts the transform which is passed in. Returns true if successful.
[email protected]45127922012-11-17 12:24:4974 bool GetInverse(Transform* transform) const WARN_UNUSED_RESULT;
75
76 // Transposes this transform in place.
77 void Transpose();
[email protected]38919392011-10-24 22:26:2378
[email protected]598080082011-04-14 19:36:3379 // Applies the transformation on the point. Returns true if the point is
80 // transformed successfully.
[email protected]2771b1c2012-10-31 05:15:4381 void TransformPoint(Point3F& point) const;
[email protected]36df22b2011-02-24 21:47:5682
[email protected]80248e32011-07-08 15:31:1183 // Applies the transformation on the point. Returns true if the point is
84 // transformed successfully. Rounds the result to the nearest point.
[email protected]0f0453e2012-10-14 18:15:3585 void TransformPoint(Point& point) const;
[email protected]36df22b2011-02-24 21:47:5686
[email protected]80248e32011-07-08 15:31:1187 // Applies the reverse transformation on the point. Returns true if the
88 // transformation can be inverted.
[email protected]2771b1c2012-10-31 05:15:4389 bool TransformPointReverse(Point3F& point) const;
[email protected]463eb0e2011-05-10 03:11:0490
[email protected]80248e32011-07-08 15:31:1191 // Applies the reverse transformation on the point. Returns true if the
92 // transformation can be inverted. Rounds the result to the nearest point.
[email protected]0f0453e2012-10-14 18:15:3593 bool TransformPointReverse(Point& point) const;
[email protected]80248e32011-07-08 15:31:1194
95 // Applies transformation on the rectangle. Returns true if the transformed
96 // rectangle was axis aligned. If it returns false, rect will be the
[email protected]91f4c792012-06-06 02:21:1997 // smallest axis aligned bounding box containing the transformed rect.
[email protected]79fbdab02012-11-14 07:28:1198 void TransformRect(RectF* rect) const;
[email protected]80248e32011-07-08 15:31:1199
100 // Applies the reverse transformation on the rectangle. Returns true if
101 // the transformed rectangle was axis aligned. If it returns false,
[email protected]91f4c792012-06-06 02:21:19102 // rect will be the smallest axis aligned bounding box containing the
[email protected]80248e32011-07-08 15:31:11103 // transformed rect.
[email protected]79fbdab02012-11-14 07:28:11104 bool TransformRectReverse(RectF* rect) const;
[email protected]277c7b72011-06-06 15:23:09105
[email protected]2fcafa02012-11-15 01:12:55106 // Decomposes |this| and |from|, interpolates the decomposed values, and
107 // sets |this| to the reconstituted result. Returns false if either matrix
108 // can't be decomposed. Uses routines described in this spec:
109 // http://www.w3.org/TR/css3-3d-transforms/.
110 //
111 // Note: this call is expensive since we need to decompose the transform. If
112 // you're going to be calling this rapidly (e.g., in an animation) you should
113 // decompose once using gfx::DecomposeTransforms and reuse your
114 // DecomposedTransform.
115 bool Blend(const Transform& from, double progress);
116
[email protected]f7c321eb2012-11-26 20:13:08117 // Returns |this| * |other|.
118 Transform operator*(const Transform& other) const;
119
120 // Sets |this| = |this| * |other|
121 Transform& operator*=(const Transform& other);
122
[email protected]b9b1e7a42011-05-17 15:29:51123 // Returns the underlying matrix.
[email protected]80248e32011-07-08 15:31:11124 const SkMatrix44& matrix() const { return matrix_; }
125 SkMatrix44& matrix() { return matrix_; }
[email protected]b9b1e7a42011-05-17 15:29:51126
127 private:
[email protected]80248e32011-07-08 15:31:11128 void TransformPointInternal(const SkMatrix44& xform,
[email protected]0f0453e2012-10-14 18:15:35129 Point& point) const;
[email protected]80248e32011-07-08 15:31:11130
131 void TransformPointInternal(const SkMatrix44& xform,
[email protected]2771b1c2012-10-31 05:15:43132 Point3F& point) const;
[email protected]80248e32011-07-08 15:31:11133
134 SkMatrix44 matrix_;
[email protected]b9b1e7a42011-05-17 15:29:51135
136 // copy/assign are allowed.
[email protected]36df22b2011-02-24 21:47:56137};
138
[email protected]0f0453e2012-10-14 18:15:35139} // namespace gfx
[email protected]36df22b2011-02-24 21:47:56140
141#endif // UI_GFX_TRANSFORM_H_