Board 0.9.6
Arrow.h
Go to the documentation of this file.
1/* -*- mode: c++ -*- */
26#ifndef BOARD_ARROW_H
27#define BOARD_ARROW_H
28
29#include <board/Line.h>
30
31namespace LibBoard
32{
33
38struct Arrow : public Line {
39
43 enum class ExtremityType
44 {
45 Stick,
46 Closed,
47 Plain
48 };
49
65 inline Arrow(double x1, double y1, double x2, double y2, ExtremityType type = ExtremityType::Plain, Color penColor = Style::defaultPenColor(), Color fillColor = Style::defaultFillColor(),
68
79 inline Arrow(double x1, double y1, double x2, double y2, ExtremityType type, const Style & style);
80
99
108 inline Arrow(Point p1, Point p2, ExtremityType type, const Style & style);
109
110
116 const std::string & name() const override;
117
126 Arrow rotated(double angle, const Point & center) const;
127
135 Arrow rotated(double angle) const;
136
145 Arrow translated(double dx, double dy) const;
146
155 Arrow scaled(double sx, double sy) const;
156
164 Arrow scaled(double s) const;
165
174 Arrow resized(double w, double h, LineWidthFlag lineWidthFlag) const;
175
181 Rect boundingBox(LineWidthFlag) const override;
182
183 void flushPostscript(std::ostream & stream, const TransformEPS & transform) const override;
184
185 void flushFIG(std::ostream & stream, const TransformFIG & transform, std::map<Color, int> & colormap) const override;
186
187 void flushSVG(std::ostream & stream, const TransformSVG & transform) const override;
188
189 void flushTikZ(std::ostream & stream, const TransformTikZ & transform) const override;
190
196 virtual void accept(ShapeVisitor & visitor) override;
197
203 virtual void accept(const ShapeVisitor & visitor) override;
204
210 virtual void accept(ConstShapeVisitor & visitor) const override;
211
217 virtual void accept(const ConstShapeVisitor & visitor) const override;
218
224 virtual Shape * accept(CompositeShapeTransform & transform) const override;
225
231 virtual Shape * accept(const CompositeShapeTransform & transform) const override;
232
233 Arrow * clone() const override;
234
235 Path extremity() const;
236
237 Arrow(const Arrow &) = default;
238 Arrow(Arrow &&) = default;
239 Arrow & operator=(Arrow &&) = default;
240 Arrow & operator=(const Arrow &) = default;
241 ~Arrow() override = default;
242
247 inline ExtremityType type() const;
248
249private:
250 static const std::string _name;
251 ExtremityType _type;
252};
253
254} // namespace LibBoard
255
256/*
257 * Inline methods
258 */
259
260namespace LibBoard
261{
262Arrow::Arrow(double x1, double y1, double x2, double y2, ExtremityType type, Color penColor, Color fillColor, double lineWidth, const LineStyle style, const LineCap cap, const LineJoin join)
263 : Line(x1, y1, x2, y2, penColor, lineWidth, style, cap, join), _type(type)
264{
265 // FIXME : Handle fill color of the tip properly
266 if (fillColor == Color::Null) {
268 } else {
270 }
271}
272
273Arrow::Arrow(double x1, double y1, double x2, double y2, ExtremityType type, const Style & style) //
274 : Line(x1, y1, x2, y2, style), _type(type)
275{
276 if (style.fillColor == Color::Null) {
278 } else {
280 }
281}
282
284 Color penColor, Color fillColor, double lineWidth, //
285 const LineStyle style, const LineCap cap, const LineJoin join) //
286 : Line(p1, p2, penColor, lineWidth, style, cap, join), _type(type)
287{
288 if (fillColor == Color::Null) {
290 } else {
292 }
293}
294
295Arrow::Arrow(Point p1, Point p2, ExtremityType type, const Style & style) //
296 : Line(p1, p2, style), _type(type)
297{
298 if (style.fillColor == Color::Null) {
300 } else {
302 }
303}
304
306{
307 return _type;
308}
309} // namespace LibBoard
310
311#endif /* BOARD_ARROW_H */
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
Structure representing an RGB triple.
Definition Color.h:43
static const Color Null
Definition Color.h:155
Definition Board.h:55
LineStyle
Definition Style.h:47
LineCap
Definition Style.h:35
LineWidthFlag
Definition Style.h:57
LineJoin
Definition Style.h:41
A line between two points with an arrow at one extremity.
Definition Arrow.h:38
Arrow * clone() const override
Definition Arrow.cpp:95
Arrow & operator=(const Arrow &)=default
Arrow translated(double dx, double dy) const
Definition Arrow.cpp:66
const std::string & name() const override
Definition Arrow.cpp:51
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< Color, int > &colormap) const override
Definition Arrow.cpp:154
Arrow(double x1, double y1, double x2, double y2, ExtremityType type=ExtremityType::Plain, Color penColor=Style::defaultPenColor(), Color fillColor=Style::defaultFillColor(), double lineWidth=Style::defaultLineWidth(), const LineStyle lineStyle=Style::defaultLineStyle(), const LineCap cap=Style::defaultLineCap(), const LineJoin join=Style::defaultLineJoin())
Definition Arrow.h:262
ExtremityType
The ExtremityType enum.
Definition Arrow.h:44
Arrow(const Arrow &)=default
ExtremityType type() const
The extremity type of the arrow.
Definition Arrow.h:305
Arrow(Arrow &&)=default
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const override
Definition Arrow.cpp:237
Arrow resized(double w, double h, LineWidthFlag lineWidthFlag) const
Definition Arrow.cpp:81
Rect boundingBox(LineWidthFlag) const override
Definition Arrow.cpp:86
~Arrow() override=default
virtual void accept(ShapeVisitor &visitor) override
Accepts a visitor object.
Definition Arrow.cpp:245
Path extremity() const
Definition Arrow.cpp:100
Arrow rotated(double angle, const Point &center) const
Definition Arrow.cpp:56
Arrow & operator=(Arrow &&)=default
Arrow scaled(double sx, double sy) const
Definition Arrow.cpp:71
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const override
Definition Arrow.cpp:112
void flushSVG(std::ostream &stream, const TransformSVG &transform) const override
Definition Arrow.cpp:197
A CompositeShapeTransform may be used to duplicate/transform a composite shape tree.
Definition ShapeVisitor.h:104
A ConstShapeVisitor may visit const shapes of a composite shape tree in back-to-front order.
Definition ShapeVisitor.h:79
A line between two points.
Definition Line.h:38
A path, according to Postscript and SVG definition.
Definition Path.h:45
Struct representing a 2D point.
Definition Point.h:42
Struct representing a rectangle on the plane.
Definition Rect.h:40
A ShapeVisitor visits all shapes in a composite shape tree in back-to-front order.
Definition ShapeVisitor.h:54
Style _style
Definition ShapeWithStyle.h:122
const Color & penColor() const
Definition ShapeWithStyle.h:143
Style style() const
Definition ShapeWithStyle.h:215
double lineWidth() const
Definition ShapeWithStyle.h:165
const Color & fillColor() const
Definition ShapeWithStyle.h:154
LineStyle lineStyle() const
Definition ShapeWithStyle.h:176
Abstract structure for a 2D shape.
Definition Shape.h:64
virtual Point center(LineWidthFlag lineWidthFlag=IgnoreLineWidth) const
Definition Shape.cpp:59
Definition Style.h:69
Color fillColor
Definition Style.h:71
Color penColor
Definition Style.h:70
static const Color & defaultPenColor()
defaultPenColor
Definition Style.h:279
static const Color & defaultFillColor()
defaultFillColor
Definition Style.h:284
static const double & defaultLineWidth()
defaultLineWidth
Definition Style.h:274
static const LineStyle & defaultLineStyle()
defaultLineStyle
Definition Style.h:289
static const LineCap & defaultLineCap()
defaultLineCap
Definition Style.h:294
static const LineJoin & defaultLineJoin()
defaultLineJoin
Definition Style.h:299
Structure representing a scaling and translation suitable for an EPS output.
Definition Transforms.h:71
Structure representing a scaling and translation suitable for an XFig output.
Definition Transforms.h:87
Structure representing a scaling and translation suitable for an SVG output.
Definition Transforms.h:109
Structure representing a scaling and translation suitable for an TikZ output.
Definition Transforms.h:126