xref: /haiku/src/libs/icon/transformable/Transformable.h (revision 1214ef1b2100f2b3299fc9d8d6142e46f70a4c3f)
1 /*
2  * Copyright 2006, Haiku.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Stephan Aßmus <superstippi@gmx.de>
7  */
8 
9 #ifndef TRANSFORMABLE_H
10 #define TRANSFORMABLE_H
11 
12 #include <Rect.h>
13 
14 #include <agg_trans_affine.h>
15 
16 namespace BPrivate {
17 namespace Icon {
18 
19 class Transformable : public agg::trans_affine {
20  public:
21 	enum {
22 		matrix_size = 6,
23 	};
24 
25 								Transformable();
26 								Transformable(const Transformable& other);
27 	virtual						~Transformable();
28 
29 			void				StoreTo(double matrix[matrix_size]) const;
30 			void				LoadFrom(const double matrix[matrix_size]);
31 
32 								// set to or combine with other matrix
33 			void				SetTransform(const Transformable& other);
34 			Transformable&		operator=(const Transformable& other);
35 			Transformable&		Multiply(const Transformable& other);
36 	virtual	void				Reset();
37 
38 			void				Invert();
39 
40 			bool				IsIdentity() const;
41 			bool				IsTranslationOnly() const;
42 			bool				IsNotDistorted() const;
43 			bool				IsValid() const;
44 
45 			bool				operator==(const Transformable& other) const;
46 			bool				operator!=(const Transformable& other) const;
47 
48 								// transforms coordiantes
49 			void				Transform(double* x, double* y) const;
50 			void				Transform(BPoint* point) const;
51 			BPoint				Transform(const BPoint& point) const;
52 
53 			void				InverseTransform(double* x, double* y) const;
54 			void				InverseTransform(BPoint* point) const;
55 			BPoint				InverseTransform(const BPoint& point) const;
56 
57 								// transforms the rectangle "bounds" and
58 								// returns the *bounding box* of that
59 			BRect				TransformBounds(BRect bounds) const;
60 
61 								// some convenience functions
62 	virtual	void				TranslateBy(BPoint offset);
63 	virtual	void				RotateBy(BPoint origin, double degrees);
64 	virtual	void				ScaleBy(BPoint origin, double xScale, double yScale);
65 	virtual	void				ShearBy(BPoint origin, double xShear, double yShear);
66 
67 	virtual	void				TransformationChanged();
68 		// hook function that is called when the transformation
69 		// is changed for some reason
70 };
71 
72 } // namespace Icon
73 } // namespace BPrivate
74 
75 using namespace BPrivate::Icon;
76 
77 #endif // TRANSFORMABLE_H
78 
79