00001
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/Shapes.h"
00019 #include "board/ShapeList.h"
00020
00021 namespace LibBoard {
00022
00028 class Board : public ShapeList {
00029
00030 public:
00031
00032 enum PageSize { BoundingBox, A4, Letter };
00033 enum Unit { PT, IN, CM, MM };
00034 static const double Degree;
00035
00041 Board( const Color & backgroundColor = Color::None );
00042
00048 Board( const Board & other );
00049
00050 ~Board();
00051
00059 Board & operator=( const Board & other );
00060
00061
00069 Board & operator<<( const Shape & shape );
00070
00078 Board & operator<<( Unit unit );
00079
00085 void clear( const Color & color = Color::None );
00086
00094 inline void clear( unsigned char red, unsigned char green, unsigned char blue );
00095
00101 void setUnit( Unit unit );
00102
00109 void setUnit( float factor, Unit unit );
00110
00118 void drawDot( float x, float y, int depth = -1 );
00119
00129 void drawLine( float x1, float y1, float x2, float y2,
00130 int depth = -1 );
00131
00142 void drawArrow( float x1, float y1, float x2, float y2,
00143 bool filled = true,
00144 int depth = -1 );
00145
00157 void drawTriangle( float x1, float y1,
00158 float x2, float y2,
00159 float x3, float y3,
00160 int depth = -1 );
00161
00170 void drawTriangle( const Point & p1,
00171 const Point & p2,
00172 const Point & p3,
00173 int depth = -1 );
00174
00186 void fillTriangle( float x1, float y1,
00187 float x2, float y2,
00188 float x3, float y3,
00189 int depth = -1 );
00190
00203 void fillGouraudTriangle( const Point & p1,
00204 const Color & color1,
00205 const Point & p2,
00206 const Color & color2,
00207 const Point & p3,
00208 const Color & color3,
00209 unsigned char divisions = 3,
00210 int depth = -1 );
00211
00227 inline void fillGouraudTriangle( const float x1, const float y1,
00228 const Color & color1,
00229 const float x2, const float y2,
00230 const Color & color2,
00231 const float x3, const float y3,
00232 const Color & color3,
00233 unsigned char divisions = 3,
00234 int depth = -1 );
00235
00248 void fillGouraudTriangle( const Point & p1,
00249 const float brightness1,
00250 const Point & p2,
00251 const float brightness2,
00252 const Point & p3,
00253 const float brightness3,
00254 unsigned char divisions = 3,
00255 int depth = -1 );
00256
00273 inline void fillGouraudTriangle( const float x1, const float y1,
00274 const float brightness1,
00275 const float x2, const float y2,
00276 const float brightness2,
00277 const float x3, const float y3,
00278 const float brightness3,
00279 unsigned char divisions = 3,
00280 int depth = -1 );
00281
00282
00291 void fillTriangle( const Point & p1,
00292 const Point & p2,
00293 const Point & p3,
00294 int depth = -1 );
00295
00305 void drawRectangle( float x, float y,
00306 float width, float height,
00307 int depth = -1 );
00308
00318 void fillRectangle( float x, float y,
00319 float width, float height,
00320 int depth = -1 );
00321
00330 void drawCircle( float x, float y, float radius,
00331 int depth = -1 );
00332
00341 void fillCircle( float x, float y, float radius,
00342 int depth = -1);
00343
00352 void drawEllipse( float x, float y,
00353 float xRadius, float yRadius,
00354 int depth = -1);
00355
00365 void fillEllipse( float x, float y,
00366 float xRadius, float yRadius,
00367 int depth = -1);
00368
00375 void drawPolyline( const std::vector<Point> & points,
00376 int depth = -1 );
00377
00384 void drawClosedPolyline( const std::vector<Point> & points,
00385 int depth = -1 );
00386
00393 void fillPolyline( const std::vector<Point> & points,
00394 int depth = -1 );
00395
00404 void drawText( float x, float y, const char * text,
00405 int depth = -1 );
00406
00415 void drawText( float x, float y, const std::string & str,
00416 int depth = -1 );
00417
00425 Board & setFont( const Fonts::Font font, float fontSize );
00426
00433 Board & setFontSize( float fontSize );
00434
00443 Board & setPenColorRGBi( unsigned char red,
00444 unsigned char green,
00445 unsigned char blue,
00446 unsigned char alpha = 255 );
00447
00457 Board & setPenColorRGBf( float red,
00458 float green,
00459 float blue,
00460 float alpha = 1.0f );
00461
00469 Board & setPenColor( const Color & color );
00470
00471
00481 Board & setFillColorRGBi( unsigned char red,
00482 unsigned char green,
00483 unsigned char blue,
00484 unsigned char alpha = 255 );
00485
00495 Board & setFillColorRGBf( float red, float green, float blue, float alpha = 1.0f );
00496
00504 Board & setFillColor( const Color & color );
00505
00512 Board & setLineWidth( float width );
00513
00522 inline Board & setLineCap( Shape::LineCap cap );
00523
00532 inline Board & setLineJoin( Shape::LineJoin join );
00533
00539 void backgroundColor( const Color & color );
00540
00546 void drawBoundingBox( int depth = -1 );
00547
00548
00558 void addDuplicates( const Shape & shape,
00559 unsigned int times,
00560 double dx, double dy );
00561
00562
00572 void save( const char * filename, PageSize size = Board::BoundingBox, float margin = 10.0 ) const;
00573
00584 void save( const char * filename, float pageWidth, float pageHeight, float margin = 10.0 ) const;
00585
00594 void saveEPS( const char * filename, PageSize size = Board::BoundingBox, float margin = 10.0 ) const ;
00595
00606 void saveEPS( const char * filename, float pageWidth, float pageHeight, float margin = 10.0 ) const ;
00607
00616 void saveFIG( const char * filename, PageSize size = Board::BoundingBox, float margin = 10.0 ) const;
00617
00628 void saveFIG( const char * filename, float pageWidth, float pageHeight, float margin = 10.0 ) const ;
00629
00638 void saveSVG( const char * filename, PageSize size = Board::BoundingBox, float margin = 10.0 ) const;
00639
00650 void saveSVG( const char * filename, float pageWidth, float pageHeight, float margin = 10.0 ) const ;
00651
00652 protected:
00653
00654 struct State {
00655 Color penColor;
00656 Color fillColor;
00657 float lineWidth;
00658 Shape::LineCap lineCap;
00659 Shape::LineJoin lineJoin;
00660 Fonts::Font font;
00661 float fontSize;
00662 float unitFactor;
00663 State();
00664 float unit( const float & x ) { return x * unitFactor; }
00665 Point unit( const Point & p ) { return Point( p.x * unitFactor, p.y * unitFactor); }
00666 void unit( Shape & shape ) { shape.scaleAll( unitFactor ); }
00667 };
00668 State _state;
00669 Color _backgroundColor;
00670 };
00671
00672 inline void
00673 Board::clear( unsigned char red, unsigned char green, unsigned char blue )
00674 {
00675 clear( Color( red, green, blue ) );
00676 }
00677
00678 inline Board &
00679 Board::setLineCap( Shape::LineCap cap )
00680 {
00681 _state.lineCap = cap;
00682 return *this;
00683 }
00684
00685 inline Board &
00686 Board::setLineJoin( Shape::LineJoin join )
00687 {
00688 _state.lineJoin = join;
00689 return *this;
00690 }
00691
00692 inline void
00693 Board::fillGouraudTriangle( const float x1, const float y1,
00694 const Color & color1,
00695 const float x2, const float y2,
00696 const Color & color2,
00697 const float x3, const float y3,
00698 const Color & color3,
00699 unsigned char divisions,
00700 int depth )
00701 {
00702 fillGouraudTriangle( Point( x1, y1 ), color1,
00703 Point( x2, y2 ), color2,
00704 Point( x3, y3 ), color3,
00705 divisions, depth );
00706 }
00707
00708 void
00709 Board::fillGouraudTriangle( const float x1, const float y1,
00710 const float brightness1,
00711 const float x2, const float y2,
00712 const float brightness2,
00713 const float x3, const float y3,
00714 const float brightness3,
00715 unsigned char divisions,
00716 int depth )
00717 {
00718 fillGouraudTriangle( Point( x1, y1 ), brightness1,
00719 Point( x2, y2 ), brightness2,
00720 Point( x3, y3 ), brightness3,
00721 divisions, depth );
00722 }
00723
00724 }
00725
00726 #endif