Canvas.hpp

Go to the documentation of this file.
00001 #pragma ident "$Id: Canvas.hpp 1644 2009-01-27 19:26:14Z ckiesch $"
00002 
00005 
00006 //============================================================================
00007 //
00008 //  This file is part of GPSTk, the GPS Toolkit.
00009 //
00010 //  The GPSTk is free software; you can redistribute it and/or modify
00011 //  it under the terms of the GNU Lesser General Public License as published
00012 //  by the Free Software Foundation; either version 2.1 of the License, or
00013 //  any later version.
00014 //
00015 //  The GPSTk is distributed in the hope that it will be useful,
00016 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 //  GNU Lesser General Public License for more details.
00019 //
00020 //  You should have received a copy of the GNU Lesser General Public
00021 //  License along with GPSTk; if not, write to the Free Software Foundation,
00022 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023 //  
00024 //  Copyright 2004, The University of Texas at Austin
00025 //
00026 //============================================================================
00027 
00028 #ifndef VDRAW_CANVAS_H
00029 #define VDRAW_CANVAS_H
00030 
00031 #include <vector>
00032 #include "VGState.hpp"
00033 #include "Path.hpp"
00034 #include "StrokeStyle.hpp"
00035 #include "Line.hpp"
00036 #include "Rectangle.hpp"
00037 #include "Circle.hpp"
00038 #include "Polygon.hpp"
00039 #include "Text.hpp"
00040 #include "Marker.hpp"
00041 #include "Comment.hpp"
00042 #include "Bitmap.hpp"
00043 
00044 namespace vdraw
00045 {
00048 
00053   class Canvas 
00054   {
00056     friend Canvas& operator<<(Canvas& canvas, const StrokeStyle& style)
00057     {
00058       canvas.setLineStyle(style);
00059       return canvas;
00060     }
00061 
00063     friend Canvas& operator<<(Canvas& canvas, const Marker& marker)
00064     {
00065       canvas.setMarker(marker);
00066       return canvas;
00067     }
00068 
00070     friend Canvas& operator<<(Canvas& canvas, const TextStyle& style)
00071     {
00072       canvas.setTextStyle(style);
00073       return canvas;
00074     }
00075 
00077     friend Canvas& operator<<(Canvas& canvas, const Color& color)
00078     {
00079       canvas.setFillColor(color);
00080       return canvas;
00081     }
00082 
00084     friend Canvas& operator<<(Canvas& canvas, const Line& line)
00085     {
00086       canvas.line(line);
00087       return canvas;
00088     }
00089 
00091     friend Canvas& operator<<(Canvas& canvas, const char *comment)
00092     {
00093       canvas.comment(Comment(comment));
00094       return canvas;
00095     }
00096 
00098     friend Canvas& operator<<(Canvas& canvas, const Comment& comment)
00099     {
00100       canvas.comment(comment);
00101       return canvas;
00102     }
00103 
00105     friend Canvas& operator<<(Canvas& canvas, const Rectangle& rect)
00106     {
00107       canvas.rectangle(rect);
00108       return canvas;
00109     }
00110 
00112     friend Canvas& operator<<(Canvas& canvas, const Circle& circle)
00113     {
00114       canvas.circle(circle);
00115       return canvas;
00116     }
00117 
00119     friend Canvas& operator<<(Canvas& canvas, const Text& text)
00120     {
00121       canvas.text(text);
00122       return canvas;
00123     }
00124 
00126     friend Canvas& operator<<(Canvas& canvas, const Polygon& polygon)
00127     {
00128       canvas.polygon(polygon);
00129       return canvas;
00130     }
00131 
00133     friend Canvas& operator<<(Canvas& canvas, const Bitmap& bitmap)
00134     {
00135       canvas.bitmap(bitmap);
00136       return canvas;
00137     }
00138 
00139 
00140     public:
00144     Canvas();
00145 
00146     ~Canvas();
00147 
00153     void setLineStyle( const StrokeStyle& newStyle ) 
00154     {defaults->setSS(newStyle);}
00155 
00160     void removeLineStyle(void) 
00161     {defaults->setSS();}
00162 
00168     virtual void setMarker( const Marker& newMarker ) 
00169     {defaults->setM(newMarker);}
00170 
00175     virtual void removeMarker(void) 
00176     {defaults->setM();}
00177 
00183     void setTextStyle( const TextStyle& newStyle ) 
00184     {defaults->setTS(newStyle);}
00185 
00190     void removeTextStyle(void) 
00191     {defaults->setTS();}
00192 
00198     void setFillColor( const Color& newColor ) 
00199     {defaults->setFC(newColor);}
00200 
00204     void removeFillColor(void) 
00205     {defaults->setFC();}
00206 
00214     virtual void line (double x1, double y1, double x2, double y2)
00215     {
00216       line(Line(x1,y1,x2,y2));
00217     };
00218 
00223     virtual void line (const Line& line)=0;
00224 
00229     virtual void rectangle (const Rectangle& rect)=0;
00230 
00235     virtual void circle (const Circle& circle)=0;
00236 
00241     virtual void text (const Text& text)=0;
00242 
00247     virtual void polygon(const Polygon& polygon)=0;
00248 
00253     virtual void bitmap(const Bitmap& bitmap)=0;
00254 
00259     virtual void comment(const Comment& comment)=0;
00260 
00266     virtual void comment(const char * format, ...)
00267     {
00268       va_list ap;
00269       va_start(ap,format);
00270       comment(Comment(format,ap));
00271       va_end(ap);
00272     }
00273 
00279     void push_state()
00280     {
00281       stateStack.push_back(defaults);
00282       defaults = new VGState();
00283     }
00284 
00289     void pop_state()
00290     {
00291       if(stateStack.size() > 0)
00292       {
00293         delete defaults;
00294         defaults = stateStack.back();
00295         stateStack.pop_back();
00296       }
00297       else
00298         defaults = new VGState();
00299     }
00300 
00305     inline double up() { return (isLL()?1:-1); }
00306 
00310     virtual bool isLL()=0;
00311 
00313     std::vector<VGState*> stateStack;
00314 
00316     VGState *defaults;
00317 
00318     private:
00319 
00320   }; // class Canvas
00321 
00323 
00324 } // namespace vdraw
00325 
00326 #endif //VDRAW_CANVAS_H
00327 

Generated on Wed Feb 8 03:30:57 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1