xref: /haiku/src/libs/icon/transformable/Transformable.h (revision 1564b19c80637a2ba13949db0056215699b7b418)
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 class Transformable : public agg::trans_affine {
17  public:
18 	enum {
19 		matrix_size = 6,
20 	};
21 
22 								Transformable();
23 								Transformable(const Transformable& other);
24 	virtual						~Transformable();
25 
26 			void				StoreTo(double matrix[matrix_size]) const;
27 			void				LoadFrom(const double matrix[matrix_size]);
28 
29 								// set to or combine with other matrix
30 			void				SetTransform(const Transformable& other);
31 			Transformable&		operator=(const Transformable& other);
32 			Transformable&		Multiply(const Transformable& other);
33 	virtual	void				Reset();
34 
35 			void				Invert();
36 
37 			bool				IsIdentity() const;
38 			bool				IsTranslationOnly() const;
39 			bool				IsNotDistorted() const;
40 			bool				IsValid() const;
41 
42 			bool				operator==(const Transformable& other) const;
43 			bool				operator!=(const Transformable& other) const;
44 
45 								// transforms coordiantes
46 			void				Transform(double* x, double* y) const;
47 			void				Transform(BPoint* point) const;
48 			BPoint				Transform(const BPoint& point) const;
49 
50 			void				InverseTransform(double* x, double* y) const;
51 			void				InverseTransform(BPoint* point) const;
52 			BPoint				InverseTransform(const BPoint& point) const;
53 
54 								// transforms the rectangle "bounds" and
55 								// returns the *bounding box* of that
56 			BRect				TransformBounds(BRect bounds) const;
57 
58 								// some convenience functions
59 	virtual	void				TranslateBy(BPoint offset);
60 	virtual	void				RotateBy(BPoint origin, double degrees);
61 	virtual	void				ScaleBy(BPoint origin, double xScale, double yScale);
62 	virtual	void				ShearBy(BPoint origin, double xShear, double yShear);
63 
64 	virtual	void				TransformationChanged();
65 		// hook function that is called when the transformation
66 		// is changed for some reason
67 };
68 
69 #endif // TRANSFORMABLE_H
70 
71