00001
00010 #ifndef _BOARD_SHAPES_H_
00011 #define _BOARD_SHAPES_H_
00012
00013 #include "board/Point.h"
00014 #include "board/Rect.h"
00015 #include "board/Color.h"
00016 #include "board/Transforms.h"
00017 #include <string>
00018 #include <vector>
00019 #include <iostream>
00020 #include <map>
00021
00022 namespace BoardLib {
00023
00028 struct Shape {
00029
00030 enum LineCap { ButtCap = 0, RoundCap, SquareCap };
00031 enum LineJoin { MiterJoin = 0, RoundJoin, BevelJoin };
00032
00033 unsigned int depth;
00034 Color penColor;
00035 Color fillColor;
00036 float lineWidth;
00037 LineCap lineCap;
00038 LineJoin lineJoin;
00048 Shape( Color penColor, Color fillColor,
00049 float lineWidth, const LineCap cap, const LineJoin join,
00050 unsigned int depth )
00051 : depth( depth ), penColor( penColor ), fillColor( fillColor ),
00052 lineWidth( lineWidth ), lineCap( cap ), lineJoin( join ) { }
00053
00057 virtual ~Shape() { }
00058
00064 inline bool filled() const { return fillColor != Color::none; }
00065
00073 virtual void flushPostscript( std::ostream & stream,
00074 const TransformEPS & transform ) const = 0;
00075
00083 virtual void flushFIG( std::ostream & stream,
00084 const TransformFIG & transform,
00085 std::map<Color,int> & colormap ) const = 0;
00086
00094 virtual void flushSVG( std::ostream & stream,
00095 const TransformSVG & transform ) const = 0;
00096
00102 virtual Rect boundingBox() const = 0;
00103
00104 protected:
00105
00112 std::string svgProperties( const TransformSVG & transform ) const;
00113 };
00114
00119 struct Line : public Shape {
00120 double x1;
00121 double y1;
00122 double x2;
00123 double y2;
00136 Line( double x1, double y1, double x2, double y2,
00137 Color color,
00138 float lineWidth, const LineCap cap = ButtCap, const LineJoin join = MiterJoin,
00139 unsigned int depth = 0 )
00140 : Shape( color, Color::none, lineWidth, cap, join, depth ),
00141 x1( x1 ), y1( y1 ), x2( x2 ), y2( y2 ) { }
00142
00143 void flushPostscript( std::ostream & stream,
00144 const TransformEPS & transform ) const;
00145
00146 void flushFIG( std::ostream & stream,
00147 const TransformFIG & transform,
00148 std::map<Color,int> & colormap ) const;
00149
00150 void flushSVG( std::ostream & stream,
00151 const TransformSVG & transform ) const;
00152
00153 Rect boundingBox() const;
00154 };
00155
00160 struct Arrow : public Line {
00161
00174 Arrow( double x1, double y1, double x2, double y2,
00175 Color penColor, Color fillColor,
00176 float lineWidth, const LineCap cap = ButtCap, const LineJoin join = MiterJoin,
00177 unsigned int depth = 0 )
00178 : Line( x1, y1, x2, y2, penColor, lineWidth, cap, join, depth ) {
00179 Shape::fillColor = fillColor;
00180 }
00181
00182 void flushPostscript( std::ostream & stream,
00183 const TransformEPS & transform ) const;
00184
00185 void flushFIG( std::ostream & stream,
00186 const TransformFIG & transform,
00187 std::map<Color,int> & colormap ) const;
00188 void flushSVG( std::ostream & stream,
00189 const TransformSVG & transform ) const;
00190
00191 };
00192
00197 struct Polyline : public Shape {
00198 std::vector<Point> points;
00199 bool closed;
00200
00201 Polyline( const std::vector<Point> & points,
00202 bool closed,
00203 Color penColor, Color fillColor,
00204 float lineWidth, const LineCap cap = ButtCap, const LineJoin join = MiterJoin,
00205 unsigned int depth = 0 )
00206 : Shape( penColor, fillColor, lineWidth, cap, join, depth ),
00207 points( points ), closed( closed ) { }
00208
00209 void flushPostscript( std::ostream & stream,
00210 const TransformEPS & transform ) const;
00211
00212 void flushFIG( std::ostream & stream,
00213 const TransformFIG & transform,
00214 std::map<Color,int> & colormap ) const;
00215
00216 void flushSVG( std::ostream & stream,
00217 const TransformSVG & transform ) const;
00218
00219 Rect boundingBox() const;
00220 };
00221
00222
00227 struct GouraudTriangle : public Polyline {
00228 Color color0;
00229 Color color1;
00230 Color color2;
00231 int subdivisions;
00232
00233 GouraudTriangle( const Point & p0, const Color & color0,
00234 const Point & p1, const Color & color1,
00235 const Point & p2, const Color & color2,
00236 int subdivisions,
00237 unsigned int depth = 0 );
00238
00239 GouraudTriangle( const Point & p0, float brightness0,
00240 const Point & p1, float brightness1,
00241 const Point & p2, float brightness2,
00242 const Color & fillColor,
00243 int subdivisions,
00244 unsigned int depth = 0 );
00245
00246 void flushPostscript( std::ostream & stream,
00247 const TransformEPS & transform ) const;
00248
00261 void flushFIG( std::ostream & stream,
00262 const TransformFIG & transform,
00263 std::map<Color,int> & colormap ) const;
00264
00265 void flushSVG( std::ostream & stream,
00266 const TransformSVG & transform ) const;
00267
00268 };
00269
00274 struct Rectangle : public Shape {
00275 double x;
00276 double y;
00277 double width;
00278 double height;
00279
00280 Rectangle( double x, double y, double width, double height,
00281 Color penColor, Color fillColor,
00282 float lineWidth, const LineCap cap = ButtCap, const LineJoin join = MiterJoin,
00283 unsigned int depth = 0 )
00284 : Shape( penColor, fillColor, lineWidth, cap, join, depth ),
00285 x( x ), y( y ), width( width ), height( height ) { }
00286
00287 Rectangle( const Rect & rect,
00288 Color penColor, Color fillColor,
00289 float lineWidth, const LineCap cap = ButtCap, const LineJoin join = MiterJoin,
00290 unsigned int depth = 0 )
00291 : Shape( penColor, fillColor, lineWidth, cap, join, depth ),
00292 x( rect.left ), y( rect.top ), width( rect.width ), height( rect.height ) { }
00293
00294 void flushPostscript( std::ostream & stream,
00295 const TransformEPS & transform ) const;
00296
00297 void flushFIG( std::ostream & stream,
00298 const TransformFIG & transform,
00299 std::map<Color,int> & colormap ) const;
00300
00301 void flushSVG( std::ostream & stream,
00302 const TransformSVG & transform ) const;
00303
00304 Rect boundingBox() const;
00305 };
00306
00311 struct Circle : public Shape {
00312 double x;
00313 double y;
00314 double radius;
00315
00316 Circle( double x, double y, double radius,
00317 Color penColor, Color fillColor,
00318 float lineWidth, const LineCap cap = ButtCap, const LineJoin join = MiterJoin,
00319 unsigned int depth = 0 )
00320 : Shape( penColor, fillColor, lineWidth, cap, join, depth ),
00321 x( x ), y( y ), radius( radius ) { }
00322
00323 void flushPostscript( std::ostream & stream,
00324 const TransformEPS & transform ) const;
00325
00326 void flushFIG( std::ostream & stream,
00327 const TransformFIG & transform,
00328 std::map<Color,int> & colormap ) const;
00329
00330 void flushSVG( std::ostream & stream,
00331 const TransformSVG & transform ) const;
00332
00333 Rect boundingBox() const;
00334 };
00335
00340 struct Ellipse : public Shape {
00341 double x;
00342 double y;
00343 double xRadius;
00344 double yRadius;
00345
00346 Ellipse( double x, double y,
00347 double xRadius, double yRadius,
00348 Color penColor, Color fillColor,
00349 float lineWidth, const LineCap cap = ButtCap, const LineJoin join = MiterJoin,
00350 unsigned int depth = 0 )
00351 : Shape( penColor, fillColor, lineWidth, cap, join, depth ),
00352 x( x ), y( y ), xRadius( xRadius ), yRadius( yRadius ) { }
00353
00354 void flushPostscript( std::ostream & stream,
00355 const TransformEPS & transform ) const;
00356
00357 void flushFIG( std::ostream & stream,
00358 const TransformFIG & transform,
00359 std::map<Color,int> & colormap ) const;
00360
00361 void flushSVG( std::ostream & stream,
00362 const TransformSVG & transform ) const;
00363
00364 Rect boundingBox() const;
00365 };
00366
00371 struct Text : public Shape {
00372 float x;
00373 float y;
00374 std::string text;
00375 std::string font;
00376 float size;
00377
00378 Text( float x, float y,
00379 const std::string & text, const std::string & font, float size,
00380 Color color, unsigned int depth )
00381 : Shape( color, Color::none, 1.0, ButtCap, MiterJoin, depth ),
00382 x( x ), y( y ), text( text ), font( font ), size( size ) { }
00383
00384 void flushPostscript( std::ostream & stream,
00385 const TransformEPS & transform ) const;
00386
00387 void flushFIG( std::ostream & stream,
00388 const TransformFIG & transform,
00389 std::map<Color,int> & colormap ) const;
00390
00391 void flushSVG( std::ostream & stream,
00392 const TransformSVG & transform ) const;
00393
00394 Rect boundingBox() const;
00395 };
00396
00405 bool shapeGreaterDepth( const Shape *s1, const Shape *s2 );
00406
00407 }
00408
00409 #endif
00410