wxBrush

A brush is a drawing tool for filling in areas. It is used for painting the background of rectangles, ellipses, etc. It has a colour and a style.

Derived from

wxGDIObject
wxObject

Include files

<wx/brush.h>

Predefined objects

Objects:

wxNullBrush

Pointers:

wxBLUE_BRUSH
wxGREEN_BRUSH
wxWHITE_BRUSH
wxBLACK_BRUSH
wxGREY_BRUSH
wxMEDIUM_GREY_BRUSH
wxLIGHT_GREY_BRUSH
wxTRANSPARENT_BRUSH
wxCYAN_BRUSH
wxRED_BRUSH

Remarks

On a monochrome display, wxWidgets shows all brushes as white unless the colour is really black.

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 wxApp::OnInit or when required.

An application may wish to create brushes with different characteristics dynamically, and there is the consequent danger that a large number of duplicate brushes will be created. Therefore an application may wish to get a pointer to a brush by using the global list of brushes wxTheBrushList, and calling the member function FindOrCreateBrush.

wxBrush uses a reference counting system, so assignments between brushes are very cheap. You can therefore use actual wxBrush objects instead of pointers without efficiency problems. Once one wxBrush object changes its data it will create its own brush data internally so that other brushes, which previously shared the data using the reference counting, are not affected.

See also

wxBrushList, wxDC, wxDC::SetBrush



wxBrush::wxBrush



wxBrush(void)

Default constructor. The brush will be uninitialised, and wxBrush::Ok will return false.



wxBrush(const wxColour& colour, int style = wxSOLID)

Constructs a brush from a colour object and style.



wxBrush(const wxString& colourName, int style)

Constructs a brush from a colour name and style.



wxBrush(const wxBitmap& stippleBitmap)

Constructs a stippled brush using a bitmap.



wxBrush(const wxBrush& brush)

Copy constructor. This uses reference counting so is a cheap operation.

Parameters

colour
Colour object.

colourName
Colour name. The name will be looked up in the colour database.

style
One of:

wxTRANSPARENT Transparent (no fill).
wxSOLID Solid.
wxSTIPPLE Uses a bitmap as a stipple.
wxBDIAGONAL_HATCH Backward diagonal hatch.
wxCROSSDIAG_HATCH Cross-diagonal hatch.
wxFDIAGONAL_HATCH Forward diagonal hatch.
wxCROSS_HATCH Cross hatch.
wxHORIZONTAL_HATCH Horizontal hatch.
wxVERTICAL_HATCH Vertical hatch.

brush
Pointer or reference to a brush to copy.

stippleBitmap
A bitmap to use for stippling.

Remarks

If a stipple brush is created, the brush style will be set to wxSTIPPLE.

See also

wxBrushList, wxColour, wxColourDatabase



wxBrush::~wxBrush



~wxBrush(void)

Destructor.

Remarks

The destructor may not delete the underlying brush object of the native windowing system, since wxBrush uses a reference counting system for efficiency.

Although all remaining brushes are deleted when the application exits, the application should try to clean up all brushes itself. This is because wxWidgets cannot know if a pointer to the brush object is stored in an application data structure, and there is a risk of double deletion.



wxBrush::GetColour

wxColour& GetColour(void) const

Returns a reference to the brush colour.

See also

wxBrush::SetColour



wxBrush::GetStipple

wxBitmap * GetStipple(void) const

Gets a pointer to the stipple bitmap. If the brush does not have a wxSTIPPLE style, this bitmap may be non-NULL but uninitialised (wxBitmap::Ok returns false).

See also

wxBrush::SetStipple



wxBrush::GetStyle

int GetStyle(void) const

Returns the brush style, one of:

wxTRANSPARENT Transparent (no fill).
wxSOLID Solid.
wxBDIAGONAL_HATCH Backward diagonal hatch.
wxCROSSDIAG_HATCH Cross-diagonal hatch.
wxFDIAGONAL_HATCH Forward diagonal hatch.
wxCROSS_HATCH Cross hatch.
wxHORIZONTAL_HATCH Horizontal hatch.
wxVERTICAL_HATCH Vertical hatch.
wxSTIPPLE Stippled using a bitmap.
wxSTIPPLE_MASK_OPAQUE Stippled using a bitmap's mask.

See also

wxBrush::SetStyle, wxBrush::SetColour, wxBrush::SetStipple



wxBrush::IsHatch

bool IsHatch(void) const

Returns true if the style of the brush is any of hatched fills.

See also

wxBrush::GetStyle



wxBrush::Ok

bool Ok(void) const

Returns true if the brush is initialised. It will return false if the default constructor has been used (for example, the brush is a member of a class, or NULL has been assigned to it).



wxBrush::SetColour



void SetColour(wxColour& colour)

Sets the brush colour using a reference to a colour object.



void SetColour(const wxString& colourName)

Sets the brush colour using a colour name from the colour database.



void SetColour(const unsigned char red, const unsigned char green, const unsigned char blue)

Sets the brush colour using red, green and blue values.

See also

wxBrush::GetColour



wxBrush::SetStipple



void SetStipple(const wxBitmap& bitmap)

Sets the stipple bitmap.

Parameters

bitmap
The bitmap to use for stippling.

Remarks

The style will be set to wxSTIPPLE, unless the bitmap has a mask associated to it, in which case the style will be set to wxSTIPPLE_MASK_OPAQUE.

If the wxSTIPPLE variant is used, the bitmap will be used to fill out the area to be drawn. If the wxSTIPPLE_MASK_OPAQUE is used, the current text foreground and text background determine what colours are used for displaying and the bits in the mask (which is a mono-bitmap actually) determine where to draw what.

Note that under Windows 95, only 8x8 pixel large stipple bitmaps are supported, Windows 98 and NT as well as GTK support arbitrary bitmaps.

See also

wxBitmap



wxBrush::SetStyle



void SetStyle(int style)

Sets the brush style.

style
One of:

wxTRANSPARENT Transparent (no fill).
wxSOLID Solid.
wxBDIAGONAL_HATCH Backward diagonal hatch.
wxCROSSDIAG_HATCH Cross-diagonal hatch.
wxFDIAGONAL_HATCH Forward diagonal hatch.
wxCROSS_HATCH Cross hatch.
wxHORIZONTAL_HATCH Horizontal hatch.
wxVERTICAL_HATCH Vertical hatch.
wxSTIPPLE Stippled using a bitmap.
wxSTIPPLE_MASK_OPAQUE Stippled using a bitmap's mask.

See also

wxBrush::GetStyle



wxBrush::operator $=$



wxBrush& operator $=$(const wxBrush& brush)

Assignment operator, using reference counting. Returns a reference to `this'.



wxBrush::operator $==$



bool operator $==$(const wxBrush& brush)

Equality operator. Two brushes are equal if they contain pointers to the same underlying brush data. It does not compare each attribute, so two independently-created brushes using the same parameters will fail the test.



wxBrush::operator $\!=$



bool operator $\!=$(const wxBrush& brush)

Inequality operator. Two brushes are not equal if they contain pointers to different underlying brush data. It does not compare each attribute.

ymasuda 平成17年11月19日