blob: 483aa564652c9cf47d2b0ae49d475406a3a9a596 [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]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]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]598080082011-04-14 19:36:3352 // Applies rotation on the current transformation.
[email protected]b9b1e7a42011-05-17 15:29:5153 void ConcatRotate(float degree);
[email protected]36df22b2011-02-24 21:47:5654
[email protected]598080082011-04-14 19:36:3355 // Applies scaling on current transform.
[email protected]b9b1e7a42011-05-17 15:29:5156 void ConcatScale(float x, float y);
[email protected]36df22b2011-02-24 21:47:5657
[email protected]598080082011-04-14 19:36:3358 // Applies translation on current transform.
[email protected]b9b1e7a42011-05-17 15:29:5159 void ConcatTranslate(float x, float y);
60
61 // Applies a transformation on the current transformation
[email protected]80248e32011-07-08 15:31:1162 // (i.e. 'this = this * transform;').
63 void PreconcatTransform(const Transform& transform);
[email protected]36df22b2011-02-24 21:47:5664
[email protected]598080082011-04-14 19:36:3365 // Applies a transformation on the current transformation
[email protected]80248e32011-07-08 15:31:1166 // (i.e. 'this = transform * this;').
67 void ConcatTransform(const Transform& transform);
[email protected]36df22b2011-02-24 21:47:5668
69 // Does the transformation change anything?
[email protected]b9b1e7a42011-05-17 15:29:5170 bool HasChange() const;
[email protected]36df22b2011-02-24 21:47:5671
[email protected]598080082011-04-14 19:36:3372 // Applies the transformation on the point. Returns true if the point is
73 // transformed successfully.
[email protected]80248e32011-07-08 15:31:1174 void TransformPoint(gfx::Point3f& point) const;
[email protected]36df22b2011-02-24 21:47:5675
[email protected]80248e32011-07-08 15:31:1176 // Applies the transformation on the point. Returns true if the point is
77 // transformed successfully. Rounds the result to the nearest point.
78 void TransformPoint(gfx::Point& point) const;
[email protected]36df22b2011-02-24 21:47:5679
[email protected]80248e32011-07-08 15:31:1180 // Applies the reverse transformation on the point. Returns true if the
81 // transformation can be inverted.
82 bool TransformPointReverse(gfx::Point3f& point) const;
[email protected]463eb0e2011-05-10 03:11:0483
[email protected]80248e32011-07-08 15:31:1184 // Applies the reverse transformation on the point. Returns true if the
85 // transformation can be inverted. Rounds the result to the nearest point.
86 bool TransformPointReverse(gfx::Point& point) const;
87
88 // Applies transformation on the rectangle. Returns true if the transformed
89 // rectangle was axis aligned. If it returns false, rect will be the
90 // smallest axis aligned bounding box containg the transformed rect.
91 void TransformRect(gfx::Rect* rect) const;
92
93 // Applies the reverse transformation on the rectangle. Returns true if
94 // the transformed rectangle was axis aligned. If it returns false,
95 // rect will be the smallest axis aligned bounding box containg the
96 // transformed rect.
[email protected]3d19a532011-06-17 17:19:5097 bool TransformRectReverse(gfx::Rect* rect) const;
[email protected]277c7b72011-06-06 15:23:0998
[email protected]b9b1e7a42011-05-17 15:29:5199 // Returns the underlying matrix.
[email protected]80248e32011-07-08 15:31:11100 const SkMatrix44& matrix() const { return matrix_; }
101 SkMatrix44& matrix() { return matrix_; }
[email protected]b9b1e7a42011-05-17 15:29:51102
103 private:
[email protected]80248e32011-07-08 15:31:11104 void TransformPointInternal(const SkMatrix44& xform,
105 gfx::Point& point) const;
106
107 void TransformPointInternal(const SkMatrix44& xform,
108 gfx::Point3f& point) const;
109
110 SkMatrix44 matrix_;
[email protected]b9b1e7a42011-05-17 15:29:51111
112 // copy/assign are allowed.
[email protected]36df22b2011-02-24 21:47:56113};
114
[email protected]80248e32011-07-08 15:31:11115}// namespace ui
[email protected]36df22b2011-02-24 21:47:56116
117#endif // UI_GFX_TRANSFORM_H_