]>
Commit | Line | Data |
---|---|---|
23324ae1 FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: brush.h | |
e54c96f1 | 3 | // Purpose: interface of wxBrush |
23324ae1 FM |
4 | // Author: wxWidgets team |
5 | // RCS-ID: $Id$ | |
526954c5 | 6 | // Licence: wxWindows licence |
23324ae1 FM |
7 | ///////////////////////////////////////////////////////////////////////////// |
8 | ||
8024723d FM |
9 | /** |
10 | The possible brush styles. | |
11 | */ | |
12 | enum wxBrushStyle | |
13 | { | |
1413ac04 FM |
14 | wxBRUSHSTYLE_INVALID = -1, |
15 | ||
8024723d FM |
16 | wxBRUSHSTYLE_SOLID = wxSOLID, |
17 | /**< Solid. */ | |
18 | ||
19 | wxBRUSHSTYLE_TRANSPARENT = wxTRANSPARENT, | |
20 | /**< Transparent (no fill). */ | |
21 | ||
22 | wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE = wxSTIPPLE_MASK_OPAQUE, | |
939dafa6 FM |
23 | /**< Uses a bitmap as a stipple; the mask is used for blitting monochrome |
24 | using text foreground and background colors. */ | |
8024723d FM |
25 | |
26 | wxBRUSHSTYLE_STIPPLE_MASK = wxSTIPPLE_MASK, | |
939dafa6 FM |
27 | /**< Uses a bitmap as a stipple; mask is used for masking areas in the |
28 | stipple bitmap. */ | |
8024723d FM |
29 | |
30 | wxBRUSHSTYLE_STIPPLE = wxSTIPPLE, | |
31 | /**< Uses a bitmap as a stipple. */ | |
32 | ||
c17eafaa | 33 | wxBRUSHSTYLE_BDIAGONAL_HATCH, |
8024723d FM |
34 | /**< Backward diagonal hatch. */ |
35 | ||
c17eafaa | 36 | wxBRUSHSTYLE_CROSSDIAG_HATCH, |
8024723d FM |
37 | /**< Cross-diagonal hatch. */ |
38 | ||
c17eafaa | 39 | wxBRUSHSTYLE_FDIAGONAL_HATCH, |
8024723d FM |
40 | /**< Forward diagonal hatch. */ |
41 | ||
c17eafaa | 42 | wxBRUSHSTYLE_CROSS_HATCH, |
8024723d FM |
43 | /**< Cross hatch. */ |
44 | ||
c17eafaa | 45 | wxBRUSHSTYLE_HORIZONTAL_HATCH, |
8024723d FM |
46 | /**< Horizontal hatch. */ |
47 | ||
c17eafaa | 48 | wxBRUSHSTYLE_VERTICAL_HATCH, |
8024723d FM |
49 | /**< Vertical hatch. */ |
50 | ||
c17eafaa VZ |
51 | wxBRUSHSTYLE_FIRST_HATCH, |
52 | /**< First of the hatch styles (inclusive). */ | |
53 | ||
54 | wxBRUSHSTYLE_LAST_HATCH | |
55 | /**< Last of the hatch styles (inclusive). */ | |
8024723d FM |
56 | }; |
57 | ||
58 | ||
59 | ||
23324ae1 FM |
60 | /** |
61 | @class wxBrush | |
7c913512 | 62 | |
23324ae1 | 63 | A brush is a drawing tool for filling in areas. It is used for painting |
8024723d FM |
64 | the background of rectangles, ellipses, etc. It has a colour and a style. |
65 | ||
66 | On a monochrome display, wxWidgets shows all brushes as white unless the | |
67 | colour is really black. | |
68 | ||
69 | Do not initialize objects on the stack before the program commences, since | |
70 | other required structures may not have been set up yet. Instead, define | |
71 | global pointers to objects and create them in wxApp::OnInit or when required. | |
72 | ||
73 | An application may wish to create brushes with different characteristics | |
74 | dynamically, and there is the consequent danger that a large number of | |
75 | duplicate brushes will be created. Therefore an application may wish to | |
76 | get a pointer to a brush by using the global list of brushes ::wxTheBrushList, | |
77 | and calling the member function wxBrushList::FindOrCreateBrush(). | |
78 | ||
79 | This class uses reference counting and copy-on-write internally so that | |
80 | assignments between two instances of this class are very cheap. | |
81 | You can therefore use actual objects instead of pointers without efficiency problems. | |
82 | If an instance of this class is changed it will create its own data internally | |
83 | so that other instances, which previously shared the data using the reference | |
84 | counting, are not affected. | |
7c913512 | 85 | |
23324ae1 FM |
86 | @library{wxcore} |
87 | @category{gdi} | |
7c913512 | 88 | |
23324ae1 | 89 | @stdobjects |
d8184587 FM |
90 | @li ::wxNullBrush |
91 | @li ::wxBLACK_BRUSH | |
92 | @li ::wxBLUE_BRUSH | |
93 | @li ::wxCYAN_BRUSH | |
94 | @li ::wxGREEN_BRUSH | |
86028025 | 95 | @li ::wxYELLOW_BRUSH |
d8184587 FM |
96 | @li ::wxGREY_BRUSH |
97 | @li ::wxLIGHT_GREY_BRUSH | |
98 | @li ::wxMEDIUM_GREY_BRUSH | |
99 | @li ::wxRED_BRUSH | |
100 | @li ::wxTRANSPARENT_BRUSH | |
101 | @li ::wxWHITE_BRUSH | |
7c913512 | 102 | |
e54c96f1 | 103 | @see wxBrushList, wxDC, wxDC::SetBrush |
23324ae1 FM |
104 | */ |
105 | class wxBrush : public wxGDIObject | |
106 | { | |
107 | public: | |
23324ae1 | 108 | /** |
8024723d FM |
109 | Default constructor. |
110 | The brush will be uninitialised, and wxBrush:IsOk() will return @false. | |
111 | */ | |
112 | wxBrush(); | |
113 | ||
114 | /** | |
115 | Constructs a brush from a colour object and @a style. | |
116 | ||
7c913512 | 117 | @param colour |
4cc4bfaf | 118 | Colour object. |
8024723d FM |
119 | @param style |
120 | One of the ::wxBrushStyle enumeration values. | |
121 | */ | |
1413ac04 | 122 | wxBrush(const wxColour& colour, wxBrushStyle style = wxBRUSHSTYLE_SOLID); |
8024723d FM |
123 | |
124 | /** | |
125 | Constructs a stippled brush using a bitmap. | |
939dafa6 | 126 | The brush style will be set to @c wxBRUSHSTYLE_STIPPLE. |
23324ae1 | 127 | */ |
7c913512 | 128 | wxBrush(const wxBitmap& stippleBitmap); |
8024723d FM |
129 | |
130 | /** | |
131 | Copy constructor, uses @ref overview_refcount "reference counting". | |
132 | */ | |
7c913512 | 133 | wxBrush(const wxBrush& brush); |
23324ae1 FM |
134 | |
135 | /** | |
136 | Destructor. | |
8024723d FM |
137 | |
138 | See @ref overview_refcount_destruct for more info. | |
139 | ||
23324ae1 | 140 | @remarks Although all remaining brushes are deleted when the application |
8024723d FM |
141 | exits, the application should try to clean up all brushes itself. |
142 | This is because wxWidgets cannot know if a pointer to the brush | |
143 | object is stored in an application data structure, and there is | |
144 | a risk of double deletion. | |
23324ae1 | 145 | */ |
d2aa927a | 146 | virtual ~wxBrush(); |
23324ae1 FM |
147 | |
148 | /** | |
149 | Returns a reference to the brush colour. | |
8024723d | 150 | |
4cc4bfaf | 151 | @see SetColour() |
23324ae1 | 152 | */ |
231b9591 | 153 | virtual wxColour GetColour() const; |
23324ae1 FM |
154 | |
155 | /** | |
939dafa6 | 156 | Gets a pointer to the stipple bitmap. If the brush does not have a @c wxBRUSHSTYLE_STIPPLE |
8024723d FM |
157 | style, this bitmap may be non-@NULL but uninitialised (i.e. wxBitmap:IsOk() returns @false). |
158 | ||
4cc4bfaf | 159 | @see SetStipple() |
23324ae1 | 160 | */ |
231b9591 | 161 | virtual wxBitmap* GetStipple() const; |
23324ae1 FM |
162 | |
163 | /** | |
8024723d FM |
164 | Returns the brush style, one of the ::wxBrushStyle values. |
165 | ||
4cc4bfaf | 166 | @see SetStyle(), SetColour(), SetStipple() |
23324ae1 | 167 | */ |
1413ac04 | 168 | virtual wxBrushStyle GetStyle() const; |
23324ae1 FM |
169 | |
170 | /** | |
171 | Returns @true if the style of the brush is any of hatched fills. | |
8024723d | 172 | |
4cc4bfaf | 173 | @see GetStyle() |
23324ae1 | 174 | */ |
d2aa927a | 175 | virtual bool IsHatch() const; |
23324ae1 FM |
176 | |
177 | /** | |
e6777e65 VZ |
178 | Returns @true if the brush is initialised. |
179 | ||
180 | Notice that an uninitialized brush object can't be queried for any | |
181 | brush properties and all calls to the accessor methods on it will | |
182 | result in an assert failure. | |
23324ae1 | 183 | */ |
0004982c | 184 | virtual bool IsOk() const; |
23324ae1 | 185 | |
e6777e65 VZ |
186 | /** |
187 | Returns @true if the brush is a valid non-transparent brush. | |
188 | ||
189 | This method returns @true if the brush object is initialized and has a | |
190 | non-transparent style. Notice that this should be used instead of | |
191 | simply testing whether GetStyle() returns a style different from | |
192 | wxBRUSHSTYLE_TRANSPARENT if the brush may be invalid as GetStyle() | |
193 | would assert in this case. | |
194 | ||
195 | @see IsTransparent() | |
196 | ||
197 | @since 2.9.2. | |
198 | */ | |
199 | bool IsNonTransparent() const; | |
200 | ||
201 | /** | |
202 | Returns @true if the brush is transparent. | |
203 | ||
204 | A transparent brush is simply a brush with wxBRUSHSTYLE_TRANSPARENT | |
205 | style. | |
206 | ||
d13b34d3 | 207 | Notice that this function works even for non-initialized brushes (for |
e6777e65 VZ |
208 | which it returns @false) unlike tests of the form <code>GetStyle() == |
209 | wxBRUSHSTYLE_TRANSPARENT</code> which would assert if the brush is | |
210 | invalid. | |
211 | ||
212 | @see IsNonTransparent() | |
213 | ||
214 | @since 2.9.2. | |
215 | */ | |
216 | bool IsTransparent() const; | |
217 | ||
218 | ||
23324ae1 FM |
219 | //@{ |
220 | /** | |
221 | Sets the brush colour using red, green and blue values. | |
8024723d | 222 | |
4cc4bfaf | 223 | @see GetColour() |
23324ae1 | 224 | */ |
882678eb | 225 | virtual void SetColour(const wxColour& colour); |
231b9591 | 226 | virtual void SetColour(unsigned char red, unsigned char green, unsigned char blue); |
23324ae1 FM |
227 | //@} |
228 | ||
229 | /** | |
230 | Sets the stipple bitmap. | |
8024723d | 231 | |
7c913512 | 232 | @param bitmap |
4cc4bfaf | 233 | The bitmap to use for stippling. |
8024723d | 234 | |
939dafa6 | 235 | @remarks The style will be set to @c wxBRUSHSTYLE_STIPPLE, unless the bitmap |
8024723d | 236 | has a mask associated to it, in which case the style will be set |
939dafa6 | 237 | to @c wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE. |
8024723d | 238 | |
4cc4bfaf | 239 | @see wxBitmap |
23324ae1 | 240 | */ |
231b9591 | 241 | virtual void SetStipple(const wxBitmap& bitmap); |
23324ae1 FM |
242 | |
243 | /** | |
244 | Sets the brush style. | |
8024723d | 245 | |
7c913512 | 246 | @param style |
8024723d FM |
247 | One of the ::wxBrushStyle values. |
248 | ||
4cc4bfaf | 249 | @see GetStyle() |
23324ae1 | 250 | */ |
231b9591 | 251 | virtual void SetStyle(wxBrushStyle style); |
23324ae1 FM |
252 | |
253 | /** | |
254 | Inequality operator. | |
8024723d | 255 | See @ref overview_refcount_equality for more info. |
23324ae1 | 256 | */ |
1413ac04 | 257 | bool operator !=(const wxBrush& brush) const; |
23324ae1 FM |
258 | |
259 | /** | |
260 | Equality operator. | |
8024723d | 261 | See @ref overview_refcount_equality for more info. |
23324ae1 | 262 | */ |
1413ac04 | 263 | bool operator ==(const wxBrush& brush) const; |
23324ae1 | 264 | }; |
e54c96f1 | 265 | |
e54c96f1 | 266 | /** |
8024723d | 267 | An empty brush. |
939dafa6 | 268 | wxBrush::IsOk() always returns @false for this object. |
e54c96f1 FM |
269 | */ |
270 | wxBrush wxNullBrush; | |
271 | ||
272 | /** | |
8024723d | 273 | Blue brush. |
939dafa6 FM |
274 | Except for the color it has all standard attributes |
275 | (@c wxBRUSHSTYLE_SOLID, no stipple bitmap, etc...). | |
e54c96f1 | 276 | */ |
8024723d | 277 | wxBrush* wxBLUE_BRUSH; |
e54c96f1 FM |
278 | |
279 | /** | |
8024723d | 280 | Green brush. |
939dafa6 FM |
281 | Except for the color it has all standard attributes |
282 | (@c wxBRUSHSTYLE_SOLID, no stipple bitmap, etc...). | |
e54c96f1 | 283 | */ |
8024723d | 284 | wxBrush* wxGREEN_BRUSH; |
e54c96f1 | 285 | |
86028025 FM |
286 | /** |
287 | Yellow brush. | |
288 | Except for the color it has all standard attributes | |
289 | (@c wxBRUSHSTYLE_SOLID, no stipple bitmap, etc...). | |
290 | */ | |
291 | wxBrush* wxYELLOW_BRUSH; | |
292 | ||
e54c96f1 | 293 | /** |
8024723d | 294 | White brush. |
939dafa6 FM |
295 | Except for the color it has all standard attributes |
296 | (@c wxBRUSHSTYLE_SOLID, no stipple bitmap, etc...). | |
e54c96f1 | 297 | */ |
8024723d | 298 | wxBrush* wxWHITE_BRUSH; |
e54c96f1 FM |
299 | |
300 | /** | |
8024723d | 301 | Black brush. |
939dafa6 FM |
302 | Except for the color it has all standard attributes |
303 | (@c wxBRUSHSTYLE_SOLID, no stipple bitmap, etc...). | |
e54c96f1 | 304 | */ |
8024723d | 305 | wxBrush* wxBLACK_BRUSH; |
e54c96f1 FM |
306 | |
307 | /** | |
8024723d | 308 | Grey brush. |
939dafa6 FM |
309 | Except for the color it has all standard attributes |
310 | (@c wxBRUSHSTYLE_SOLID, no stipple bitmap, etc...). | |
e54c96f1 | 311 | */ |
8024723d | 312 | wxBrush* wxGREY_BRUSH; |
e54c96f1 FM |
313 | |
314 | /** | |
8024723d | 315 | Medium grey brush. |
939dafa6 FM |
316 | Except for the color it has all standard attributes |
317 | (@c wxBRUSHSTYLE_SOLID, no stipple bitmap, etc...). | |
e54c96f1 | 318 | */ |
8024723d | 319 | wxBrush* wxMEDIUM_GREY_BRUSH; |
e54c96f1 FM |
320 | |
321 | /** | |
8024723d | 322 | Light grey brush. |
939dafa6 FM |
323 | Except for the color it has all standard attributes |
324 | (@c wxBRUSHSTYLE_SOLID, no stipple bitmap, etc...). | |
e54c96f1 | 325 | */ |
8024723d | 326 | wxBrush* wxLIGHT_GREY_BRUSH; |
e54c96f1 FM |
327 | |
328 | /** | |
8024723d | 329 | Transparent brush. |
939dafa6 FM |
330 | Except for the color it has all standard attributes |
331 | (@c wxBRUSHSTYLE_SOLID, no stipple bitmap, etc...). | |
e54c96f1 | 332 | */ |
8024723d | 333 | wxBrush* wxTRANSPARENT_BRUSH; |
e54c96f1 FM |
334 | |
335 | /** | |
8024723d | 336 | Cyan brush. |
939dafa6 FM |
337 | Except for the color it has all standard attributes |
338 | (@c wxBRUSHSTYLE_SOLID, no stipple bitmap, etc...). | |
e54c96f1 | 339 | */ |
8024723d | 340 | wxBrush* wxCYAN_BRUSH; |
e54c96f1 FM |
341 | |
342 | /** | |
8024723d | 343 | Red brush. |
939dafa6 FM |
344 | Except for the color it has all standard attributes |
345 | (@c wxBRUSHSTYLE_SOLID, no stipple bitmap, etc...). | |
e54c96f1 | 346 | */ |
8024723d FM |
347 | wxBrush* wxRED_BRUSH; |
348 | ||
349 | ||
e54c96f1 FM |
350 | |
351 | /** | |
8024723d | 352 | @class wxBrushList |
8024723d FM |
353 | |
354 | A brush list is a list containing all brushes which have been created. | |
355 | ||
1413ac04 FM |
356 | The application should not construct its own brush list: it should use the |
357 | object pointer ::wxTheBrushList. | |
358 | ||
8024723d FM |
359 | @library{wxcore} |
360 | @category{gdi} | |
361 | ||
362 | @see wxBrush | |
e54c96f1 | 363 | */ |
8024723d FM |
364 | class wxBrushList : public wxList |
365 | { | |
366 | public: | |
8024723d FM |
367 | /** |
368 | Finds a brush with the specified attributes and returns it, else creates a new | |
369 | brush, adds it to the brush list, and returns it. | |
e54c96f1 | 370 | |
8024723d FM |
371 | @param colour |
372 | Colour object. | |
373 | @param style | |
374 | Brush style. See ::wxBrushStyle for a list of styles. | |
375 | */ | |
376 | wxBrush* FindOrCreateBrush(const wxColour& colour, | |
377 | wxBrushStyle style = wxBRUSHSTYLE_SOLID); | |
378 | }; | |
379 | ||
380 | /** | |
381 | The global wxBrushList instance. | |
382 | */ | |
383 | wxBrushList* wxTheBrushList; |