Pen.h
1/* Copyright (C) 2006-2015 Laurentiu-Gheorghe Crisan
2 Copyright (C) 2006-2015 Marc Boris Duerner
3 Copyright (C) 2017-2017 Aloysius Indrayanto
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 As a special exception, you may use this file as part of a free
11 software library without restriction. Specifically, if other files
12 instantiate templates or use macros or inline functions from this
13 file, or you compile this file and link it with other files to
14 produce an executable, this file does not by itself cause the
15 resulting executable to be covered by the GNU General Public
16 License. This exception does not however invalidate any other
17 reasons why the executable file might be covered by the GNU Library
18 General Public License.
19
20 This library is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 Lesser General Public License for more details.
24
25 You should have received a copy of the GNU Lesser General Public
26 License along with this library; if not, write to the Free Software
27 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
28 MA 02110-1301 USA
29*/
30
31#ifndef PT_GFX_PEN_H
32#define PT_GFX_PEN_H
33
34#include <Pt/Gfx/Api.h>
35#include <Pt/Gfx/Color.h>
36#include <Pt/SmartPtr.h>
37#include <cstddef>
38
39namespace Pt {
40
41namespace Gfx {
42
43class PenData;
44
58class PT_GFX_API Pen
59{
60 public:
63 enum Style
64 {
65 Solid = 0,
66 Dot = 1,
67 Dash = 2,
68 DashPattern = 3
69 };
70
74 {
75 FlatCap = 0,
76 SquareCap = 1,
77 RoundCap = 2
78 };
79
83 {
84 NoJoin = 0,
85 BevelJoin = 1,
86 MiterJoin = 2,
87 RoundJoin = 3
88 };
89
94 Pen();
95
101 Pen(const Color& color);
102
105 Pen(const Color& color, std::size_t width, Style style = Solid,
106 CapStyle cap = FlatCap, JoinStyle join = BevelJoin);
107
110 Pen(const Color& color, std::size_t width,
111 const std::vector<Pt::uint8_t>& dashPattern,
112 CapStyle cap = FlatCap, JoinStyle join = BevelJoin);
113
116 bool isNull() const;
117
120 void setSize(std::size_t size);
121
124 std::size_t size() const;
125
128 void setColor(const Color& color);
129
132 const Color& color() const;
133
136 void setStyle(Style style = Solid);
137
140 Style style() const;
141
144 bool isSolid() const
145 { return style() == Solid; }
146
149 void setDashPattern(const std::vector<Pt::uint8_t>& dashPattern);
150
153 const std::vector<Pt::uint8_t>& dashPattern() const;
154
157 void setCapStyle(CapStyle cap = FlatCap);
158
162
165 void setJoinStyle(JoinStyle join = BevelJoin);
166
170
173 const void* instance() const
174 {
175 return _penData.get();
176 }
177
178 private:
179 SmartPtr<PenData> _penData;
180};
181
182
183class PT_GFX_API PenData
184{
185 public:
186 PenData(const Color& color, std::size_t size,
187 Pen::Style style, Pen::CapStyle cap, Pen::JoinStyle join)
188 : _color(color)
189 , _size(size)
190 , _style(style)
191 , _capStyle(cap)
192 , _joinStyle(join)
193 {}
194
195 PenData(const Color& color, std::size_t size,
196 Pen::Style style, const std::vector<Pt::uint8_t>& dashPattern, Pen::CapStyle cap, Pen::JoinStyle join)
197 : _color(color)
198 , _size(size)
199 , _style(style)
200 , _dashPattern(dashPattern)
201 , _capStyle(cap)
202 , _joinStyle(join)
203 {}
204
205 PenData(const Color& color, std::size_t size,
206 Pen::Style style, const Pt::uint8_t* dashPatternBeg, const Pt::uint8_t* dashPatternEnd, Pen::CapStyle cap, Pen::JoinStyle join)
207 : _color(color)
208 , _size(size)
209 , _style(style)
210 , _dashPattern(dashPatternBeg, dashPatternEnd)
211 , _capStyle(cap)
212 , _joinStyle(join)
213 {}
214
215 void setColor(const Color& color)
216 { _color = color; }
217
218 const Color& color() const
219 { return _color; }
220
221 void setSize(std::size_t size)
222 { _size = size; }
223
224 std::size_t size() const
225 { return _size; }
226
227 void setStyle(Pen::Style style)
228 {
229 _style = style;
230 _dashPattern.clear();
231 }
232
233 Pen::Style style() const
234 { return _style; }
235
236 void setDashPattern(const std::vector<Pt::uint8_t>& dashPattern)
237 {
238 _style = Pen::DashPattern;
239 _dashPattern = dashPattern;
240 }
241
242 const std::vector<Pt::uint8_t>& dashPattern() const
243 { return _dashPattern; }
244
245 void setCapStyle(Pen::CapStyle cap)
246 { _capStyle = cap;}
247
248 Pen::CapStyle capStyle() const
249 { return _capStyle;}
250
251 void setJoinStyle(Pen::JoinStyle join)
252 { _joinStyle = join; }
253
254 Pen::JoinStyle joinStyle() const
255 { return _joinStyle; }
256
257 private:
258 Color _color;
259 std::size_t _size;
260 Pen::Style _style;
261 std::vector<Pt::uint8_t> _dashPattern;
262 Pen::CapStyle _capStyle;
263 Pen::JoinStyle _joinStyle;
264};
265
266} // namespace
267
268} // namespace
269
270#endif
8-bit ARGB color.
Definition Color.h:65
void setDashPattern(const std::vector< Pt::uint8_t > &dashPattern)
Sets the pen user dash pattern.
void setJoinStyle(JoinStyle join=BevelJoin)
Sets the join style.
Pen()
Constructs a null pen.
Pen(const Color &color, std::size_t width, const std::vector< Pt::uint8_t > &dashPattern, CapStyle cap=FlatCap, JoinStyle join=BevelJoin)
Constructs a pen with a custom dash pattern.
void setSize(std::size_t size)
Sets the size of the pen.
JoinStyle
Identifies how connected line segments are joined.
Definition Pen.h:83
void setColor(const Color &color)
Sets the color of the pen.
bool isSolid() const
Returns true if the pen is solid.
Definition Pen.h:144
CapStyle
Identifies how open line ends are rendered.
Definition Pen.h:74
Pen(const Color &color)
Constructs a pen with the specified color.
JoinStyle joinStyle() const
Returns the join style.
Pen(const Color &color, std::size_t width, Style style=Solid, CapStyle cap=FlatCap, JoinStyle join=BevelJoin)
Constructs a pen with the specified size, color and styles.
CapStyle capStyle() const
Returns the cap style.
const Color & color() const
Returns the color of the pen.
void setStyle(Style style=Solid)
Sets the pen style.
bool isNull() const
Returns true if the pen is null.
Style style() const
Returns the pen style.
const void * instance() const
Returns an implementation-specific pen instance.
Definition Pen.h:173
const std::vector< Pt::uint8_t > & dashPattern() const
Returns the pen user dash pattern.
Style
Identifies how outlines are stroked.
Definition Pen.h:64
std::size_t size() const
Returns the size of the pen.
void setCapStyle(CapStyle cap=FlatCap)
Sets the cap style.
Policy based smart pointer.
Definition SmartPtr.h:462
uint_type uint8_t
Unsigned 8-bit integer type.
Definition Api-Types.h:24
Graphics and imaging services.
Definition Api-Argb32Image.h:12
Core module.
Definition Allocator.h:33