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