1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxPen* classes
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
10 The possible styles for a wxPen.
21 /**< Long dashed style. */
23 wxPENSTYLE_SHORT_DASH
,
24 /**< Short dashed style. */
27 /**< Dot and dash style. */
30 /**< Use the user dashes: see wxPen::SetDashes. */
32 wxPENSTYLE_TRANSPARENT
,
33 /**< No pen is used. */
35 wxPENSTYLE_STIPPLE_MASK_OPAQUE
,
36 /**< @todo WHAT's this? */
38 wxPENSTYLE_STIPPLE_MASK
,
39 /**< @todo WHAT's this? */
42 /**< Use the stipple bitmap. */
44 wxPENSTYLE_BDIAGONAL_HATCH
,
45 /**< Backward diagonal hatch. */
47 wxPENSTYLE_CROSSDIAG_HATCH
,
48 /**< Cross-diagonal hatch. */
50 wxPENSTYLE_FDIAGONAL_HATCH
,
51 /**< Forward diagonal hatch. */
53 wxPENSTYLE_CROSS_HATCH
,
56 wxPENSTYLE_HORIZONTAL_HATCH
,
57 /**< Horizontal hatch. */
59 wxPENSTYLE_VERTICAL_HATCH
,
60 /**< Vertical hatch. */
62 wxPENSTYLE_FIRST_HATCH
= wxPENSTYLE_BDIAGONAL_HATCH
,
63 wxPENSTYLE_LAST_HATCH
= wxPENSTYLE_VERTICAL_HATCH
,
68 The possible join values of a wxPen.
70 @todo use wxPENJOIN_ prefix
83 The possible cap values of a wxPen.
85 @todo use wxPENCAP_ prefix
102 A pen is a drawing tool for drawing outlines. It is used for drawing
103 lines and painting the outline of rectangles, ellipses, etc.
104 It has a colour, a width and a style.
106 On a monochrome display, wxWidgets shows all non-white pens as black.
108 Do not initialize objects on the stack before the program commences,
109 since other required structures may not have been set up yet.
110 Instead, define global pointers to objects and create them in wxApp::OnInit
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
116 the global list of pens wxThePenList, and calling the member function
117 wxPenList::FindOrCreatePen().
118 See the entry for wxPenList.
120 This class uses reference counting and copy-on-write internally so that
121 assignments between two instances of this class are very cheap.
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.
131 ::wxNullPen, ::wxRED_PEN, ::wxCYAN_PEN, ::wxGREEN_PEN, ::wxBLACK_PEN,
132 ::wxWHITE_PEN, ::wxTRANSPARENT_PEN, ::wxBLACK_DASHED_PEN, ::wxGREY_PEN,
133 ::wxMEDIUM_GREY_PEN, ::wxLIGHT_GREY_PEN
135 @see wxPenList, wxDC, wxDC::SetPen
137 class wxPen
: public wxGDIObject
141 Default constructor. The pen will be uninitialised, and wxPen:IsOk will return @false.
146 Constructs a pen from a colour object, pen width and style.
148 wxPen(const wxColour
& colour
, int width
= 1, wxPenStyle style
= wxSOLID
);
151 Constructs a pen from a colour name, pen width and style.
153 wxPen(const wxString
& colourName
, int width
, wxPenStyle style
);
156 Constructs a stippled pen from a stipple bitmap and a width.
158 wxPen(const wxBitmap
& stipple
, int width
);
161 Copy constructor, uses @ref overview_refcount "reference counting".
168 Pen width. Under Windows, the pen width cannot be greater than 1 if
169 the style is wxDOT, wxLONG_DASH, wxSHORT_DASH, wxDOT_DASH, or wxUSER_DASH.
173 A pointer or reference to a pen to copy.
175 The style may be one of the ::wxPenStyle values.
177 @remarks Different versions of Windows and different versions of other
178 platforms support very different subsets of the styles
179 above - there is no similarity even between Windows95
180 and Windows98 - so handle with care.
182 @see SetStyle(), SetColour(), SetWidth(), SetStipple()
184 wxPen(const wxPen
& pen
);
188 See @ref overview_refcountdestruct "reference-counted object destruction" for
191 @remarks Although all remaining pens are deleted when the application
192 exits, the application should try to clean up all pens
193 itself. This is because wxWidgets cannot know if a
194 pointer to the pen object is stored in an application
195 data structure, and there is a risk of double deletion.
200 Returns the pen cap style, which may be one of @b wxCAP_ROUND, @b
202 @b wxCAP_BUTT. The default is @b wxCAP_ROUND.
206 wxPenCap
GetCap() const;
209 Returns a reference to the pen colour.
213 wxColour
GetColour() const;
216 Gets an array of dashes (defined as char in X, DWORD under Windows).
217 @a dashes is a pointer to the internal array. Do not deallocate or store this
219 The function returns the number of dashes associated with this pen.
223 int GetDashes(wxDash
** dashes
) const;
226 Returns the pen join style, which may be one of @b wxJOIN_BEVEL, @b
228 @b wxJOIN_MITER. The default is @b wxJOIN_ROUND.
232 wxPenJoin
GetJoin() const;
235 Gets a pointer to the stipple bitmap.
239 wxBitmap
* GetStipple() const;
242 Returns the pen style.
244 @see wxPen(), SetStyle()
246 wxPenStyle
GetStyle() const;
249 Returns the pen width.
253 int GetWidth() const;
256 Returns @true if the pen is initialised.
261 Sets the pen cap style, which may be one of @b wxCAP_ROUND, @b wxCAP_PROJECTING
263 @b wxCAP_BUTT. The default is @b wxCAP_ROUND.
267 void SetCap(wxPenCap capStyle
);
271 The pen's colour is changed to the given colour.
275 void SetColour(wxColour
& colour
);
276 void SetColour(const wxString
& colourName
);
277 void SetColour(unsigned char red
, unsigned char green
,
282 Associates an array of pointers to dashes (defined as char in X, DWORD under
284 with the pen. The array is not deallocated by wxPen, but neither must it be
285 deallocated by the calling application until the pen is deleted or this
286 function is called with a @NULL array.
290 void SetDashes(int n
, wxDash
* dashes
);
293 Sets the pen join style, which may be one of @b wxJOIN_BEVEL, @b wxJOIN_ROUND
295 @b wxJOIN_MITER. The default is @b wxJOIN_ROUND.
299 void SetJoin(wxPenJoin join_style
);
302 Sets the bitmap for stippling.
306 void SetStipple(wxBitmap
* stipple
);
313 void SetStyle(wxPenStyle style
);
320 void SetWidth(int width
);
324 See @ref overview_refcountequality "reference-counted object comparison" for
327 bool operator !=(const wxPen
& pen
);
330 Assignment operator, using @ref overview_trefcount "reference counting".
332 wxPen
operator =(const wxPen
& pen
);
336 See @ref overview_refcountequality "reference-counted object comparison" for
339 bool operator ==(const wxPen
& pen
);
375 wxPen wxTRANSPARENT_PEN
;
380 wxPen wxBLACK_DASHED_PEN
;
390 wxPen wxMEDIUM_GREY_PEN
;
395 wxPen wxLIGHT_GREY_PEN
;
403 There is only one instance of this class: ::wxThePenList.
404 Use this object to search for a previously created pen of the desired
405 type and create it if not already found. In some windowing systems,
406 the pen may be a scarce resource, so it can pay to reuse old
407 resources if possible. When an application finishes, all pens will
408 be deleted and their resources freed, eliminating the possibility of
409 'memory leaks'. However, it is best not to rely on this automatic
410 cleanup because it can lead to double deletion in some circumstances.
412 There are two mechanisms in recent versions of wxWidgets which make the
413 pen list less useful than it once was. Under Windows, scarce resources
414 are cleaned up internally if they are not being used. Also, a referencing
415 counting mechanism applied to all GDI objects means that some sharing
416 of underlying resources is possible. You don't have to keep track of pointers,
417 working out when it is safe delete a pen, because the referencing counting does
418 it for you. For example, you can set a pen in a device context, and then
419 immediately delete the pen you passed, because the pen is 'copied'.
421 So you may find it easier to ignore the pen list, and instead create
422 and copy pens as you see fit. If your Windows resource meter suggests
423 your application is using too many resources, you can resort to using
424 GDI lists to share objects explicitly.
426 The only compelling use for the pen list is for wxWidgets to keep
427 track of pens in order to clean them up on exit. It is also kept for
428 backward compatibility with earlier versions of wxWidgets.
442 Constructor. The application should not construct its own pen list:
443 use the object pointer ::wxThePenList.
448 Finds a pen with the specified attributes and returns it, else creates a
449 new pen, adds it to the pen list, and returns it.
456 Pen style. See ::wxPenStyle for a list of styles.
458 wxPen
* FindOrCreatePen(const wxColour
& colour
, int width
, wxPenStyle style
);
462 The global list of wxPen objects ready to be re-used (for better performances).
464 wxPenList
* wxThePenList
;