- Main Page
- Classes
- Files
- Examples

- File List
- File Members

# include/Board.h

Go to the documentation of this file.

    00001 /* -*- mode: c++ -*- */
    00010 #ifndef _BOARD_BOARD_H_
    00011 #define _BOARD_BOARD_H_
    00012
    00013 #include <ostream>
    00014 #include <string>
    00015 #include <vector>
    00016
    00017 #include "board/Point.h"
    00018 #include "board/Path.h"
    00019 #include "board/Shapes.h"
    00020 #include "board/ShapeList.h"
    00021
    00022 namespace LibBoard {
    00023
    00029 class Board : public ShapeList {
    00030
    00031 public:
    00032
    00033   enum PageSize { BoundingBox, A4, Letter };
    00034   enum Unit { UPoint, UInche, UCentimeter, UMillimeter };
    00035   static const double Degree;
    00036
    00042   Board( const Color & backgroundColor = Color::None );
    00043
    00049   Board( const Board & other );
    00050
    00051   ~Board();
    00052
    00060   Board & operator=( const Board & other );
    00061
    00062
    00070   Board & operator<<( const Shape & shape );
    00071
    00079   Board & operator<<( Unit unit );
    00080
    00086   void clear( const Color & color = Color::None );
    00087
    00095   inline void clear( unsigned char red, unsigned char green, unsigned char blue );
    00096
    00097
    00098
    00099   Board & rotate( double angle, const Point & center );
    00100
    00101   Board & rotate( double angle );
    00102
    00103   Board & translate( double dx, double dy );
    00104
    00105   Board & scale( double sx, double sy );
    00106
    00107   Board & scale( double s );
    00108
    00109   Board rotated( double angle, const Point & center );
    00110
    00111   Board rotated( double angle );
    00112
    00113   Board translated( double dx, double dy );
    00114
    00115   Board scaled( double sx, double sy );
    00116
    00117   Board scaled( double s );
    00118
    00119
    00120
    00126   void setUnit( Unit unit );
    00127
    00134   void setUnit( double factor, Unit unit );
    00135
    00143   void drawDot( double x, double y, int depth = -1 );
    00144
    00154   void drawLine( double x1, double y1, double x2, double y2,
    00155                  int depth = -1 );
    00156
    00167   void drawArrow( double x1, double y1, double x2, double y2,
    00168                   bool filled = true,
    00169                   int depth = -1 );
    00170
    00182   void drawTriangle( double x1, double y1,
    00183                      double x2, double y2,
    00184                      double x3, double y3,
    00185                      int depth = -1 );
    00186
    00195   void drawTriangle( const Point & p1,
    00196                      const Point & p2,
    00197                      const Point & p3,
    00198                      int depth = -1 );
    00199
    00211   void fillTriangle( double x1, double y1,
    00212                      double x2, double y2,
    00213                      double x3, double y3,
    00214                      int depth = -1 );
    00215
    00228   void fillGouraudTriangle( const Point & p1,
    00229                             const Color & color1,
    00230                             const Point & p2,
    00231                             const Color & color2,
    00232                             const Point & p3,
    00233                             const Color & color3,
    00234                             unsigned char divisions = 3,
    00235                             int depth = -1 );
    00236
    00252   inline void fillGouraudTriangle( const double x1, const double y1,
    00253                                    const Color & color1,
    00254                                    const double x2, const double y2,
    00255                                    const Color & color2,
    00256                                    const double x3, const double y3,
    00257                                    const Color & color3,
    00258                                    unsigned char divisions = 3,
    00259                                    int depth = -1 );
    00260
    00273   void fillGouraudTriangle( const Point & p1,
    00274                             const float brightness1,
    00275                             const Point & p2,
    00276                             const float brightness2,
    00277                             const Point & p3,
    00278                             const float brightness3,
    00279                             unsigned char divisions = 3,
    00280                             int depth = -1 );
    00281
    00298   inline void fillGouraudTriangle( const double x1, const double y1,
    00299                                    const float brightness1,
    00300                                    const double x2, const double y2,
    00301                                    const float brightness2,
    00302                                    const double x3, const double y3,
    00303                                    const float brightness3,
    00304                                    unsigned char divisions = 3,
    00305                                    int depth = -1 );
    00306
    00307
    00316   void fillTriangle( const Point & p1,
    00317                      const Point & p2,
    00318                      const Point & p3,
    00319                      int depth = -1 );
    00320
    00330   void drawRectangle( double x, double y,
    00331                       double width, double height,
    00332                       int depth = -1 );
    00333
    00343   void fillRectangle( double x, double y,
    00344                       double width, double height,
    00345                       int depth = -1 );
    00346
    00355   void drawCircle( double x, double y, double radius,
    00356                    int depth = -1 );
    00357
    00366   void fillCircle( double x, double y, double radius,
    00367                    int depth = -1);
    00368
    00377   void drawEllipse( double x, double y,
    00378                     double xRadius, double yRadius,
    00379                     int depth = -1);
    00380
    00390   void fillEllipse( double x, double y,
    00391                     double xRadius, double yRadius,
    00392                     int depth = -1);
    00393
    00400   void drawPolyline( const std::vector<Point> & points,
    00401                      int depth = -1 );
    00402
    00409   void drawClosedPolyline( const std::vector<Point> & points,
    00410                            int depth = -1 );
    00411
    00418   void fillPolyline( const std::vector<Point> & points,
    00419                      int depth = -1 );
    00420
    00429   void drawText( double x, double y, const char * text,
    00430                  int depth = -1 );
    00431
    00440   void drawText( double x, double y, const std::string & str,
    00441                  int depth = -1 );
    00442
    00450   Board & setFont( const Fonts::Font font, double fontSize );
    00451
    00458   Board & setFontSize( double fontSize );
    00459
    00468   Board & setPenColorRGBi( unsigned char red,
    00469                            unsigned char green,
    00470                            unsigned char blue,
    00471                            unsigned char alpha = 255 );
    00472
    00482   Board & setPenColorRGBf(  float red,
    00483                             float green,
    00484                             float blue,
    00485                             float alpha = 1.0f );
    00486
    00494   Board & setPenColor( const Color & color );
    00495
    00496
    00506   Board & setFillColorRGBi( unsigned char red,
    00507                             unsigned char green,
    00508                             unsigned char blue,
    00509                             unsigned char alpha = 255 );
    00510
    00520   Board & setFillColorRGBf( float red, float green, float blue, float alpha = 1.0f );
    00521
    00529   Board & setFillColor( const Color & color );
    00530
    00537   Board & setLineWidth( double width );
    00538
    00545   inline Board & setLineStyle( Shape::LineStyle style );
    00546
    00555   inline Board & setLineCap( Shape::LineCap cap );
    00556
    00565   inline Board & setLineJoin( Shape::LineJoin join );
    00566
    00572   void backgroundColor( const Color & color );
    00573
    00579   void drawBoundingBox( int depth = -1 );
    00580
    00581
    00590   void setClippingRectangle(  double x, double y,
    00591                               double width, double height );
    00592
    00598   void setClippingPath(  const std::vector<Point> & points  );
    00599
    00605   void setClippingPath( const Path & path );
    00606
    00617   void addDuplicates( const Shape & shape,
    00618                       unsigned int times,
    00619                       double dx, double dy, double scale = 1.0 );
    00620
    00634   void addDuplicates( const Shape & shape,
    00635                       unsigned int times,
    00636                       double dx, double dy,
    00637                       double scaleX,
    00638                       double scaleY,
    00639                       double angle = 0.0 );
    00640
    00650   void save( const char * filename, PageSize size = Board::BoundingBox, double margin = 10.0 ) const;
    00651
    00662   void save( const char * filename, double pageWidth, double pageHeight, double margin = 10.0 ) const;
    00663
    00672   void saveEPS( const char * filename, PageSize size = Board::BoundingBox, double margin = 10.0 ) const ;
    00673
    00684   void saveEPS( const char * filename, double pageWidth, double pageHeight, double margin = 10.0 ) const ;
    00685
    00694   void saveFIG( const char * filename, PageSize size = Board::BoundingBox, double margin = 10.0 ) const;
    00695
    00706   void saveFIG( const char * filename, double pageWidth, double pageHeight, double margin = 10.0 ) const ;
    00707
    00716   void saveSVG( const char * filename, PageSize size = Board::BoundingBox, double margin = 10.0 ) const;
    00717
    00728   void saveSVG( const char * filename, double pageWidth, double pageHeight, double margin = 10.0 ) const ;
    00729
    00730  protected:
    00731
    00736   struct State {
    00737     Color penColor;
    00738     Color fillColor;
    00739     double lineWidth;
    00740     Shape::LineStyle lineStyle;
    00741     Shape::LineCap lineCap;
    00742     Shape::LineJoin lineJoin;
    00743     Fonts::Font font;
    00744     double fontSize;
    00745     double unitFactor;
    00746     State();
    00747     double unit( const double & x ) { return x * unitFactor; }
    00748     Point unit( const Point & p ) { return Point( p.x * unitFactor, p.y * unitFactor); }
    00749     void unit( Shape & shape ) {  shape.scaleAll( unitFactor ); }
    00750   };
    00751   State _state;
    00752   Color _backgroundColor;
    00753   Path _clippingPath;
    00754 };
    00755
    00756 void
    00757 Board::clear( unsigned char red, unsigned char green, unsigned char blue )
    00758 {
    00759   clear( Color( red, green, blue ) );
    00760 }
    00761
    00762 Board &
    00763 Board::setLineStyle( Shape::LineStyle style )
    00764 {
    00765   _state.lineStyle = style;
    00766   return *this;
    00767 }
    00768
    00769 Board &
    00770 Board::setLineCap( Shape::LineCap cap )
    00771 {
    00772   _state.lineCap = cap;
    00773   return *this;
    00774 }
    00775
    00776 Board &
    00777 Board::setLineJoin( Shape::LineJoin join )
    00778 {
    00779   _state.lineJoin = join;
    00780   return *this;
    00781 }
    00782
    00783 void
    00784 Board::fillGouraudTriangle( const double x1, const double y1,
    00785                             const Color & color1,
    00786                             const double x2, const double y2,
    00787                             const Color & color2,
    00788                             const double x3, const double y3,
    00789                             const Color & color3,
    00790                             unsigned char divisions,
    00791                             int depth /* = -1 */ )
    00792 {
    00793   fillGouraudTriangle( Point( x1, y1 ), color1,
    00794                        Point( x2, y2 ), color2,
    00795                        Point( x3, y3 ), color3,
    00796                        divisions, depth );
    00797 }
    00798
    00799 void
    00800 Board::fillGouraudTriangle( const double x1, const double y1,
    00801                             const float brightness1,
    00802                             const double x2, const double y2,
    00803                             const float brightness2,
    00804                             const double x3, const double y3,
    00805                             const float brightness3,
    00806                             unsigned char divisions,
    00807                             int depth /* = -1 */ )
    00808 {
    00809   fillGouraudTriangle( Point( x1, y1 ), brightness1,
    00810                        Point( x2, y2 ), brightness2,
    00811                        Point( x3, y3 ), brightness3,
    00812                        divisions, depth );
    00813 }
    00814
    00815 } // namespace Board
    00816
    00817 #endif