1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_GFX_TRANSFORM_H_
#define UI_GFX_TRANSFORM_H_
#pragma once
#include "third_party/skia/include/utils/SkMatrix44.h"
#include "ui/base/ui_export.h"
namespace gfx {
class Rect;
class Point;
class Point3f;
}
namespace ui {
// 4x4 transformation matrix. Transform is cheap and explicitly allows
// copy/assign.
class UI_EXPORT Transform {
public:
Transform();
~Transform();
bool operator==(const Transform& rhs) const;
bool operator!=(const Transform& rhs) const;
// NOTE: The 'Set' functions overwrite the previously set transformation
// parameters. The 'Concat' functions apply a transformation (e.g. rotation,
// scale, translate) on top of the existing transforms, instead of overwriting
// them.
// NOTE: The order of the 'Set' function calls do not matter. However, the
// order of the 'Concat' function calls do matter, especially when combined
// with the 'Set' functions.
// Sets the rotation of the transformation.
void SetRotate(float degree);
// Sets the rotation of the transform (about a vector).
void SetRotateAbout(const gfx::Point3f& point, float degree);
// Sets the scaling parameters.
void SetScaleX(float x);
void SetScaleY(float y);
void SetScale(float x, float y);
// Sets the translation parameters.
void SetTranslateX(float x);
void SetTranslateY(float y);
void SetTranslate(float x, float y);
// Creates a perspective matrix.
// Based on the 'perspective' operation from
// http://www.w3.org/TR/css3-3d-transforms/#transform-functions
void SetPerspectiveDepth(float depth);
// Applies a rotation on the current transformation.
void ConcatRotate(float degree);
// Applies an axis-angle rotation on the current transformation.
void ConcatRotateAbout(const gfx::Point3f& point, float degree);
// Applies scaling on current transform.
void ConcatScale(float x, float y);
// Applies translation on current transform.
void ConcatTranslate(float x, float y);
// Applies a transformation on the current transformation
// (i.e. 'this = this * transform;').
void PreconcatTransform(const Transform& transform);
// Applies a transformation on the current transformation
// (i.e. 'this = transform * this;').
void ConcatTransform(const Transform& transform);
// Does the transformation change anything?
bool HasChange() const;
// Inverts the transform which is passed in. Returns true if successful.
bool GetInverse(Transform* transform) const;
// Applies the transformation on the point. Returns true if the point is
// transformed successfully.
void TransformPoint(gfx::Point3f& point) const;
// Applies the transformation on the point. Returns true if the point is
// transformed successfully. Rounds the result to the nearest point.
void TransformPoint(gfx::Point& point) const;
// Applies the reverse transformation on the point. Returns true if the
// transformation can be inverted.
bool TransformPointReverse(gfx::Point3f& point) const;
// Applies the reverse transformation on the point. Returns true if the
// transformation can be inverted. Rounds the result to the nearest point.
bool TransformPointReverse(gfx::Point& point) const;
// Applies transformation on the rectangle. Returns true if the transformed
// rectangle was axis aligned. If it returns false, rect will be the
// smallest axis aligned bounding box containg the transformed rect.
void TransformRect(gfx::Rect* rect) const;
// Applies the reverse transformation on the rectangle. Returns true if
// the transformed rectangle was axis aligned. If it returns false,
// rect will be the smallest axis aligned bounding box containg the
// transformed rect.
bool TransformRectReverse(gfx::Rect* rect) const;
// Returns the underlying matrix.
const SkMatrix44& matrix() const { return matrix_; }
SkMatrix44& matrix() { return matrix_; }
private:
void TransformPointInternal(const SkMatrix44& xform,
gfx::Point& point) const;
void TransformPointInternal(const SkMatrix44& xform,
gfx::Point3f& point) const;
SkMatrix44 matrix_;
// copy/assign are allowed.
};
}// namespace ui
#endif // UI_GFX_TRANSFORM_H_
|