]>
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$ | |
6 | // Licence: wxWindows license | |
7 | ///////////////////////////////////////////////////////////////////////////// | |
8 | ||
8024723d FM |
9 | /** |
10 | The possible brush styles. | |
11 | */ | |
12 | enum wxBrushStyle | |
13 | { | |
14 | wxBRUSHSTYLE_SOLID = wxSOLID, | |
15 | /**< Solid. */ | |
16 | ||
17 | wxBRUSHSTYLE_TRANSPARENT = wxTRANSPARENT, | |
18 | /**< Transparent (no fill). */ | |
19 | ||
20 | wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE = wxSTIPPLE_MASK_OPAQUE, | |
21 | /**< @todo WHAT's THIS?? */ | |
22 | ||
23 | wxBRUSHSTYLE_STIPPLE_MASK = wxSTIPPLE_MASK, | |
24 | /**< @todo WHAT's THIS?? */ | |
25 | ||
26 | wxBRUSHSTYLE_STIPPLE = wxSTIPPLE, | |
27 | /**< Uses a bitmap as a stipple. */ | |
28 | ||
29 | wxBRUSHSTYLE_BDIAGONAL_HATCH = wxBDIAGONAL_HATCH, | |
30 | /**< Backward diagonal hatch. */ | |
31 | ||
32 | wxBRUSHSTYLE_CROSSDIAG_HATCH = wxCROSSDIAG_HATCH, | |
33 | /**< Cross-diagonal hatch. */ | |
34 | ||
35 | wxBRUSHSTYLE_FDIAGONAL_HATCH = wxFDIAGONAL_HATCH, | |
36 | /**< Forward diagonal hatch. */ | |
37 | ||
38 | wxBRUSHSTYLE_CROSS_HATCH = wxCROSS_HATCH, | |
39 | /**< Cross hatch. */ | |
40 | ||
41 | wxBRUSHSTYLE_HORIZONTAL_HATCH = wxHORIZONTAL_HATCH, | |
42 | /**< Horizontal hatch. */ | |
43 | ||
44 | wxBRUSHSTYLE_VERTICAL_HATCH = wxVERTICAL_HATCH, | |
45 | /**< Vertical hatch. */ | |
46 | ||
47 | wxBRUSHSTYLE_FIRST_HATCH = wxFIRST_HATCH, | |
48 | wxBRUSHSTYLE_LAST_HATCH = wxLAST_HATCH, | |
49 | wxBRUSHSTYLE_MAX | |
50 | }; | |
51 | ||
52 | ||
53 | ||
23324ae1 FM |
54 | /** |
55 | @class wxBrush | |
56 | @wxheader{brush.h} | |
7c913512 | 57 | |
23324ae1 | 58 | A brush is a drawing tool for filling in areas. It is used for painting |
8024723d FM |
59 | the background of rectangles, ellipses, etc. It has a colour and a style. |
60 | ||
61 | On a monochrome display, wxWidgets shows all brushes as white unless the | |
62 | colour is really black. | |
63 | ||
64 | Do not initialize objects on the stack before the program commences, since | |
65 | other required structures may not have been set up yet. Instead, define | |
66 | global pointers to objects and create them in wxApp::OnInit or when required. | |
67 | ||
68 | An application may wish to create brushes with different characteristics | |
69 | dynamically, and there is the consequent danger that a large number of | |
70 | duplicate brushes will be created. Therefore an application may wish to | |
71 | get a pointer to a brush by using the global list of brushes ::wxTheBrushList, | |
72 | and calling the member function wxBrushList::FindOrCreateBrush(). | |
73 | ||
74 | This class uses reference counting and copy-on-write internally so that | |
75 | assignments between two instances of this class are very cheap. | |
76 | You can therefore use actual objects instead of pointers without efficiency problems. | |
77 | If an instance of this class is changed it will create its own data internally | |
78 | so that other instances, which previously shared the data using the reference | |
79 | counting, are not affected. | |
7c913512 | 80 | |
23324ae1 FM |
81 | @library{wxcore} |
82 | @category{gdi} | |
7c913512 | 83 | |
23324ae1 | 84 | @stdobjects |
8024723d FM |
85 | ::wxNullBrush, ::wxBLUE_BRUSH, ::wxGREEN_BRUSH, ::wxWHITE_BRUSH, |
86 | ::wxBLACK_BRUSH, ::wxGREY_BRUSH, ::wxMEDIUM_GREY_BRUSH, ::wxLIGHT_GREY_BRUSH, | |
87 | ::wxTRANSPARENT_BRUSH, ::wxCYAN_BRUSH, ::wxRED_BRUSH | |
7c913512 | 88 | |
e54c96f1 | 89 | @see wxBrushList, wxDC, wxDC::SetBrush |
23324ae1 FM |
90 | */ |
91 | class wxBrush : public wxGDIObject | |
92 | { | |
93 | public: | |
23324ae1 | 94 | /** |
8024723d FM |
95 | Default constructor. |
96 | The brush will be uninitialised, and wxBrush:IsOk() will return @false. | |
97 | */ | |
98 | wxBrush(); | |
99 | ||
100 | /** | |
101 | Constructs a brush from a colour object and @a style. | |
102 | ||
7c913512 | 103 | @param colour |
4cc4bfaf | 104 | Colour object. |
8024723d FM |
105 | @param style |
106 | One of the ::wxBrushStyle enumeration values. | |
107 | */ | |
108 | wxBrush(const wxColour& colour, wxBrushStyle style = wxSOLID); | |
109 | ||
110 | /** | |
111 | Constructs a brush from a colour name and @a style. | |
112 | ||
7c913512 | 113 | @param colourName |
4cc4bfaf | 114 | Colour name. The name will be looked up in the colour database. |
7c913512 | 115 | @param style |
8024723d FM |
116 | One of the ::wxBrushStyle enumeration values. |
117 | ||
118 | @see wxColourDatabase | |
119 | */ | |
120 | wxBrush(const wxString& colourName, wxBrushStyle style); | |
121 | ||
122 | /** | |
123 | Constructs a stippled brush using a bitmap. | |
124 | The brush style will be set to wxBRUSHSTYLE_STIPPLE. | |
23324ae1 | 125 | */ |
7c913512 | 126 | wxBrush(const wxBitmap& stippleBitmap); |
8024723d FM |
127 | |
128 | /** | |
129 | Copy constructor, uses @ref overview_refcount "reference counting". | |
130 | */ | |
7c913512 | 131 | wxBrush(const wxBrush& brush); |
23324ae1 FM |
132 | |
133 | /** | |
134 | Destructor. | |
8024723d FM |
135 | |
136 | See @ref overview_refcount_destruct for more info. | |
137 | ||
23324ae1 | 138 | @remarks Although all remaining brushes are deleted when the application |
8024723d FM |
139 | exits, the application should try to clean up all brushes itself. |
140 | This is because wxWidgets cannot know if a pointer to the brush | |
141 | object is stored in an application data structure, and there is | |
142 | a risk of double deletion. | |
23324ae1 FM |
143 | */ |
144 | ~wxBrush(); | |
145 | ||
146 | /** | |
147 | Returns a reference to the brush colour. | |
8024723d | 148 | |
4cc4bfaf | 149 | @see SetColour() |
23324ae1 | 150 | */ |
328f5751 | 151 | wxColour GetColour() const; |
23324ae1 FM |
152 | |
153 | /** | |
8024723d FM |
154 | Gets a pointer to the stipple bitmap. If the brush does not have a wxBRUSHSTYLE_STIPPLE |
155 | style, this bitmap may be non-@NULL but uninitialised (i.e. wxBitmap:IsOk() returns @false). | |
156 | ||
4cc4bfaf | 157 | @see SetStipple() |
23324ae1 | 158 | */ |
328f5751 | 159 | wxBitmap* GetStipple() const; |
23324ae1 FM |
160 | |
161 | /** | |
8024723d FM |
162 | Returns the brush style, one of the ::wxBrushStyle values. |
163 | ||
4cc4bfaf | 164 | @see SetStyle(), SetColour(), SetStipple() |
23324ae1 | 165 | */ |
8024723d | 166 | wxBrushStyle GetStyle() const; |
23324ae1 FM |
167 | |
168 | /** | |
169 | Returns @true if the style of the brush is any of hatched fills. | |
8024723d | 170 | |
4cc4bfaf | 171 | @see GetStyle() |
23324ae1 | 172 | */ |
328f5751 | 173 | bool IsHatch() const; |
23324ae1 FM |
174 | |
175 | /** | |
176 | Returns @true if the brush is initialised. It will return @false if the default | |
177 | constructor has been used (for example, the brush is a member of a class, or | |
178 | @NULL has been assigned to it). | |
179 | */ | |
328f5751 | 180 | bool IsOk() const; |
23324ae1 FM |
181 | |
182 | //@{ | |
183 | /** | |
184 | Sets the brush colour using red, green and blue values. | |
8024723d | 185 | |
4cc4bfaf | 186 | @see GetColour() |
23324ae1 FM |
187 | */ |
188 | void SetColour(wxColour& colour); | |
7c913512 FM |
189 | void SetColour(const wxString& colourName); |
190 | void SetColour(unsigned char red, unsigned char green, | |
191 | unsigned char blue); | |
23324ae1 FM |
192 | //@} |
193 | ||
194 | /** | |
195 | Sets the stipple bitmap. | |
8024723d | 196 | |
7c913512 | 197 | @param bitmap |
4cc4bfaf | 198 | The bitmap to use for stippling. |
8024723d FM |
199 | |
200 | @remarks The style will be set to wxBRUSHSTYLE_STIPPLE, unless the bitmap | |
201 | has a mask associated to it, in which case the style will be set | |
202 | to wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE. | |
203 | ||
4cc4bfaf | 204 | @see wxBitmap |
23324ae1 FM |
205 | */ |
206 | void SetStipple(const wxBitmap& bitmap); | |
207 | ||
208 | /** | |
209 | Sets the brush style. | |
8024723d | 210 | |
7c913512 | 211 | @param style |
8024723d FM |
212 | One of the ::wxBrushStyle values. |
213 | ||
4cc4bfaf | 214 | @see GetStyle() |
23324ae1 | 215 | */ |
8024723d | 216 | void SetStyle(wxBrushStyle style); |
23324ae1 FM |
217 | |
218 | /** | |
219 | Inequality operator. | |
8024723d | 220 | See @ref overview_refcount_equality for more info. |
23324ae1 FM |
221 | */ |
222 | bool operator !=(const wxBrush& brush); | |
223 | ||
224 | /** | |
8024723d | 225 | Assignment operator, using @ref overview_refcount "reference counting". |
23324ae1 FM |
226 | */ |
227 | wxBrush operator =(const wxBrush& brush); | |
228 | ||
229 | /** | |
230 | Equality operator. | |
8024723d | 231 | See @ref overview_refcount_equality for more info. |
23324ae1 FM |
232 | */ |
233 | bool operator ==(const wxBrush& brush); | |
234 | }; | |
e54c96f1 | 235 | |
e54c96f1 | 236 | /** |
8024723d | 237 | An empty brush. |
e54c96f1 FM |
238 | */ |
239 | wxBrush wxNullBrush; | |
240 | ||
241 | /** | |
8024723d | 242 | Blue brush. |
e54c96f1 | 243 | */ |
8024723d | 244 | wxBrush* wxBLUE_BRUSH; |
e54c96f1 FM |
245 | |
246 | /** | |
8024723d | 247 | Green brush. |
e54c96f1 | 248 | */ |
8024723d | 249 | wxBrush* wxGREEN_BRUSH; |
e54c96f1 FM |
250 | |
251 | /** | |
8024723d | 252 | White brush. |
e54c96f1 | 253 | */ |
8024723d | 254 | wxBrush* wxWHITE_BRUSH; |
e54c96f1 FM |
255 | |
256 | /** | |
8024723d | 257 | Black brush. |
e54c96f1 | 258 | */ |
8024723d | 259 | wxBrush* wxBLACK_BRUSH; |
e54c96f1 FM |
260 | |
261 | /** | |
8024723d | 262 | Grey brush. |
e54c96f1 | 263 | */ |
8024723d | 264 | wxBrush* wxGREY_BRUSH; |
e54c96f1 FM |
265 | |
266 | /** | |
8024723d | 267 | Medium grey brush. |
e54c96f1 | 268 | */ |
8024723d | 269 | wxBrush* wxMEDIUM_GREY_BRUSH; |
e54c96f1 FM |
270 | |
271 | /** | |
8024723d | 272 | Light grey brush. |
e54c96f1 | 273 | */ |
8024723d | 274 | wxBrush* wxLIGHT_GREY_BRUSH; |
e54c96f1 FM |
275 | |
276 | /** | |
8024723d | 277 | Transparent brush. |
e54c96f1 | 278 | */ |
8024723d | 279 | wxBrush* wxTRANSPARENT_BRUSH; |
e54c96f1 FM |
280 | |
281 | /** | |
8024723d | 282 | Cyan brush. |
e54c96f1 | 283 | */ |
8024723d | 284 | wxBrush* wxCYAN_BRUSH; |
e54c96f1 FM |
285 | |
286 | /** | |
8024723d | 287 | Red brush. |
e54c96f1 | 288 | */ |
8024723d FM |
289 | wxBrush* wxRED_BRUSH; |
290 | ||
291 | ||
e54c96f1 FM |
292 | |
293 | /** | |
8024723d FM |
294 | @class wxBrushList |
295 | @wxheader{gdicmn.h} | |
296 | ||
297 | A brush list is a list containing all brushes which have been created. | |
298 | ||
299 | @library{wxcore} | |
300 | @category{gdi} | |
301 | ||
302 | @see wxBrush | |
e54c96f1 | 303 | */ |
8024723d FM |
304 | class wxBrushList : public wxList |
305 | { | |
306 | public: | |
307 | /** | |
308 | Constructor. The application should not construct its own brush list: | |
309 | use the object pointer ::wxTheBrushList. | |
310 | */ | |
311 | wxBrushList(); | |
e54c96f1 | 312 | |
8024723d FM |
313 | /** |
314 | Finds a brush with the specified attributes and returns it, else creates a new | |
315 | brush, adds it to the brush list, and returns it. | |
e54c96f1 | 316 | |
8024723d FM |
317 | @param colour |
318 | Colour object. | |
319 | @param style | |
320 | Brush style. See ::wxBrushStyle for a list of styles. | |
321 | */ | |
322 | wxBrush* FindOrCreateBrush(const wxColour& colour, | |
323 | wxBrushStyle style = wxBRUSHSTYLE_SOLID); | |
324 | }; | |
325 | ||
326 | /** | |
327 | The global wxBrushList instance. | |
328 | */ | |
329 | wxBrushList* wxTheBrushList; |