]>
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 | |
7c913512 | 101 | |
23324ae1 | 102 | A pen is a drawing tool for drawing outlines. It is used for drawing |
8024723d FM |
103 | lines and painting the outline of rectangles, ellipses, etc. |
104 | It has a colour, a width and a style. | |
105 | ||
4d7b68d1 | 106 | @note On a monochrome display, wxWidgets shows all non-white pens as black. |
8024723d FM |
107 | |
108 | Do not initialize objects on the stack before the program commences, | |
109 | since other required structures may not have been set up yet. | |
74bf4e64 | 110 | Instead, define global pointers to objects and create them in wxApp::OnInit() |
8024723d FM |
111 | or when required. |
112 | ||
113 | An application may wish to dynamically create pens with different characteristics, | |
114 | and there is the consequent danger that a large number of duplicate pens will | |
115 | be created. Therefore an application may wish to get a pointer to a pen by using | |
74bf4e64 | 116 | the global list of pens ::wxThePenList, and calling the member function |
8024723d | 117 | wxPenList::FindOrCreatePen(). |
4d7b68d1 | 118 | See wxPenList for more info. |
8024723d | 119 | |
74bf4e64 FM |
120 | This class uses @ref overview_refcount "reference counting and copy-on-write" internally |
121 | so that assignments between two instances of this class are very cheap. | |
8024723d FM |
122 | You can therefore use actual objects instead of pointers without efficiency problems. |
123 | If an instance of this class is changed it will create its own data internally | |
124 | so that other instances, which previously shared the data using the reference | |
125 | counting, are not affected. | |
7c913512 | 126 | |
23324ae1 FM |
127 | @library{wxcore} |
128 | @category{gdi} | |
7c913512 | 129 | |
23324ae1 | 130 | @stdobjects |
b1b95a65 | 131 | @li ::wxNullPen |
d8184587 FM |
132 | @li ::wxBLACK_DASHED_PEN |
133 | @li ::wxBLACK_PEN | |
134 | @li ::wxBLUE_PEN | |
b1b95a65 FM |
135 | @li ::wxCYAN_PEN |
136 | @li ::wxGREEN_PEN | |
b1b95a65 | 137 | @li ::wxGREY_PEN |
b1b95a65 | 138 | @li ::wxLIGHT_GREY_PEN |
d8184587 FM |
139 | @li ::wxMEDIUM_GREY_PEN |
140 | @li ::wxRED_PEN | |
141 | @li ::wxTRANSPARENT_PEN | |
142 | @li ::wxWHITE_PEN | |
7c913512 | 143 | |
74bf4e64 | 144 | @see wxPenList, wxDC, wxDC::SetPen() |
23324ae1 FM |
145 | */ |
146 | class wxPen : public wxGDIObject | |
147 | { | |
148 | public: | |
23324ae1 | 149 | /** |
74bf4e64 | 150 | Default constructor. The pen will be uninitialised, and IsOk() will return @false. |
8024723d FM |
151 | */ |
152 | wxPen(); | |
153 | ||
154 | /** | |
155 | Constructs a pen from a colour object, pen width and style. | |
8024723d | 156 | |
7c913512 | 157 | @param colour |
4cc4bfaf | 158 | A colour object. |
7c913512 | 159 | @param width |
4cc4bfaf | 160 | Pen width. Under Windows, the pen width cannot be greater than 1 if |
939dafa6 FM |
161 | the style is @c wxPENSTYLE_DOT, @c wxPENSTYLE_LONG_DASH, @c wxPENSTYLE_SHORT_DASH, |
162 | @c wxPENSTYLE_DOT_DASH, or @c wxPENSTYLE_USER_DASH. | |
7c913512 | 163 | @param style |
8024723d FM |
164 | The style may be one of the ::wxPenStyle values. |
165 | ||
23324ae1 | 166 | @remarks Different versions of Windows and different versions of other |
bb69632a FM |
167 | platforms support very different subsets of the styles above |
168 | - there is no similarity even between Windows95 and Windows98 - | |
169 | so handle with care. | |
8024723d | 170 | |
74bf4e64 FM |
171 | @see SetStyle(), SetColour(), SetWidth() |
172 | */ | |
173 | wxPen(const wxColour& colour, int width = 1, wxPenStyle style = wxPENSTYLE_SOLID); | |
174 | ||
175 | /** | |
176 | Constructs a stippled pen from a stipple bitmap and a width. | |
177 | ||
178 | @param width | |
179 | Pen width. Under Windows, the pen width cannot be greater than 1 if | |
939dafa6 FM |
180 | the style is @c wxPENSTYLE_DOT, @c wxPENSTYLE_LONG_DASH, @c wxPENSTYLE_SHORT_DASH, |
181 | @c wxPENSTYLE_DOT_DASH, or @c wxPENSTYLE_USER_DASH. | |
74bf4e64 FM |
182 | @param stipple |
183 | A stipple bitmap. | |
184 | ||
0f6c9085 | 185 | @onlyfor{wxmsw,wxosx} |
0a98423e | 186 | |
74bf4e64 FM |
187 | @see SetWidth(), SetStipple() |
188 | */ | |
189 | wxPen(const wxBitmap& stipple, int width); | |
190 | ||
191 | /** | |
192 | Copy constructor, uses @ref overview_refcount. | |
193 | ||
194 | @param pen | |
195 | A pointer or reference to a pen to copy. | |
23324ae1 | 196 | */ |
7c913512 | 197 | wxPen(const wxPen& pen); |
23324ae1 FM |
198 | |
199 | /** | |
200 | Destructor. | |
74bf4e64 | 201 | @see @ref overview_refcount_destruct "reference-counted object destruction" |
8024723d | 202 | |
23324ae1 | 203 | @remarks Although all remaining pens are deleted when the application |
4cc4bfaf FM |
204 | exits, the application should try to clean up all pens |
205 | itself. This is because wxWidgets cannot know if a | |
206 | pointer to the pen object is stored in an application | |
207 | data structure, and there is a risk of double deletion. | |
23324ae1 | 208 | */ |
adaaa686 | 209 | virtual ~wxPen(); |
23324ae1 FM |
210 | |
211 | /** | |
939dafa6 FM |
212 | Returns the pen cap style, which may be one of @c wxCAP_ROUND, |
213 | @c wxCAP_PROJECTING and @c wxCAP_BUTT. | |
74bf4e64 FM |
214 | |
215 | The default is @c wxCAP_ROUND. | |
8024723d | 216 | |
4cc4bfaf | 217 | @see SetCap() |
23324ae1 | 218 | */ |
231b9591 | 219 | virtual wxPenCap GetCap() const; |
23324ae1 FM |
220 | |
221 | /** | |
222 | Returns a reference to the pen colour. | |
8024723d | 223 | |
4cc4bfaf | 224 | @see SetColour() |
23324ae1 | 225 | */ |
231b9591 | 226 | virtual wxColour GetColour() const; |
23324ae1 FM |
227 | |
228 | /** | |
939dafa6 | 229 | Gets an array of dashes (defined as @c char in X, @c DWORD under Windows). |
4cc4bfaf | 230 | @a dashes is a pointer to the internal array. Do not deallocate or store this |
23324ae1 | 231 | pointer. |
74bf4e64 FM |
232 | |
233 | @return The number of dashes associated with this pen. | |
8024723d | 234 | |
4cc4bfaf | 235 | @see SetDashes() |
23324ae1 | 236 | */ |
231b9591 | 237 | virtual int GetDashes(wxDash** dashes) const; |
23324ae1 FM |
238 | |
239 | /** | |
939dafa6 FM |
240 | Returns the pen join style, which may be one of @c wxJOIN_BEVEL, |
241 | @c wxJOIN_ROUND and @c wxJOIN_MITER. | |
74bf4e64 FM |
242 | |
243 | The default is @c wxJOIN_ROUND. | |
8024723d | 244 | |
4cc4bfaf | 245 | @see SetJoin() |
23324ae1 | 246 | */ |
231b9591 | 247 | virtual wxPenJoin GetJoin() const; |
23324ae1 FM |
248 | |
249 | /** | |
250 | Gets a pointer to the stipple bitmap. | |
8024723d | 251 | |
4cc4bfaf | 252 | @see SetStipple() |
23324ae1 | 253 | */ |
231b9591 | 254 | virtual wxBitmap* GetStipple() const; |
23324ae1 FM |
255 | |
256 | /** | |
257 | Returns the pen style. | |
8024723d | 258 | |
4cc4bfaf | 259 | @see wxPen(), SetStyle() |
23324ae1 | 260 | */ |
231b9591 | 261 | virtual wxPenStyle GetStyle() const; |
23324ae1 FM |
262 | |
263 | /** | |
264 | Returns the pen width. | |
8024723d | 265 | |
4cc4bfaf | 266 | @see SetWidth() |
23324ae1 | 267 | */ |
231b9591 | 268 | virtual int GetWidth() const; |
23324ae1 FM |
269 | |
270 | /** | |
271 | Returns @true if the pen is initialised. | |
272 | */ | |
0004982c | 273 | virtual bool IsOk() const; |
23324ae1 FM |
274 | |
275 | /** | |
74bf4e64 FM |
276 | Sets the pen cap style, which may be one of @c wxCAP_ROUND, @c wxCAP_PROJECTING |
277 | and @c wxCAP_BUTT. The default is @c wxCAP_ROUND. | |
8024723d | 278 | |
4cc4bfaf | 279 | @see GetCap() |
23324ae1 | 280 | */ |
231b9591 | 281 | virtual void SetCap(wxPenCap capStyle); |
23324ae1 FM |
282 | |
283 | //@{ | |
284 | /** | |
285 | The pen's colour is changed to the given colour. | |
8024723d | 286 | |
4cc4bfaf | 287 | @see GetColour() |
23324ae1 | 288 | */ |
231b9591 FM |
289 | virtual void SetColour(wxColour& colour); |
290 | virtual void SetColour(unsigned char red, unsigned char green, unsigned char blue); | |
23324ae1 FM |
291 | //@} |
292 | ||
293 | /** | |
939dafa6 | 294 | Associates an array of pointers to dashes (defined as @c char in X, @c DWORD under |
74bf4e64 FM |
295 | Windows) with the pen. |
296 | ||
297 | The array is not deallocated by wxPen, but neither must it be deallocated by | |
298 | the calling application until the pen is deleted or this function is called | |
299 | with a @NULL array. | |
8024723d | 300 | |
4cc4bfaf | 301 | @see GetDashes() |
23324ae1 | 302 | */ |
43c48e1e | 303 | virtual void SetDashes(int n, const wxDash* dash); |
23324ae1 FM |
304 | |
305 | /** | |
74bf4e64 FM |
306 | Sets the pen join style, which may be one of @c wxJOIN_BEVEL, @c wxJOIN_ROUND |
307 | and @c wxJOIN_MITER. | |
308 | ||
309 | The default is @c wxJOIN_ROUND. | |
8024723d | 310 | |
4cc4bfaf | 311 | @see GetJoin() |
23324ae1 | 312 | */ |
231b9591 | 313 | virtual void SetJoin(wxPenJoin join_style); |
23324ae1 FM |
314 | |
315 | /** | |
316 | Sets the bitmap for stippling. | |
8024723d | 317 | |
4cc4bfaf | 318 | @see GetStipple() |
23324ae1 | 319 | */ |
43c48e1e | 320 | virtual void SetStipple(const wxBitmap& stipple); |
23324ae1 FM |
321 | |
322 | /** | |
323 | Set the pen style. | |
8024723d | 324 | |
4cc4bfaf | 325 | @see wxPen() |
23324ae1 | 326 | */ |
231b9591 | 327 | virtual void SetStyle(wxPenStyle style); |
23324ae1 FM |
328 | |
329 | /** | |
330 | Sets the pen width. | |
8024723d | 331 | |
4cc4bfaf | 332 | @see GetWidth() |
23324ae1 | 333 | */ |
231b9591 | 334 | virtual void SetWidth(int width); |
23324ae1 FM |
335 | |
336 | /** | |
337 | Inequality operator. | |
4d7b68d1 | 338 | |
74bf4e64 | 339 | See @ref overview_refcount_equality "reference-counted object comparison" for |
23324ae1 FM |
340 | more info. |
341 | */ | |
fadc2df6 | 342 | bool operator!=(const wxPen& pen) const; |
23324ae1 FM |
343 | |
344 | /** | |
74bf4e64 | 345 | Assignment operator, using @ref overview_refcount. |
23324ae1 | 346 | */ |
43c48e1e | 347 | wxPen& operator=(const wxPen& pen); |
23324ae1 FM |
348 | |
349 | /** | |
350 | Equality operator. | |
4d7b68d1 | 351 | |
74bf4e64 | 352 | See @ref overview_refcount_equality "reference-counted object comparison" for |
23324ae1 FM |
353 | more info. |
354 | */ | |
fadc2df6 | 355 | bool operator==(const wxPen& pen) const; |
23324ae1 | 356 | }; |
e54c96f1 | 357 | |
e54c96f1 | 358 | /** |
231b9591 | 359 | An empty pen. |
939dafa6 | 360 | wxPen::IsOk() always returns @false for this object. |
e54c96f1 FM |
361 | */ |
362 | wxPen wxNullPen; | |
363 | ||
e54c96f1 | 364 | /** |
231b9591 | 365 | Red pen. |
939dafa6 FM |
366 | Except for the color it has all standard attributes |
367 | (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...). | |
e54c96f1 | 368 | */ |
4d7b68d1 | 369 | wxPen* wxRED_PEN; |
e54c96f1 | 370 | |
939dafa6 FM |
371 | /** |
372 | Blue pen. | |
373 | Except for the color it has all standard attributes | |
374 | (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...). | |
375 | */ | |
376 | wxPen* wxBLUE_PEN; | |
377 | ||
e54c96f1 | 378 | /** |
231b9591 | 379 | Cyan pen. |
939dafa6 FM |
380 | Except for the color it has all standard attributes |
381 | (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...). | |
e54c96f1 | 382 | */ |
4d7b68d1 | 383 | wxPen* wxCYAN_PEN; |
e54c96f1 FM |
384 | |
385 | /** | |
231b9591 | 386 | Green pen. |
939dafa6 FM |
387 | Except for the color it has all standard attributes |
388 | (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...). | |
e54c96f1 | 389 | */ |
4d7b68d1 | 390 | wxPen* wxGREEN_PEN; |
e54c96f1 FM |
391 | |
392 | /** | |
231b9591 | 393 | Black pen. |
939dafa6 FM |
394 | Except for the color it has all standard attributes |
395 | (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...). | |
e54c96f1 | 396 | */ |
4d7b68d1 | 397 | wxPen* wxBLACK_PEN; |
e54c96f1 FM |
398 | |
399 | /** | |
231b9591 | 400 | White pen. |
939dafa6 FM |
401 | Except for the color it has all standard attributes |
402 | (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...). | |
e54c96f1 | 403 | */ |
4d7b68d1 | 404 | wxPen* wxWHITE_PEN; |
e54c96f1 FM |
405 | |
406 | /** | |
231b9591 | 407 | Transparent pen. |
939dafa6 FM |
408 | Except for the color it has all standard attributes |
409 | (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...). | |
e54c96f1 | 410 | */ |
4d7b68d1 | 411 | wxPen* wxTRANSPARENT_PEN; |
e54c96f1 FM |
412 | |
413 | /** | |
231b9591 | 414 | Black dashed pen. |
939dafa6 FM |
415 | Except for the color and for the @c wxPENSTYLE_SHORT_DASH it has all standard attributes |
416 | (1-pixel width, @c wxCAP_ROUND style, etc...). | |
e54c96f1 | 417 | */ |
4d7b68d1 | 418 | wxPen* wxBLACK_DASHED_PEN; |
e54c96f1 FM |
419 | |
420 | /** | |
231b9591 | 421 | Grey pen. |
939dafa6 FM |
422 | Except for the color it has all standard attributes |
423 | (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...). | |
e54c96f1 | 424 | */ |
4d7b68d1 | 425 | wxPen* wxGREY_PEN; |
e54c96f1 FM |
426 | |
427 | /** | |
231b9591 | 428 | Medium-grey pen. |
939dafa6 FM |
429 | Except for the color it has all standard attributes |
430 | (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...). | |
e54c96f1 | 431 | */ |
4d7b68d1 | 432 | wxPen* wxMEDIUM_GREY_PEN; |
e54c96f1 FM |
433 | |
434 | /** | |
231b9591 | 435 | Light-grey pen. |
939dafa6 FM |
436 | Except for the color it has all standard attributes |
437 | (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...). | |
e54c96f1 | 438 | */ |
4d7b68d1 | 439 | wxPen* wxLIGHT_GREY_PEN; |
e54c96f1 FM |
440 | |
441 | ||
8024723d FM |
442 | |
443 | /** | |
444 | @class wxPenList | |
8024723d FM |
445 | |
446 | There is only one instance of this class: ::wxThePenList. | |
447 | Use this object to search for a previously created pen of the desired | |
448 | type and create it if not already found. In some windowing systems, | |
449 | the pen may be a scarce resource, so it can pay to reuse old | |
450 | resources if possible. When an application finishes, all pens will | |
451 | be deleted and their resources freed, eliminating the possibility of | |
452 | 'memory leaks'. However, it is best not to rely on this automatic | |
453 | cleanup because it can lead to double deletion in some circumstances. | |
454 | ||
455 | There are two mechanisms in recent versions of wxWidgets which make the | |
456 | pen list less useful than it once was. Under Windows, scarce resources | |
457 | are cleaned up internally if they are not being used. Also, a referencing | |
458 | counting mechanism applied to all GDI objects means that some sharing | |
459 | of underlying resources is possible. You don't have to keep track of pointers, | |
460 | working out when it is safe delete a pen, because the referencing counting does | |
461 | it for you. For example, you can set a pen in a device context, and then | |
462 | immediately delete the pen you passed, because the pen is 'copied'. | |
463 | ||
464 | So you may find it easier to ignore the pen list, and instead create | |
465 | and copy pens as you see fit. If your Windows resource meter suggests | |
466 | your application is using too many resources, you can resort to using | |
467 | GDI lists to share objects explicitly. | |
468 | ||
469 | The only compelling use for the pen list is for wxWidgets to keep | |
470 | track of pens in order to clean them up on exit. It is also kept for | |
471 | backward compatibility with earlier versions of wxWidgets. | |
472 | ||
473 | @library{wxcore} | |
474 | @category{gdi} | |
475 | ||
476 | @stdobjects | |
477 | ::wxThePenList | |
478 | ||
479 | @see wxPen | |
480 | */ | |
481 | class wxPenList | |
482 | { | |
483 | public: | |
484 | /** | |
485 | Constructor. The application should not construct its own pen list: | |
486 | use the object pointer ::wxThePenList. | |
487 | */ | |
488 | wxPenList(); | |
489 | ||
490 | /** | |
491 | Finds a pen with the specified attributes and returns it, else creates a | |
492 | new pen, adds it to the pen list, and returns it. | |
493 | ||
494 | @param colour | |
495 | Colour object. | |
496 | @param width | |
497 | Width of pen. | |
498 | @param style | |
499 | Pen style. See ::wxPenStyle for a list of styles. | |
500 | */ | |
5d2d8f6a VZ |
501 | wxPen* FindOrCreatePen(const wxColour& colour, |
502 | int width = 1, | |
503 | wxPenStyle style = wxPENSTYLE_SOLID); | |
8024723d FM |
504 | }; |
505 | ||
506 | /** | |
507 | The global list of wxPen objects ready to be re-used (for better performances). | |
508 | */ | |
509 | wxPenList* wxThePenList; | |
510 |