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
}
16 \wxheading{Predefined objects
}
30 wxBLACK
\_DASHED\_PEN\\
37 On a monochrome display, wxWindows shows all non-white pens as black.
39 Do not initialize objects on the stack before the program commences,
40 since other required structures may not have been set up yet. Instead,
41 define global pointers to objects and create them in
{\it OnInit
} or
44 An application may wish to dynamically create pens with different
45 characteristics, and there is the consequent danger that a large number
46 of duplicate pens will be created. Therefore an application may wish to
47 get a pointer to a pen by using the global list of pens
{\bf
48 wxThePenList
}, and calling the member function
{\bf FindOrCreatePen
}.
49 See the entry for
\helpref{wxPenList
}{wxpenlist
}.
51 wxPen uses a reference counting system, so assignments between brushes are very
52 cheap. You can therefore use actual wxPen objects instead of pointers without
53 efficiency problems. Once one wxPen object changes its data it will create its
54 own pen data internally so that other pens, which previously shared the
55 data using the reference counting, are not affected.
57 %TODO: an overview for wxPen.
60 \helpref{wxPenList
}{wxpenlist
},
\helpref{wxDC
}{wxdc
},
\helpref{wxDC::SetPen
}{wxdcsetpen
}
62 \latexignore{\rtfignore{\wxheading{Members
}}}
64 \membersection{wxPen::wxPen
}\label{wxpenconstr
}
68 Default constructor. The pen will be uninitialised, and
\helpref{wxPen::Ok
}{wxpenok
} will
71 \func{}{wxPen
}{\param{const wxColour\&
}{ colour
},
\param{int
}{ width
},
\param{int
}{ style
}}
73 Constructs a pen from a colour object, pen width and style.
75 \func{}{wxPen
}{\param{const wxString\&
}{colourName
},
\param{int
}{ width
},
\param{int
}{ style
}}
77 Constructs a pen from a colour name, pen width and style.
79 \func{}{wxPen
}{\param{const wxBitmap\&
}{ stipple
},
\param{int
}{ width
}}
81 Constructs a stippled pen from a stipple bitmap and a width.
83 \func{}{wxPen
}{\param{const wxPen\&
}{ pen
}}
85 Copy constructor. This uses reference counting so is a cheap operation.
87 \wxheading{Parameters
}
89 \docparam{colour
}{A colour object.
}
91 \docparam{colourName
}{A colour name.
}
93 \docparam{width
}{Pen width. Under Windows, the pen width cannot be greater than
1 if
94 the style is wxDOT, wxLONG
\_DASH, wxSHORT
\_DASH, wxDOT
\_DASH, or wxUSER
\_DASH.
}
96 \docparam{stipple
}{A stipple bitmap.
}
98 \docparam{pen
}{A pointer or reference to a pen to copy.
}
100 \docparam{width
}{Pen width. Under Windows, the pen width cannot be greater than
1 if
101 the style is wxDOT, wxLONG
\_DASH, wxSHORT
\_DASH, wxDOT
\_DASH, or wxUSER
\_DASH.
}
103 \docparam{style
}{The style may be one of the following:
105 \begin{twocollist
}\itemsep=
0pt
106 \twocolitem{{\bf wxSOLID
}}{Solid style.
}
107 \twocolitem{{\bf wxTRANSPARENT
}}{No pen is used.
}
108 \twocolitem{{\bf wxDOT
}}{Dotted style.
}
109 \twocolitem{{\bf wxLONG
\_DASH}}{Long dashed style.
}
110 \twocolitem{{\bf wxSHORT
\_DASH}}{Short dashed style.
}
111 \twocolitem{{\bf wxDOT
\_DASH}}{Dot and dash style.
}
112 \twocolitem{{\bf wxSTIPPLE
}}{Use the stipple bitmap.
}
113 \twocolitem{{\bf wxUSER
\_DASH}}{Use the user dashes: see
\helpref{wxPen::SetDashes
}{wxpensetdashes
}.
}
114 \twocolitem{{\bf wxBDIAGONAL
\_HATCH}}{Backward diagonal hatch.
}
115 \twocolitem{{\bf wxCROSSDIAG
\_HATCH}}{Cross-diagonal hatch.
}
116 \twocolitem{{\bf wxFDIAGONAL
\_HATCH}}{Forward diagonal hatch.
}
117 \twocolitem{{\bf wxCROSS
\_HATCH}}{Cross hatch.
}
118 \twocolitem{{\bf wxHORIZONTAL
\_HATCH}}{Horizontal hatch.
}
119 \twocolitem{{\bf wxVERTICAL
\_HATCH}}{Vertical hatch.
}
124 If the named colour form is used, an appropriate
{\bf wxColour
} structure
125 is found in the colour database.
127 {\it style
} may be one of wxSOLID, wxDOT, wxLONG
\_DASH, wxSHORT
\_DASH and
132 \helpref{wxPen::SetStyle
}{wxpensetstyle
},
\helpref{wxPen::SetColour
}{wxpensetcolour
},
\rtfsp
133 \helpref{wxPen::SetWidth
}{wxpensetwidth
},
\helpref{wxPen::SetStipple
}{wxpensetstipple
}
135 \membersection{wxPen::
\destruct{wxPen
}}
137 \func{}{\destruct{wxPen
}}{\void}
143 The destructor may not delete the underlying pen object of the native windowing
144 system, since wxBrush uses a reference counting system for efficiency.
146 Although all remaining pens are deleted when the application exits,
147 the application should try to clean up all pens itself. This is because
148 wxWindows cannot know if a pointer to the pen object is stored in an
149 application data structure, and there is a risk of double deletion.
151 \membersection{wxPen::GetCap
}\label{wxpengetcap
}
153 \constfunc{int
}{GetCap
}{\void}
155 Returns the pen cap style, which may be one of
{\bf wxCAP
\_ROUND},
{\bf wxCAP
\_PROJECTING} and
156 \rtfsp{\bf wxCAP
\_BUTT}. The default is
{\bf wxCAP
\_ROUND}.
160 \helpref{wxPen::SetCap
}{wxpensetcap
}
162 \membersection{wxPen::GetColour
}\label{wxpengetcolour
}
164 \constfunc{wxColour\&
}{GetColour
}{\void}
166 Returns a reference to the pen colour.
170 \helpref{wxPen::SetColour
}{wxpensetcolour
}
172 \membersection{wxPen::GetDashes
}\label{wxpengetdashes
}
174 \constfunc{int
}{GetDashes
}{\param{wxDash**
}{ dashes
}}
176 Gets an array of dashes (defined as char in X, DWORD under Windows).
177 {\it dashes
} is a pointer to the internal array. Do not deallocate or store this pointer.
178 The function returns the number of dashes associated with this pen.
182 \helpref{wxPen::SetDashes
}{wxpensetdashes
}
184 \membersection{wxPen::GetJoin
}\label{wxpengetjoin
}
186 \constfunc{int
}{GetJoin
}{\void}
188 Returns the pen join style, which may be one of
{\bf wxJOIN
\_BEVEL},
{\bf wxJOIN
\_ROUND} and
189 \rtfsp{\bf wxJOIN
\_MITER}. The default is
{\bf wxJOIN
\_ROUND}.
193 \helpref{wxPen::SetJoin
}{wxpensetjoin
}
195 \membersection{wxPen::GetStipple
}\label{wxpengetstipple
}
197 \constfunc{wxBitmap*
}{GetStipple
}{\void}
199 Gets a pointer to the stipple bitmap.
203 \helpref{wxPen::SetStipple
}{wxpensetstipple
}
205 \membersection{wxPen::GetStyle
}\label{wxpengetstyle
}
207 \constfunc{int
}{GetStyle
}{\void}
209 Returns the pen style.
213 \helpref{wxPen::wxPen
}{wxpenconstr
},
\helpref{wxPen::SetStyle
}{wxpensetstyle
}
215 \membersection{wxPen::GetWidth
}\label{wxpengetwidth
}
217 \constfunc{int
}{GetWidth
}{\void}
219 Returns the pen width.
223 \helpref{wxPen::SetWidth
}{wxpensetwidth
}
225 \membersection{wxPen::Ok
}\label{wxpenok
}
227 \constfunc{bool
}{Ok
}{\void}
229 Returns TRUE if the pen is initialised.
231 \membersection{wxPen::SetCap
}\label{wxpensetcap
}
233 \func{void
}{SetCap
}{\param{int
}{ capStyle
}}
235 Sets the pen cap style, which may be one of
{\bf wxCAP
\_ROUND},
{\bf wxCAP
\_PROJECTING} and
236 \rtfsp{\bf wxCAP
\_BUTT}. The default is
{\bf wxCAP
\_ROUND}.
240 \helpref{wxPen::GetCap
}{wxpengetcap
}
242 \membersection{wxPen::SetColour
}\label{wxpensetcolour
}
244 \func{void
}{SetColour
}{\param{wxColour\&
}{ colour
}}
246 \func{void
}{SetColour
}{\param{const wxString\&
}{colourName
}}
248 \func{void
}{SetColour
}{\param{int
}{ red
},
\param{int
}{ green
},
\param{int
}{ blue
}}
250 The pen's colour is changed to the given colour.
254 \helpref{wxPen::GetColour
}{wxpengetcolour
}
256 \membersection{wxPen::SetDashes
}\label{wxpensetdashes
}
258 \func{void
}{SetDashes
}{\param{int
}{n
},
\param{wxDash*
}{ dashes
}}
260 Associates an array of pointers to dashes (defined as char in X, DWORD under Windows)
261 with the pen. The array is not deallocated by wxPen, but neither must it be
262 deallocated by the calling application until the pen is deleted or this
263 function is called with a NULL array.
265 %TODO: describe in detail.
268 \helpref{wxPen::GetDashes
}{wxpengetdashes
}
270 \membersection{wxPen::SetJoin
}\label{wxpensetjoin
}
272 \func{void
}{SetJoin
}{\param{int
}{join
\_style}}
274 Sets the pen join style, which may be one of
{\bf wxJOIN
\_BEVEL},
{\bf wxJOIN
\_ROUND} and
275 \rtfsp{\bf wxJOIN
\_MITER}. The default is
{\bf wxJOIN
\_ROUND}.
279 \helpref{wxPen::GetJoin
}{wxpengetjoin
}
281 \membersection{wxPen::SetStipple
}\label{wxpensetstipple
}
283 \func{void
}{SetStipple
}{\param{wxBitmap*
}{stipple
}}
285 Sets the bitmap for stippling.
289 \helpref{wxPen::GetStipple
}{wxpengetstipple
}
291 \membersection{wxPen::SetStyle
}\label{wxpensetstyle
}
293 \func{void
}{SetStyle
}{\param{int
}{ style
}}
299 \helpref{wxPen::wxPen
}{wxpenconstr
}
301 \membersection{wxPen::SetWidth
}\label{wxpensetwidth
}
303 \func{void
}{SetWidth
}{\param{int
}{ width
}}
309 \helpref{wxPen::GetWidth
}{wxpengetwidth
}
311 \membersection{wxPen::operator $=$
}\label{wxpenassignment
}
313 \func{wxPen\&
}{operator $=$
}{\param{const wxPen\&
}{pen
}}
315 Assignment operator, using reference counting. Returns a reference
318 \membersection{wxPen::operator $==$
}\label{wxpenequals
}
320 \func{bool
}{operator $==$
}{\param{const wxPen\&
}{pen
}}
322 Equality operator. Two pens are equal if they contain pointers
323 to the same underlying pen data. It does not compare each attribute,
324 so two independently-created pens using the same parameters will
327 \membersection{wxPen::operator $!=$
}\label{wxpennotequals
}
329 \func{bool
}{operator $!=$
}{\param{const wxPen\&
}{pen
}}
331 Inequality operator. Two pens are not equal if they contain pointers
332 to different underlying pen data. It does not compare each attribute.
334 \section{\class{wxPenList
}}\label{wxpenlist
}
336 There is only one instance of this class:
{\bf wxThePenList
}. Use
337 this object to search for a previously created pen of the desired
338 type and create it if not already found. In some windowing systems,
339 the pen may be a scarce resource, so it can pay to reuse old
340 resources if possible. When an application finishes, all pens will
341 be deleted and their resources freed, eliminating the possibility of
342 `memory leaks'. However, it is best not to rely on this automatic
343 cleanup because it can lead to double deletion in some circumstances.
345 There are two mechanisms in recent versions of wxWindows which make the
346 pen list less useful than it once was. Under Windows, scarce resources
347 are cleaned up internally if they are not being used. Also, a referencing
348 counting mechanism applied to all GDI objects means that some sharing
349 of underlying resources is possible. You don't have to keep track of pointers,
350 working out when it is safe delete a pen, because the referencing counting does
351 it for you. For example, you can set a pen in a device context, and then
352 immediately delete the pen you passed, because the pen is `copied'.
354 So you may find it easier to ignore the pen list, and instead create
355 and copy pens as you see fit. If your Windows resource meter suggests
356 your application is using too many resources, you can resort to using
357 GDI lists to share objects explicitly.
359 The only compelling use for the pen list is for wxWindows to keep
360 track of pens in order to clean them up on exit. It is also kept for
361 backward compatibility with earlier versions of wxWindows.
365 \helpref{wxPen
}{wxpen
}
367 \latexignore{\rtfignore{\wxheading{Members
}}}
369 \membersection{wxPenList::wxPenList
}
371 \func{void
}{wxPenList
}{\void}
373 Constructor. The application should not construct its own pen list:
374 use the object pointer
{\bf wxThePenList
}.
376 \membersection{wxPenList::AddPen
}\label{wxpenlistaddpen
}
378 \func{void
}{AddPen
}{\param{wxPen*
}{ pen
}}
380 Used internally by wxWindows to add a pen to the list.
382 \membersection{wxPenList::FindOrCreatePen
}\label{wxpenlistfindorcreatepen
}
384 \func{wxPen*
}{FindOrCreatePen
}{\param{const wxColour\&
}{colour
},
\param{int
}{ width
},
\param{int
}{ style
}}
386 Finds a pen with the specified attributes and returns it, else creates a new pen, adds it
387 to the pen list, and returns it.
389 \func{wxPen*
}{FindOrCreatePen
}{\param{const wxString\&
}{colourName
},
\param{int
}{ width
},
\param{int
}{ style
}}
391 Finds a pen with the specified attributes and returns it, else creates a new pen, adds it
392 to the pen list, and returns it.
394 \wxheading{Parameters
}
396 \docparam{colour
}{Colour object.
}
398 \docparam{colourName
}{Colour name, which should be in the
\helpref{colour database
}{wxcolourdatabase
}.
}
400 \docparam{width
}{Width of pen.
}
402 \docparam{style
}{Pen style. See
\helpref{wxPen::wxPen
}{wxpenconstr
} for a list of styles.
}
404 \membersection{wxPenList::RemovePen
}\label{wxpenlistremovepen
}
406 \func{void
}{RemovePen
}{\param{wxPen*
}{ pen
}}
408 Used by wxWindows to remove a pen from the list.