Public Types | Public Member Functions | Protected Member Functions

DrawableButton Class Reference

A button that displays a Drawable. More...

Inherits Button.

List of all members.

Public Types

enum  ButtonStyle { ImageFitted, ImageRaw, ImageAboveTextLabel, ImageOnButtonBackground }
enum  ColourIds { textColourId = 0x1004010 }
 

A set of colour IDs to use to change the colour of various aspects of the link.

More...

Public Member Functions

 DrawableButton (const String &buttonName, ButtonStyle buttonStyle)
 Creates a DrawableButton.
 ~DrawableButton ()
 Destructor.
void setImages (const Drawable *normalImage, const Drawable *overImage=nullptr, const Drawable *downImage=nullptr, const Drawable *disabledImage=nullptr, const Drawable *normalImageOn=nullptr, const Drawable *overImageOn=nullptr, const Drawable *downImageOn=nullptr, const Drawable *disabledImageOn=nullptr)
 Sets up the images to draw for the various button states.
void setButtonStyle (ButtonStyle newStyle)
 Changes the button's style.
void setBackgroundColours (const Colour &toggledOffColour, const Colour &toggledOnColour)
 Changes the button's background colours.
const ColourgetBackgroundColour () const noexcept
 Returns the current background colour being used.
void setEdgeIndent (int numPixelsIndent)
 Gives the button an optional amount of space around the edge of the drawable.
DrawablegetCurrentImage () const noexcept
 Returns the image that the button is currently displaying.
DrawablegetNormalImage () const noexcept
DrawablegetOverImage () const noexcept
DrawablegetDownImage () const noexcept

Protected Member Functions

void paintButton (Graphics &g, bool isMouseOverButton, bool isButtonDown)
 Subclasses should override this to actually paint the button's contents.
void buttonStateChanged ()
 Called when the button's up/down/over state changes.
void resized ()
 Called when this component's size has been changed.

Detailed Description

A button that displays a Drawable.

Up to three Drawable objects can be given to this button, to represent the 'normal', 'over' and 'down' states.

See also:
Button

Member Enumeration Documentation

Enumerator:
ImageFitted 

The button will just display the images, but will resize and centre them to fit inside it.

ImageRaw 

The button will just display the images in their normal size and position.

This leaves it up to the caller to make sure the images are the correct size and position for the button.

ImageAboveTextLabel 

Draws the button as a text label across the bottom with the image resized and scaled to fit above it.

ImageOnButtonBackground 

Draws the button as a standard rounded-rectangle button with the image on top.

A set of colour IDs to use to change the colour of various aspects of the link.

These constants can be used either via the Component::setColour(), or LookAndFeel::setColour() methods.

See also:
Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
Enumerator:
textColourId 

The colour to use for the URL text.


Constructor & Destructor Documentation

DrawableButton::DrawableButton ( const String buttonName,
ButtonStyle  buttonStyle 
)

Creates a DrawableButton.

After creating one of these, use setImages() to specify the drawables to use.

Parameters:
buttonNamethe name to give the component
buttonStylethe layout to use
See also:
ButtonStyle, setButtonStyle, setImages
DrawableButton::~DrawableButton (  )

Destructor.


Member Function Documentation

void DrawableButton::setImages ( const Drawable normalImage,
const Drawable overImage = nullptr,
const Drawable downImage = nullptr,
const Drawable disabledImage = nullptr,
const Drawable normalImageOn = nullptr,
const Drawable overImageOn = nullptr,
const Drawable downImageOn = nullptr,
const Drawable disabledImageOn = nullptr 
)

Sets up the images to draw for the various button states.

The button will keep its own internal copies of these drawables.

Parameters:
normalImagethe thing to draw for the button's 'normal' state. An internal copy will be made of the object passed-in if it is non-zero.
overImagethe thing to draw for the button's 'over' state - if this is zero, the button's normal image will be used when the mouse is over it. An internal copy will be made of the object passed-in if it is non-zero.
downImagethe thing to draw for the button's 'down' state - if this is zero, the 'over' image will be used instead (or the normal image as a last resort). An internal copy will be made of the object passed-in if it is non-zero.
disabledImagean image to draw when the button is disabled. If this is zero, the normal image will be drawn with a reduced opacity instead. An internal copy will be made of the object passed-in if it is non-zero.
normalImageOnsame as the normalImage, but this is used when the button's toggle state is 'on'. If this is 0, the normal image is used instead
overImageOnsame as the overImage, but this is used when the button's toggle state is 'on'. If this is 0, the normalImageOn is drawn instead
downImageOnsame as the downImage, but this is used when the button's toggle state is 'on'. If this is 0, the overImageOn is drawn instead
disabledImageOnsame as the disabledImage, but this is used when the button's toggle state is 'on'. If this is 0, the normal image will be drawn instead with a reduced opacity
void DrawableButton::setButtonStyle ( ButtonStyle  newStyle )

Changes the button's style.

See also:
ButtonStyle
void DrawableButton::setBackgroundColours ( const Colour toggledOffColour,
const Colour toggledOnColour 
)

Changes the button's background colours.

The toggledOffColour is the colour to use when the button's toggle state is off, and toggledOnColour when it's on.

For an ImageOnly or ImageAboveTextLabel style, the background colour is used to fill the background of the component.

For an ImageOnButtonBackground style, the colour is used to draw the button's lozenge shape and exactly how the colour's used will depend on the LookAndFeel.

const Colour& DrawableButton::getBackgroundColour (  ) const

Returns the current background colour being used.

See also:
setBackgroundColour
void DrawableButton::setEdgeIndent ( int  numPixelsIndent )

Gives the button an optional amount of space around the edge of the drawable.

This will only apply to ImageFitted or ImageRaw styles, it won't affect the ones on a button background. If the button is too small for the given gap, a smaller gap will be used.

By default there's a gap of about 3 pixels.

Drawable* DrawableButton::getCurrentImage (  ) const

Returns the image that the button is currently displaying.

Drawable* DrawableButton::getNormalImage (  ) const
Drawable* DrawableButton::getOverImage (  ) const
Drawable* DrawableButton::getDownImage (  ) const
void DrawableButton::paintButton ( Graphics g,
bool  isMouseOverButton,
bool  isButtonDown 
) [protected, virtual]

Subclasses should override this to actually paint the button's contents.

It's better to use this than the paint method, because it gives you information about the over/down state of the button.

Parameters:
gthe graphics context to use
isMouseOverButtontrue if the button is either in the 'over' or 'down' state
isButtonDowntrue if the button should be drawn in the 'down' position

Implements Button.

void DrawableButton::buttonStateChanged (  ) [protected, virtual]

Called when the button's up/down/over state changes.

Subclasses can override this if they need to do something special when the button goes up or down.

See also:
isDown, isOver

Reimplemented from Button.

void DrawableButton::resized (  ) [protected, virtual]

Called when this component's size has been changed.

A component can implement this method to do things such as laying out its child components when its width or height changes.

The method is called synchronously as a result of the setBounds or setSize methods, so repeatedly changing a components size will repeatedly call its resized method (unlike things like repainting, where multiple calls to repaint are coalesced together).

If the component is a top-level window on the desktop, its size could also be changed by operating-system factors beyond the application's control.

See also:
moved, setSize

Reimplemented from Component.


The documentation for this class was generated from the following file:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines