blob: 1002e71b88edf7bb3289fb7bbd19f26d60f865e4 [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]b9b1e7a42011-05-17 15:29:519#include "base/basictypes.h"
10#include "base/compiler_specific.h"
11#include "third_party/skia/include/core/SkMatrix.h"
12
[email protected]36df22b2011-02-24 21:47:5613namespace gfx {
14class Point;
15class Rect;
16}
17
18namespace ui {
19
[email protected]b9b1e7a42011-05-17 15:29:5120// 3x3 transformation matrix. Transform is cheap and explicitly allows
21// copy/assign.
22// TODO: make this a 4x4.
[email protected]36df22b2011-02-24 21:47:5623class Transform {
24 public:
[email protected]b9b1e7a42011-05-17 15:29:5125 Transform();
26 ~Transform();
[email protected]36df22b2011-02-24 21:47:5627
[email protected]598080082011-04-14 19:36:3328 // NOTE: The 'Set' functions overwrite the previously set transformation
29 // parameters. The 'Concat' functions apply a transformation (e.g. rotation,
30 // scale, translate) on top of the existing transforms, instead of overwriting
31 // them.
32
33 // NOTE: The order of the 'Set' function calls do not matter. However, the
34 // order of the 'Concat' function calls do matter, especially when combined
35 // with the 'Set' functions.
36
37 // Sets the rotation of the transformation.
[email protected]b9b1e7a42011-05-17 15:29:5138 void SetRotate(float degree);
[email protected]36df22b2011-02-24 21:47:5639
[email protected]598080082011-04-14 19:36:3340 // Sets the scaling parameters.
[email protected]b9b1e7a42011-05-17 15:29:5141 void SetScaleX(float x);
42 void SetScaleY(float y);
43 void SetScale(float x, float y);
[email protected]36df22b2011-02-24 21:47:5644
[email protected]598080082011-04-14 19:36:3345 // Sets the translation parameters.
[email protected]b9b1e7a42011-05-17 15:29:5146 void SetTranslateX(float x);
47 void SetTranslateY(float y);
48 void SetTranslate(float x, float y);
[email protected]36df22b2011-02-24 21:47:5649
[email protected]598080082011-04-14 19:36:3350 // Applies rotation on the current transformation.
[email protected]b9b1e7a42011-05-17 15:29:5151 void ConcatRotate(float degree);
[email protected]36df22b2011-02-24 21:47:5652
[email protected]598080082011-04-14 19:36:3353 // Applies scaling on current transform.
[email protected]b9b1e7a42011-05-17 15:29:5154 void ConcatScale(float x, float y);
[email protected]36df22b2011-02-24 21:47:5655
[email protected]598080082011-04-14 19:36:3356 // Applies translation on current transform.
[email protected]b9b1e7a42011-05-17 15:29:5157 void ConcatTranslate(float x, float y);
58
59 // Applies a transformation on the current transformation
60 // (i.e. 'this = transform * this;'). Returns true if the result can be
61 // represented.
62 bool PreconcatTransform(const Transform& transform);
[email protected]36df22b2011-02-24 21:47:5663
[email protected]598080082011-04-14 19:36:3364 // Applies a transformation on the current transformation
65 // (i.e. 'this = this * transform;'). Returns true if the result can be
66 // represented.
[email protected]b9b1e7a42011-05-17 15:29:5167 bool 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]b9b1e7a42011-05-17 15:29:5174 bool TransformPoint(gfx::Point* point);
[email protected]36df22b2011-02-24 21:47:5675
[email protected]598080082011-04-14 19:36:3376 // Applies the reverse transformation on the point. Returns true if the point
77 // is transformed successfully.
[email protected]b9b1e7a42011-05-17 15:29:5178 bool TransformPointReverse(gfx::Point* point);
[email protected]36df22b2011-02-24 21:47:5679
[email protected]598080082011-04-14 19:36:3380 // Applies transformation on the rectangle. Returns true of the rectangle is
81 // transformed successfully.
[email protected]b9b1e7a42011-05-17 15:29:5182 bool TransformRect(gfx::Rect* rect);
[email protected]463eb0e2011-05-10 03:11:0483
[email protected]b9b1e7a42011-05-17 15:29:5184 // Returns the underlying matrix.
85 const SkMatrix& matrix() const { return matrix_; }
86
87 private:
88 SkMatrix matrix_;
89
90 // copy/assign are allowed.
[email protected]36df22b2011-02-24 21:47:5691};
92
93} // namespace ui
94
95#endif // UI_GFX_TRANSFORM_H_