Wx::Brush

From WxPerl wiki

Jump to: navigation, search

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.

Contents

Inheritance

Derives from Wx::GDIObject and Wx::Object

Predefined objects

wxNullBrush
wxBLUE_BRUSH
wxGREEN_BRUSH
wxWHITE_BRUSH
wxBLACK_BRUSH
wxGREY_BRUSH
wxMEDIUM_GREY_BRUSH
wxLIGHT_GREY_BRUSH
wxTRANSPARENT_BRUSH
wxCYAN_BRUSH
wxRED_BRUSH

Notes

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

Do not initialize brush objects before the Wx::App commences, since other required structures may not have been set up yet. Instead, define global pointers to objects and create them in Wx::App::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.

This class uses reference counting and copy-on-write internally so that assignments between two instances of this class are very cheap. You can therefore use actual objects instead of pointers without efficiency problems. If an instance of this class is changed it will create its own data internally so that other instances, which previously shared the data using the reference counting, are not affected.

See also

Wx::BrushList, Wx::DC, Wx::DC::SetBrush


Constructor

new

Default constructor. The brush will be uninitialised, and IsOk will return false.

$brush = Wx::Brush->new($colour, $style);

Constructs a brush from a colour object and style.

$brush = Wx::Brush->new($colourName, $style);

Constructs a brush from a colour name and style.

$brush = Wx::Brush->new($stippleBitmap);

Constructs a stippled brush using a bitmap.

$brush = Wx::Brush->new($other_brush);

Copy constructor, uses reference counting.


Param Description
$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 Wx::BrushList, Wx::Colour, Wx::ColourDatabase.

Methods

GetColour

$color = $win->GetColour();

Returns a reference to the brush colour.

See also SetColour.

GetStipple

$bitmap = $win->GetStipple();

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

See also SetStipple

GetStyle

$int = $win->GetStyle();

Returns the brush style, one of:

Param Description
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 SetStyle, SetColour, SetStipple.


IsHatch

$bool = $win->IsHatch();

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

See also GetStyle


IsOk

$bool = $win->IsOk();

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).


SetColour

$win->SetColour($colour);

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

$win->SetColour($colourName);

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

$win->SetColour($red, $green, $blue);

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

See also GetColour


SetStipple

$win->SetStipple($bitmap);

Sets the stipple bitmap.

Param Description
$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 Wx::Bitmap


SetStyle

$win->SetStyle($style);

Sets the brush style. $style may be one of the following:

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 GetStyle

Google AdSense