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
00021 namespace BoardLib {
00022
00028 class Board {
00029 public:
00030
00036 Board( const Color & backgroundColor = Color::none );
00037
00038 ~Board();
00039
00045 void clear( const Color & color = Color::none );
00046
00054 inline void clear( unsigned char red, unsigned char green, unsigned char blue );
00055
00065 void drawLine( float x1, float y1, float x2, float y2,
00066 unsigned int depth = 0 );
00067
00078 void drawArrow( float x1, float y1, float x2, float y2,
00079 bool filled = false,
00080 unsigned int depth = 0 );
00081
00093 void drawTriangle( float x1, float y1,
00094 float x2, float y2,
00095 float x3, float y3,
00096 unsigned int depth = 0 );
00097
00106 void drawTriangle( const Point & p1,
00107 const Point & p2,
00108 const Point & p3,
00109 unsigned int depth = 0 );
00110
00122 void fillTriangle( float x1, float y1,
00123 float x2, float y2,
00124 float x3, float y3,
00125 unsigned int depth = 0 );
00126
00139 void fillGouraudTriangle( const Point & p1,
00140 const Color & color1,
00141 const Point & p2,
00142 const Color & color2,
00143 const Point & p3,
00144 const Color & color3,
00145 unsigned char divisions = 3,
00146 unsigned int depth = 0 );
00147
00163 inline void fillGouraudTriangle( const float x1, const float y1,
00164 const Color & color1,
00165 const float x2, const float y2,
00166 const Color & color2,
00167 const float x3, const float y3,
00168 const Color & color3,
00169 unsigned char divisions = 3,
00170 unsigned int depth = 0 );
00171
00184 void fillGouraudTriangle( const Point & p1,
00185 const float brightness1,
00186 const Point & p2,
00187 const float brightness2,
00188 const Point & p3,
00189 const float brightness3,
00190 unsigned char divisions = 3,
00191 unsigned int depth = 0 );
00192
00209 inline void fillGouraudTriangle( const float x1, const float y1,
00210 const float brightness1,
00211 const float x2, const float y2,
00212 const float brightness1,
00213 const float x3, const float y3,
00214 const float brightness1,
00215 unsigned char divisions = 3,
00216 unsigned int depth = 0 );
00217
00218
00227 void fillTriangle( const Point & p1,
00228 const Point & p2,
00229 const Point & p3,
00230 unsigned int depth = 0 );
00231
00241 void drawRectangle( float x, float y,
00242 float width, float height,
00243 unsigned int depth = 0 );
00244
00254 void fillRectangle( float x, float y,
00255 float width, float height,
00256 unsigned int depth = 0 );
00257
00266 void drawCircle( float x, float y, float radius,
00267 unsigned int depth = 0 );
00268
00277 void fillCircle( float x, float y, float radius,
00278 unsigned int depth = 0);
00279
00288 void drawEllipse( float x, float y,
00289 float xRadius, float yRadius,
00290 unsigned int depth = 0);
00291
00301 void fillEllipse( float x, float y,
00302 float xRadius, float yRadius,
00303 unsigned int depth = 0);
00304
00311 void drawPolyline( const std::vector<Point> & points,
00312 unsigned int depth = 0 );
00313
00320 void drawClosedPolyline( const std::vector<Point> & points,
00321 unsigned int depth = 0 );
00322
00329 void fillPolyline( const std::vector<Point> & points,
00330 unsigned int depth = 0 );
00331
00340 void drawText( float x, float y, const char * text,
00341 unsigned int depth = 0 );
00342
00350 Board & setFont( std::string font, float fontSize );
00351
00358 Board & setFontSize( float fontSize );
00359
00368 Board & setPenColorRGBi( unsigned char red,
00369 unsigned char green,
00370 unsigned char blue,
00371 unsigned char alpha = 255 );
00372
00382 Board & setPenColorRGBf( float red,
00383 float green,
00384 float blue,
00385 float alpha = 1.0f );
00386
00394 Board & setPenColor( const Color & color );
00395
00396
00406 Board & setFillColorRGBi( unsigned char red,
00407 unsigned char green,
00408 unsigned char blue,
00409 unsigned char alpha = 255 );
00410
00420 Board & setFillColorRGBf( float red, float green, float blue, float alpha = 1.0f );
00421
00429 Board & setFillColor( const Color & color );
00430
00437 Board & setLineWidth( float width );
00438
00447 inline Board & setLineCap( Shape::LineCap cap );
00448
00457 inline Board & setLineJoin( Shape::LineJoin join );
00458
00464 void backgroundColor( const Color & color );
00465
00471 void drawBoundingBox( unsigned int depth = 0 );
00472
00479 void save( const char * filename ) const;
00480
00487 void saveEPS( const char * filename, float scale = 1.0f ) const ;
00488
00495 void saveFIG( const char * filename, float scale = 1.0f ) const;
00496
00503 void saveSVG( const char * filename, float scale = 1.0f ) const;
00504
00505
00506 protected:
00507
00513 Rect computeBoundingBox() const;
00514
00515 Color _penColor;
00516 Color _fillColor;
00517 float _lineWidth;
00518 Shape::LineCap _lineCap;
00519 Shape::LineJoin _lineJoin;
00520 std::string _font;
00521 float _fontSize;
00522 unsigned int _depth;
00523 std::vector< Shape* > _shapes;
00525 Color _backgroundColor;
00526 };
00527
00528 extern const char * XFigPostscriptFontnames[];
00529
00530 inline void
00531 Board::clear( unsigned char red, unsigned char green, unsigned char blue )
00532 {
00533 clear( Color( red, green, blue ) );
00534 }
00535
00536 inline Board &
00537 Board::setLineCap( Shape::LineCap cap )
00538 {
00539 _lineCap = cap;
00540 return *this;
00541 }
00542
00543 inline Board &
00544 Board::setLineJoin( Shape::LineJoin join )
00545 {
00546 _lineJoin = join;
00547 return *this;
00548 }
00549
00550 inline void
00551 Board::fillGouraudTriangle( const float x1, const float y1,
00552 const Color & color1,
00553 const float x2, const float y2,
00554 const Color & color2,
00555 const float x3, const float y3,
00556 const Color & color3,
00557 unsigned char divisions,
00558 unsigned int depth )
00559 {
00560 fillGouraudTriangle( Point( x1, y1 ), color1,
00561 Point( x2, y2 ), color2,
00562 Point( x3, y3 ), color3,
00563 divisions, depth );
00564 }
00565
00566 void
00567 Board::fillGouraudTriangle( const float x1, const float y1,
00568 const float brightness1,
00569 const float x2, const float y2,
00570 const float brightness2,
00571 const float x3, const float y3,
00572 const float brightness3,
00573 unsigned char divisions,
00574 unsigned int depth )
00575 {
00576 fillGouraudTriangle( Point( x1, y1 ), brightness1,
00577 Point( x2, y2 ), brightness2,
00578 Point( x3, y3 ), brightness3,
00579 divisions, depth );
00580 }
00581
00582 }
00583
00584 #endif