00001
00010 #ifndef _BOARD_BOARD_H_
00011 #define _BOARD_BOARD_H_
00012
00013 #include <ostream>
00014 #include <string>
00015
00016 #include <vector>
00017
00018 #include "board/Point.h"
00019 #include "board/Shapes.h"
00020 #include "board/ShapeList.h"
00021
00022 namespace BoardLib {
00023
00029 class Board : public ShapeList {
00030
00031 public:
00032
00038 Board( const Color & backgroundColor = Color::none );
00039
00045 Board( const Board & other );
00046
00047 ~Board();
00048
00056 Board & operator=( const Board & other );
00057
00063 void clear( const Color & color = Color::none );
00064
00072 inline void clear( unsigned char red, unsigned char green, unsigned char blue );
00073
00083 void drawLine( float x1, float y1, float x2, float y2,
00084 int depth = -1 );
00085
00096 void drawArrow( float x1, float y1, float x2, float y2,
00097 bool filled = false,
00098 int depth = -1 );
00099
00111 void drawTriangle( float x1, float y1,
00112 float x2, float y2,
00113 float x3, float y3,
00114 int depth = -1 );
00115
00124 void drawTriangle( const Point & p1,
00125 const Point & p2,
00126 const Point & p3,
00127 int depth = -1 );
00128
00140 void fillTriangle( float x1, float y1,
00141 float x2, float y2,
00142 float x3, float y3,
00143 int depth = -1 );
00144
00157 void fillGouraudTriangle( const Point & p1,
00158 const Color & color1,
00159 const Point & p2,
00160 const Color & color2,
00161 const Point & p3,
00162 const Color & color3,
00163 unsigned char divisions = 3,
00164 int depth = -1 );
00165
00181 inline void fillGouraudTriangle( const float x1, const float y1,
00182 const Color & color1,
00183 const float x2, const float y2,
00184 const Color & color2,
00185 const float x3, const float y3,
00186 const Color & color3,
00187 unsigned char divisions = 3,
00188 int depth = -1 );
00189
00202 void fillGouraudTriangle( const Point & p1,
00203 const float brightness1,
00204 const Point & p2,
00205 const float brightness2,
00206 const Point & p3,
00207 const float brightness3,
00208 unsigned char divisions = 3,
00209 int depth = -1 );
00210
00227 inline void fillGouraudTriangle( const float x1, const float y1,
00228 const float brightness1,
00229 const float x2, const float y2,
00230 const float brightness1,
00231 const float x3, const float y3,
00232 const float brightness1,
00233 unsigned char divisions = 3,
00234 int depth = -1 );
00235
00236
00245 void fillTriangle( const Point & p1,
00246 const Point & p2,
00247 const Point & p3,
00248 int depth = -1 );
00249
00259 void drawRectangle( float x, float y,
00260 float width, float height,
00261 int depth = -1 );
00262
00272 void fillRectangle( float x, float y,
00273 float width, float height,
00274 int depth = -1 );
00275
00284 void drawCircle( float x, float y, float radius,
00285 int depth = -1 );
00286
00295 void fillCircle( float x, float y, float radius,
00296 int depth = -1);
00297
00306 void drawEllipse( float x, float y,
00307 float xRadius, float yRadius,
00308 int depth = -1);
00309
00319 void fillEllipse( float x, float y,
00320 float xRadius, float yRadius,
00321 int depth = -1);
00322
00329 void drawPolyline( const std::vector<Point> & points,
00330 int depth = -1 );
00331
00338 void drawClosedPolyline( const std::vector<Point> & points,
00339 int depth = -1 );
00340
00347 void fillPolyline( const std::vector<Point> & points,
00348 int depth = -1 );
00349
00358 void drawText( float x, float y, const char * text,
00359 int depth = -1 );
00360
00368 Board & setFont( std::string font, float fontSize );
00369
00376 Board & setFontSize( float fontSize );
00377
00386 Board & setPenColorRGBi( unsigned char red,
00387 unsigned char green,
00388 unsigned char blue,
00389 unsigned char alpha = 255 );
00390
00400 Board & setPenColorRGBf( float red,
00401 float green,
00402 float blue,
00403 float alpha = 1.0f );
00404
00412 Board & setPenColor( const Color & color );
00413
00414
00424 Board & setFillColorRGBi( unsigned char red,
00425 unsigned char green,
00426 unsigned char blue,
00427 unsigned char alpha = 255 );
00428
00438 Board & setFillColorRGBf( float red, float green, float blue, float alpha = 1.0f );
00439
00447 Board & setFillColor( const Color & color );
00448
00455 Board & setLineWidth( float width );
00456
00465 inline Board & setLineCap( Shape::LineCap cap );
00466
00475 inline Board & setLineJoin( Shape::LineJoin join );
00476
00482 void backgroundColor( const Color & color );
00483
00489 void drawBoundingBox( int depth = -1 );
00490
00497 void save( const char * filename ) const;
00498
00505 void saveEPS( const char * filename, float scale = 1.0f ) const ;
00506
00513 void saveFIG( const char * filename, float scale = 1.0f ) const;
00514
00521 void saveSVG( const char * filename, float scale = 1.0f ) const;
00522
00523 protected:
00524
00525 struct State {
00526 Color penColor;
00527 Color fillColor;
00528 float lineWidth;
00529 Shape::LineCap lineCap;
00530 Shape::LineJoin lineJoin;
00531 std::string font;
00532 float fontSize;
00533 State();
00534 };
00535
00536 State _state;
00537
00538 Color _backgroundColor;
00539 };
00540
00541 extern const char * XFigPostscriptFontnames[];
00542
00543 inline void
00544 Board::clear( unsigned char red, unsigned char green, unsigned char blue )
00545 {
00546 clear( Color( red, green, blue ) );
00547 }
00548
00549 inline Board &
00550 Board::setLineCap( Shape::LineCap cap )
00551 {
00552 _state.lineCap = cap;
00553 return *this;
00554 }
00555
00556 inline Board &
00557 Board::setLineJoin( Shape::LineJoin join )
00558 {
00559 _state.lineJoin = join;
00560 return *this;
00561 }
00562
00563 inline void
00564 Board::fillGouraudTriangle( const float x1, const float y1,
00565 const Color & color1,
00566 const float x2, const float y2,
00567 const Color & color2,
00568 const float x3, const float y3,
00569 const Color & color3,
00570 unsigned char divisions,
00571 int depth )
00572 {
00573 fillGouraudTriangle( Point( x1, y1 ), color1,
00574 Point( x2, y2 ), color2,
00575 Point( x3, y3 ), color3,
00576 divisions, depth );
00577 }
00578
00579 void
00580 Board::fillGouraudTriangle( const float x1, const float y1,
00581 const float brightness1,
00582 const float x2, const float y2,
00583 const float brightness2,
00584 const float x3, const float y3,
00585 const float brightness3,
00586 unsigned char divisions,
00587 int depth )
00588 {
00589 fillGouraudTriangle( Point( x1, y1 ), brightness1,
00590 Point( x2, y2 ), brightness2,
00591 Point( x3, y3 ), brightness3,
00592 divisions, depth );
00593 }
00594
00595 }
00596
00597 #endif