FIFE
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
gcn::ToggleButton Class Reference

An implementation of a toggleable button. More...

#include <togglebutton.h>

Inherits Button, and ActionListener.

+ Collaboration diagram for gcn::ToggleButton:

Public Member Functions

 ToggleButton (Image *up_image=0, Image *down_image=0, Image *hover_image=0, const std::string &caption="", const std::string &group="")
 Constructor. More...
 
 ~ToggleButton ()
 Destructor. More...
 
void draw (Graphics *graphics)
 Draws the button. More...
 
void adjustSize ()
 Adjust size to fit image and caption. More...
 
void setUpImage (Image *image)
 Sets the image that will be displayed when the button isn't toggled. More...
 
void setDownImage (Image *image)
 Sets the image that will be displayed when the button is toggled or pressed. More...
 
void setHoverImage (Image *image)
 Sets the image which will be displayed when the mouse cursor is over the button. More...
 
void setDownOffset (int32_t x, int32_t y)
 Sets the number of pixels the image or text will be offset from the top left corner of button when the button is pressed or toggled. More...
 
int32_t getDownXOffset () const
 Gets the number of pixels the image or text will be offset from the left of button when the button is pressed or toggled. More...
 
int32_t getDownYOffset () const
 Gets the number of pixels the image or text will be offset from the top of button when the button is pressed or toggled. More...
 
bool isToggled () const
 Checks if the radio button is selected. More...
 
void setToggled (bool toggled)
 Sets the radio button to selected or not. More...
 
void setGroup (const std::string &group)
 Sets the group the toggle button should belong to. More...
 
const std::string & getGroup () const
 Gets the group the toggle button belongs to. More...
 

Protected Member Functions

void action (const ActionEvent &actionEvent)
 Toggle button when it is activated. More...
 

Private Types

typedef std::multimap
< std::string, ToggleButton * > 
GroupMap
 Typedef. More...
 
typedef GroupMap::iterator GroupIterator
 Typedef. More...
 

Private Attributes

Image * m_upImage
 
Image * m_downImage
 
Image * m_hoverImage
 
int32_t x_downoffset
 
int32_t y_downoffset
 
bool m_toggled
 Whether the button is toggled or not. More...
 
std::string m_group
 Holds the group of the toggle button. More...
 

Static Private Attributes

static GroupMap m_groupMap
 Holds all available toggle button groups. More...
 

Detailed Description

An implementation of a toggleable button.

If the button is in a group, all other buttons in that group will be untoggled when a button gets toggled. If the button is already toggled, you can untoggle it by clicking on it.

Definition at line 47 of file togglebutton.h.

Member Typedef Documentation

typedef GroupMap::iterator gcn::ToggleButton::GroupIterator
private

Typedef.

Definition at line 204 of file togglebutton.h.

typedef std::multimap<std::string, ToggleButton *> gcn::ToggleButton::GroupMap
private

Typedef.

Definition at line 199 of file togglebutton.h.

Constructor & Destructor Documentation

gcn::ToggleButton::ToggleButton ( Image *  up_image = 0,
Image *  down_image = 0,
Image *  hover_image = 0,
const std::string &  caption = "",
const std::string &  group = "" 
)

Constructor.

Parameters
up_imageImage displayed when the button isn't toggled
down_imageImage displayed when the button is toggled
hover_imageImage displayed when the mouse cursor is over button
captionText to be displayed on button
groupThe group the button belongs to

Definition at line 48 of file togglebutton.cpp.

References adjustSize(), m_group, m_hoverImage, m_toggled, and setGroup().

gcn::ToggleButton::~ToggleButton ( )

Destructor.

Definition at line 67 of file togglebutton.cpp.

References setGroup().

Member Function Documentation

void gcn::ToggleButton::action ( const ActionEvent &  actionEvent)
protected

Toggle button when it is activated.

Parameters
actionEventActionEvent object

Definition at line 169 of file togglebutton.cpp.

References m_toggled, and setToggled().

void gcn::ToggleButton::adjustSize ( )

Adjust size to fit image and caption.

Definition at line 173 of file togglebutton.cpp.

References m_downImage, m_hoverImage, and m_upImage.

Referenced by setDownImage(), setHoverImage(), setUpImage(), and ToggleButton().

+ Here is the caller graph for this function:

void gcn::ToggleButton::draw ( Graphics *  graphics)

Draws the button.

Definition at line 76 of file togglebutton.cpp.

References gcn::_log, FL_WARN, m_downImage, m_hoverImage, m_toggled, m_upImage, x_downoffset, and y_downoffset.

int32_t gcn::ToggleButton::getDownXOffset ( ) const

Gets the number of pixels the image or text will be offset from the left of button when the button is pressed or toggled.

Returns
Offset from left when button is pressed
See Also
setDownOffset

Definition at line 259 of file togglebutton.cpp.

References x_downoffset.

int32_t gcn::ToggleButton::getDownYOffset ( ) const

Gets the number of pixels the image or text will be offset from the top of button when the button is pressed or toggled.

Returns
Offset from top when button is pressed
See Also
setDownOffset

Definition at line 263 of file togglebutton.cpp.

References y_downoffset.

const std::string & gcn::ToggleButton::getGroup ( ) const

Gets the group the toggle button belongs to.

Returns
The group the toggle button belongs to.
See Also
setGroup

Definition at line 255 of file togglebutton.cpp.

References m_group.

bool gcn::ToggleButton::isToggled ( ) const

Checks if the radio button is selected.

Returns
True if the radio button is selecte, false otherwise.
See Also
setSelected

Definition at line 213 of file togglebutton.cpp.

References m_toggled.

void gcn::ToggleButton::setDownImage ( Image *  image)

Sets the image that will be displayed when the button is toggled or pressed.

Parameters
imageImage to be displayed

Definition at line 203 of file togglebutton.cpp.

References adjustSize(), and m_downImage.

void gcn::ToggleButton::setDownOffset ( int32_t  x,
int32_t  y 
)

Sets the number of pixels the image or text will be offset from the top left corner of button when the button is pressed or toggled.

Parameters
xOffset from left
yOffset from top
See Also
getDownXOffset
getDownYOffset

Definition at line 71 of file togglebutton.cpp.

References x_downoffset, and y_downoffset.

void gcn::ToggleButton::setGroup ( const std::string &  group)

Sets the group the toggle button should belong to.

Note that a toggle button group is unique per application, not per Gui object as the group is stored in a static map.

Parameters
groupThe name of the group.
See Also
getGroup

Definition at line 233 of file togglebutton.cpp.

References m_group, and m_groupMap.

Referenced by ToggleButton(), and ~ToggleButton().

+ Here is the caller graph for this function:

void gcn::ToggleButton::setHoverImage ( Image *  image)

Sets the image which will be displayed when the mouse cursor is over the button.

Parameters
imageImage to be displayed

Definition at line 208 of file togglebutton.cpp.

References adjustSize(), and m_hoverImage.

void gcn::ToggleButton::setToggled ( bool  toggled)

Sets the radio button to selected or not.

Parameters
toggledTrue if the radio button should be selected, false otherwise.
See Also
isSelected

Definition at line 217 of file togglebutton.cpp.

References m_group, m_groupMap, and m_toggled.

Referenced by action().

+ Here is the caller graph for this function:

void gcn::ToggleButton::setUpImage ( Image *  image)

Sets the image that will be displayed when the button isn't toggled.

Parameters
imageImage to be displayed

Definition at line 198 of file togglebutton.cpp.

References adjustSize(), and m_upImage.

Member Data Documentation

Image* gcn::ToggleButton::m_downImage
private

Definition at line 175 of file togglebutton.h.

Referenced by adjustSize(), draw(), and setDownImage().

std::string gcn::ToggleButton::m_group
private

Holds the group of the toggle button.

Definition at line 194 of file togglebutton.h.

Referenced by getGroup(), setGroup(), setToggled(), and ToggleButton().

ToggleButton::GroupMap gcn::ToggleButton::m_groupMap
staticprivate

Holds all available toggle button groups.

Definition at line 209 of file togglebutton.h.

Referenced by setGroup(), and setToggled().

Image* gcn::ToggleButton::m_hoverImage
private

Definition at line 178 of file togglebutton.h.

Referenced by adjustSize(), draw(), setHoverImage(), and ToggleButton().

bool gcn::ToggleButton::m_toggled
private

Whether the button is toggled or not.

Definition at line 188 of file togglebutton.h.

Referenced by action(), draw(), isToggled(), setToggled(), and ToggleButton().

Image* gcn::ToggleButton::m_upImage
private

Definition at line 172 of file togglebutton.h.

Referenced by adjustSize(), draw(), and setUpImage().

int32_t gcn::ToggleButton::x_downoffset
private

Definition at line 182 of file togglebutton.h.

Referenced by draw(), getDownXOffset(), and setDownOffset().

int32_t gcn::ToggleButton::y_downoffset
private

Definition at line 183 of file togglebutton.h.

Referenced by draw(), getDownYOffset(), and setDownOffset().


The documentation for this class was generated from the following files: