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