00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef PAPYRUSLINEARGRADIENT_H
00021 #define PAPYRUSLINEARGRADIENT_H
00022
00023 #include <papyrus/primitives.h>
00024 #include <papyrus/gradient.h>
00025
00026 namespace Papyrus
00027 {
00028
00037 class LinearGradient : public Gradient
00038 {
00039 public:
00040 struct Point: public Papyrus::Point {
00041 Point( double x=0.0, double y=0.0, Quantity q=ABSOLUTE ): Papyrus::Point(x,y), quantity_x(q), quantity_y(q) { }
00042 Point( double x, double y, Quantity qx, Quantity qy ): Papyrus::Point(x,y), quantity_x(qx), quantity_y(qy) { }
00043 Point( const Papyrus::Point& p, Quantity q=ABSOLUTE ): Papyrus::Point(p), quantity_x(q), quantity_y(q) { }
00044 Point( const Papyrus::Point& p, Quantity qx, Quantity qy ): Papyrus::Point(p), quantity_x(qx), quantity_y(qy) { }
00045 Point( const Point& p ): Papyrus::Point(p), quantity_x(p.quantity_x), quantity_y(p.quantity_y) { }
00046
00047 bool has_percent() { return quantity_x == PERCENT or quantity_y == PERCENT; }
00048
00049 Quantity quantity_x, quantity_y;
00050
00051 };
00052
00053 struct Vector: public LineSegment<Point> {
00054 Vector ( double x1=0.0, double y1=0.0, double x2=0.0, double y2=0.0, Quantity q=ABSOLUTE ): p0(x1,y1,q), p1(x2,y2,q) { }
00055 Vector ( const Papyrus::Point& point0, const Papyrus::Point& point1, Quantity q=ABSOLUTE ): p0(point0,q), p1(point1,q) { }
00056 Vector ( const Point& point0, const Point& point1 ): p0(point0), p1(point1) { }
00057 Vector ( const Vector& v ): p0(v.p0), p1(v.p1) { }
00058
00059 Point p0, p1;
00060
00061 bool has_percent() { return p0.has_percent() or p1.has_percent(); }
00062
00063 void invalidate() { p0.invalidate(); p1.invalidate(); }
00064
00065 operator bool() { return ( p0 and p1 ); }
00066
00067 Point& operator [](int i) { if ( i <= 0 ) return p0; else return p1; }
00068 const Point& operator [](int i) const { if ( i <= 0 ) return p0; else return p1; }
00069 };
00070
00071
00072 protected:
00073 LinearGradient(const Vector& v);
00074
00075 public:
00076 PAPYRUS_RENDERABLE(LinearGradient);
00077
00078 static pointer create( double x0, double y0, double x1, double y1, Quantity q=ABSOLUTE );
00079 static pointer create( const Papyrus::Point& p0, const Papyrus::Point& p1, Quantity q=ABSOLUTE );
00080 static pointer create( const Point& p0, const Point& p1 );
00081 static pointer create( const Vector& v );
00082
00083 virtual ~LinearGradient();
00084
00085 const Vector& vector() const;
00086
00087 void set_vector( const Vector& v );
00088
00089 virtual void render ( Context& cairo ) const;
00090
00091 protected:
00092 Vector m_vector;
00093 };
00094
00095 }
00096
00097 #endif