1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxPen* classes
4 // Author: wxWidgets team
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
10 The possible styles for a wxPen.
12 Note that hatched pen styles are not supported by X11-based ports,
17 wxPENSTYLE_INVALID
= -1,
26 /**< Long dashed style. */
28 wxPENSTYLE_SHORT_DASH
,
29 /**< Short dashed style. */
32 /**< Dot and dash style. */
35 /**< Use the user dashes: see wxPen::SetDashes. */
37 wxPENSTYLE_TRANSPARENT
,
38 /**< No pen is used. */
40 wxPENSTYLE_STIPPLE_MASK_OPAQUE
,
41 /**< @todo WHAT's this? */
43 wxPENSTYLE_STIPPLE_MASK
,
44 /**< @todo WHAT's this? */
47 /**< Use the stipple bitmap. */
49 wxPENSTYLE_BDIAGONAL_HATCH
,
50 /**< Backward diagonal hatch. */
52 wxPENSTYLE_CROSSDIAG_HATCH
,
53 /**< Cross-diagonal hatch. */
55 wxPENSTYLE_FDIAGONAL_HATCH
,
56 /**< Forward diagonal hatch. */
58 wxPENSTYLE_CROSS_HATCH
,
61 wxPENSTYLE_HORIZONTAL_HATCH
,
62 /**< Horizontal hatch. */
64 wxPENSTYLE_VERTICAL_HATCH
,
65 /**< Vertical hatch. */
67 wxPENSTYLE_FIRST_HATCH
= wxPENSTYLE_BDIAGONAL_HATCH
,
68 wxPENSTYLE_LAST_HATCH
= wxPENSTYLE_VERTICAL_HATCH
72 The possible join values of a wxPen.
74 @todo use wxPENJOIN_ prefix
87 The possible cap values of a wxPen.
89 @todo use wxPENCAP_ prefix
105 A pen is a drawing tool for drawing outlines. It is used for drawing
106 lines and painting the outline of rectangles, ellipses, etc.
107 It has a colour, a width and a style.
109 @note On a monochrome display, wxWidgets shows all non-white pens as black.
111 Do not initialize objects on the stack before the program commences,
112 since other required structures may not have been set up yet.
113 Instead, define global pointers to objects and create them in wxApp::OnInit()
116 An application may wish to dynamically create pens with different characteristics,
117 and there is the consequent danger that a large number of duplicate pens will
118 be created. Therefore an application may wish to get a pointer to a pen by using
119 the global list of pens ::wxThePenList, and calling the member function
120 wxPenList::FindOrCreatePen().
121 See wxPenList for more info.
123 This class uses @ref overview_refcount "reference counting and copy-on-write" internally
124 so that assignments between two instances of this class are very cheap.
125 You can therefore use actual objects instead of pointers without efficiency problems.
126 If an instance of this class is changed it will create its own data internally
127 so that other instances, which previously shared the data using the reference
128 counting, are not affected.
135 @li ::wxBLACK_DASHED_PEN
142 @li ::wxLIGHT_GREY_PEN
143 @li ::wxMEDIUM_GREY_PEN
145 @li ::wxTRANSPARENT_PEN
148 @see wxPenList, wxDC, wxDC::SetPen()
150 class wxPen
: public wxGDIObject
154 Default constructor. The pen will be uninitialised, and IsOk() will return @false.
159 Constructs a pen from a colour object, pen width and style.
164 Pen width. Under Windows, the pen width cannot be greater than 1 if
165 the style is @c wxPENSTYLE_DOT, @c wxPENSTYLE_LONG_DASH, @c wxPENSTYLE_SHORT_DASH,
166 @c wxPENSTYLE_DOT_DASH, or @c wxPENSTYLE_USER_DASH.
168 The style may be one of the ::wxPenStyle values.
170 @remarks Different versions of Windows and different versions of other
171 platforms support very different subsets of the styles above
172 - there is no similarity even between Windows95 and Windows98 -
175 @see SetStyle(), SetColour(), SetWidth()
177 wxPen(const wxColour
& colour
, int width
= 1, wxPenStyle style
= wxPENSTYLE_SOLID
);
180 Constructs a stippled pen from a stipple bitmap and a width.
183 Pen width. Under Windows, the pen width cannot be greater than 1 if
184 the style is @c wxPENSTYLE_DOT, @c wxPENSTYLE_LONG_DASH, @c wxPENSTYLE_SHORT_DASH,
185 @c wxPENSTYLE_DOT_DASH, or @c wxPENSTYLE_USER_DASH.
189 @onlyfor{wxmsw,wxosx}
191 @see SetWidth(), SetStipple()
193 wxPen(const wxBitmap
& stipple
, int width
);
196 Copy constructor, uses @ref overview_refcount.
199 A pointer or reference to a pen to copy.
201 wxPen(const wxPen
& pen
);
205 @see @ref overview_refcount_destruct "reference-counted object destruction"
207 @remarks Although all remaining pens are deleted when the application
208 exits, the application should try to clean up all pens
209 itself. This is because wxWidgets cannot know if a
210 pointer to the pen object is stored in an application
211 data structure, and there is a risk of double deletion.
216 Returns the pen cap style, which may be one of @c wxCAP_ROUND,
217 @c wxCAP_PROJECTING and @c wxCAP_BUTT.
219 The default is @c wxCAP_ROUND.
223 virtual wxPenCap
GetCap() const;
226 Returns a reference to the pen colour.
230 virtual wxColour
GetColour() const;
233 Gets an array of dashes (defined as @c char in X, @c DWORD under Windows).
234 @a dashes is a pointer to the internal array. Do not deallocate or store this
237 @return The number of dashes associated with this pen.
241 virtual int GetDashes(wxDash
** dashes
) const;
244 Returns the pen join style, which may be one of @c wxJOIN_BEVEL,
245 @c wxJOIN_ROUND and @c wxJOIN_MITER.
247 The default is @c wxJOIN_ROUND.
251 virtual wxPenJoin
GetJoin() const;
254 Gets a pointer to the stipple bitmap.
258 virtual wxBitmap
* GetStipple() const;
261 Returns the pen style.
263 @see wxPen(), SetStyle()
265 virtual wxPenStyle
GetStyle() const;
268 Returns the pen width.
272 virtual int GetWidth() const;
275 Returns @true if the pen is initialised.
277 Notice that an uninitialized pen object can't be queried for any pen
278 properties and all calls to the accessor methods on it will result in
281 virtual bool IsOk() const;
284 Returns @true if the pen is a valid non-transparent pen.
286 This method returns @true if the pen object is initialized and has a
287 non-transparent style. Notice that this should be used instead of
288 simply testing whether GetStyle() returns a style different from
289 wxPENSTYLE_TRANSPARENT if the pen may be invalid as GetStyle() would
296 bool IsNonTransparent() const;
299 Returns @true if the pen is transparent.
301 A transparent pen is simply a pen with wxPENSTYLE_TRANSPARENT style.
303 Notice that this function works even for non-initialized pens (for
304 which it returns @false) unlike tests of the form <code>GetStyle() ==
305 wxPENSTYLE_TRANSPARENT</code> which would assert if the pen is invalid.
307 @see IsNonTransparent()
311 bool IsTransparent() const;
314 Sets the pen cap style, which may be one of @c wxCAP_ROUND, @c wxCAP_PROJECTING
315 and @c wxCAP_BUTT. The default is @c wxCAP_ROUND.
319 virtual void SetCap(wxPenCap capStyle
);
323 The pen's colour is changed to the given colour.
327 virtual void SetColour(wxColour
& colour
);
328 virtual void SetColour(unsigned char red
, unsigned char green
, unsigned char blue
);
332 Associates an array of pointers to dashes (defined as @c char in X, @c DWORD under
333 Windows) with the pen.
335 The array is not deallocated by wxPen, but neither must it be deallocated by
336 the calling application until the pen is deleted or this function is called
341 virtual void SetDashes(int n
, const wxDash
* dash
);
344 Sets the pen join style, which may be one of @c wxJOIN_BEVEL, @c wxJOIN_ROUND
347 The default is @c wxJOIN_ROUND.
351 virtual void SetJoin(wxPenJoin join_style
);
354 Sets the bitmap for stippling.
358 virtual void SetStipple(const wxBitmap
& stipple
);
365 virtual void SetStyle(wxPenStyle style
);
372 virtual void SetWidth(int width
);
377 See @ref overview_refcount_equality "reference-counted object comparison" for
380 bool operator!=(const wxPen
& pen
) const;
383 Assignment operator, using @ref overview_refcount.
385 wxPen
& operator=(const wxPen
& pen
);
390 See @ref overview_refcount_equality "reference-counted object comparison" for
393 bool operator==(const wxPen
& pen
) const;
398 wxPen::IsOk() always returns @false for this object.
404 Except for the color it has all standard attributes
405 (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...).
411 Except for the color it has all standard attributes
412 (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...).
418 Except for the color it has all standard attributes
419 (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...).
425 Except for the color it has all standard attributes
426 (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...).
432 Except for the color it has all standard attributes
433 (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...).
439 Except for the color it has all standard attributes
440 (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...).
446 Except for the color it has all standard attributes
447 (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...).
453 Except for the color it has all standard attributes
454 (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...).
456 wxPen
* wxTRANSPARENT_PEN
;
460 Except for the color and for the @c wxPENSTYLE_SHORT_DASH it has all standard attributes
461 (1-pixel width, @c wxCAP_ROUND style, etc...).
463 wxPen
* wxBLACK_DASHED_PEN
;
467 Except for the color it has all standard attributes
468 (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...).
474 Except for the color it has all standard attributes
475 (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...).
477 wxPen
* wxMEDIUM_GREY_PEN
;
481 Except for the color it has all standard attributes
482 (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...).
484 wxPen
* wxLIGHT_GREY_PEN
;
491 There is only one instance of this class: ::wxThePenList.
492 Use this object to search for a previously created pen of the desired
493 type and create it if not already found. In some windowing systems,
494 the pen may be a scarce resource, so it can pay to reuse old
495 resources if possible. When an application finishes, all pens will
496 be deleted and their resources freed, eliminating the possibility of
497 'memory leaks'. However, it is best not to rely on this automatic
498 cleanup because it can lead to double deletion in some circumstances.
500 There are two mechanisms in recent versions of wxWidgets which make the
501 pen list less useful than it once was. Under Windows, scarce resources
502 are cleaned up internally if they are not being used. Also, a referencing
503 counting mechanism applied to all GDI objects means that some sharing
504 of underlying resources is possible. You don't have to keep track of pointers,
505 working out when it is safe delete a pen, because the referencing counting does
506 it for you. For example, you can set a pen in a device context, and then
507 immediately delete the pen you passed, because the pen is 'copied'.
509 So you may find it easier to ignore the pen list, and instead create
510 and copy pens as you see fit. If your Windows resource meter suggests
511 your application is using too many resources, you can resort to using
512 GDI lists to share objects explicitly.
514 The only compelling use for the pen list is for wxWidgets to keep
515 track of pens in order to clean them up on exit. It is also kept for
516 backward compatibility with earlier versions of wxWidgets.
530 Constructor. The application should not construct its own pen list:
531 use the object pointer ::wxThePenList.
536 Finds a pen with the specified attributes and returns it, else creates a
537 new pen, adds it to the pen list, and returns it.
544 Pen style. See ::wxPenStyle for a list of styles.
546 wxPen
* FindOrCreatePen(const wxColour
& colour
,
548 wxPenStyle style
= wxPENSTYLE_SOLID
);
552 The global list of wxPen objects ready to be re-used (for better performances).
554 wxPenList
* wxThePenList
;