]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/brush.tex
corrected GetAppName() link
[wxWidgets.git] / docs / latex / wx / brush.tex
CommitLineData
a660d684
KB
1\section{\class{wxBrush}}\label{wxbrush}
2
3A brush is a drawing tool for filling in areas. It is used for painting
4the background of rectangles, ellipses, etc. It has a colour and a
5style.
6
7\wxheading{Derived from}
8
9\helpref{wxGDIObject}{wxgdiobject}\\
10\helpref{wxObject}{wxobject}
11
954b8ae6
JS
12\wxheading{Include files}
13
14<wx/brush.h>
15
20e85460
JS
16\wxheading{Predefined objects}
17
18Objects:
19
20{\bf wxNullBrush}
21
22Pointers:
23
24{\bf wxBLUE\_BRUSH\\
25wxGREEN\_BRUSH\\
26wxWHITE\_BRUSH\\
27wxBLACK\_BRUSH\\
28wxGREY\_BRUSH\\
29wxMEDIUM\_GREY\_BRUSH\\
30wxLIGHT\_GREY\_BRUSH\\
31wxTRANSPARENT\_BRUSH\\
32wxCYAN\_BRUSH\\
33wxRED\_BRUSH}
34
a660d684
KB
35\wxheading{Remarks}
36
fc2171bd 37On a monochrome display, wxWidgets shows
a660d684
KB
38all brushes as white unless the colour is really black.
39
40Do not initialize objects on the stack before the program commences,
41since other required structures may not have been set up yet. Instead,
42define global pointers to objects and create them in \helpref{wxApp::OnInit}{wxapponinit} or
43when required.
44
45An application may wish to create brushes with different
46characteristics dynamically, and there is the consequent danger that a
47large number of duplicate brushes will be created. Therefore an
48application may wish to get a pointer to a brush by using the global
49list of brushes {\bf wxTheBrushList}, and calling the member function
50\rtfsp{\bf FindOrCreateBrush}.
51
52wxBrush uses a reference counting system, so assignments between brushes are very
53cheap. You can therefore use actual wxBrush objects instead of pointers without
12a44087
RR
54efficiency problems. Once one wxBrush object changes its data it will create its
55own brush data internally so that other brushes, which previously shared the
56data using the reference counting, are not affected.
a660d684 57
5b6aa0ff 58%TODO: an overview for wxBrush.
a660d684
KB
59\wxheading{See also}
60
61\helpref{wxBrushList}{wxbrushlist}, \helpref{wxDC}{wxdc}, \helpref{wxDC::SetBrush}{wxdcsetbrush}
62
63\latexignore{\rtfignore{\wxheading{Members}}}
64
f510b7b2 65\membersection{wxBrush::wxBrush}\label{wxbrushctor}
a660d684
KB
66
67\func{}{wxBrush}{\void}
68
69Default constructor. The brush will be uninitialised, and \helpref{wxBrush::Ok}{wxbrushok} will
cc81d32f 70return false.
a660d684 71
559b61bf 72\func{}{wxBrush}{\param{const wxColour\&}{ colour}, \param{int}{ style = {\tt wxSOLID}}}
a660d684
KB
73
74Constructs a brush from a colour object and style.
75
eaaa6a06 76\func{}{wxBrush}{\param{const wxString\& }{colourName}, \param{int}{ style}}
a660d684
KB
77
78Constructs a brush from a colour name and style.
79
80\func{}{wxBrush}{\param{const wxBitmap\& }{stippleBitmap}}
81
82Constructs a stippled brush using a bitmap.
83
84\func{}{wxBrush}{\param{const wxBrush\&}{ brush}}
85
86Copy constructor. This uses reference counting so is a cheap operation.
87
a660d684
KB
88\wxheading{Parameters}
89
90\docparam{colour}{Colour object.}
91
92\docparam{colourName}{Colour name. The name will be looked up in the colour database.}
93
94\docparam{style}{One of:
95
96\begin{twocollist}\itemsep=0pt
97\twocolitem{{\bf wxTRANSPARENT}}{Transparent (no fill).}
98\twocolitem{{\bf wxSOLID}}{Solid.}
03ca23b6 99\twocolitem{{\bf wxSTIPPLE}}{Uses a bitmap as a stipple.}
a660d684
KB
100\twocolitem{{\bf wxBDIAGONAL\_HATCH}}{Backward diagonal hatch.}
101\twocolitem{{\bf wxCROSSDIAG\_HATCH}}{Cross-diagonal hatch.}
102\twocolitem{{\bf wxFDIAGONAL\_HATCH}}{Forward diagonal hatch.}
103\twocolitem{{\bf wxCROSS\_HATCH}}{Cross hatch.}
104\twocolitem{{\bf wxHORIZONTAL\_HATCH}}{Horizontal hatch.}
105\twocolitem{{\bf wxVERTICAL\_HATCH}}{Vertical hatch.}
106\end{twocollist}}
107
108\docparam{brush}{Pointer or reference to a brush to copy.}
109
110\docparam{stippleBitmap}{A bitmap to use for stippling.}
111
112\wxheading{Remarks}
113
114If a stipple brush is created, the brush style will be set to wxSTIPPLE.
115
116\wxheading{See also}
117
118\helpref{wxBrushList}{wxbrushlist}, \helpref{wxColour}{wxcolour}, \helpref{wxColourDatabase}{wxcolourdatabase}
119
f510b7b2 120\membersection{wxBrush::\destruct{wxBrush}}\label{wxbrushdtor}
a660d684 121
0e10e38d 122\func{}{\destruct{wxBrush}}{\void}
a660d684
KB
123
124Destructor.
125
126\wxheading{Remarks}
127
128The destructor may not delete the underlying brush object of the native windowing
129system, since wxBrush uses a reference counting system for efficiency.
130
131Although all remaining brushes are deleted when the application exits,
132the application should try to clean up all brushes itself. This is because
fc2171bd 133wxWidgets cannot know if a pointer to the brush object is stored in an
a660d684
KB
134application data structure, and there is a risk of double deletion.
135
136\membersection{wxBrush::GetColour}\label{wxbrushgetcolour}
137
138\constfunc{wxColour\&}{GetColour}{\void}
139
140Returns a reference to the brush colour.
141
142\wxheading{See also}
143
144\helpref{wxBrush::SetColour}{wxbrushsetcolour}
145
146\membersection{wxBrush::GetStipple}\label{wxbrushgetstipple}
147
148\constfunc{wxBitmap *}{GetStipple}{\void}
149
150Gets a pointer to the stipple bitmap. If the brush does not have a wxSTIPPLE style,
cc81d32f 151this bitmap may be non-NULL but uninitialised (\helpref{wxBitmap::Ok}{wxbitmapok} returns false).
a660d684
KB
152
153\wxheading{See also}
154
155\helpref{wxBrush::SetStipple}{wxbrushsetstipple}
156
157\membersection{wxBrush::GetStyle}\label{wxbrushgetstyle}
158
159\constfunc{int}{GetStyle}{\void}
160
161Returns the brush style, one of:
162
163\begin{twocollist}\itemsep=0pt
164\twocolitem{{\bf wxTRANSPARENT}}{Transparent (no fill).}
165\twocolitem{{\bf wxSOLID}}{Solid.}
166\twocolitem{{\bf wxBDIAGONAL\_HATCH}}{Backward diagonal hatch.}
167\twocolitem{{\bf wxCROSSDIAG\_HATCH}}{Cross-diagonal hatch.}
168\twocolitem{{\bf wxFDIAGONAL\_HATCH}}{Forward diagonal hatch.}
169\twocolitem{{\bf wxCROSS\_HATCH}}{Cross hatch.}
170\twocolitem{{\bf wxHORIZONTAL\_HATCH}}{Horizontal hatch.}
171\twocolitem{{\bf wxVERTICAL\_HATCH}}{Vertical hatch.}
172\twocolitem{{\bf wxSTIPPLE}}{Stippled using a bitmap.}
e7240349 173\twocolitem{{\bf wxSTIPPLE\_MASK\_OPAQUE}}{Stippled using a bitmap's mask.}
a660d684
KB
174\end{twocollist}
175
176\wxheading{See also}
177
178\helpref{wxBrush::SetStyle}{wxbrushsetstyle}, \helpref{wxBrush::SetColour}{wxbrushsetcolour},\rtfsp
179\helpref{wxBrush::SetStipple}{wxbrushsetstipple}
180
ab9d0a8c
WS
181\membersection{wxBrush::IsHatch}\label{wxbrushishatch}
182
183\constfunc{bool}{IsHatch}{\void}
184
185Returns true if the style of the brush is any of hatched fills.
186
187\wxheading{See also}
188
189\helpref{wxBrush::GetStyle}{wxbrushgetstyle}
190
a660d684
KB
191\membersection{wxBrush::Ok}\label{wxbrushok}
192
193\constfunc{bool}{Ok}{\void}
194
cc81d32f 195Returns true if the brush is initialised. It will return false if the default
a660d684
KB
196constructor has been used (for example, the brush is a member of a class, or
197NULL has been assigned to it).
198
199\membersection{wxBrush::SetColour}\label{wxbrushsetcolour}
200
201\func{void}{SetColour}{\param{wxColour\& }{colour}}
202
203Sets the brush colour using a reference to a colour object.
204
205\func{void}{SetColour}{\param{const wxString\& }{colourName}}
206
207Sets the brush colour using a colour name from the colour database.
208
209\func{void}{SetColour}{\param{const unsigned char}{ red}, \param{const unsigned char}{ green}, \param{const unsigned char}{ blue}}
210
211Sets the brush colour using red, green and blue values.
212
213\wxheading{See also}
214
215\helpref{wxBrush::GetColour}{wxbrushgetcolour}
216
217\membersection{wxBrush::SetStipple}\label{wxbrushsetstipple}
218
219\func{void}{SetStipple}{\param{const wxBitmap\&}{ bitmap}}
220
221Sets the stipple bitmap.
222
223\wxheading{Parameters}
224
225\docparam{bitmap}{The bitmap to use for stippling.}
226
227\wxheading{Remarks}
228
6e7b6cc6 229The style will be set to wxSTIPPLE, unless the bitmap has a mask associated
e7240349 230to it, in which case the style will be set to wxSTIPPLE\_MASK\_OPAQUE.
a660d684 231
6e7b6cc6 232If the wxSTIPPLE variant is used, the bitmap will be used to fill out the
e7240349 233area to be drawn. If the wxSTIPPLE\_MASK\_OPAQUE is used, the current
6e7b6cc6
RR
234text foreground and text background determine what colours are used for
235displaying and the bits in the mask (which is a mono-bitmap actually)
236determine where to draw what.
237
238Note that under Windows 95, only 8x8 pixel large stipple bitmaps are
239supported, Windows 98 and NT as well as GTK support arbitrary bitmaps.
a660d684
KB
240
241\wxheading{See also}
242
243\helpref{wxBitmap}{wxbitmap}
244
245\membersection{wxBrush::SetStyle}\label{wxbrushsetstyle}
246
eaaa6a06 247\func{void}{SetStyle}{\param{int}{ style}}
a660d684
KB
248
249Sets the brush style.
250
251\docparam{style}{One of:
252
253\begin{twocollist}\itemsep=0pt
254\twocolitem{{\bf wxTRANSPARENT}}{Transparent (no fill).}
255\twocolitem{{\bf wxSOLID}}{Solid.}
256\twocolitem{{\bf wxBDIAGONAL\_HATCH}}{Backward diagonal hatch.}
257\twocolitem{{\bf wxCROSSDIAG\_HATCH}}{Cross-diagonal hatch.}
258\twocolitem{{\bf wxFDIAGONAL\_HATCH}}{Forward diagonal hatch.}
259\twocolitem{{\bf wxCROSS\_HATCH}}{Cross hatch.}
260\twocolitem{{\bf wxHORIZONTAL\_HATCH}}{Horizontal hatch.}
261\twocolitem{{\bf wxVERTICAL\_HATCH}}{Vertical hatch.}
262\twocolitem{{\bf wxSTIPPLE}}{Stippled using a bitmap.}
e7240349 263\twocolitem{{\bf wxSTIPPLE\_MASK\_OPAQUE}}{Stippled using a bitmap's mask.}
a660d684
KB
264\end{twocollist}}
265
266\wxheading{See also}
267
268\helpref{wxBrush::GetStyle}{wxbrushgetstyle}
269
270\membersection{wxBrush::operator $=$}\label{wxbrushassignment}
271
272\func{wxBrush\&}{operator $=$}{\param{const wxBrush\& }{brush}}
273
274Assignment operator, using reference counting. Returns a reference
275to `this'.
276
277\membersection{wxBrush::operator $==$}\label{wxbrushequals}
278
279\func{bool}{operator $==$}{\param{const wxBrush\& }{brush}}
280
281Equality operator. Two brushes are equal if they contain pointers
282to the same underlying brush data. It does not compare each attribute,
283so two independently-created brushes using the same parameters will
284fail the test.
285
286\membersection{wxBrush::operator $!=$}\label{wxbrushnotequals}
287
288\func{bool}{operator $!=$}{\param{const wxBrush\& }{brush}}
289
290Inequality operator. Two brushes are not equal if they contain pointers
291to different underlying brush data. It does not compare each attribute.
292
293\section{\class{wxBrushList}}\label{wxbrushlist}
294
295A brush list is a list containing all brushes which have been created.
296
297\wxheading{Derived from}
298
299\helpref{wxList}{wxlist}\\
300\helpref{wxObject}{wxobject}
301
954b8ae6
JS
302\wxheading{Include files}
303
304<wx/gdicmn.h>
305
a660d684
KB
306\wxheading{Remarks}
307
308There is only one instance of this class: {\bf wxTheBrushList}. Use
309this object to search for a previously created brush of the desired
310type and create it if not already found. In some windowing systems,
311the brush may be a scarce resource, so it can pay to reuse old
312resources if possible. When an application finishes, all brushes will
313be deleted and their resources freed, eliminating the possibility of
314`memory leaks'. However, it is best not to rely on this automatic
315cleanup because it can lead to double deletion in some circumstances.
316
fc2171bd 317There are two mechanisms in recent versions of wxWidgets which make the
a660d684
KB
318brush list less useful than it once was. Under Windows, scarce resources
319are cleaned up internally if they are not being used. Also, a referencing
320counting mechanism applied to all GDI objects means that some sharing
321of underlying resources is possible. You don't have to keep track of pointers,
322working out when it is safe delete a brush, because the referencing counting does
323it for you. For example, you can set a brush in a device context, and then
324immediately delete the brush you passed, because the brush is `copied'.
325
326So you may find it easier to ignore the brush list, and instead create
327and copy brushes as you see fit. If your Windows resource meter suggests
328your application is using too many resources, you can resort to using
329GDI lists to share objects explicitly.
330
fc2171bd 331The only compelling use for the brush list is for wxWidgets to keep
a660d684 332track of brushes in order to clean them up on exit. It is also kept for
fc2171bd 333backward compatibility with earlier versions of wxWidgets.
a660d684
KB
334
335\wxheading{See also}
336
337\helpref{wxBrush}{wxbrush}
338
339\latexignore{\rtfignore{\wxheading{Members}}}
340
341\membersection{wxBrushList::wxBrushList}\label{wxbrushlistconstr}
342
343\func{void}{wxBrushList}{\void}
344
345Constructor. The application should not construct its own brush list:
346use the object pointer {\bf wxTheBrushList}.
347
348\membersection{wxBrushList::AddBrush}\label{wxbrushlistaddbrush}
349
350\func{void}{AddBrush}{\param{wxBrush *}{brush}}
351
fc2171bd 352Used internally by wxWidgets to add a brush to the list.
a660d684
KB
353
354\membersection{wxBrushList::FindOrCreateBrush}\label{wxbrushlistfindorcreatebrush}
355
eaaa6a06 356\func{wxBrush *}{FindOrCreateBrush}{\param{const wxColour\& }{colour}, \param{int}{ style}}
a660d684
KB
357
358Finds a brush with the specified attributes and returns it, else creates a new brush, adds it
359to the brush list, and returns it.
360
eaaa6a06 361\func{wxBrush *}{FindOrCreateBrush}{\param{const wxString\& }{colourName}, \param{int}{ style}}
a660d684
KB
362
363Finds a brush with the specified attributes and returns it, else creates a new brush, adds it
364to the brush list, and returns it.
365
366Finds a brush of the given specification, or creates one and adds it to the list.
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}{Brush style. See \helpref{wxBrush::SetStyle}{wxbrushsetstyle} for a list of styles.}
375
376\membersection{wxBrushList::RemoveBrush}\label{wxbrushlistremovebrush}
377
378\func{void}{RemoveBrush}{\param{wxBrush *}{brush}}
379
fc2171bd 380Used by wxWidgets to remove a brush from the list.
a660d684
KB
381
382