]>
Commit | Line | Data |
---|---|---|
23324ae1 FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: pen.h | |
8024723d | 3 | // Purpose: interface of wxPen* classes |
23324ae1 FM |
4 | // Author: wxWidgets team |
5 | // RCS-ID: $Id$ | |
6 | // Licence: wxWindows license | |
7 | ///////////////////////////////////////////////////////////////////////////// | |
8 | ||
8024723d FM |
9 | /** |
10 | The possible styles for a wxPen. | |
11 | */ | |
12 | enum wxPenStyle | |
13 | { | |
1413ac04 FM |
14 | wxPENSTYLE_INVALID = -1, |
15 | ||
8024723d FM |
16 | wxPENSTYLE_SOLID, |
17 | /**< Solid style. */ | |
18 | ||
19 | wxPENSTYLE_DOT, | |
20 | /**< Dotted style. */ | |
21 | ||
22 | wxPENSTYLE_LONG_DASH, | |
23 | /**< Long dashed style. */ | |
24 | ||
25 | wxPENSTYLE_SHORT_DASH, | |
26 | /**< Short dashed style. */ | |
27 | ||
28 | wxPENSTYLE_DOT_DASH, | |
29 | /**< Dot and dash style. */ | |
30 | ||
31 | wxPENSTYLE_USER_DASH, | |
32 | /**< Use the user dashes: see wxPen::SetDashes. */ | |
33 | ||
34 | wxPENSTYLE_TRANSPARENT, | |
35 | /**< No pen is used. */ | |
36 | ||
37 | wxPENSTYLE_STIPPLE_MASK_OPAQUE, | |
38 | /**< @todo WHAT's this? */ | |
39 | ||
40 | wxPENSTYLE_STIPPLE_MASK, | |
41 | /**< @todo WHAT's this? */ | |
42 | ||
43 | wxPENSTYLE_STIPPLE, | |
44 | /**< Use the stipple bitmap. */ | |
45 | ||
46 | wxPENSTYLE_BDIAGONAL_HATCH, | |
47 | /**< Backward diagonal hatch. */ | |
48 | ||
49 | wxPENSTYLE_CROSSDIAG_HATCH, | |
50 | /**< Cross-diagonal hatch. */ | |
51 | ||
52 | wxPENSTYLE_FDIAGONAL_HATCH, | |
53 | /**< Forward diagonal hatch. */ | |
54 | ||
55 | wxPENSTYLE_CROSS_HATCH, | |
56 | /**< Cross hatch. */ | |
57 | ||
58 | wxPENSTYLE_HORIZONTAL_HATCH, | |
59 | /**< Horizontal hatch. */ | |
60 | ||
61 | wxPENSTYLE_VERTICAL_HATCH, | |
62 | /**< Vertical hatch. */ | |
63 | ||
64 | wxPENSTYLE_FIRST_HATCH = wxPENSTYLE_BDIAGONAL_HATCH, | |
1413ac04 | 65 | wxPENSTYLE_LAST_HATCH = wxPENSTYLE_VERTICAL_HATCH |
8024723d FM |
66 | }; |
67 | ||
68 | /** | |
69 | The possible join values of a wxPen. | |
70 | ||
71 | @todo use wxPENJOIN_ prefix | |
72 | */ | |
73 | enum wxPenJoin | |
74 | { | |
75 | wxJOIN_INVALID = -1, | |
76 | ||
77 | wxJOIN_BEVEL = 120, | |
78 | wxJOIN_MITER, | |
79 | wxJOIN_ROUND, | |
80 | }; | |
81 | ||
82 | ||
83 | /** | |
84 | The possible cap values of a wxPen. | |
85 | ||
86 | @todo use wxPENCAP_ prefix | |
87 | */ | |
88 | enum wxPenCap | |
89 | { | |
90 | wxCAP_INVALID = -1, | |
91 | ||
92 | wxCAP_ROUND = 130, | |
93 | wxCAP_PROJECTING, | |
94 | wxCAP_BUTT | |
95 | }; | |
96 | ||
97 | ||
98 | ||
23324ae1 FM |
99 | /** |
100 | @class wxPen | |
101 | @wxheader{pen.h} | |
7c913512 | 102 | |
23324ae1 | 103 | A pen is a drawing tool for drawing outlines. It is used for drawing |
8024723d FM |
104 | lines and painting the outline of rectangles, ellipses, etc. |
105 | It has a colour, a width and a style. | |
106 | ||
107 | On a monochrome display, wxWidgets shows all non-white pens as black. | |
108 | ||
109 | Do not initialize objects on the stack before the program commences, | |
110 | since other required structures may not have been set up yet. | |
111 | Instead, define global pointers to objects and create them in wxApp::OnInit | |
112 | or when required. | |
113 | ||
114 | An application may wish to dynamically create pens with different characteristics, | |
115 | and there is the consequent danger that a large number of duplicate pens will | |
116 | be created. Therefore an application may wish to get a pointer to a pen by using | |
117 | the global list of pens wxThePenList, and calling the member function | |
118 | wxPenList::FindOrCreatePen(). | |
119 | See the entry for wxPenList. | |
120 | ||
121 | This class uses reference counting and copy-on-write internally so that | |
122 | assignments between two instances of this class are very cheap. | |
123 | You can therefore use actual objects instead of pointers without efficiency problems. | |
124 | If an instance of this class is changed it will create its own data internally | |
125 | so that other instances, which previously shared the data using the reference | |
126 | counting, are not affected. | |
7c913512 | 127 | |
23324ae1 FM |
128 | @library{wxcore} |
129 | @category{gdi} | |
7c913512 | 130 | |
23324ae1 | 131 | @stdobjects |
8024723d FM |
132 | ::wxNullPen, ::wxRED_PEN, ::wxCYAN_PEN, ::wxGREEN_PEN, ::wxBLACK_PEN, |
133 | ::wxWHITE_PEN, ::wxTRANSPARENT_PEN, ::wxBLACK_DASHED_PEN, ::wxGREY_PEN, | |
134 | ::wxMEDIUM_GREY_PEN, ::wxLIGHT_GREY_PEN | |
7c913512 | 135 | |
e54c96f1 | 136 | @see wxPenList, wxDC, wxDC::SetPen |
23324ae1 FM |
137 | */ |
138 | class wxPen : public wxGDIObject | |
139 | { | |
140 | public: | |
23324ae1 | 141 | /** |
8024723d FM |
142 | Default constructor. The pen will be uninitialised, and wxPen:IsOk will return @false. |
143 | */ | |
144 | wxPen(); | |
145 | ||
146 | /** | |
147 | Constructs a pen from a colour object, pen width and style. | |
148 | */ | |
1413ac04 | 149 | wxPen(const wxColour& colour, int width = 1, wxPenStyle style = wxPENSTYLE_SOLID); |
8024723d FM |
150 | |
151 | /** | |
152 | Constructs a stippled pen from a stipple bitmap and a width. | |
153 | */ | |
154 | wxPen(const wxBitmap& stipple, int width); | |
155 | ||
156 | /** | |
157 | Copy constructor, uses @ref overview_refcount "reference counting". | |
158 | ||
7c913512 | 159 | @param colour |
4cc4bfaf | 160 | A colour object. |
7c913512 | 161 | @param colourName |
4cc4bfaf | 162 | A colour name. |
7c913512 | 163 | @param width |
4cc4bfaf FM |
164 | Pen width. Under Windows, the pen width cannot be greater than 1 if |
165 | the style is wxDOT, wxLONG_DASH, wxSHORT_DASH, wxDOT_DASH, or wxUSER_DASH. | |
7c913512 | 166 | @param stipple |
4cc4bfaf | 167 | A stipple bitmap. |
7c913512 | 168 | @param pen |
4cc4bfaf | 169 | A pointer or reference to a pen to copy. |
7c913512 | 170 | @param style |
8024723d FM |
171 | The style may be one of the ::wxPenStyle values. |
172 | ||
23324ae1 | 173 | @remarks Different versions of Windows and different versions of other |
4cc4bfaf FM |
174 | platforms support very different subsets of the styles |
175 | above - there is no similarity even between Windows95 | |
176 | and Windows98 - so handle with care. | |
8024723d | 177 | |
4cc4bfaf | 178 | @see SetStyle(), SetColour(), SetWidth(), SetStipple() |
23324ae1 | 179 | */ |
7c913512 | 180 | wxPen(const wxPen& pen); |
23324ae1 FM |
181 | |
182 | /** | |
183 | Destructor. | |
184 | See @ref overview_refcountdestruct "reference-counted object destruction" for | |
185 | more info. | |
8024723d | 186 | |
23324ae1 | 187 | @remarks Although all remaining pens are deleted when the application |
4cc4bfaf FM |
188 | exits, the application should try to clean up all pens |
189 | itself. This is because wxWidgets cannot know if a | |
190 | pointer to the pen object is stored in an application | |
191 | data structure, and there is a risk of double deletion. | |
23324ae1 FM |
192 | */ |
193 | ~wxPen(); | |
194 | ||
195 | /** | |
196 | Returns the pen cap style, which may be one of @b wxCAP_ROUND, @b | |
197 | wxCAP_PROJECTING and | |
198 | @b wxCAP_BUTT. The default is @b wxCAP_ROUND. | |
8024723d | 199 | |
4cc4bfaf | 200 | @see SetCap() |
23324ae1 | 201 | */ |
231b9591 | 202 | virtual wxPenCap GetCap() const; |
23324ae1 FM |
203 | |
204 | /** | |
205 | Returns a reference to the pen colour. | |
8024723d | 206 | |
4cc4bfaf | 207 | @see SetColour() |
23324ae1 | 208 | */ |
231b9591 | 209 | virtual wxColour GetColour() const; |
23324ae1 FM |
210 | |
211 | /** | |
212 | Gets an array of dashes (defined as char in X, DWORD under Windows). | |
4cc4bfaf | 213 | @a dashes is a pointer to the internal array. Do not deallocate or store this |
23324ae1 FM |
214 | pointer. |
215 | The function returns the number of dashes associated with this pen. | |
8024723d | 216 | |
4cc4bfaf | 217 | @see SetDashes() |
23324ae1 | 218 | */ |
231b9591 | 219 | virtual int GetDashes(wxDash** dashes) const; |
23324ae1 FM |
220 | |
221 | /** | |
222 | Returns the pen join style, which may be one of @b wxJOIN_BEVEL, @b | |
223 | wxJOIN_ROUND and | |
224 | @b wxJOIN_MITER. The default is @b wxJOIN_ROUND. | |
8024723d | 225 | |
4cc4bfaf | 226 | @see SetJoin() |
23324ae1 | 227 | */ |
231b9591 | 228 | virtual wxPenJoin GetJoin() const; |
23324ae1 FM |
229 | |
230 | /** | |
231 | Gets a pointer to the stipple bitmap. | |
8024723d | 232 | |
4cc4bfaf | 233 | @see SetStipple() |
23324ae1 | 234 | */ |
231b9591 | 235 | virtual wxBitmap* GetStipple() const; |
23324ae1 FM |
236 | |
237 | /** | |
238 | Returns the pen style. | |
8024723d | 239 | |
4cc4bfaf | 240 | @see wxPen(), SetStyle() |
23324ae1 | 241 | */ |
231b9591 | 242 | virtual wxPenStyle GetStyle() const; |
23324ae1 FM |
243 | |
244 | /** | |
245 | Returns the pen width. | |
8024723d | 246 | |
4cc4bfaf | 247 | @see SetWidth() |
23324ae1 | 248 | */ |
231b9591 | 249 | virtual int GetWidth() const; |
23324ae1 FM |
250 | |
251 | /** | |
252 | Returns @true if the pen is initialised. | |
253 | */ | |
328f5751 | 254 | bool IsOk() const; |
23324ae1 FM |
255 | |
256 | /** | |
257 | Sets the pen cap style, which may be one of @b wxCAP_ROUND, @b wxCAP_PROJECTING | |
258 | and | |
259 | @b wxCAP_BUTT. The default is @b wxCAP_ROUND. | |
8024723d | 260 | |
4cc4bfaf | 261 | @see GetCap() |
23324ae1 | 262 | */ |
231b9591 | 263 | virtual void SetCap(wxPenCap capStyle); |
23324ae1 FM |
264 | |
265 | //@{ | |
266 | /** | |
267 | The pen's colour is changed to the given colour. | |
8024723d | 268 | |
4cc4bfaf | 269 | @see GetColour() |
23324ae1 | 270 | */ |
231b9591 FM |
271 | virtual void SetColour(wxColour& colour); |
272 | virtual void SetColour(unsigned char red, unsigned char green, unsigned char blue); | |
23324ae1 FM |
273 | //@} |
274 | ||
275 | /** | |
276 | Associates an array of pointers to dashes (defined as char in X, DWORD under | |
277 | Windows) | |
278 | with the pen. The array is not deallocated by wxPen, but neither must it be | |
279 | deallocated by the calling application until the pen is deleted or this | |
280 | function is called with a @NULL array. | |
8024723d | 281 | |
4cc4bfaf | 282 | @see GetDashes() |
23324ae1 | 283 | */ |
231b9591 | 284 | virtual void SetDashes(int n, wxDash* dashes); |
23324ae1 FM |
285 | |
286 | /** | |
287 | Sets the pen join style, which may be one of @b wxJOIN_BEVEL, @b wxJOIN_ROUND | |
288 | and | |
289 | @b wxJOIN_MITER. The default is @b wxJOIN_ROUND. | |
8024723d | 290 | |
4cc4bfaf | 291 | @see GetJoin() |
23324ae1 | 292 | */ |
231b9591 | 293 | virtual void SetJoin(wxPenJoin join_style); |
23324ae1 FM |
294 | |
295 | /** | |
296 | Sets the bitmap for stippling. | |
8024723d | 297 | |
4cc4bfaf | 298 | @see GetStipple() |
23324ae1 | 299 | */ |
231b9591 | 300 | virtual void SetStipple(wxBitmap* stipple); |
23324ae1 FM |
301 | |
302 | /** | |
303 | Set the pen style. | |
8024723d | 304 | |
4cc4bfaf | 305 | @see wxPen() |
23324ae1 | 306 | */ |
231b9591 | 307 | virtual void SetStyle(wxPenStyle style); |
23324ae1 FM |
308 | |
309 | /** | |
310 | Sets the pen width. | |
8024723d | 311 | |
4cc4bfaf | 312 | @see GetWidth() |
23324ae1 | 313 | */ |
231b9591 | 314 | virtual void SetWidth(int width); |
23324ae1 FM |
315 | |
316 | /** | |
317 | Inequality operator. | |
318 | See @ref overview_refcountequality "reference-counted object comparison" for | |
319 | more info. | |
320 | */ | |
321 | bool operator !=(const wxPen& pen); | |
322 | ||
323 | /** | |
324 | Assignment operator, using @ref overview_trefcount "reference counting". | |
325 | */ | |
326 | wxPen operator =(const wxPen& pen); | |
327 | ||
328 | /** | |
329 | Equality operator. | |
330 | See @ref overview_refcountequality "reference-counted object comparison" for | |
331 | more info. | |
332 | */ | |
333 | bool operator ==(const wxPen& pen); | |
334 | }; | |
e54c96f1 | 335 | |
e54c96f1 | 336 | /** |
231b9591 | 337 | An empty pen. |
e54c96f1 FM |
338 | */ |
339 | wxPen wxNullPen; | |
340 | ||
e54c96f1 | 341 | /** |
231b9591 | 342 | Red pen. |
e54c96f1 FM |
343 | */ |
344 | wxPen wxRED_PEN; | |
345 | ||
346 | /** | |
231b9591 | 347 | Cyan pen. |
e54c96f1 FM |
348 | */ |
349 | wxPen wxCYAN_PEN; | |
350 | ||
351 | /** | |
231b9591 | 352 | Green pen. |
e54c96f1 FM |
353 | */ |
354 | wxPen wxGREEN_PEN; | |
355 | ||
356 | /** | |
231b9591 | 357 | Black pen. |
e54c96f1 FM |
358 | */ |
359 | wxPen wxBLACK_PEN; | |
360 | ||
361 | /** | |
231b9591 | 362 | White pen. |
e54c96f1 FM |
363 | */ |
364 | wxPen wxWHITE_PEN; | |
365 | ||
366 | /** | |
231b9591 | 367 | Transparent pen. |
e54c96f1 FM |
368 | */ |
369 | wxPen wxTRANSPARENT_PEN; | |
370 | ||
371 | /** | |
231b9591 | 372 | Black dashed pen. |
e54c96f1 FM |
373 | */ |
374 | wxPen wxBLACK_DASHED_PEN; | |
375 | ||
376 | /** | |
231b9591 | 377 | Grey pen. |
e54c96f1 FM |
378 | */ |
379 | wxPen wxGREY_PEN; | |
380 | ||
381 | /** | |
231b9591 | 382 | Medium-grey pen. |
e54c96f1 FM |
383 | */ |
384 | wxPen wxMEDIUM_GREY_PEN; | |
385 | ||
386 | /** | |
231b9591 | 387 | Light-grey pen. |
e54c96f1 FM |
388 | */ |
389 | wxPen wxLIGHT_GREY_PEN; | |
390 | ||
391 | ||
8024723d FM |
392 | |
393 | /** | |
394 | @class wxPenList | |
395 | @wxheader{gdicmn.h} | |
396 | ||
397 | There is only one instance of this class: ::wxThePenList. | |
398 | Use this object to search for a previously created pen of the desired | |
399 | type and create it if not already found. In some windowing systems, | |
400 | the pen may be a scarce resource, so it can pay to reuse old | |
401 | resources if possible. When an application finishes, all pens will | |
402 | be deleted and their resources freed, eliminating the possibility of | |
403 | 'memory leaks'. However, it is best not to rely on this automatic | |
404 | cleanup because it can lead to double deletion in some circumstances. | |
405 | ||
406 | There are two mechanisms in recent versions of wxWidgets which make the | |
407 | pen list less useful than it once was. Under Windows, scarce resources | |
408 | are cleaned up internally if they are not being used. Also, a referencing | |
409 | counting mechanism applied to all GDI objects means that some sharing | |
410 | of underlying resources is possible. You don't have to keep track of pointers, | |
411 | working out when it is safe delete a pen, because the referencing counting does | |
412 | it for you. For example, you can set a pen in a device context, and then | |
413 | immediately delete the pen you passed, because the pen is 'copied'. | |
414 | ||
415 | So you may find it easier to ignore the pen list, and instead create | |
416 | and copy pens as you see fit. If your Windows resource meter suggests | |
417 | your application is using too many resources, you can resort to using | |
418 | GDI lists to share objects explicitly. | |
419 | ||
420 | The only compelling use for the pen list is for wxWidgets to keep | |
421 | track of pens in order to clean them up on exit. It is also kept for | |
422 | backward compatibility with earlier versions of wxWidgets. | |
423 | ||
424 | @library{wxcore} | |
425 | @category{gdi} | |
426 | ||
427 | @stdobjects | |
428 | ::wxThePenList | |
429 | ||
430 | @see wxPen | |
431 | */ | |
432 | class wxPenList | |
433 | { | |
434 | public: | |
435 | /** | |
436 | Constructor. The application should not construct its own pen list: | |
437 | use the object pointer ::wxThePenList. | |
438 | */ | |
439 | wxPenList(); | |
440 | ||
441 | /** | |
442 | Finds a pen with the specified attributes and returns it, else creates a | |
443 | new pen, adds it to the pen list, and returns it. | |
444 | ||
445 | @param colour | |
446 | Colour object. | |
447 | @param width | |
448 | Width of pen. | |
449 | @param style | |
450 | Pen style. See ::wxPenStyle for a list of styles. | |
451 | */ | |
5d2d8f6a VZ |
452 | wxPen* FindOrCreatePen(const wxColour& colour, |
453 | int width = 1, | |
454 | wxPenStyle style = wxPENSTYLE_SOLID); | |
8024723d FM |
455 | }; |
456 | ||
457 | /** | |
458 | The global list of wxPen objects ready to be re-used (for better performances). | |
459 | */ | |
460 | wxPenList* wxThePenList; | |
461 |