Board  0.9.4
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
LibBoard::Shape Struct Referenceabstract

Abstract structure for a 2D shape. More...

#include <Shapes.h>

Inheritance diagram for LibBoard::Shape:
LibBoard::Dot LibBoard::Ellipse LibBoard::Image LibBoard::Line LibBoard::Polyline LibBoard::ShapeList LibBoard::Text LibBoard::Circle LibBoard::Arrow LibBoard::GouraudTriangle LibBoard::Rectangle LibBoard::Triangle LibBoard::Board LibBoard::Group

Public Types

enum  LineCap { ButtCap = 0, RoundCap, SquareCap }
 
enum  LineJoin { MiterJoin = 0, RoundJoin, BevelJoin }
 
enum  LineStyle {
  SolidStyle = 0, DashStyle, DotStyle, DashDotStyle,
  DashDotDotStyle, DashDotDotDotStyle
}
 
enum  LineWidthFlag { IgnoreLineWidth, UseLineWidth }
 

Public Member Functions

 Shape (Color penColor, Color fillColor, double lineWidth, LineStyle style, const LineCap cap, const LineJoin join, int depth)
 
virtual ~Shape ()
 
virtual const std::string & name () const
 
virtual Shapeclone () const =0
 
bool filled () const
 
virtual Point center (LineWidthFlag lineWidthFlag=IgnoreLineWidth) const
 
virtual Shaperotate (double angle, const Point &center)=0
 
virtual Shaperotate (double angle)=0
 
ShaperotateDeg (double angle, const Point &center)
 
ShaperotateDeg (double angle)
 
virtual Shapetranslate (double dx, double dy)=0
 
ShapemoveCenter (double x, double y, LineWidthFlag lineWidthFlag=IgnoreLineWidth)
 
ShapemoveCenter (Point p, LineWidthFlag lineWidthFlag=IgnoreLineWidth)
 
virtual Shapescale (double sx, double sy)=0
 
virtual Shapescale (double s)=0
 
ShapescaleToWidth (double w, LineWidthFlag lineWidthFlag)
 
ShapescaleToHeight (double h, LineWidthFlag lineWidthFlag)
 
virtual Rect boundingBox (LineWidthFlag) const =0
 
Rect bbox (LineWidthFlag) const
 
Shapeoperator-- ()
 
Shapeoperator++ ()
 
virtual void scaleAll (double s)=0
 
virtual void flushPostscript (std::ostream &stream, const TransformEPS &transform) const =0
 
virtual void flushFIG (std::ostream &stream, const TransformFIG &transform, std::map< Color, int > &colormap) const =0
 
virtual void flushSVG (std::ostream &stream, const TransformSVG &transform) const =0
 
virtual void flushTikZ (std::ostream &stream, const TransformTikZ &transform) const =0
 
int depth () const
 
virtual void depth (int)
 
virtual void shiftDepth (int shift)
 
const ColorpenColor () const
 
const ColorfillColor () const
 
virtual void accept (ShapeVisitor &visitor)
 Accepts a visitor object. More...
 
virtual void accept (const ShapeVisitor &visitor)
 Accepts a visitor object. More...
 

Static Public Member Functions

static void enableLineWidthScaling ()
 
static void disableLineWidthScaling ()
 
static void setLineWidthScaling (bool)
 
static void setDefaultLineWidth (double)
 
static void setDefaultPenColor (Color)
 
static void setDefaultFillColor (Color)
 
static void setDefaultLineStyle (Shape::LineStyle)
 
static void setDefaultLineCap (Shape::LineCap)
 
static void setDefaultLineJoin (Shape::LineJoin)
 
static double defaultLineWidth ()
 defaultLineWidth More...
 
static Color defaultPenColor ()
 defaultPenColor More...
 
static Color defaultFillColor ()
 defaultFillColor More...
 
static Shape::LineStyle defaultLineStyle ()
 defaultLineStyle More...
 
static Shape::LineCap defaultLineCap ()
 defaultLineCap More...
 
static Shape::LineJoin defaultLineJoin ()
 defaultLineJoin More...
 

Protected Member Functions

void updateLineWidth (double s)
 
std::string svgProperties (const TransformSVG &transform) const
 
std::string postscriptProperties (const TransformEPS &transform) const
 
std::string tikzProperties (const TransformTikZ &transform) const
 

Protected Attributes

int _depth
 
Color _penColor
 
Color _fillColor
 
double _lineWidth
 
LineStyle _lineStyle
 
LineCap _lineCap
 
LineJoin _lineJoin
 

Static Protected Attributes

static bool _lineWidthScaling = true
 
static double _defaultLineWidth = 1.0
 
static Color _defaultPenColor = Color::Black
 
static Color _defaultFillColor = Color::Null
 
static Shape::LineStyle _defaultLineStyle = Shape::SolidStyle
 
static Shape::LineCap _defaultLineCap = Shape::ButtCap
 
static Shape::LineJoin _defaultLineJoin = Shape::MiterJoin
 

Detailed Description

Abstract structure for a 2D shape.

Shape structure.

Constructor & Destructor Documentation

LibBoard::Shape::Shape ( Color  penColor,
Color  fillColor,
double  lineWidth,
LineStyle  style,
const LineCap  cap,
const LineJoin  join,
int  depth 
)
inline

Shape constructor.

Parameters
penColorThe pen color of the shape.
fillColorThe fill color of the shape.
lineWidthThe line thickness.
depthThe depth of the shape.
virtual LibBoard::Shape::~Shape ( )
inlinevirtual

Shape destructor.

Member Function Documentation

void LibBoard::Shape::accept ( ShapeVisitor visitor)
virtual

Accepts a visitor object.

Parameters
visitorA visitor object.

Reimplemented in LibBoard::ShapeList.

void LibBoard::Shape::accept ( const ShapeVisitor visitor)
virtual

Accepts a visitor object.

Parameters
visitorA visitor object.

Reimplemented in LibBoard::ShapeList.

Rect LibBoard::Shape::bbox ( LineWidthFlag  ) const
inline

Compute the bounding box of the figure. (Convenience method to call "boundingBox" with a short name.)

Referenced by LibBoard::Board::drawBoundingBox(), LibBoard::Image::flushFIG(), LibBoard::Group::flushFIG(), LibBoard::Board::saveEPS(), LibBoard::Board::saveFIG(), and LibBoard::Board::saveSVG().

virtual Rect LibBoard::Shape::boundingBox ( LineWidthFlag  ) const
pure virtual
Point LibBoard::Shape::center ( LineWidthFlag  lineWidthFlag = IgnoreLineWidth) const
virtual
virtual Shape* LibBoard::Shape::clone ( ) const
pure virtual
Color LibBoard::Shape::defaultFillColor ( )
static

defaultFillColor

Returns
Default fill color for shapes (initialized as Color::None)
Shape::LineCap LibBoard::Shape::defaultLineCap ( )
static

defaultLineCap

Returns
Default line cap for shapes (initialized as ButtCap)
Shape::LineJoin LibBoard::Shape::defaultLineJoin ( )
static

defaultLineJoin

Returns
Default line join for shapes (initialized as MiterJoin)
Shape::LineStyle LibBoard::Shape::defaultLineStyle ( )
static

defaultLineStyle

Returns
Default line style for shapes (initialized as SolidStyle)
double LibBoard::Shape::defaultLineWidth ( )
static

defaultLineWidth

Returns
Default lineWidth value for shapes (intialized as 1.0).
Color LibBoard::Shape::defaultPenColor ( )
static

defaultPenColor

Returns
Default pen color for shapes (initialized as Black)
void LibBoard::Shape::disableLineWidthScaling ( )
static

Globally disable linewidth scaling when using scale functions.

Examples:
examples/example1.cpp, examples/example2.cpp, and examples/logo.cpp.

References _lineWidthScaling.

void LibBoard::Shape::enableLineWidthScaling ( )
static

Globally enable linewidth scaling when using scale functions.

Examples:
examples/logo.cpp, and examples/stroke_path.cpp.

References _lineWidthScaling.

bool LibBoard::Shape::filled ( ) const
inline
virtual void LibBoard::Shape::flushFIG ( std::ostream &  stream,
const TransformFIG transform,
std::map< Color, int > &  colormap 
) const
pure virtual

Write the FIG code of the shape in a stream according to a transform.

Parameters
streamThe output stream.
transformA 2D transform to be applied.

Implemented in LibBoard::Text, LibBoard::Ellipse, LibBoard::GouraudTriangle, LibBoard::Rectangle, LibBoard::Polyline, LibBoard::Arrow, LibBoard::Line, LibBoard::Dot, LibBoard::Group, LibBoard::Image, and LibBoard::ShapeList.

virtual void LibBoard::Shape::flushPostscript ( std::ostream &  stream,
const TransformEPS transform 
) const
pure virtual

Write the EPS code of the shape in a stream according to a transform.

Parameters
streamThe output stream.
transformA 2D transform to be applied.

Implemented in LibBoard::Text, LibBoard::Ellipse, LibBoard::GouraudTriangle, LibBoard::Polyline, LibBoard::Arrow, LibBoard::Line, LibBoard::Dot, LibBoard::Group, LibBoard::Image, and LibBoard::ShapeList.

virtual void LibBoard::Shape::flushSVG ( std::ostream &  stream,
const TransformSVG transform 
) const
pure virtual

Write the SVG code of the shape in a stream according to a transform.

Parameters
streamThe output stream.
transformA 2D transform to be applied.

Implemented in LibBoard::Text, LibBoard::Circle, LibBoard::Ellipse, LibBoard::GouraudTriangle, LibBoard::Rectangle, LibBoard::Polyline, LibBoard::Arrow, LibBoard::Line, LibBoard::Dot, LibBoard::Group, LibBoard::Image, and LibBoard::ShapeList.

virtual void LibBoard::Shape::flushTikZ ( std::ostream &  stream,
const TransformTikZ transform 
) const
pure virtual

Write the TikZ code of the shape in a stream according to a transform.

Parameters
streamThe output stream.
transformA 2D transform to be applied.

Implemented in LibBoard::Text, LibBoard::Circle, LibBoard::Ellipse, LibBoard::GouraudTriangle, LibBoard::Rectangle, LibBoard::Polyline, LibBoard::Arrow, LibBoard::Line, LibBoard::Dot, LibBoard::Group, LibBoard::Image, and LibBoard::ShapeList.

Shape & LibBoard::Shape::moveCenter ( double  x,
double  y,
LineWidthFlag  lineWidthFlag = IgnoreLineWidth 
)

Move the center of the shape.

Parameters
xThe new x coordinate of the center.
yThe new y coordinate of the center.
lineWidthFlagShould the line width be considered when computing bounding boxes.
Returns
A reference to the shape itself.

References center(), translate(), LibBoard::Point::x, and LibBoard::Point::y.

Referenced by LibBoard::ShapeList::append().

Shape & LibBoard::Shape::moveCenter ( Point  p,
LineWidthFlag  lineWidthFlag = IgnoreLineWidth 
)

Move the center of the shape.

Parameters
pThe new center.
lineWidthFlagShould the line width be considered when computing bounding boxes.
Returns
A reference to the shape itself.

References center(), translate(), LibBoard::Point::x, and LibBoard::Point::y.

const std::string & LibBoard::Shape::name ( ) const
virtual
Shape& LibBoard::Shape::operator++ ( )
inline

Increment the depth of the shape. (Push the shape toward the background.)

Returns
A reference to the shape itself.
Shape& LibBoard::Shape::operator-- ( )
inline

Decrement the depth of the shape. (Pull the shape toward the foreground.)

Returns
A reference to the shape itself.
std::string LibBoard::Shape::postscriptProperties ( const TransformEPS transform) const
protected

Return a string of the properties lineWidth, penColor, lineCap, and lineJoin as Postscript commands.

Returns
A string of the Postscript commands.

References _lineCap, _lineJoin, _lineStyle, and _lineWidth.

Referenced by LibBoard::Dot::flushPostscript(), LibBoard::Line::flushPostscript(), LibBoard::Arrow::flushPostscript(), LibBoard::Polyline::flushPostscript(), and LibBoard::Ellipse::flushPostscript().

virtual Shape& LibBoard::Shape::rotate ( double  angle,
const Point center 
)
pure virtual

Rotate the shape around a given center of rotation.

Parameters
angleThe rotation angle in radian.
centerThe center of rotation.
Returns
A reference to the shape itself.

Implemented in LibBoard::Text, LibBoard::Circle, LibBoard::Ellipse, LibBoard::GouraudTriangle, LibBoard::Polyline, LibBoard::Line, LibBoard::Dot, LibBoard::Group, LibBoard::Board, LibBoard::ShapeList, and LibBoard::Image.

Referenced by LibBoard::Board::addDuplicates(), LibBoard::ShapeList::repeat(), and LibBoard::ShapeList::ShapeList().

virtual Shape& LibBoard::Shape::rotate ( double  angle)
pure virtual

Rotate the shape around its center.

Parameters
angleThe rotation angle in radian.
Returns
A reference to the shape itself.

Implemented in LibBoard::Text, LibBoard::Circle, LibBoard::Ellipse, LibBoard::GouraudTriangle, LibBoard::Polyline, LibBoard::Line, LibBoard::Dot, LibBoard::Group, LibBoard::Board, LibBoard::ShapeList, and LibBoard::Image.

Shape& LibBoard::Shape::rotateDeg ( double  angle,
const Point center 
)
inline

Rotate the shape around a given center of rotation.

Parameters
angleThe rotation angle in degree.
centerThe center of rotation.
Returns
A reference to the shape itself.
Examples:
examples/example4.cpp, and examples/tilings.cpp.
Shape& LibBoard::Shape::rotateDeg ( double  angle)
inline

Rotate the shape around its center.

Parameters
angleThe rotation angle in degree.
centerThe center of rotation.
Returns
A reference to the shape itself.
virtual Shape& LibBoard::Shape::scale ( double  sx,
double  sy 
)
pure virtual

Scale the shape along the x an y axis.

Parameters
sxThe scaling factor along the x axis.
syThe scaling factor along the y axis.
Returns
The shape itself.

Implemented in LibBoard::Text, LibBoard::Circle, LibBoard::Ellipse, LibBoard::Polyline, LibBoard::Line, LibBoard::Dot, LibBoard::Group, LibBoard::Image, LibBoard::Board, and LibBoard::ShapeList.

Referenced by LibBoard::Board::addDuplicates(), LibBoard::ShapeList::repeat(), scaleToHeight(), scaleToWidth(), and LibBoard::ShapeList::ShapeList().

virtual Shape& LibBoard::Shape::scale ( double  s)
pure virtual

Scale the shape along both axis.

Parameters
sThe scaling factor along both axis.
Returns
The shape itself.

Implemented in LibBoard::Text, LibBoard::Circle, LibBoard::Ellipse, LibBoard::Polyline, LibBoard::Line, LibBoard::Dot, LibBoard::Group, LibBoard::Image, LibBoard::Board, and LibBoard::ShapeList.

virtual void LibBoard::Shape::scaleAll ( double  s)
pure virtual

Scale all the values (positions, dimensions, etc.) associated with the shape.

Parameters
sThe scaling factor.

Implemented in LibBoard::Text, LibBoard::Circle, LibBoard::Ellipse, LibBoard::GouraudTriangle, LibBoard::Rectangle, LibBoard::Polyline, LibBoard::Line, LibBoard::Dot, LibBoard::Image, and LibBoard::ShapeList.

Shape & LibBoard::Shape::scaleToHeight ( double  h,
Shape::LineWidthFlag  lineWidthFlag 
)

Scale the shape to a given height.

Parameters
hThe requested new height.
lineWidthFlagShould the line width be considered when computing bounding boxes.
Returns
The shape itself.

References boundingBox(), LibBoard::Rect::height, and scale().

Shape & LibBoard::Shape::scaleToWidth ( double  w,
Shape::LineWidthFlag  lineWidthFlag 
)

Scale the shape to a given width.

Parameters
wThe requested new width.
lineWidthFlagShould the line width be considered when computing bounding boxes.
Returns
The shape itself.
Examples:
examples/arithmetic.cpp, examples/arrows.cpp, examples/clipping.cpp, examples/example4.cpp, examples/flag.cpp, examples/graph.cpp, examples/koch.cpp, examples/line_segment.cpp, examples/line_style.cpp, examples/logo.cpp, examples/ruler.cpp, examples/scale_ellipse.cpp, examples/stroke_path.cpp, and examples/tilings.cpp.

References boundingBox(), scale(), and LibBoard::Rect::width.

void LibBoard::Shape::setLineWidthScaling ( bool  on)
static

Globally enable/disable linewidth scaling when using scale functions.

References _lineWidthScaling.

std::string LibBoard::Shape::svgProperties ( const TransformSVG transform) const
protected

Return a string of the svg properties lineWidth, opacity, penColor, fillColor, lineCap, and lineJoin.

Returns
A string of the properties suitable for inclusion in an svg tag.

References _fillColor, _lineCap, _lineJoin, _lineStyle, _lineWidth, _penColor, and LibBoard::Color::svgAlpha().

Referenced by LibBoard::Dot::flushSVG(), LibBoard::Line::flushSVG(), LibBoard::Polyline::flushSVG(), LibBoard::Rectangle::flushSVG(), LibBoard::Ellipse::flushSVG(), and LibBoard::Circle::flushSVG().

std::string LibBoard::Shape::tikzProperties ( const TransformTikZ transform) const
protected

Return a string of the properties lineWidth, penColor, lineCap, and lineJoin as TikZ commands.

Returns
A string of the TikZ commands.

References _fillColor, _lineCap, _lineJoin, _lineStyle, _lineWidth, _penColor, and LibBoard::Color::tikz().

Referenced by LibBoard::Line::flushTikZ(), LibBoard::Arrow::flushTikZ(), LibBoard::Polyline::flushTikZ(), LibBoard::Ellipse::flushTikZ(), LibBoard::Circle::flushTikZ(), and LibBoard::Text::flushTikZ().

virtual Shape& LibBoard::Shape::translate ( double  dx,
double  dy 
)
pure virtual

Member Data Documentation

int LibBoard::Shape::_depth
protected
Color LibBoard::Shape::_fillColor
protected
LineCap LibBoard::Shape::_lineCap
protected
LineJoin LibBoard::Shape::_lineJoin
protected
LineStyle LibBoard::Shape::_lineStyle
protected
double LibBoard::Shape::_lineWidth
protected
bool LibBoard::Shape::_lineWidthScaling = true
staticprotected

Linewidth should be scaled by scaling functions.

Referenced by disableLineWidthScaling(), enableLineWidthScaling(), and setLineWidthScaling().

Color LibBoard::Shape::_penColor
protected

The documentation for this struct was generated from the following files: