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