1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxPen* classes
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
10 The possible styles for a wxPen.
14 wxPENSTYLE_INVALID
= -1,
23 /**< Long dashed style. */
25 wxPENSTYLE_SHORT_DASH
,
26 /**< Short dashed style. */
29 /**< Dot and dash style. */
32 /**< Use the user dashes: see wxPen::SetDashes. */
34 wxPENSTYLE_TRANSPARENT
,
35 /**< No pen is used. */
37 wxPENSTYLE_STIPPLE_MASK_OPAQUE
,
38 /**< @todo WHAT's this? */
40 wxPENSTYLE_STIPPLE_MASK
,
41 /**< @todo WHAT's this? */
44 /**< Use the stipple bitmap. */
46 wxPENSTYLE_BDIAGONAL_HATCH
,
47 /**< Backward diagonal hatch. */
49 wxPENSTYLE_CROSSDIAG_HATCH
,
50 /**< Cross-diagonal hatch. */
52 wxPENSTYLE_FDIAGONAL_HATCH
,
53 /**< Forward diagonal hatch. */
55 wxPENSTYLE_CROSS_HATCH
,
58 wxPENSTYLE_HORIZONTAL_HATCH
,
59 /**< Horizontal hatch. */
61 wxPENSTYLE_VERTICAL_HATCH
,
62 /**< Vertical hatch. */
64 wxPENSTYLE_FIRST_HATCH
= wxPENSTYLE_BDIAGONAL_HATCH
,
65 wxPENSTYLE_LAST_HATCH
= wxPENSTYLE_VERTICAL_HATCH
69 The possible join values of a wxPen.
71 @todo use wxPENJOIN_ prefix
84 The possible cap values of a wxPen.
86 @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 @note 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 wxPenList for more info.
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.
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.
132 @li ::wxBLACK_DASHED_PEN
139 @li ::wxLIGHT_GREY_PEN
140 @li ::wxMEDIUM_GREY_PEN
142 @li ::wxTRANSPARENT_PEN
145 @see wxPenList, wxDC, wxDC::SetPen()
147 class wxPen
: public wxGDIObject
151 Default constructor. The pen will be uninitialised, and IsOk() will return @false.
156 Constructs a pen from a colour object, pen width and style.
161 Pen width. Under Windows, the pen width cannot be greater than 1 if
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.
165 The style may be one of the ::wxPenStyle values.
167 @remarks Different versions of Windows and different versions of other
168 platforms support very different subsets of the styles above
169 - there is no similarity even between Windows95 and Windows98 -
172 @see SetStyle(), SetColour(), SetWidth()
174 wxPen(const wxColour
& colour
, int width
= 1, wxPenStyle style
= wxPENSTYLE_SOLID
);
177 Constructs a stippled pen from a stipple bitmap and a width.
180 Pen width. Under Windows, the pen width cannot be greater than 1 if
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.
186 @onlyfor{wxmsw,wxosx}
188 @see SetWidth(), SetStipple()
190 wxPen(const wxBitmap
& stipple
, int width
);
193 Copy constructor, uses @ref overview_refcount.
196 A pointer or reference to a pen to copy.
198 wxPen(const wxPen
& pen
);
202 @see @ref overview_refcount_destruct "reference-counted object destruction"
204 @remarks Although all remaining pens are deleted when the application
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.
213 Returns the pen cap style, which may be one of @c wxCAP_ROUND,
214 @c wxCAP_PROJECTING and @c wxCAP_BUTT.
216 The default is @c wxCAP_ROUND.
220 virtual wxPenCap
GetCap() const;
223 Returns a reference to the pen colour.
227 virtual wxColour
GetColour() const;
230 Gets an array of dashes (defined as @c char in X, @c DWORD under Windows).
231 @a dashes is a pointer to the internal array. Do not deallocate or store this
234 @return The number of dashes associated with this pen.
238 virtual int GetDashes(wxDash
** dashes
) const;
241 Returns the pen join style, which may be one of @c wxJOIN_BEVEL,
242 @c wxJOIN_ROUND and @c wxJOIN_MITER.
244 The default is @c wxJOIN_ROUND.
248 virtual wxPenJoin
GetJoin() const;
251 Gets a pointer to the stipple bitmap.
255 virtual wxBitmap
* GetStipple() const;
258 Returns the pen style.
260 @see wxPen(), SetStyle()
262 virtual wxPenStyle
GetStyle() const;
265 Returns the pen width.
269 virtual int GetWidth() const;
272 Returns @true if the pen is initialised.
274 virtual bool IsOk() const;
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.
282 virtual void SetCap(wxPenCap capStyle
);
286 The pen's colour is changed to the given colour.
290 virtual void SetColour(wxColour
& colour
);
291 virtual void SetColour(unsigned char red
, unsigned char green
, unsigned char blue
);
295 Associates an array of pointers to dashes (defined as @c char in X, @c DWORD under
296 Windows) with the pen.
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
304 virtual void SetDashes(int n
, const wxDash
* dash
);
307 Sets the pen join style, which may be one of @c wxJOIN_BEVEL, @c wxJOIN_ROUND
310 The default is @c wxJOIN_ROUND.
314 virtual void SetJoin(wxPenJoin join_style
);
317 Sets the bitmap for stippling.
321 virtual void SetStipple(const wxBitmap
& stipple
);
328 virtual void SetStyle(wxPenStyle style
);
335 virtual void SetWidth(int width
);
340 See @ref overview_refcount_equality "reference-counted object comparison" for
343 bool operator!=(const wxPen
& pen
) const;
346 Assignment operator, using @ref overview_refcount.
348 wxPen
& operator=(const wxPen
& pen
);
353 See @ref overview_refcount_equality "reference-counted object comparison" for
356 bool operator==(const wxPen
& pen
) const;
361 wxPen::IsOk() always returns @false for this object.
367 Except for the color it has all standard attributes
368 (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...).
374 Except for the color it has all standard attributes
375 (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...).
381 Except for the color it has all standard attributes
382 (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...).
388 Except for the color it has all standard attributes
389 (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...).
395 Except for the color it has all standard attributes
396 (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...).
402 Except for the color it has all standard attributes
403 (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...).
409 Except for the color it has all standard attributes
410 (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...).
416 Except for the color it has all standard attributes
417 (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...).
419 wxPen
* wxTRANSPARENT_PEN
;
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...).
426 wxPen
* wxBLACK_DASHED_PEN
;
430 Except for the color it has all standard attributes
431 (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...).
437 Except for the color it has all standard attributes
438 (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...).
440 wxPen
* wxMEDIUM_GREY_PEN
;
444 Except for the color it has all standard attributes
445 (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...).
447 wxPen
* wxLIGHT_GREY_PEN
;
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.
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'.
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.
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.
493 Constructor. The application should not construct its own pen list:
494 use the object pointer ::wxThePenList.
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.
507 Pen style. See ::wxPenStyle for a list of styles.
509 wxPen
* FindOrCreatePen(const wxColour
& colour
,
511 wxPenStyle style
= wxPENSTYLE_SOLID
);
515 The global list of wxPen objects ready to be re-used (for better performances).
517 wxPenList
* wxThePenList
;