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 agg::trans_affine& other);
36			Transformable&		operator=(const Transformable& other);
37			Transformable&		Multiply(const Transformable& other);
38			void				Reset();
39
40			bool				IsIdentity() const;
41			bool				IsDilation() const;
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(const BRect& bounds) const;
57
58			bool				IsTranslationOnly() const;
59
60								// some convenience functions
61	virtual	void				TranslateBy(BPoint offset);
62	virtual	void				RotateBy(BPoint origin, double radians);
63	virtual	void				ScaleBy(BPoint origin, double xScale, double yScale);
64	virtual	void				ShearBy(BPoint origin, double xShear, double yShear);
65
66	virtual	void				TransformationChanged() {}
67};
68
69#endif // TRANSFORMABLE_H
70
71