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