]> git.saurik.com Git - wxWidgets.git/blame_incremental - docs/latex/wx/pen.tex
a bit more docs
[wxWidgets.git] / docs / latex / wx / pen.tex
... / ...
CommitLineData
1\section{\class{wxPen}}\label{wxpen}
2
3A pen is a drawing tool for drawing outlines. It is used for drawing
4lines and painting the outline of rectangles, ellipses, etc. It has a
5colour, a width and a style.
6
7\wxheading{Remarks}
8
9On a monochrome display, wxWindows shows all non-white pens as black.
10
11Do not initialize objects on the stack before the program commences,
12since other required structures may not have been set up yet. Instead,
13define global pointers to objects and create them in {\it OnInit} or
14when required.
15
16An application may wish to dynamically create pens with different
17characteristics, and there is the consequent danger that a large number
18of duplicate pens will be created. Therefore an application may wish to
19get a pointer to a pen by using the global list of pens {\bf
20wxThePenList}, and calling the member function {\bf FindOrCreatePen}.
21See the entry for \helpref{wxPenList}{wxpenlist}.
22
23wxPen uses a reference counting system, so assignments between brushes are very
24cheap. You can therefore use actual wxPen objects instead of pointers without
25efficiency problems. Once one wxPen object changes its data it will create its
26own pen data internally so that other pens, which previously shared the
27data using the reference counting, are not affected.
28
29TODO: an overview for wxPen.
30
31\wxheading{See also}
32
33\helpref{wxPenList}{wxpenlist}, \helpref{wxDC}{wxdc}, \helpref{wxDC::SetPen}{wxdcsetpen}
34
35\latexignore{\rtfignore{\wxheading{Members}}}
36
37\membersection{wxPen::wxPen}\label{wxpenconstr}
38
39\func{}{wxPen}{\void}
40
41Default constructor. The pen will be uninitialised, and \helpref{wxPen::Ok}{wxpenok} will
42return FALSE.
43
44\func{}{wxPen}{\param{const wxColour\&}{ colour}, \param{int}{ width}, \param{int}{ style}}
45
46Constructs a pen from a colour object, pen width and style.
47
48\func{}{wxPen}{\param{const wxString\& }{colourName}, \param{int}{ width}, \param{int}{ style}}
49
50Constructs a pen from a colour name, pen width and style.
51
52\func{}{wxPen}{\param{const wxBitmap\&}{ stipple}, \param{int}{ width}}
53
54Constructs a stippled pen from a stipple bitmap and a width.
55
56\func{}{wxPen}{\param{const wxPen\&}{ pen}}
57
58Copy constructor. This uses reference counting so is a cheap operation.
59
60\wxheading{Parameters}
61
62\docparam{colour}{A colour object.}
63
64\docparam{colourName}{A colour name.}
65
66\docparam{width}{Pen width. Under Windows, the pen width cannot be greater than 1 if
67the style is wxDOT, wxLONG\_DASH, wxSHORT\_DASH, wxDOT\_DASH, or wxUSER\_DASH.}
68
69\docparam{stipple}{A stipple bitmap.}
70
71\docparam{pen}{A pointer or reference to a pen to copy.}
72
73\docparam{width}{Pen width. Under Windows, the pen width cannot be greater than 1 if
74the style is wxDOT, wxLONG\_DASH, wxSHORT\_DASH, wxDOT\_DASH, or wxUSER\_DASH.}
75
76\docparam{style}{The style may be one of the following:
77
78\begin{twocollist}\itemsep=0pt
79\twocolitem{{\bf wxSOLID}}{Solid style.}
80\twocolitem{{\bf wxTRANSPARENT}}{No pen is used.}
81\twocolitem{{\bf wxDOT}}{Dotted style.}
82\twocolitem{{\bf wxLONG\_DASH}}{Long dashed style.}
83\twocolitem{{\bf wxSHORT\_DASH}}{Short dashed style.}
84\twocolitem{{\bf wxDOT\_DASH}}{Dot and dash style.}
85\twocolitem{{\bf wxSTIPPLE}}{Use the stipple bitmap.}
86\twocolitem{{\bf wxUSER\_DASH}}{Use the user dashes: see \helpref{wxPen::SetDashes}{wxpensetdashes}.}
87\twocolitem{{\bf wxBDIAGONAL\_HATCH}}{Backward diagonal hatch.}
88\twocolitem{{\bf wxCROSSDIAG\_HATCH}}{Cross-diagonal hatch.}
89\twocolitem{{\bf wxFDIAGONAL\_HATCH}}{Forward diagonal hatch.}
90\twocolitem{{\bf wxCROSS\_HATCH}}{Cross hatch.}
91\twocolitem{{\bf wxHORIZONTAL\_HATCH}}{Horizontal hatch.}
92\twocolitem{{\bf wxVERTICAL\_HATCH}}{Vertical hatch.}
93\end{twocollist}}
94
95\wxheading{Remarks}
96
97If the named colour form is used, an appropriate {\bf wxColour} structure
98is found in the colour database.
99
100{\it style} may be one of wxSOLID, wxDOT, wxLONG\_DASH, wxSHORT\_DASH and
101wxDOT\_DASH.
102
103\wxheading{See also}
104
105\helpref{wxPen::SetStyle}{wxpensetstyle}, \helpref{wxPen::SetColour}{wxpensetcolour},\rtfsp
106\helpref{wxPen::SetWidth}{wxpensetwidth}, \helpref{wxPen::SetStipple}{wxpensetstipple}
107
108\membersection{wxPen::\destruct{wxPen}}
109
110\func{}{\destruct{wxPen}}{\void}
111
112Destructor.
113
114\wxheading{Remarks}
115
116The destructor may not delete the underlying pen object of the native windowing
117system, since wxBrush uses a reference counting system for efficiency.
118
119Although all remaining pens are deleted when the application exits,
120the application should try to clean up all pens itself. This is because
121wxWindows cannot know if a pointer to the pen object is stored in an
122application data structure, and there is a risk of double deletion.
123
124\membersection{wxPen::GetCap}\label{wxpengetcap}
125
126\constfunc{int}{GetCap}{\void}
127
128Returns the pen cap style, which may be one of {\bf wxCAP\_ROUND}, {\bf wxCAP\_PROJECTING} and
129\rtfsp{\bf wxCAP\_BUTT}. The default is {\bf wxCAP\_ROUND}.
130
131\wxheading{See also}
132
133\helpref{wxPen::SetCap}{wxpensetcap}
134
135\membersection{wxPen::GetColour}\label{wxpengetcolour}
136
137\constfunc{wxColour\&}{GetColour}{\void}
138
139Returns a reference to the pen colour.
140
141\wxheading{See also}
142
143\helpref{wxPen::SetColour}{wxpensetcolour}
144
145\membersection{wxPen::GetDashes}\label{wxpengetdashes}
146
147\constfunc{int}{GetDashes}{\param{wxDash**}{ dashes}}
148
149Gets an array of dashes (defined as char in X, DWORD under Windows).
150{\it dashes} is a pointer to the internal array. Do not deallocate or store this pointer.
151The function returns the number of dashes associated with this pen.
152
153\wxheading{See also}
154
155\helpref{wxPen::SetDashes}{wxpensetdashes}
156
157\membersection{wxPen::GetJoin}\label{wxpengetjoin}
158
159\constfunc{int}{GetJoin}{\void}
160
161Returns the pen join style, which may be one of {\bf wxJOIN\_BEVEL}, {\bf wxJOIN\_ROUND} and
162\rtfsp{\bf wxJOIN\_MITER}. The default is {\bf wxJOIN\_ROUND}.
163
164\wxheading{See also}
165
166\helpref{wxPen::SetJoin}{wxpensetjoin}
167
168\membersection{wxPen::GetStipple}\label{wxpengetstipple}
169
170\constfunc{wxBitmap* }{GetStipple}{\void}
171
172Gets a pointer to the stipple bitmap.
173
174\wxheading{See also}
175
176\helpref{wxPen::SetStipple}{wxpensetstipple}
177
178\membersection{wxPen::GetStyle}\label{wxpengetstyle}
179
180\constfunc{int}{GetStyle}{\void}
181
182Returns the pen style.
183
184\wxheading{See also}
185
186\helpref{wxPen::wxPen}{wxpenconstr}, \helpref{wxPen::SetStyle}{wxpensetstyle}
187
188\membersection{wxPen::GetWidth}\label{wxpengetwidth}
189
190\constfunc{int}{GetWidth}{\void}
191
192Returns the pen width.
193
194\wxheading{See also}
195
196\helpref{wxPen::SetWidth}{wxpensetwidth}
197
198\membersection{wxPen::Ok}\label{wxpenok}
199
200\constfunc{bool}{Ok}{\void}
201
202Returns TRUE if the pen is initialised.
203
204\membersection{wxPen::SetCap}\label{wxpensetcap}
205
206\func{void}{SetCap}{\param{int}{ capStyle}}
207
208Sets the pen cap style, which may be one of {\bf wxCAP\_ROUND}, {\bf wxCAP\_PROJECTING} and
209\rtfsp{\bf wxCAP\_BUTT}. The default is {\bf wxCAP\_ROUND}.
210
211\wxheading{See also}
212
213\helpref{wxPen::GetCap}{wxpengetcap}
214
215\membersection{wxPen::SetColour}\label{wxpensetcolour}
216
217\func{void}{SetColour}{\param{wxColour\&}{ colour}}
218
219\func{void}{SetColour}{\param{const wxString\& }{colourName}}
220
221\func{void}{SetColour}{\param{int}{ red}, \param{int}{ green}, \param{int}{ blue}}
222
223The pen's colour is changed to the given colour.
224
225\wxheading{See also}
226
227\helpref{wxPen::GetColour}{wxpengetcolour}
228
229\membersection{wxPen::SetDashes}\label{wxpensetdashes}
230
231\func{void}{SetDashes}{\param{int }{n}, \param{wxDash*}{ dashes}}
232
233Associates an array of pointers to dashes (defined as char in X, DWORD under Windows)
234with the pen. The array is not deallocated by wxPen, but neither must it be
235deallocated by the calling application until the pen is deleted or this
236function is called with a NULL array.
237
238TODO: describe in detail.
239
240\wxheading{See also}
241
242\helpref{wxPen::GetDashes}{wxpengetdashes}
243
244\membersection{wxPen::SetJoin}\label{wxpensetjoin}
245
246\func{void}{SetJoin}{\param{int}{join\_style}}
247
248Sets the pen join style, which may be one of {\bf wxJOIN\_BEVEL}, {\bf wxJOIN\_ROUND} and
249\rtfsp{\bf wxJOIN\_MITER}. The default is {\bf wxJOIN\_ROUND}.
250
251\wxheading{See also}
252
253\helpref{wxPen::GetJoin}{wxpengetjoin}
254
255\membersection{wxPen::SetStipple}\label{wxpensetstipple}
256
257\func{void}{SetStipple}{\param{wxBitmap* }{stipple}}
258
259Sets the bitmap for stippling.
260
261\wxheading{See also}
262
263\helpref{wxPen::GetStipple}{wxpengetstipple}
264
265\membersection{wxPen::SetStyle}\label{wxpensetstyle}
266
267\func{void}{SetStyle}{\param{int}{ style}}
268
269Set the pen style.
270
271\wxheading{See also}
272
273\helpref{wxPen::wxPen}{wxpenconstr}
274
275\membersection{wxPen::SetWidth}\label{wxpensetwidth}
276
277\func{void}{SetWidth}{\param{int}{ width}}
278
279Sets the pen width.
280
281\wxheading{See also}
282
283\helpref{wxPen::GetWidth}{wxpengetwidth}
284
285\membersection{wxPen::operator $=$}\label{wxpenassignment}
286
287\func{wxPen\&}{operator $=$}{\param{const wxPen\& }{pen}}
288
289Assignment operator, using reference counting. Returns a reference
290to `this'.
291
292\membersection{wxPen::operator $==$}\label{wxpenequals}
293
294\func{bool}{operator $==$}{\param{const wxPen\& }{pen}}
295
296Equality operator. Two pens are equal if they contain pointers
297to the same underlying pen data. It does not compare each attribute,
298so two independently-created pens using the same parameters will
299fail the test.
300
301\membersection{wxPen::operator $!=$}\label{wxpennotequals}
302
303\func{bool}{operator $!=$}{\param{const wxPen\& }{pen}}
304
305Inequality operator. Two pens are not equal if they contain pointers
306to different underlying pen data. It does not compare each attribute.
307
308\section{\class{wxPenList}}\label{wxpenlist}
309
310There is only one instance of this class: {\bf wxThePenList}. Use
311this object to search for a previously created pen of the desired
312type and create it if not already found. In some windowing systems,
313the pen may be a scarce resource, so it can pay to reuse old
314resources if possible. When an application finishes, all pens will
315be deleted and their resources freed, eliminating the possibility of
316`memory leaks'. However, it is best not to rely on this automatic
317cleanup because it can lead to double deletion in some circumstances.
318
319There are two mechanisms in recent versions of wxWindows which make the
320pen list less useful than it once was. Under Windows, scarce resources
321are cleaned up internally if they are not being used. Also, a referencing
322counting mechanism applied to all GDI objects means that some sharing
323of underlying resources is possible. You don't have to keep track of pointers,
324working out when it is safe delete a pen, because the referencing counting does
325it for you. For example, you can set a pen in a device context, and then
326immediately delete the pen you passed, because the pen is `copied'.
327
328So you may find it easier to ignore the pen list, and instead create
329and copy pens as you see fit. If your Windows resource meter suggests
330your application is using too many resources, you can resort to using
331GDI lists to share objects explicitly.
332
333The only compelling use for the pen list is for wxWindows to keep
334track of pens in order to clean them up on exit. It is also kept for
335backward compatibility with earlier versions of wxWindows.
336
337\wxheading{See also}
338
339\helpref{wxPen}{wxpen}
340
341\latexignore{\rtfignore{\wxheading{Members}}}
342
343\membersection{wxPenList::wxPenList}
344
345\func{void}{wxPenList}{\void}
346
347Constructor. The application should not construct its own pen list:
348use the object pointer {\bf wxThePenList}.
349
350\membersection{wxPenList::AddPen}\label{wxpenlistaddpen}
351
352\func{void}{AddPen}{\param{wxPen*}{ pen}}
353
354Used internally by wxWindows to add a pen to the list.
355
356\membersection{wxPenList::FindOrCreatePen}\label{wxpenlistfindorcreatepen}
357
358\func{wxPen*}{FindOrCreatePen}{\param{const wxColour\& }{colour}, \param{int}{ width}, \param{int}{ style}}
359
360Finds a pen with the specified attributes and returns it, else creates a new pen, adds it
361to the pen list, and returns it.
362
363\func{wxPen*}{FindOrCreatePen}{\param{const wxString\& }{colourName}, \param{int}{ width}, \param{int}{ style}}
364
365Finds a pen with the specified attributes and returns it, else creates a new pen, adds it
366to the pen list, and returns it.
367
368\wxheading{Parameters}
369
370\docparam{colour}{Colour object.}
371
372\docparam{colourName}{Colour name, which should be in the colour database.}
373
374\docparam{style}{Pen style. See \helpref{wxPen::wxPen}{wxpenconstr} for a list of styles.}
375
376\membersection{wxPenList::RemovePen}\label{wxpenlistremovepen}
377
378\func{void}{RemovePen}{\param{wxPen*}{ pen}}
379
380Used by wxWindows to remove a pen from the list.
381
382