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