wxClearButton

A completely custom-drawn bitmapped button.  The class wxClearButton provides a number of features: When the user mouses over, if the button is enabled, the cursor is changed to a hand, indicating the user can click the button.  When clicked, the button shifts itself one pixel right and down, to give visual feedback that is in the down state.  The click message to the parent is not sent unless the mouse button is released, and the mouse is still over the button.  This emulates the Windows OS.  The button may also be set with a certain color, which “colorizes” the bitmap with that color, allowing for custom colors with minimal fuss.  If the button is disabled, it is shown with no color at all, indicating its disabled state.  The button is drawn using memory bitmaps, to completely remove flicker.  Finally, the font used to draw the label on the button is resized if the button is resized so that its height is always around 70% or less of the available button height, giving a consistent look, even on differently sized buttons.

Derived From

wxWindow (see http://www.wxwindows.org/manuals/2.4.2/wx411.htm)

Project

UICore

Include

ClearButton.h

Summary
A completely custom-drawn bitmapped button.
The wxClearButton constructor.
Enables or disables the button.
Sets the button text.
The wxWidgets event table declaration.
Mouse handling flags.
Paints the button using the disabled/enabled bitmap image and the label text.
Paints the button.
Erases the button.
Resizes the button.
Handles the mouse entering the button’s rectangle.
Handles the left mouse down event.
Handles the left mouse up event.
Handles the mouse leaving the button’s rectangle.
The memory bitmap for the window.
The button text.
The enabled bitmap.
The disabled bitmap.
The color the button is colorized with.
The font the button text is drawn with.
The button mode.

Public

Summary
The wxClearButton constructor.
Enables or disables the button.
Sets the button text.
The wxWidgets event table declaration.

Constructors

wxClearButton

wxClearButton(wxWindow *parent, 
wxWindowID id, 
const wxString &label, 
const wxSize &size = sDefaultSize,
const wxColour &color = sButtonColor)

The wxClearButton constructor.  Creates the button with the given label, size, and color.

Parameters

parentThe parent window.  Must not be NULL.
idThe message handling ID.  Should be a unique (to the parent window) ID, if the parent window wants to receive messages from the control.
labelThe button text.
sizeThe button size.
colorThe color the button should be colorized with.

Functions

Enable

bool Enable(bool enable = true)

Enables or disables the button.

Parameters

enableThe enable flag.  True if the button should be enabled, false if it should be disabled.

SetLabel

void SetLabel(const wxString &label)

Sets the button text.

Parameters

labelThe new text of the button.

Variables

DECLARE_EVENT_TABLE

The wxWidgets event table declaration.

Private

Summary
Mouse handling flags.
Paints the button using the disabled/enabled bitmap image and the label text.
Paints the button.
Erases the button.
Resizes the button.
Handles the mouse entering the button’s rectangle.
Handles the left mouse down event.
Handles the left mouse up event.
Handles the mouse leaving the button’s rectangle.
The memory bitmap for the window.
The button text.
The enabled bitmap.
The disabled bitmap.
The color the button is colorized with.
The font the button text is drawn with.
The button mode.

Enumerations

Mode

Mouse handling flags.  Used when the user is holding down the left mouse button while moving the mouse around.  Flags are: ModeNone, ModeDown, ModeDownOutside.

Functions

Paint

void Paint(wxMemoryDC &dc)

Paints the button using the disabled/enabled bitmap image and the label text.

Parameters

dcThe memory device context to draw to.

Event Message Handling

OnPaint

void OnPaint(wxPaintEvent &event)

Paints the button.  Selects the memory bitmap into the device context and then calls the Paint function.

Parameters

eventThe paint event.

OnBackground

void OnBackground(wxEraseEvent &event)

Erases the button.  Necessary in order to prevent flickering when redrawing the window.

Parameters

eventThe erase event.

OnSize

void OnSize(wxSizeEvent &event)

Resizes the button.  Adjusts the font size to be at or below 70% of the total button height.

Parameters

eventThe size event.

OnEnterWindow

void OnEnterWindow(wxMouseEvent &event)

Handles the mouse entering the button’s rectangle.  Used to keep track of when the mouse has come back in to the button space after leaving while the left mouse button is down.

Parameters

eventThe mouse event.

OnLeftDown

void OnLeftDown(wxMouseEvent &event)

Handles the left mouse down event.  Puts the button in ModeDown state.

Parameters

eventThe mouse event.

OnLeftUp

void OnLeftUp(wxMouseEvent &event)

Handles the left mouse up event.  Sends a click message to the parent if the button is in ModeDown state.

Parameters

eventThe mouse event.

OnLeaveWindow

void OnLeaveWindow(wxMouseEvent &event)

Handles the mouse leaving the button’s rectangle.  Used to keep track of when the mouse has leaves the button space while the left mouse button is down.

Parameters

eventThe mouse event.

Variables

mMemBitmap

wxBitmap mMemBitmap

The memory bitmap for the window.  Prevents flickering by having the entire scene drawn into the memory bitmap via the Paint function and then blitting the bitmap in one pass to the screen in OnPaint.

mLabel

wxString mLabel

The button text.

mEnabledBitmap

wxBitmap mEnabledBitmap

The enabled bitmap.  Drawn when the bitmap is in the enabled state.

mDisabledBitmap

wxBitmap mDisabledBitmap

The disabled bitmap.  Drawn when the bitmap is in the disabled state.

mColor

wxColour mColor

The color the button is colorized with.

mFont

wxFont mFont

The font the button text is drawn with.

mMode

Mode mMode

The button mode.

wxClearButton(wxWindow *parent, 
wxWindowID id, 
const wxString &label, 
const wxSize &size = sDefaultSize,
const wxColour &color = sButtonColor)
The wxClearButton constructor.
bool Enable(bool enable = true)
Enables or disables the button.
void SetLabel(const wxString &label)
Sets the button text.
void Paint(wxMemoryDC &dc)
Paints the button using the disabled/enabled bitmap image and the label text.
void OnPaint(wxPaintEvent &event)
Paints the button.
void OnBackground(wxEraseEvent &event)
Erases the button.
void OnSize(wxSizeEvent &event)
Resizes the button.
void OnEnterWindow(wxMouseEvent &event)
Handles the mouse entering the button’s rectangle.
void OnLeftDown(wxMouseEvent &event)
Handles the left mouse down event.
void OnLeftUp(wxMouseEvent &event)
Handles the left mouse up event.
void OnLeaveWindow(wxMouseEvent &event)
Handles the mouse leaving the button’s rectangle.
wxBitmap mMemBitmap
The memory bitmap for the window.
wxString mLabel
The button text.
wxBitmap mEnabledBitmap
The enabled bitmap.
wxBitmap mDisabledBitmap
The disabled bitmap.
wxColour mColor
The color the button is colorized with.
wxFont mFont
The font the button text is drawn with.
Mode mMode
The button mode.
UICore provides a set of common UI controls that promote a constant look and feel across all aspects of the UI.