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 
39 namespace Pt {
40 
41 namespace Gfx {
42 
43 class PenData;
44 
52 class PT_GFX_API Pen
53 {
54  public:
57  enum Style { Solid = 0,
58  Dot = 1,
59  DoubleDot = 2,
60  Dash = 3,
61  DoubleDash = 4,
62  DotDash = 5,
63  UserDefined = 6
64  };
65 
68  enum CapStyle { ButtCap = 0,
69  SquareCap = 1,
70  RoundCap = 2,
71  TriangularOutCap = 3,
72  TriangularInCap = 4,
73  RoundHoleCap = 5,
74  Arrow1Cap = 6,
75  Arrow2Cap = 7,
76  FlatCap = 0, // FlatCap and ButtCap are the same
77  ProjectingCap = 1, // ProjectingCap and SquareCap are the same
78  TriangularCap = 3, // TriangularCap and TriangularOutCap are the same
79  NotLastCap = 9 // What is this ???
80  };
81 
84  enum JoinStyle { NoJoin = 0,
85  BevelJoin = 1,
86  MiterJoin = 2,
87  RoundJoin = 3,
88  TriangularJoin = 9 // What is this ???
89  };
90 
95  Pen();
96 
102  Pen(const Color& color);
103 
106  Pen(const Color& color, std::size_t width,
107  Style style = Solid, CapStyle cap = FlatCap,
108  JoinStyle join = BevelJoin);
109 
112  Pen(const Color& color, std::size_t width,
113  Pt::uint64_t stylePattern, CapStyle cap = FlatCap,
114  JoinStyle join = BevelJoin);
115 
118  void setSize(std::size_t size);
119 
122  std::size_t size() const;
123 
126  void setColor(const Color& color);
127 
130  const Color& color() const;
131 
134  void setStyle(Style style = Solid);
135 
138  void setStyle(Pt::uint64_t stylePattern);
139 
142  Style style() const;
143 
146  Pt::uint64_t styleUserPattern() const;
147 
150  void setCapStyle(CapStyle cap = FlatCap);
151 
154  CapStyle capStyle() const;
155 
158  void setJoinStyle(JoinStyle join = BevelJoin);
159 
162  JoinStyle joinStyle() const;
163 
166  bool isNull() const;
167 
168  private:
169  SmartPtr<PenData> _penData;
170 };
171 
172 
173 class PT_GFX_API PenData
174 {
175  public:
176  PenData(const Color& color, std::size_t size,
177  Pen::Style style, Pt::uint64_t userPattern, Pen::CapStyle cap, Pen::JoinStyle join)
178  : _color(color)
179  , _size(size)
180  , _style(style )
181  , _userPattern(userPattern)
182  , _capStyle(cap)
183  , _joinStyle(join)
184  {}
185 
186  void setColor(const Color& color)
187  { _color = color; }
188 
189  const Color& color() const
190  { return _color; }
191 
192  void setSize(std::size_t size)
193  { _size = size; }
194 
195  std::size_t size() const
196  { return _size; }
197 
198  void setStyle(Pen::Style style, Pt::uint64_t userPattern)
199  {
200  _style = style;
201  _userPattern = userPattern;
202  }
203 
204  Pen::Style style() const
205  { return _style; }
206 
207  Pt::uint64_t styleUserPattern() const
208  { return _userPattern; }
209 
210  void setCapStyle(Pen::CapStyle cap)
211  { _capStyle = cap;}
212 
213  Pen::CapStyle capStyle() const
214  { return _capStyle;}
215 
216  void setJoinStyle(Pen::JoinStyle join)
217  { _joinStyle = join; }
218 
219  Pen::JoinStyle joinStyle() const
220  { return _joinStyle; }
221 
222  private:
223  Color _color;
224  std::size_t _size;
225  Pen::Style _style;
226  Pt::uint64_t _userPattern;
227  Pen::CapStyle _capStyle;
228  Pen::JoinStyle _joinStyle;
229 };
230 
231 } // namespace
232 
233 } // namespace
234 
235 #endif
JoinStyle
Pen join style.
Definition: Pen.h:84
Attributs for the drawing of outlines.
Definition: Pen.h:52
CapStyle
Pen cap style.
Definition: Pen.h:68
uint_type uint64_t
Unsigned 64-bit integer type.
Definition: Types.h:54
Style
Pen line style.
Definition: Pen.h:57