papyrus logo

lineargradient.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2009 by Rick L. Vinyard, Jr.                            *
00003  *   rvinyard@cs.nmsu.edu                                                  *
00004  *                                                                         *
00005  *   This file is part of the papyrus library.                             *
00006  *                                                                         *
00007  *   papyrus is free software; you can redistribute it and/or modify       *
00008  *   it under the terms of the GNU Lesser General Public License           *
00009  *   version 3.0 as published by the Free Software Foundation.             *
00010  *                                                                         *
00011  *   papyrus is distributed in the hope that it will be useful,            *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Lesser General Public License version 3.0 for more details.       *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Lesser General Public      *
00017  *   License along with the papyrus library. If not, see                   *
00018  *   <http://www.gnu.org/licenses/>.                                       *
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

Generated on Fri Apr 16 12:40:10 2010 for papyrus by doxygen 1.6.1