1/*
2 * Copyright 2005, Stephan A��mus <superstippi@gmx.de>. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 * A handy front-end to agg::trans_affine transformation matrix.
6 *
7 */
8
9
10#ifndef TRANSFORMABLE_H
11#define TRANSFORMABLE_H
12
13#include <Archivable.h>
14#include <Rect.h>
15
16#include <agg_trans_affine.h>
17
18class Transformable : public BArchivable,
19					  public agg::trans_affine {
20 public:
21								Transformable();
22								Transformable(const Transformable& other);
23								Transformable(const BMessage* archive);
24	virtual						~Transformable();
25
26								// the BArchivable protocol
27								// stores matrix directly to message, deep is ignored
28	virtual	status_t			Archive(BMessage* into, bool deep = true) const;
29
30			void				StoreTo(double matrix[6]) const;
31			void				LoadFrom(double matrix[6]);
32
33								// set to or combine with other matrix
34			void				SetTransformable(const Transformable& other);
35			Transformable&		operator=(const Transformable& other);
36			Transformable&		Multiply(const Transformable& other);
37			void				Reset();
38
39			bool				IsIdentity() const;
40			bool				operator==(const Transformable& other) const;
41			bool				operator!=(const Transformable& other) const;
42
43								// transforms coordiantes
44			void				Transform(double* x, double* y) const;
45			void				Transform(BPoint* point) const;
46			BPoint				Transform(const BPoint& point) const;
47
48			void				InverseTransform(double* x, double* y) const;
49			void				InverseTransform(BPoint* point) const;
50			BPoint				InverseTransform(const BPoint& point) const;
51
52								// transforms the rectangle "bounds" and
53								// returns the *bounding box* of that
54			BRect				TransformBounds(const BRect& bounds) const;
55
56								// some convenience functions
57	virtual	void				TranslateBy(BPoint offset);
58	virtual	void				RotateBy(BPoint origin, double radians);
59	virtual	void				ScaleBy(BPoint origin, double xScale, double yScale);
60	virtual	void				ShearBy(BPoint origin, double xShear, double yShear);
61
62	virtual	void				TransformationChanged() {}
63};
64
65#endif // TRANSFORMABLE_H
66
67