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