Board  0.9.5
ShapeWithStyle.h
Go to the documentation of this file.
1 /* -*- mode: c++ -*- */
26 #ifndef BOARD_SHAPE_WITH_STYLE_H
27 #define BOARD_SHAPE_WITH_STYLE_H
28 
29 #include "board/Shape.h"
30 
31 namespace LibBoard
32 {
33 
38 struct ShapeWithStyle : public Shape {
39 
50  inline ShapeWithStyle(Color penColor, Color fillColor, double lineWidth, LineStyle style, const LineCap cap, const LineJoin join);
51 
57  inline ShapeWithStyle(const Style & style);
58 
59  ShapeWithStyle(const ShapeWithStyle & other);
60 
61  ShapeWithStyle & operator=(const ShapeWithStyle & other);
62 
67 
71  const std::string & name() const;
72 
73  Shape * clone() const = 0;
74 
75  inline const Color & penColor() const;
76 
77  inline ShapeWithStyle & setPenColor(const Color &);
78 
79  inline const Color & fillColor() const;
80 
81  inline ShapeWithStyle & setFillColor(const Color &);
82 
83  inline double lineWidth() const;
84 
85  inline ShapeWithStyle & setLineWidth(double);
86 
87  inline LineStyle lineStyle() const;
88 
89  inline ShapeWithStyle & setLineStyle(LineStyle);
90 
91  inline LineCap lineCap() const;
92 
93  inline ShapeWithStyle & setLineCap(LineCap);
94 
95  inline LineJoin lineJoin() const;
96 
97  inline ShapeWithStyle & setLineJoin(LineJoin);
98 
99  inline Style style() const;
100 
101  inline ShapeWithStyle & setStyle(const Style &);
102 
106  static void setLineWidthScaling(bool);
107 
113  inline bool filled() const;
114 
115 private:
116  static const std::string _name;
117  static bool _lineWidthScaling;
118 
119 protected:
120  inline void updateLineWidth(double s);
121 
122  Style _style;
123 };
124 
125 } // namespace LibBoard
126 
127 /*
128  * Inline methods
129  */
130 
131 namespace LibBoard
132 {
133 ShapeWithStyle::ShapeWithStyle(Color penColor, Color fillColor, double lineWidth, LineStyle lineStyle, const LineCap lineCap, const LineJoin lineJoin)
134  : _style{penColor, fillColor, lineWidth, lineStyle, lineCap, lineJoin}
135 {
136 }
137 
139  : _style(style)
140 {
141 }
142 
143 const Color & ShapeWithStyle::penColor() const
144 {
145  return _style.penColor;
146 }
147 
148 ShapeWithStyle & ShapeWithStyle::setPenColor(const Color & color)
149 {
150  _style.penColor = color;
151  return *this;
152 }
153 
154 const Color & ShapeWithStyle::fillColor() const
155 {
156  return _style.fillColor;
157 }
158 
159 ShapeWithStyle & ShapeWithStyle::setFillColor(const Color & color)
160 {
161  _style.fillColor = color;
162  return *this;
163 }
164 
165 double ShapeWithStyle::lineWidth() const
166 {
167  return _style.lineWidth;
168 }
169 
170 ShapeWithStyle & ShapeWithStyle::setLineWidth(double width)
171 {
172  _style.lineWidth = width;
173  return *this;
174 }
175 
176 LineStyle ShapeWithStyle::lineStyle() const
177 {
178  return _style.lineStyle;
179 }
180 
181 ShapeWithStyle & ShapeWithStyle::setLineStyle(LineStyle style)
182 {
183  _style.lineStyle = style;
184  return *this;
185 }
186 
187 LineCap ShapeWithStyle::lineCap() const
188 {
189  return _style.lineCap;
190 }
191 
192 ShapeWithStyle & ShapeWithStyle::setLineCap(LineCap cap)
193 {
194  _style.lineCap = cap;
195  return *this;
196 }
197 
198 LineJoin ShapeWithStyle::lineJoin() const
199 {
200  return _style.lineJoin;
201 }
202 
203 ShapeWithStyle & ShapeWithStyle::setLineJoin(LineJoin join)
204 {
205  _style.lineJoin = join;
206  return *this;
207 }
208 
209 ShapeWithStyle & ShapeWithStyle::setStyle(const Style & style)
210 {
211  _style = style;
212  return *this;
213 }
214 
215 Style ShapeWithStyle::style() const
216 {
217  return _style;
218 }
219 
221 {
222  return fillColor() != Color::Null;
223 }
224 
225 void ShapeWithStyle::updateLineWidth(double s)
226 {
227  if (_lineWidthScaling) {
228  _style.lineWidth *= s;
229  }
230 }
231 
232 } // namespace LibBoard
233 
234 #endif /* BOARD_SHAPE_WITH_STYLE_H */
Shape.h
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
LibBoard::Style
Definition: Style.h:69
LibBoard::ShapeWithStyle::ShapeWithStyle
ShapeWithStyle(Color penColor, Color fillColor, double lineWidth, LineStyle style, const LineCap cap, const LineJoin join)
Definition: ShapeWithStyle.h:133
LibBoard::ShapeWithStyle::filled
bool filled() const
Definition: ShapeWithStyle.h:220
LibBoard::Shape
Abstract structure for a 2D shape.
Definition: Shape.h:63
LibBoard::ShapeWithStyle::clone
Shape * clone() const =0
LibBoard::ShapeWithStyle::name
const std::string & name() const
Definition: ShapeWithStyle.cpp:37
LibBoard::ShapeWithStyle::setLineWidthScaling
static void setLineWidthScaling(bool)
Definition: ShapeWithStyle.cpp:42
LibBoard::ShapeWithStyle::~ShapeWithStyle
~ShapeWithStyle()
Definition: ShapeWithStyle.cpp:35
LibBoard::Color
Structure representing an RGB triple.
Definition: Color.h:43
LibBoard::ShapeWithStyle
Abstract structure for a 2D shape.
Definition: ShapeWithStyle.h:38