1fb07ece0SStephan Aßmus /* 2*c6c2c042SZardshard * Copyright 2006-2007, 2023, Haiku. 3fb07ece0SStephan Aßmus * Distributed under the terms of the MIT License. 4fb07ece0SStephan Aßmus * 5fb07ece0SStephan Aßmus * Authors: 6fb07ece0SStephan Aßmus * Stephan Aßmus <superstippi@gmx.de> 7*c6c2c042SZardshard * Zardshard 8fb07ece0SStephan Aßmus */ 9fb07ece0SStephan Aßmus #ifndef PERSPECTIVE_TRANSFORMER_H 10fb07ece0SStephan Aßmus #define PERSPECTIVE_TRANSFORMER_H 11fb07ece0SStephan Aßmus 12325a6253SAxel Dörfler 13*c6c2c042SZardshard #include <Rect.h> 14*c6c2c042SZardshard #include <Point.h> 15325a6253SAxel Dörfler 16fb07ece0SStephan Aßmus #include <agg_conv_transform.h> 17fb07ece0SStephan Aßmus #include <agg_trans_perspective.h> 18fb07ece0SStephan Aßmus 19*c6c2c042SZardshard #include "IconBuild.h" 20*c6c2c042SZardshard #include "Transformer.h" 21*c6c2c042SZardshard #ifdef ICON_O_MATIC 22*c6c2c042SZardshard #include "Observer.h" 23*c6c2c042SZardshard #endif 24*c6c2c042SZardshard #include "PathTransformer.h" 25*c6c2c042SZardshard #include "StyleTransformer.h" 26*c6c2c042SZardshard #include "VertexSource.h" 27*c6c2c042SZardshard 28325a6253SAxel Dörfler 2925dc253dSIngo Weinhold _BEGIN_ICON_NAMESPACE 3025dc253dSIngo Weinhold 31*c6c2c042SZardshard class Shape; 32fb07ece0SStephan Aßmus 33fb07ece0SStephan Aßmus 34*c6c2c042SZardshard typedef agg::conv_transform<VertexSource, agg::trans_perspective> Perspective; 35*c6c2c042SZardshard 36*c6c2c042SZardshard /*! Transforms from the VertexSource's bounding rect to the specified 37*c6c2c042SZardshard quadrilateral. This class watches out for invalid transformations if 38*c6c2c042SZardshard \c ICON_O_MATIC is set. 39*c6c2c042SZardshard */ 40fb07ece0SStephan Aßmus class PerspectiveTransformer : public Transformer, 41*c6c2c042SZardshard public PathTransformer, 42*c6c2c042SZardshard public StyleTransformer, 43*c6c2c042SZardshard #ifdef ICON_O_MATIC 44*c6c2c042SZardshard public Observer, 45*c6c2c042SZardshard #endif 46fb07ece0SStephan Aßmus public Perspective, 47fb07ece0SStephan Aßmus public agg::trans_perspective { 48fb07ece0SStephan Aßmus public: 49fb07ece0SStephan Aßmus enum { 50fb07ece0SStephan Aßmus archive_code = 'prsp', 51fb07ece0SStephan Aßmus }; 52fb07ece0SStephan Aßmus 53*c6c2c042SZardshard /*! Initializes starting with the identity transformation. 54*c6c2c042SZardshard A valid perspective transformation can be rendered invalid if the shape 55*c6c2c042SZardshard changes. Listens to \a shape for updates and determines if the 56*c6c2c042SZardshard transformation is still valid if \c ICON_O_MATIC is set. 57*c6c2c042SZardshard */ 58fb07ece0SStephan Aßmus PerspectiveTransformer( 59fb07ece0SStephan Aßmus VertexSource& source, 60*c6c2c042SZardshard Shape* shape); 61*c6c2c042SZardshard PerspectiveTransformer( 62*c6c2c042SZardshard VertexSource& source, 63*c6c2c042SZardshard Shape* shape, 64fb07ece0SStephan Aßmus BMessage* archive); 65*c6c2c042SZardshard PerspectiveTransformer( 66*c6c2c042SZardshard const PerspectiveTransformer& other); 678b8d44bfSMichael Lotz 68fb07ece0SStephan Aßmus virtual ~PerspectiveTransformer(); 69fb07ece0SStephan Aßmus 70fb07ece0SStephan Aßmus // Transformer interface 71*c6c2c042SZardshard virtual Transformer* Clone() const; 72fb07ece0SStephan Aßmus 73*c6c2c042SZardshard // PathTransformer interface 74fb07ece0SStephan Aßmus virtual void rewind(unsigned path_id); 75fb07ece0SStephan Aßmus virtual unsigned vertex(double* x, double* y); 76fb07ece0SStephan Aßmus 77fb07ece0SStephan Aßmus virtual void SetSource(VertexSource& source); 78fb07ece0SStephan Aßmus 79fb07ece0SStephan Aßmus virtual double ApproximationScale() const; 80fb07ece0SStephan Aßmus 81*c6c2c042SZardshard // StyleTransformer interface transform(double * x,double * y)82*c6c2c042SZardshard virtual void transform(double* x, double* y) const 83*c6c2c042SZardshard #ifdef ICON_O_MATIC 84*c6c2c042SZardshard { if (fValid) agg::trans_perspective::transform(x, y); } 85*c6c2c042SZardshard #else 86*c6c2c042SZardshard { agg::trans_perspective::transform(x, y); } 87*c6c2c042SZardshard #endif 88*c6c2c042SZardshard 89*c6c2c042SZardshard /*! Inverts the perspective transformation. 90*c6c2c042SZardshard \warning This class can mostly only transform points when inverted. Most 91*c6c2c042SZardshard other features either have not been tested or are missing. 92*c6c2c042SZardshard */ 93*c6c2c042SZardshard virtual void Invert(); 94*c6c2c042SZardshard 95fb07ece0SStephan Aßmus #ifdef ICON_O_MATIC 96fb07ece0SStephan Aßmus // IconObject interface 97fb07ece0SStephan Aßmus virtual status_t Archive(BMessage* into, 98fb07ece0SStephan Aßmus bool deep = true) const; 99fb07ece0SStephan Aßmus 100*c6c2c042SZardshard // Observer interface 101*c6c2c042SZardshard virtual void ObjectChanged(const Observable* object); 102*c6c2c042SZardshard 103*c6c2c042SZardshard // PerspectiveTransformer 104*c6c2c042SZardshard void TransformTo(BPoint leftTop, BPoint rightTop, 105*c6c2c042SZardshard BPoint leftBottom, BPoint rightBottom); 106*c6c2c042SZardshard LeftTop()107*c6c2c042SZardshard BPoint LeftTop() 108*c6c2c042SZardshard { return fToLeftTop; } RightTop()109*c6c2c042SZardshard BPoint RightTop() 110*c6c2c042SZardshard { return fToRightTop; } LeftBottom()111*c6c2c042SZardshard BPoint LeftBottom() 112*c6c2c042SZardshard { return fToLeftBottom; } RightBottom()113*c6c2c042SZardshard BPoint RightBottom() 114*c6c2c042SZardshard { return fToRightBottom; } 115*c6c2c042SZardshard 116*c6c2c042SZardshard private: 117*c6c2c042SZardshard void _CheckValidity(); 118*c6c2c042SZardshard #endif // ICON_O_MATIC 119*c6c2c042SZardshard 120*c6c2c042SZardshard private: 121*c6c2c042SZardshard Shape* fShape; 122*c6c2c042SZardshard #ifdef ICON_O_MATIC 123*c6c2c042SZardshard bool fInverted; 124*c6c2c042SZardshard BRect fFromBox; 125*c6c2c042SZardshard BPoint fToLeftTop; 126*c6c2c042SZardshard BPoint fToRightTop; 127*c6c2c042SZardshard BPoint fToLeftBottom; 128*c6c2c042SZardshard BPoint fToRightBottom; 129*c6c2c042SZardshard bool fValid; 130fb07ece0SStephan Aßmus #endif 131fb07ece0SStephan Aßmus }; 132fb07ece0SStephan Aßmus 13325dc253dSIngo Weinhold 13425dc253dSIngo Weinhold _END_ICON_NAMESPACE 13525dc253dSIngo Weinhold 136325a6253SAxel Dörfler 137fb07ece0SStephan Aßmus #endif // PERSPECTIVE_TRANSFORMER_H 138