Board  0.9.2
Board.h
Go to the documentation of this file.
1 /* -*- mode: c++ -*- */
27 #ifndef _BOARD_BOARD_H_
28 #define _BOARD_BOARD_H_
29 
30 #include <ostream>
31 #include <string>
32 #include <vector>
33 
34 #include "board/Point.h"
35 #include "board/Path.h"
36 #include "board/Shapes.h"
37 #include "board/Image.h"
38 #include "board/ShapeList.h"
39 
40 namespace LibBoard {
41 
47 class Board : public ShapeList {
48 
49 public:
50 
51  enum PageSize { BoundingBox = 0,
52  A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10,
53  Letter, Legal, Executive };
54 
55  enum Unit { UPoint, UInche, UCentimeter, UMillimeter };
56  static const double Degree;
57 
63  Board( const Color & backgroundColor = Color::None );
64 
70  Board( const Board & other );
71 
72  ~Board();
73 
81  Board & operator=( const Board & other );
82 
83 
91  Board & operator<<( const Shape & shape );
92 
100  Board & operator<<( Unit unit );
101 
107  void clear( const Color & color = Color::None );
108 
116  inline void clear( unsigned char red, unsigned char green, unsigned char blue );
117 
118 
119 
120  Board & rotate( double angle, const Point & center );
121 
122  Board & rotate( double angle );
123 
124  Board & translate( double dx, double dy );
125 
126  Board & scale( double sx, double sy );
127 
128  Board & scale( double s );
129 
130  Board rotated( double angle, const Point & center );
131 
132  Board rotated( double angle );
133 
134  Board translated( double dx, double dy );
135 
136  Board scaled( double sx, double sy );
137 
138  Board scaled( double s );
139 
140 
141 
147  void setUnit( Unit unit );
148 
155  void setUnit( double factor, Unit unit );
156 
164  void drawDot( double x, double y, int depth = -1 );
165 
175  void drawLine( double x1, double y1, double x2, double y2,
176  int depth = -1 );
177 
188  void drawArrow( double x1, double y1, double x2, double y2,
189  bool filled = true,
190  int depth = -1 );
191 
203  void drawTriangle( double x1, double y1,
204  double x2, double y2,
205  double x3, double y3,
206  int depth = -1 );
207 
216  void drawTriangle( const Point & p1,
217  const Point & p2,
218  const Point & p3,
219  int depth = -1 );
220 
232  void fillTriangle( double x1, double y1,
233  double x2, double y2,
234  double x3, double y3,
235  int depth = -1 );
236 
249  void fillGouraudTriangle( const Point & p1,
250  const Color & color1,
251  const Point & p2,
252  const Color & color2,
253  const Point & p3,
254  const Color & color3,
255  unsigned char divisions = 3,
256  int depth = -1 );
257 
273  inline void fillGouraudTriangle( const double x1, const double y1,
274  const Color & color1,
275  const double x2, const double y2,
276  const Color & color2,
277  const double x3, const double y3,
278  const Color & color3,
279  unsigned char divisions = 3,
280  int depth = -1 );
281 
294  void fillGouraudTriangle( const Point & p1,
295  const float brightness1,
296  const Point & p2,
297  const float brightness2,
298  const Point & p3,
299  const float brightness3,
300  unsigned char divisions = 3,
301  int depth = -1 );
302 
319  inline void fillGouraudTriangle( const double x1, const double y1,
320  const float brightness1,
321  const double x2, const double y2,
322  const float brightness2,
323  const double x3, const double y3,
324  const float brightness3,
325  unsigned char divisions = 3,
326  int depth = -1 );
327 
328 
337  void fillTriangle( const Point & p1,
338  const Point & p2,
339  const Point & p3,
340  int depth = -1 );
341 
351  void drawRectangle( double left, double top,
352  double width, double height,
353  int depth = -1 );
354 
364  void fillRectangle( double left, double top,
365  double width, double height,
366  int depth = -1 );
367 
376  void drawCircle( double x, double y, double radius,
377  int depth = -1 );
378 
387  void fillCircle( double x, double y, double radius,
388  int depth = -1);
389 
398  void drawEllipse( double x, double y,
399  double xRadius, double yRadius,
400  int depth = -1);
401 
411  void fillEllipse( double x, double y,
412  double xRadius, double yRadius,
413  int depth = -1);
414 
421  void drawPolyline( const std::vector<Point> & points,
422  int depth = -1 );
423 
430  void drawClosedPolyline( const std::vector<Point> & points,
431  int depth = -1 );
432 
439  void fillPolyline( const std::vector<Point> & points,
440  int depth = -1 );
441 
450  void drawText( double x, double y, const char * text,
451  int depth = -1 );
452 
461  void drawText( double x, double y, const std::string & str,
462  int depth = -1 );
463 
471  Board & setFont( const Fonts::Font font, double fontSize );
472 
479  Board & setFontSize( double fontSize );
480 
489  Board & setPenColorRGBi( unsigned char red,
490  unsigned char green,
491  unsigned char blue,
492  unsigned char alpha = 255 );
493 
503  Board & setPenColorRGBf( float red,
504  float green,
505  float blue,
506  float alpha = 1.0f );
507 
515  Board & setPenColor( const Color & color );
516 
517 
527  Board & setFillColorRGBi( unsigned char red,
528  unsigned char green,
529  unsigned char blue,
530  unsigned char alpha = 255 );
531 
541  Board & setFillColorRGBf( float red, float green, float blue, float alpha = 1.0f );
542 
550  Board & setFillColor( const Color & color );
551 
558  Board & setLineWidth( double width );
559 
566  Board & setLineStyle( Shape::LineStyle style );
567 
576  inline Board & setLineCap( Shape::LineCap cap );
577 
586  inline Board & setLineJoin( Shape::LineJoin join );
587 
593  void backgroundColor( const Color & color );
594 
600  void drawBoundingBox( int depth = -1 );
601 
610  void setClippingRectangle( double x, double y,
611  double width, double height );
612 
618  void setClippingPath( const std::vector<Point> & points );
619 
625  void setClippingPath( const Path & path );
626 
637  void addDuplicates( const Shape & shape,
638  std::size_t times,
639  double dx,
640  double dy,
641  double scale = 1.0 );
642 
655  void addDuplicates( const Shape & shape,
656  std::size_t times,
657  double dx, double dy,
658  double scaleX, double scaleY,
659  double angle = 0.0 );
660 
670  void save( const char * filename, PageSize size = Board::BoundingBox, double margin = 10.0 ) const;
671 
682  void save( const char * filename, double pageWidth, double pageHeight, double margin = 10.0 ) const;
683 
693  void saveEPS( std::ostream & out, PageSize size = Board::BoundingBox, double margin = 10.0, const std::string & title = std::string() ) const ;
694 
703  void saveEPS( const char * filename, PageSize size = Board::BoundingBox, double margin = 10.0, const std::string & title = std::string() ) const ;
704 
715  void saveEPS( std::ostream & out, double pageWidth, double pageHeight, double margin = 10.0, const std::string & title = std::string() ) const ;
716 
727  void saveEPS( const char * filename, double pageWidth, double pageHeight, double margin = 10.0, const std::string & title = std::string() ) const ;
728 
737  void saveFIG( const char * filename, PageSize size = Board::BoundingBox, double margin = 10.0 ) const;
738 
747  void saveFIG( std::ostream & out, PageSize size = Board::BoundingBox, double margin = 10.0 ) const;
748 
759  void saveFIG( const char * filename, double pageWidth, double pageHeight, double margin = 10.0 ) const ;
760 
771  void saveFIG( std::ostream & out, double pageWidth, double pageHeight, double margin = 10.0 ) const ;
772 
781  void saveSVG( const char * filename, PageSize size = Board::BoundingBox, double margin = 10.0 ) const;
782 
791  void saveSVG( std::ostream & out, PageSize size = Board::BoundingBox, double margin = 10.0 ) const;
792 
803  void saveSVG( const char * filename, double pageWidth, double pageHeight, double margin = 10.0 ) const ;
804 
815  void saveSVG( std::ostream & out, double pageWidth, double pageHeight, double margin = 10.0 ) const ;
816 
825  void saveTikZ( const char * filename, PageSize size = Board::BoundingBox, double margin = 10.0 ) const;
826 
835  void saveTikZ( std::ostream & out, PageSize size = Board::BoundingBox, double margin = 10.0 ) const;
836 
847  void saveTikZ( const char * filename, double pageWidth, double pageHeight, double margin = 10.0 ) const ;
848 
859  void saveTikZ( std::ostream & out, double pageWidth, double pageHeight, double margin = 10.0 ) const ;
860 
861 
879  static Group makeGrid(Point topLeft, size_t columns, size_t rows,
880  double width, double height,
881  Color penColor, Color fillColor,
882  double lineWidth,
883  const LineStyle style = SolidStyle,
884  const LineCap cap = ButtCap,
885  const LineJoin join = MiterJoin,
886  int depth = -1 );
887 
888 protected:
889 
894  struct State {
897  double lineWidth;
898  Shape::LineStyle lineStyle;
899  Shape::LineCap lineCap;
900  Shape::LineJoin lineJoin;
901  Fonts::Font font;
902  double fontSize;
903  double unitFactor;
904  State();
905  double unit( const double & x ) { return x * unitFactor; }
906  Point unit( const Point & p ) { return Point( p.x * unitFactor, p.y * unitFactor); }
907  void unit( Shape & shape ) { shape.scaleAll( unitFactor ); }
908  };
911  Path _clippingPath;
912 };
913 } // namespace LibBoard
914 
915 #include "board/Board.ih"
916 
917 #endif
void drawRectangle(double left, double top, double width, double height, int depth=-1)
Definition: Board.cpp:389
Abstract structure for a 2D shape.
Definition: Shapes.h:56
Board & setLineWidth(double width)
Definition: Board.cpp:310
Board & operator<<(const Shape &shape)
Definition: Board.cpp:116
Board & rotate(double angle, const Point &center)
Definition: Board.cpp:141
Board & setFillColorRGBi(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha=255)
Definition: Board.cpp:286
Structure representing an RGB triple.
Definition: Color.h:39
void drawText(double x, double y, const char *text, int depth=-1)
Definition: Board.cpp:650
Class for EPS, FIG or SVG drawings.
Definition: Board.h:47
static Group makeGrid(Point topLeft, size_t columns, size_t rows, double width, double height, Color penColor, Color fillColor, double lineWidth, const LineStyle style=SolidStyle, const LineCap cap=ButtCap, const LineJoin join=MiterJoin, int depth=-1)
Definition: Board.cpp:1110
void fillEllipse(double x, double y, double xRadius, double yRadius, int depth=-1)
Definition: Board.cpp:456
virtual Point center() const
Definition: Shapes.cpp:88
double fontSize
Definition: Board.h:902
void drawTriangle(double x1, double y1, double x2, double y2, double x3, double y3, int depth=-1)
Definition: Board.cpp:524
Board & setLineJoin(Shape::LineJoin join)
Shape::LineJoin lineJoin
Definition: Board.h:900
void setClippingPath(const std::vector< Point > &points)
Definition: Board.cpp:698
Definition: Board.h:40
Board & operator=(const Board &other)
Definition: Board.cpp:100
The Point structure. @copyright This source code is part of the Board project, a C++ library whose pu...
Classes ShapeList and Group.
A group of shapes. A group is basically a ShapeList except that when rendered in either an SVG of a F...
Definition: ShapeList.h:260
void fillTriangle(double x1, double y1, double x2, double y2, double x3, double y3, int depth=-1)
Definition: Board.cpp:563
void fillRectangle(double left, double top, double width, double height, int depth=-1)
Definition: Board.cpp:404
A path, according to Postscript and SVG definition.
Definition: Path.h:41
void save(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1170
void fillGouraudTriangle(const Point &p1, const Color &color1, const Point &p2, const Color &color2, const Point &p3, const Color &color3, unsigned char divisions=3, int depth=-1)
Definition: Board.cpp:601
Struct representing a 2D point.
Definition: Point.h:38
Shape::LineCap lineCap
Definition: Board.h:899
Shape::LineStyle lineStyle
Definition: Board.h:898
Board & setFillColorRGBf(float red, float green, float blue, float alpha=1.0f)
Definition: Board.cpp:296
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
void backgroundColor(const Color &color)
Definition: Board.cpp:332
double x
Definition: Point.h:39
void saveTikZ(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1062
Board(const Color &backgroundColor=Color::None)
Definition: Board.cpp:87
void saveEPS(std::ostream &out, PageSize size=Board::BoundingBox, double margin=10.0, const std::string &title=std::string()) const
Definition: Board.cpp:767
Color _backgroundColor
Definition: Board.h:910
Board & setLineStyle(Shape::LineStyle style)
Board & setPenColorRGBf(float red, float green, float blue, float alpha=1.0f)
Definition: Board.cpp:269
A group of shapes.
Definition: ShapeList.h:41
void drawCircle(double x, double y, double radius, int depth=-1)
Definition: Board.cpp:420
void clear(const Color &color=Color::None)
Definition: Board.cpp:134
void setClippingRectangle(double x, double y, double width, double height)
Definition: Board.cpp:687
void saveFIG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:866
Board & setFontSize(double fontSize)
Definition: Board.cpp:325
Board & setFillColor(const Color &color)
Definition: Board.cpp:303
void fillCircle(double x, double y, double radius, int depth=-1)
Definition: Board.cpp:431
void addDuplicates(const Shape &shape, std::size_t times, double dx, double dy, double scale=1.0)
Definition: Board.cpp:726
void drawLine(double x1, double y1, double x2, double y2, int depth=-1)
Definition: Board.cpp:349
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:967
void drawEllipse(double x, double y, double xRadius, double yRadius, int depth=-1)
Definition: Board.cpp:441
void fillPolyline(const std::vector< Point > &points, int depth=-1)
Definition: Board.cpp:511
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
double lineWidth
Definition: Board.h:897
double unitFactor
Definition: Board.h:903
void drawDot(double x, double y, int depth=-1)
Definition: Board.cpp:338
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
Color penColor
Definition: Board.h:895
virtual void scaleAll(double s)=0
Board & setFont(const Fonts::Font font, double fontSize)
Definition: Board.cpp:317
bool filled() const
Definition: Shapes.h:106
Board & scale(double sx, double sy)
Definition: Board.cpp:165
void drawArrow(double x1, double y1, double x2, double y2, bool filled=true, int depth=-1)
Definition: Board.cpp:367
Fonts::Font font
Definition: Board.h:901
Color fillColor
Definition: Board.h:896
void drawBoundingBox(int depth=-1)
Definition: Board.cpp:669
State _state
Definition: Board.h:909
Board & translate(double dx, double dy)
Definition: Board.cpp:157
Board & setPenColorRGBi(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha=255)
Definition: Board.cpp:259
Board & setLineCap(Shape::LineCap cap)
Shape & top()
Definition: ShapeList.cpp:569
double y
Definition: Point.h:40
void setUnit(Unit unit)
Definition: Board.cpp:221
Definition: Board.h:894
void drawClosedPolyline(const std::vector< Point > &points, int depth=-1)
Definition: Board.cpp:491
Board & setPenColor(const Color &color)
Definition: Board.cpp:279
void drawPolyline(const std::vector< Point > &points, int depth=-1)
Definition: Board.cpp:471