1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxPen* classes
4 // Author: wxWidgets team
5 // Licence: wxWindows licence
6 /////////////////////////////////////////////////////////////////////////////
9 The possible styles for a wxPen.
11 Note that hatched pen styles are not supported by X11-based ports,
16 wxPENSTYLE_INVALID
= -1,
25 /**< Long dashed style. */
27 wxPENSTYLE_SHORT_DASH
,
28 /**< Short dashed style. */
31 /**< Dot and dash style. */
34 /**< Use the user dashes: see wxPen::SetDashes. */
36 wxPENSTYLE_TRANSPARENT
,
37 /**< No pen is used. */
39 wxPENSTYLE_STIPPLE_MASK_OPAQUE
,
40 /**< @todo WHAT's this? */
42 wxPENSTYLE_STIPPLE_MASK
,
43 /**< @todo WHAT's this? */
46 /**< Use the stipple bitmap. */
48 wxPENSTYLE_BDIAGONAL_HATCH
,
49 /**< Backward diagonal hatch. */
51 wxPENSTYLE_CROSSDIAG_HATCH
,
52 /**< Cross-diagonal hatch. */
54 wxPENSTYLE_FDIAGONAL_HATCH
,
55 /**< Forward diagonal hatch. */
57 wxPENSTYLE_CROSS_HATCH
,
60 wxPENSTYLE_HORIZONTAL_HATCH
,
61 /**< Horizontal hatch. */
63 wxPENSTYLE_VERTICAL_HATCH
,
64 /**< Vertical hatch. */
66 wxPENSTYLE_FIRST_HATCH
,
67 /**< First of the hatch styles (inclusive). */
70 /**< Last of the hatch styles (inclusive). */
74 The possible join values of a wxPen.
76 @todo use wxPENJOIN_ prefix
89 The possible cap values of a wxPen.
91 @todo use wxPENCAP_ prefix
107 A pen is a drawing tool for drawing outlines. It is used for drawing
108 lines and painting the outline of rectangles, ellipses, etc.
109 It has a colour, a width and a style.
111 @note On a monochrome display, wxWidgets shows all non-white pens as black.
113 Do not initialize objects on the stack before the program commences,
114 since other required structures may not have been set up yet.
115 Instead, define global pointers to objects and create them in wxApp::OnInit()
118 An application may wish to dynamically create pens with different characteristics,
119 and there is the consequent danger that a large number of duplicate pens will
120 be created. Therefore an application may wish to get a pointer to a pen by using
121 the global list of pens ::wxThePenList, and calling the member function
122 wxPenList::FindOrCreatePen().
123 See wxPenList for more info.
125 This class uses @ref overview_refcount "reference counting and copy-on-write" internally
126 so that assignments between two instances of this class are very cheap.
127 You can therefore use actual objects instead of pointers without efficiency problems.
128 If an instance of this class is changed it will create its own data internally
129 so that other instances, which previously shared the data using the reference
130 counting, are not affected.
137 @li ::wxBLACK_DASHED_PEN
144 @li ::wxLIGHT_GREY_PEN
145 @li ::wxMEDIUM_GREY_PEN
147 @li ::wxTRANSPARENT_PEN
150 @see wxPenList, wxDC, wxDC::SetPen()
152 class wxPen
: public wxGDIObject
156 Default constructor. The pen will be uninitialised, and IsOk() will return @false.
161 Constructs a pen from a colour object, pen width and style.
166 Pen width. Under Windows, the pen width cannot be greater than 1 if
167 the style is @c wxPENSTYLE_DOT, @c wxPENSTYLE_LONG_DASH, @c wxPENSTYLE_SHORT_DASH,
168 @c wxPENSTYLE_DOT_DASH, or @c wxPENSTYLE_USER_DASH.
170 The style may be one of the ::wxPenStyle values.
172 @remarks Different versions of Windows and different versions of other
173 platforms support very different subsets of the styles above
174 - there is no similarity even between Windows95 and Windows98 -
177 @see SetStyle(), SetColour(), SetWidth()
179 wxPen(const wxColour
& colour
, int width
= 1, wxPenStyle style
= wxPENSTYLE_SOLID
);
182 Constructs a stippled pen from a stipple bitmap and a width.
185 Pen width. Under Windows, the pen width cannot be greater than 1 if
186 the style is @c wxPENSTYLE_DOT, @c wxPENSTYLE_LONG_DASH, @c wxPENSTYLE_SHORT_DASH,
187 @c wxPENSTYLE_DOT_DASH, or @c wxPENSTYLE_USER_DASH.
191 @onlyfor{wxmsw,wxosx}
193 @see SetWidth(), SetStipple()
195 wxPen(const wxBitmap
& stipple
, int width
);
198 Copy constructor, uses @ref overview_refcount.
201 A pointer or reference to a pen to copy.
203 wxPen(const wxPen
& pen
);
207 @see @ref overview_refcount_destruct "reference-counted object destruction"
209 @remarks Although all remaining pens are deleted when the application
210 exits, the application should try to clean up all pens
211 itself. This is because wxWidgets cannot know if a
212 pointer to the pen object is stored in an application
213 data structure, and there is a risk of double deletion.
218 Returns the pen cap style, which may be one of @c wxCAP_ROUND,
219 @c wxCAP_PROJECTING and @c wxCAP_BUTT.
221 The default is @c wxCAP_ROUND.
225 virtual wxPenCap
GetCap() const;
228 Returns a reference to the pen colour.
232 virtual wxColour
GetColour() const;
235 Gets an array of dashes (defined as @c char in X, @c DWORD under Windows).
236 @a dashes is a pointer to the internal array. Do not deallocate or store this
239 @return The number of dashes associated with this pen.
243 virtual int GetDashes(wxDash
** dashes
) const;
246 Returns the pen join style, which may be one of @c wxJOIN_BEVEL,
247 @c wxJOIN_ROUND and @c wxJOIN_MITER.
249 The default is @c wxJOIN_ROUND.
253 virtual wxPenJoin
GetJoin() const;
256 Gets a pointer to the stipple bitmap.
260 virtual wxBitmap
* GetStipple() const;
263 Returns the pen style.
265 @see wxPen(), SetStyle()
267 virtual wxPenStyle
GetStyle() const;
270 Returns the pen width.
274 virtual int GetWidth() const;
277 Returns @true if the pen is initialised.
279 Notice that an uninitialized pen object can't be queried for any pen
280 properties and all calls to the accessor methods on it will result in
283 virtual bool IsOk() const;
286 Returns @true if the pen is a valid non-transparent pen.
288 This method returns @true if the pen object is initialized and has a
289 non-transparent style. Notice that this should be used instead of
290 simply testing whether GetStyle() returns a style different from
291 wxPENSTYLE_TRANSPARENT if the pen may be invalid as GetStyle() would
298 bool IsNonTransparent() const;
301 Returns @true if the pen is transparent.
303 A transparent pen is simply a pen with wxPENSTYLE_TRANSPARENT style.
305 Notice that this function works even for non-initialized pens (for
306 which it returns @false) unlike tests of the form <code>GetStyle() ==
307 wxPENSTYLE_TRANSPARENT</code> which would assert if the pen is invalid.
309 @see IsNonTransparent()
313 bool IsTransparent() const;
316 Sets the pen cap style, which may be one of @c wxCAP_ROUND, @c wxCAP_PROJECTING
317 and @c wxCAP_BUTT. The default is @c wxCAP_ROUND.
321 virtual void SetCap(wxPenCap capStyle
);
325 The pen's colour is changed to the given colour.
329 virtual void SetColour(wxColour
& colour
);
330 virtual void SetColour(unsigned char red
, unsigned char green
, unsigned char blue
);
334 Associates an array of dash values (defined as @c char in X, @c DWORD under
335 Windows) with the pen.
337 The array is not deallocated by wxPen, but neither must it be deallocated by
338 the calling application until the pen is deleted or this function is called
343 virtual void SetDashes(int n
, const wxDash
* dash
);
346 Sets the pen join style, which may be one of @c wxJOIN_BEVEL, @c wxJOIN_ROUND
349 The default is @c wxJOIN_ROUND.
353 virtual void SetJoin(wxPenJoin join_style
);
356 Sets the bitmap for stippling.
360 virtual void SetStipple(const wxBitmap
& stipple
);
367 virtual void SetStyle(wxPenStyle style
);
374 virtual void SetWidth(int width
);
379 See @ref overview_refcount_equality "reference-counted object comparison" for
382 bool operator!=(const wxPen
& pen
) const;
385 Assignment operator, using @ref overview_refcount.
387 wxPen
& operator=(const wxPen
& pen
);
392 See @ref overview_refcount_equality "reference-counted object comparison" for
395 bool operator==(const wxPen
& pen
) const;
400 wxPen::IsOk() always returns @false for this object.
406 Except for the color it has all standard attributes
407 (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...).
413 Except for the color it has all standard attributes
414 (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...).
420 Except for the color it has all standard attributes
421 (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...).
427 Except for the color it has all standard attributes
428 (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...).
434 Except for the color it has all standard attributes
435 (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...).
441 Except for the color it has all standard attributes
442 (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...).
448 Except for the color it has all standard attributes
449 (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...).
455 Except for the color it has all standard attributes
456 (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...).
458 wxPen
* wxTRANSPARENT_PEN
;
462 Except for the color and for the @c wxPENSTYLE_SHORT_DASH it has all standard attributes
463 (1-pixel width, @c wxCAP_ROUND style, etc...).
465 wxPen
* wxBLACK_DASHED_PEN
;
469 Except for the color it has all standard attributes
470 (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...).
476 Except for the color it has all standard attributes
477 (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...).
479 wxPen
* wxMEDIUM_GREY_PEN
;
483 Except for the color it has all standard attributes
484 (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...).
486 wxPen
* wxLIGHT_GREY_PEN
;
493 There is only one instance of this class: ::wxThePenList.
494 Use this object to search for a previously created pen of the desired
495 type and create it if not already found. In some windowing systems,
496 the pen may be a scarce resource, so it can pay to reuse old
497 resources if possible. When an application finishes, all pens will
498 be deleted and their resources freed, eliminating the possibility of
499 'memory leaks'. However, it is best not to rely on this automatic
500 cleanup because it can lead to double deletion in some circumstances.
502 There are two mechanisms in recent versions of wxWidgets which make the
503 pen list less useful than it once was. Under Windows, scarce resources
504 are cleaned up internally if they are not being used. Also, a referencing
505 counting mechanism applied to all GDI objects means that some sharing
506 of underlying resources is possible. You don't have to keep track of pointers,
507 working out when it is safe delete a pen, because the referencing counting does
508 it for you. For example, you can set a pen in a device context, and then
509 immediately delete the pen you passed, because the pen is 'copied'.
511 So you may find it easier to ignore the pen list, and instead create
512 and copy pens as you see fit. If your Windows resource meter suggests
513 your application is using too many resources, you can resort to using
514 GDI lists to share objects explicitly.
516 The only compelling use for the pen list is for wxWidgets to keep
517 track of pens in order to clean them up on exit. It is also kept for
518 backward compatibility with earlier versions of wxWidgets.
532 Constructor. The application should not construct its own pen list:
533 use the object pointer ::wxThePenList.
538 Finds a pen with the specified attributes and returns it, else creates a
539 new pen, adds it to the pen list, and returns it.
546 Pen style. See ::wxPenStyle for a list of styles.
548 wxPen
* FindOrCreatePen(const wxColour
& colour
,
550 wxPenStyle style
= wxPENSTYLE_SOLID
);
554 The global list of wxPen objects ready to be re-used (for better performances).
556 wxPenList
* wxThePenList
;