1 \section{\class{wxPen
}}\label{wxpen
}
3 A pen is a drawing tool for drawing outlines. It is used for drawing
4 lines and painting the outline of rectangles, ellipses, etc. It has a
5 colour, a width and a style.
7 \wxheading{Derived from
}
9 \helpref{wxGDIObject
}{wxgdiobject
}\\
10 \helpref{wxObject
}{wxobject
}
12 \wxheading{Include files
}
18 On a monochrome display, wxWindows shows all non-white pens as black.
20 Do not initialize objects on the stack before the program commences,
21 since other required structures may not have been set up yet. Instead,
22 define global pointers to objects and create them in
{\it OnInit
} or
25 An application may wish to dynamically create pens with different
26 characteristics, and there is the consequent danger that a large number
27 of duplicate pens will be created. Therefore an application may wish to
28 get a pointer to a pen by using the global list of pens
{\bf
29 wxThePenList
}, and calling the member function
{\bf FindOrCreatePen
}.
30 See the entry for
\helpref{wxPenList
}{wxpenlist
}.
32 wxPen uses a reference counting system, so assignments between brushes are very
33 cheap. You can therefore use actual wxPen objects instead of pointers without
34 efficiency problems. Once one wxPen object changes its data it will create its
35 own pen data internally so that other pens, which previously shared the
36 data using the reference counting, are not affected.
38 %TODO: an overview for wxPen.
41 \helpref{wxPenList
}{wxpenlist
},
\helpref{wxDC
}{wxdc
},
\helpref{wxDC::SetPen
}{wxdcsetpen
}
43 \latexignore{\rtfignore{\wxheading{Members
}}}
45 \membersection{wxPen::wxPen
}\label{wxpenconstr
}
49 Default constructor. The pen will be uninitialised, and
\helpref{wxPen::Ok
}{wxpenok
} will
52 \func{}{wxPen
}{\param{const wxColour\&
}{ colour
},
\param{int
}{ width
},
\param{int
}{ style
}}
54 Constructs a pen from a colour object, pen width and style.
56 \func{}{wxPen
}{\param{const wxString\&
}{colourName
},
\param{int
}{ width
},
\param{int
}{ style
}}
58 Constructs a pen from a colour name, pen width and style.
60 \func{}{wxPen
}{\param{const wxBitmap\&
}{ stipple
},
\param{int
}{ width
}}
62 Constructs a stippled pen from a stipple bitmap and a width.
64 \func{}{wxPen
}{\param{const wxPen\&
}{ pen
}}
66 Copy constructor. This uses reference counting so is a cheap operation.
68 \wxheading{Parameters
}
70 \docparam{colour
}{A colour object.
}
72 \docparam{colourName
}{A colour name.
}
74 \docparam{width
}{Pen width. Under Windows, the pen width cannot be greater than
1 if
75 the style is wxDOT, wxLONG
\_DASH, wxSHORT
\_DASH, wxDOT
\_DASH, or wxUSER
\_DASH.
}
77 \docparam{stipple
}{A stipple bitmap.
}
79 \docparam{pen
}{A pointer or reference to a pen to copy.
}
81 \docparam{width
}{Pen width. Under Windows, the pen width cannot be greater than
1 if
82 the style is wxDOT, wxLONG
\_DASH, wxSHORT
\_DASH, wxDOT
\_DASH, or wxUSER
\_DASH.
}
84 \docparam{style
}{The style may be one of the following:
86 \begin{twocollist
}\itemsep=
0pt
87 \twocolitem{{\bf wxSOLID
}}{Solid style.
}
88 \twocolitem{{\bf wxTRANSPARENT
}}{No pen is used.
}
89 \twocolitem{{\bf wxDOT
}}{Dotted style.
}
90 \twocolitem{{\bf wxLONG
\_DASH}}{Long dashed style.
}
91 \twocolitem{{\bf wxSHORT
\_DASH}}{Short dashed style.
}
92 \twocolitem{{\bf wxDOT
\_DASH}}{Dot and dash style.
}
93 \twocolitem{{\bf wxSTIPPLE
}}{Use the stipple bitmap.
}
94 \twocolitem{{\bf wxUSER
\_DASH}}{Use the user dashes: see
\helpref{wxPen::SetDashes
}{wxpensetdashes
}.
}
95 \twocolitem{{\bf wxBDIAGONAL
\_HATCH}}{Backward diagonal hatch.
}
96 \twocolitem{{\bf wxCROSSDIAG
\_HATCH}}{Cross-diagonal hatch.
}
97 \twocolitem{{\bf wxFDIAGONAL
\_HATCH}}{Forward diagonal hatch.
}
98 \twocolitem{{\bf wxCROSS
\_HATCH}}{Cross hatch.
}
99 \twocolitem{{\bf wxHORIZONTAL
\_HATCH}}{Horizontal hatch.
}
100 \twocolitem{{\bf wxVERTICAL
\_HATCH}}{Vertical hatch.
}
105 If the named colour form is used, an appropriate
{\bf wxColour
} structure
106 is found in the colour database.
108 {\it style
} may be one of wxSOLID, wxDOT, wxLONG
\_DASH, wxSHORT
\_DASH and
113 \helpref{wxPen::SetStyle
}{wxpensetstyle
},
\helpref{wxPen::SetColour
}{wxpensetcolour
},
\rtfsp
114 \helpref{wxPen::SetWidth
}{wxpensetwidth
},
\helpref{wxPen::SetStipple
}{wxpensetstipple
}
116 \membersection{wxPen::
\destruct{wxPen
}}
118 \func{}{\destruct{wxPen
}}{\void}
124 The destructor may not delete the underlying pen object of the native windowing
125 system, since wxBrush uses a reference counting system for efficiency.
127 Although all remaining pens are deleted when the application exits,
128 the application should try to clean up all pens itself. This is because
129 wxWindows cannot know if a pointer to the pen object is stored in an
130 application data structure, and there is a risk of double deletion.
132 \membersection{wxPen::GetCap
}\label{wxpengetcap
}
134 \constfunc{int
}{GetCap
}{\void}
136 Returns the pen cap style, which may be one of
{\bf wxCAP
\_ROUND},
{\bf wxCAP
\_PROJECTING} and
137 \rtfsp{\bf wxCAP
\_BUTT}. The default is
{\bf wxCAP
\_ROUND}.
141 \helpref{wxPen::SetCap
}{wxpensetcap
}
143 \membersection{wxPen::GetColour
}\label{wxpengetcolour
}
145 \constfunc{wxColour\&
}{GetColour
}{\void}
147 Returns a reference to the pen colour.
151 \helpref{wxPen::SetColour
}{wxpensetcolour
}
153 \membersection{wxPen::GetDashes
}\label{wxpengetdashes
}
155 \constfunc{int
}{GetDashes
}{\param{wxDash**
}{ dashes
}}
157 Gets an array of dashes (defined as char in X, DWORD under Windows).
158 {\it dashes
} is a pointer to the internal array. Do not deallocate or store this pointer.
159 The function returns the number of dashes associated with this pen.
163 \helpref{wxPen::SetDashes
}{wxpensetdashes
}
165 \membersection{wxPen::GetJoin
}\label{wxpengetjoin
}
167 \constfunc{int
}{GetJoin
}{\void}
169 Returns the pen join style, which may be one of
{\bf wxJOIN
\_BEVEL},
{\bf wxJOIN
\_ROUND} and
170 \rtfsp{\bf wxJOIN
\_MITER}. The default is
{\bf wxJOIN
\_ROUND}.
174 \helpref{wxPen::SetJoin
}{wxpensetjoin
}
176 \membersection{wxPen::GetStipple
}\label{wxpengetstipple
}
178 \constfunc{wxBitmap*
}{GetStipple
}{\void}
180 Gets a pointer to the stipple bitmap.
184 \helpref{wxPen::SetStipple
}{wxpensetstipple
}
186 \membersection{wxPen::GetStyle
}\label{wxpengetstyle
}
188 \constfunc{int
}{GetStyle
}{\void}
190 Returns the pen style.
194 \helpref{wxPen::wxPen
}{wxpenconstr
},
\helpref{wxPen::SetStyle
}{wxpensetstyle
}
196 \membersection{wxPen::GetWidth
}\label{wxpengetwidth
}
198 \constfunc{int
}{GetWidth
}{\void}
200 Returns the pen width.
204 \helpref{wxPen::SetWidth
}{wxpensetwidth
}
206 \membersection{wxPen::Ok
}\label{wxpenok
}
208 \constfunc{bool
}{Ok
}{\void}
210 Returns TRUE if the pen is initialised.
212 \membersection{wxPen::SetCap
}\label{wxpensetcap
}
214 \func{void
}{SetCap
}{\param{int
}{ capStyle
}}
216 Sets the pen cap style, which may be one of
{\bf wxCAP
\_ROUND},
{\bf wxCAP
\_PROJECTING} and
217 \rtfsp{\bf wxCAP
\_BUTT}. The default is
{\bf wxCAP
\_ROUND}.
221 \helpref{wxPen::GetCap
}{wxpengetcap
}
223 \membersection{wxPen::SetColour
}\label{wxpensetcolour
}
225 \func{void
}{SetColour
}{\param{wxColour\&
}{ colour
}}
227 \func{void
}{SetColour
}{\param{const wxString\&
}{colourName
}}
229 \func{void
}{SetColour
}{\param{int
}{ red
},
\param{int
}{ green
},
\param{int
}{ blue
}}
231 The pen's colour is changed to the given colour.
235 \helpref{wxPen::GetColour
}{wxpengetcolour
}
237 \membersection{wxPen::SetDashes
}\label{wxpensetdashes
}
239 \func{void
}{SetDashes
}{\param{int
}{n
},
\param{wxDash*
}{ dashes
}}
241 Associates an array of pointers to dashes (defined as char in X, DWORD under Windows)
242 with the pen. The array is not deallocated by wxPen, but neither must it be
243 deallocated by the calling application until the pen is deleted or this
244 function is called with a NULL array.
246 %TODO: describe in detail.
249 \helpref{wxPen::GetDashes
}{wxpengetdashes
}
251 \membersection{wxPen::SetJoin
}\label{wxpensetjoin
}
253 \func{void
}{SetJoin
}{\param{int
}{join
\_style}}
255 Sets the pen join style, which may be one of
{\bf wxJOIN
\_BEVEL},
{\bf wxJOIN
\_ROUND} and
256 \rtfsp{\bf wxJOIN
\_MITER}. The default is
{\bf wxJOIN
\_ROUND}.
260 \helpref{wxPen::GetJoin
}{wxpengetjoin
}
262 \membersection{wxPen::SetStipple
}\label{wxpensetstipple
}
264 \func{void
}{SetStipple
}{\param{wxBitmap*
}{stipple
}}
266 Sets the bitmap for stippling.
270 \helpref{wxPen::GetStipple
}{wxpengetstipple
}
272 \membersection{wxPen::SetStyle
}\label{wxpensetstyle
}
274 \func{void
}{SetStyle
}{\param{int
}{ style
}}
280 \helpref{wxPen::wxPen
}{wxpenconstr
}
282 \membersection{wxPen::SetWidth
}\label{wxpensetwidth
}
284 \func{void
}{SetWidth
}{\param{int
}{ width
}}
290 \helpref{wxPen::GetWidth
}{wxpengetwidth
}
292 \membersection{wxPen::operator $=$
}\label{wxpenassignment
}
294 \func{wxPen\&
}{operator $=$
}{\param{const wxPen\&
}{pen
}}
296 Assignment operator, using reference counting. Returns a reference
299 \membersection{wxPen::operator $==$
}\label{wxpenequals
}
301 \func{bool
}{operator $==$
}{\param{const wxPen\&
}{pen
}}
303 Equality operator. Two pens are equal if they contain pointers
304 to the same underlying pen data. It does not compare each attribute,
305 so two independently-created pens using the same parameters will
308 \membersection{wxPen::operator $!=$
}\label{wxpennotequals
}
310 \func{bool
}{operator $!=$
}{\param{const wxPen\&
}{pen
}}
312 Inequality operator. Two pens are not equal if they contain pointers
313 to different underlying pen data. It does not compare each attribute.
315 \section{\class{wxPenList
}}\label{wxpenlist
}
317 There is only one instance of this class:
{\bf wxThePenList
}. Use
318 this object to search for a previously created pen of the desired
319 type and create it if not already found. In some windowing systems,
320 the pen may be a scarce resource, so it can pay to reuse old
321 resources if possible. When an application finishes, all pens will
322 be deleted and their resources freed, eliminating the possibility of
323 `memory leaks'. However, it is best not to rely on this automatic
324 cleanup because it can lead to double deletion in some circumstances.
326 There are two mechanisms in recent versions of wxWindows which make the
327 pen list less useful than it once was. Under Windows, scarce resources
328 are cleaned up internally if they are not being used. Also, a referencing
329 counting mechanism applied to all GDI objects means that some sharing
330 of underlying resources is possible. You don't have to keep track of pointers,
331 working out when it is safe delete a pen, because the referencing counting does
332 it for you. For example, you can set a pen in a device context, and then
333 immediately delete the pen you passed, because the pen is `copied'.
335 So you may find it easier to ignore the pen list, and instead create
336 and copy pens as you see fit. If your Windows resource meter suggests
337 your application is using too many resources, you can resort to using
338 GDI lists to share objects explicitly.
340 The only compelling use for the pen list is for wxWindows to keep
341 track of pens in order to clean them up on exit. It is also kept for
342 backward compatibility with earlier versions of wxWindows.
346 \helpref{wxPen
}{wxpen
}
348 \latexignore{\rtfignore{\wxheading{Members
}}}
350 \membersection{wxPenList::wxPenList
}
352 \func{void
}{wxPenList
}{\void}
354 Constructor. The application should not construct its own pen list:
355 use the object pointer
{\bf wxThePenList
}.
357 \membersection{wxPenList::AddPen
}\label{wxpenlistaddpen
}
359 \func{void
}{AddPen
}{\param{wxPen*
}{ pen
}}
361 Used internally by wxWindows to add a pen to the list.
363 \membersection{wxPenList::FindOrCreatePen
}\label{wxpenlistfindorcreatepen
}
365 \func{wxPen*
}{FindOrCreatePen
}{\param{const wxColour\&
}{colour
},
\param{int
}{ width
},
\param{int
}{ style
}}
367 Finds a pen with the specified attributes and returns it, else creates a new pen, adds it
368 to the pen list, and returns it.
370 \func{wxPen*
}{FindOrCreatePen
}{\param{const wxString\&
}{colourName
},
\param{int
}{ width
},
\param{int
}{ style
}}
372 Finds a pen with the specified attributes and returns it, else creates a new pen, adds it
373 to the pen list, and returns it.
375 \wxheading{Parameters
}
377 \docparam{colour
}{Colour object.
}
379 \docparam{colourName
}{Colour name, which should be in the
\helpref{colour database
}{wxcolourdatabase
}.
}
381 \docparam{width
}{Width of pen.
}
383 \docparam{style
}{Pen style. See
\helpref{wxPen::wxPen
}{wxpenconstr
} for a list of styles.
}
385 \membersection{wxPenList::RemovePen
}\label{wxpenlistremovepen
}
387 \func{void
}{RemovePen
}{\param{wxPen*
}{ pen
}}
389 Used by wxWindows to remove a pen from the list.