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