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