Contents Up Previous Next

wxPen: wxObject

A pen is a drawing tool for drawing outlines. It is used for drawing lines and painting the outline of rectangles, ellipses, etc. It has a colour, a width and a style. On a monochrome display, the default behaviour is to show all non-white pens as black. To change this, set the Colour member of the device context to TRUE, and select appropriate colours.

The style may be one of wxSOLID, wxDOT, wxLONG_DASH, wxSHORT_DASH and wxDOT_DASH. The names of these styles should be self explanatory.

Do not initialize objects on the stack before the program commences, since other required structures may not have been set up yet. Instead, define global pointers to objects and create them in OnInit or when required.

An application may wish to dynamically create pens with different characteristics, and there is the consequent danger that a large number of duplicate pens will be created. Therefore an application may wish to get a pointer to a pen by using the global list of pens wxThePenList, and calling the member function FindOrCreatePen. See the entry for wxPenList.

wxPen::wxPen
wxPen::~wxPen
wxPen::GetCap
wxPen::GetColour
wxPen::GetDashes
wxPen::GetJoin
wxPen::GetStipple
wxPen::GetStyle
wxPen::GetWidth
wxPen::SetCap
wxPen::SetColour
wxPen::SetDashes
wxPen::SetJoin
wxPen::SetStipple
wxPen::SetStyle
wxPen::SetWidth


wxPen::wxPen

void wxPen(void)

void wxPen(wxColour&colour, int width, int style)

void wxPen(char *colour_name, int width, int style)

Constructs a pen, uninitialized, initialized with an RGB colour, a width and a style, or initialized using a colour name, a width and a style. If the named colour form is used, an appropriate wxColour structure is found in the colour database.

style may be one of wxSOLID, wxDOT, wxLONG_DASH, wxSHORT_DASH and wxDOT_DASH.


wxPen::~wxPen

void ~wxPen(void)

Destructor, destroying the pen. Note that pens should very rarely be deleted since windows may contain pointers to them. All pens will be deleted when the application terminates.

If you have to delete the pen (for example, you are creating a lot of them), then call wxDC::SetPen with a NULL argument to ensure that the old pen is restored, and the current pen is selected out of the device context.


wxPen::GetCap

int GetCap(void)

Returns the pen cap style, which may be one of wxCAP_ROUND, wxCAP_PROJECTING and wxCAP_BUTT. The default is wxCAP_ROUND.


wxPen::GetColour

wxColour& GetColour(void)

Returns a reference to the pen colour.


wxPen::GetDashes

int GetDashes(wxDash **dashes)

Gets an array of dashes (defined as char in X, DWORD under Windows). dashes is a pointer to the array (not allocated by the application). The function returns the number of dashes associated with this pen.


wxPen::GetJoin

int GetJoin(void)

Returns the pen join style, which may be one of wxJOIN_BEVEL, wxJOIN_ROUND and wxJOIN_MITER. The default is wxJOIN_ROUND.


wxPen::GetStipple

wxBitmap * GetStipple(void)

Gets the stipple bitmap.


wxPen::GetStyle

int GetStyle(void)

Returns the pen style.


wxPen::GetWidth

int GetWidth(void)

Returns the pen width.


wxPen::SetCap

void SetCap(intcap_style)

Sets the pen cap style, which may be one of wxCAP_ROUND, wxCAP_PROJECTING and wxCAP_BUTT. The default is wxCAP_ROUND.


wxPen::SetColour

void SetColour(wxColour &colour)

void SetColour(char *colour_name)

void SetColour(int red, int green, int blue)

The pen's colour is changed to the given colour.


wxPen::SetDashes

void SetDashes(int n, wxDash *dashes)

Associates an array of pointers to dashes (defined as char in X, DWORD under Windows) with the pen. The array is not deallocated by wxPen, but neither must it be deallocated by the calling application until the pen is deleted or this function is called with a NULL array.

Sorry, I don't yet have information as to how the dashes work.


wxPen::SetJoin

void SetJoin(intjoin_style)

Sets the pen join style, which may be one of wxJOIN_BEVEL, wxJOIN_ROUND and wxJOIN_MITER. The default is wxJOIN_ROUND.


wxPen::SetStipple

void SetStipple(wxBitmap * stipple)

Sets the bitmap for stippling.


wxPen::SetStyle

void SetStyle(int style)

Set the pen style (wxSOLID or wxTRANSPARENT).


wxPen::SetWidth

void SetWidth(int width)

Set the pen width.