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