libgui 2.01
libgui is a GUI library for the GameCube, Wii, and Wii U
 
Loading...
Searching...
No Matches
GuiButton Class Reference

Display, manage, and manipulate buttons in the GUI. More...

#include <GuiButton.h>

Inheritance diagram for GuiButton:
[legend]

Public Member Functions

 GuiButton (int w=0, int h=0)
 Constructor.
 
 ~GuiButton ()
 Destructor.
 
void setImage (GuiElement *i)
 Sets the button's image.
 
void setImageOver (GuiElement *i)
 Sets the button's image on over.
 
void setImageHold (GuiElement *i)
 Sets the button's image on hold.
 
void setImageClick (GuiElement *i)
 Sets the button's image on click.
 
void setIcon (GuiElement *i)
 Sets the button's icon.
 
void setIconOver (GuiElement *i)
 Sets the button's icon on over.
 
void setIconHold (GuiElement *i)
 Sets the button's icon on hold.
 
void setIconClick (GuiElement *i)
 Sets the button's icon on click.
 
void setLabel (GuiText *t, int n=0)
 Sets the button's label.
 
void setLabelOver (GuiText *t, int n=0)
 Sets the button's label on over (eg: different colored text)
 
void setLabelHold (GuiText *t, int n=0)
 Sets the button's label on hold.
 
void setLabelClick (GuiText *t, int n=0)
 Sets the button's label on click.
 
void setSoundOver (GuiSound *s)
 Sets the sound to play on over.
 
void setSoundHold (GuiSound *s)
 Sets the sound to play on hold.
 
void setSoundClick (GuiSound *s)
 Sets the sound to play on click.
 
void draw () override
 Constantly called to draw the GuiButton.
 
void resetText ()
 Resets the text for all contained elements.
 
void setState (STATE s, int c=-1) override
 Sets the state and mirrors it into the button's images and icons, so a state-aware element such as GuiShape can restyle itself.
 
void resetState () override
 Resets the state and mirrors it into the button's images and icons.
 
void update (InputController *c)
 Constantly called to allow the GuiButton to respond to updated input data.
 
- Public Member Functions inherited from GuiElement
 GuiElement ()
 Constructor.
 
virtual ~GuiElement ()
 Destructor.
 
void setParent (GuiElement *e)
 Set the element's parent.
 
GuiElement * getParent ()
 Gets the element's parent.
 
virtual void remove (GuiElement *)
 Removes the specified child.
 
void setRemoveOnDestroy (bool autoRemove)
 Whether to notify parent on destruction to allow removal.
 
int getLeft ()
 Gets the current leftmost coordinate of the element Considers horizontal alignment, x offset, width, and parent element's GetLeft() / GetWidth() values.
 
int getTop ()
 Gets the current topmost coordinate of the element Considers vertical alignment, y offset, height, and parent element's GetTop() / GetHeight() values.
 
void setMinY (int y)
 Sets the minimum y offset of the element.
 
int getMinY ()
 Gets the minimum y offset of the element.
 
void setMaxY (int y)
 Sets the maximum y offset of the element.
 
int getMaxY ()
 Gets the maximum y offset of the element.
 
void setMinX (int x)
 Sets the minimum x offset of the element.
 
int getMinX ()
 Gets the minimum x offset of the element.
 
void setMaxX (int x)
 Sets the maximum x offset of the element.
 
int getMaxX ()
 Gets the maximum x offset of the element.
 
int getWidth ()
 Gets the current width of the element.
 
int getHeight ()
 Gets the height of the element.
 
void setSize (int w, int h)
 Sets the size (width/height) of the element.
 
bool isVisible ()
 Checks whether or not the element is visible.
 
bool isSelectable ()
 Checks whether or not the element is selectable.
 
bool isClickable ()
 Checks whether or not the element is clickable.
 
bool isHoldable ()
 Checks whether or not the element is holdable.
 
void setSelectable (bool s)
 Sets whether or not the element is selectable.
 
void setClickable (bool c)
 Sets whether or not the element is clickable.
 
void setHoldable (bool h)
 Sets whether or not the element is holdable.
 
STATE getState ()
 Gets the element's current state.
 
int getStateChan ()
 Gets the controller channel that last changed the element's state.
 
void setAlpha (int a)
 Sets the element's alpha value.
 
int getAlpha ()
 Gets the element's alpha value Considers alpha, alphaDyn, and the parent element's GetAlpha() value.
 
void setScale (float s)
 Sets the element's x and y scale.
 
void setScaleX (float s)
 Sets the element's x scale.
 
void setScaleY (float s)
 Sets the element's y scale.
 
void setScale (int w, int h)
 Sets the element's x and y scale, using the provided max width/height.
 
float getScale ()
 Gets the element's current scale Considers scale, scaleDyn, and the parent element's GetScale() value.
 
float getScaleX ()
 Gets the element's current x scale Considers scale, scaleDyn, and the parent element's GetScale() value.
 
float getScaleY ()
 Gets the element's current y scale Considers scale, scaleDyn, and the parent element's GetScale() value.
 
void setTrigger (GuiTrigger *t)
 Set a new GuiTrigger for the element.
 
void setTrigger (uint8_t i, GuiTrigger *t)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool isRumble ()
 Checks whether rumble was requested by the element.
 
void setRumble (bool r)
 Sets whether or not the element is requesting a rumble event.
 
void setEffect (int e, int a, int t=0)
 Set an effect for the element.
 
void setEffectOnOver (int e, int a, int t=0)
 Sets an effect to be enabled on wiimote cursor over.
 
void setEffectGrow ()
 Shortcut to SetEffectOnOver(EFFECT::SCALE, 4, 110)
 
int getEffect ()
 Gets the current element effects.
 
bool isInside (int x, int y)
 Checks whether the specified coordinates are within the element's boundaries.
 
void setPosition (int x, int y)
 Sets the element's position.
 
void updateEffects ()
 Updates the element's effects (dynamic values) Called by Draw(), used for animation purposes.
 
void setUpdateCallback (UpdateCallback u)
 Sets a function to called after after Update() Callback function can be used to response to changes in the state of the element, and/or update the element's attributes.
 
int isFocused ()
 Checks whether the element is in focus.
 
virtual void setVisible (bool v)
 Sets the element's visibility.
 
virtual void setFocus (int f)
 Sets the element's focus.
 
virtual int getSelected ()
 Gets whether or not the element is in STATE::SELECTED.
 
virtual void setAlignment (ALIGN_H hor, ALIGN_V vert)
 Sets the element's alignment respective to its parent element.
 
virtual void getNaturalSize (int &w, int &h)
 Layout protocol: how a layout container (GuiRow, GuiColumn, GuiGrid, GuiOverlay) asks about and arranges its children.
 
virtual void setLayoutPosition (int x, int y)
 Places the element so its top-left corner is at (x, y) relative to its parent's top-left (default: LEFT/TOP alignment plus an offset)
 
virtual void setLayoutSize (int w, int h)
 Gives the element a size chosen by a container (default: sets width and height)
 
virtual void layout ()
 Brings the element's own layout up to date.
 
virtual void collectNavigable (std::vector< GuiElement * > &out)
 Appends the elements that selection can move between (default: this element; layout containers add their children instead, so the D-pad moves through them)
 

Protected Attributes

GuiElement * image
 Button image (default): a GuiImage, GuiShape or any element.
 
GuiElement * imageOver
 Button image for STATE::SELECTED.
 
GuiElement * imageHold
 Button image for STATE::HELD.
 
GuiElement * imageClick
 Button image for STATE::CLICKED.
 
GuiElement * icon
 Button icon (drawn after button image)
 
GuiElement * iconOver
 Button icon for STATE::SELECTED.
 
GuiElement * iconHold
 Button icon for STATE::HELD.
 
GuiElement * iconClick
 Button icon for STATE::CLICKED.
 
GuiText * label [MAX_BTN_LABELS]
 Label(s) to display (default)
 
GuiText * labelOver [MAX_BTN_LABELS]
 Label(s) to display for STATE::SELECTED.
 
GuiText * labelHold [MAX_BTN_LABELS]
 Label(s) to display for STATE::HELD.
 
GuiText * labelClick [MAX_BTN_LABELS]
 Label(s) to display for STATE::CLICKED.
 
GuiSound * soundOver
 Sound to play for STATE::SELECTED.
 
GuiSound * soundHold
 Sound to play for STATE::HELD.
 
GuiSound * soundClick
 Sound to play for STATE::CLICKED.
 
- Protected Attributes inherited from GuiElement
GuiTrigger * trigger [MAX_TRIGGERS]
 GuiTriggers (input actions) that this element responds to.
 
UpdateCallback updateCB
 Callback function to call when this element is updated.
 
GuiElement * parentElement
 Parent element.
 
bool removeOnDestroy
 Whether to instruct parent to remove this element when it is destroyed.
 
int focus
 Element focus (-1 = focus disabled, 0 = not focused, 1 = focused)
 
int width
 Element width.
 
int height
 Element height.
 
int xoffset
 Element X offset.
 
int yoffset
 Element Y offset.
 
int ymin
 Element's min Y offset allowed.
 
int ymax
 Element's max Y offset allowed.
 
int xmin
 Element's min X offset allowed.
 
int xmax
 Element's max X offset allowed.
 
int xoffsetDyn
 Element X offset, dynamic (added to xoffset value for animation effects)
 
int yoffsetDyn
 Element Y offset, dynamic (added to yoffset value for animation effects)
 
int alpha
 Element alpha value (0-255)
 
int alphaDyn
 Element alpha, dynamic (multiplied by alpha value for blending/fading effects)
 
float xscale
 Element X scale (1 = 100%)
 
float yscale
 Element Y scale (1 = 100%)
 
float scaleDyn
 Element scale, dynamic (multiplied by alpha value for blending/fading effects)
 
int effects
 Currently enabled effect(s).
 
int effectAmount
 Effect amount.
 
int effectTarget
 Effect target amount.
 
int effectsOver
 Effects to enable when wiimote cursor is over this element.
 
int effectAmountOver
 EffectAmount to set when wiimote cursor is over this element.
 
int effectTargetOver
 EffectTarget to set when wiimote cursor is over this element.
 
ALIGN_H alignmentHor
 Horizontal element alignment, respective to parent element (LEFT, RIGHT, CENTRE)
 
ALIGN_V alignmentVert
 Horizontal element alignment, respective to parent element (TOP, BOTTOM, MIDDLE)
 
STATE state
 Element state (DEFAULT, SELECTED, CLICKED, DISABLED)
 
int stateChan
 Which controller channel is responsible for the last change in state.
 
bool selectable
 Whether or not this element selectable (can change to SELECTED state)
 
bool clickable
 Whether or not this element is clickable (can change to CLICKED state)
 
bool holdable
 Whether or not this element is holdable (can change to HELD state)
 
bool visible
 Visibility of the element.
 
bool rumble
 Wiimote rumble (on/off) - set to on when this element requests a rumble event.
 

Detailed Description

Display, manage, and manipulate buttons in the GUI.

Buttons can have images, icons, text, and sound set (all of which are optional)

Definition at line 12 of file GuiButton.h.

Constructor & Destructor Documentation

◆ GuiButton()

GuiButton::GuiButton ( int w = 0,
int h = 0 )

Constructor.

Parameters
wWidth
hHeight

Definition at line 9 of file GuiButton.cpp.

◆ ~GuiButton()

GuiButton::~GuiButton ( )

Destructor.

Definition at line 38 of file GuiButton.cpp.

Member Function Documentation

◆ draw()

void GuiButton::draw ( )
overridevirtual

Constantly called to draw the GuiButton.

Draw the button on screen.

Implements GuiElement.

Definition at line 140 of file GuiButton.cpp.

◆ resetState()

void GuiButton::resetState ( )
overridevirtual

Resets the state and mirrors it into the button's images and icons.

Reimplemented from GuiElement.

Definition at line 115 of file GuiButton.cpp.

◆ resetText()

void GuiButton::resetText ( )
virtual

Resets the text for all contained elements.

Reimplemented from GuiElement.

Definition at line 180 of file GuiButton.cpp.

◆ setIcon()

void GuiButton::setIcon ( GuiElement * i)

Sets the button's icon.

Parameters
iPointer to a GuiImage, GuiShape or other element

Definition at line 62 of file GuiButton.cpp.

◆ setIconClick()

void GuiButton::setIconClick ( GuiElement * i)

Sets the button's icon on click.

Parameters
iPointer to a GuiImage, GuiShape or other element

Definition at line 77 of file GuiButton.cpp.

◆ setIconHold()

void GuiButton::setIconHold ( GuiElement * i)

Sets the button's icon on hold.

Parameters
iPointer to a GuiImage, GuiShape or other element

Definition at line 72 of file GuiButton.cpp.

◆ setIconOver()

void GuiButton::setIconOver ( GuiElement * i)

Sets the button's icon on over.

Parameters
iPointer to a GuiImage, GuiShape or other element

Definition at line 67 of file GuiButton.cpp.

◆ setImage()

void GuiButton::setImage ( GuiElement * i)

Sets the button's image.

Parameters
iPointer to a GuiImage, GuiShape or other element

Definition at line 42 of file GuiButton.cpp.

◆ setImageClick()

void GuiButton::setImageClick ( GuiElement * i)

Sets the button's image on click.

Parameters
iPointer to a GuiImage, GuiShape or other element

Definition at line 57 of file GuiButton.cpp.

◆ setImageHold()

void GuiButton::setImageHold ( GuiElement * i)

Sets the button's image on hold.

Parameters
iPointer to a GuiImage, GuiShape or other element

Definition at line 52 of file GuiButton.cpp.

◆ setImageOver()

void GuiButton::setImageOver ( GuiElement * i)

Sets the button's image on over.

Parameters
iPointer to a GuiImage, GuiShape or other element

Definition at line 47 of file GuiButton.cpp.

◆ setLabel()

void GuiButton::setLabel ( GuiText * t,
int n = 0 )

Sets the button's label.

Parameters
tPointer to GuiText object
nIndex of label to set (optional, default is 0)

Definition at line 82 of file GuiButton.cpp.

◆ setLabelClick()

void GuiButton::setLabelClick ( GuiText * t,
int n = 0 )

Sets the button's label on click.

Parameters
tPointer to GuiText object
nIndex of label to set (optional, default is 0)

Definition at line 100 of file GuiButton.cpp.

◆ setLabelHold()

void GuiButton::setLabelHold ( GuiText * t,
int n = 0 )

Sets the button's label on hold.

Parameters
tPointer to GuiText object
nIndex of label to set (optional, default is 0)

Definition at line 94 of file GuiButton.cpp.

◆ setLabelOver()

void GuiButton::setLabelOver ( GuiText * t,
int n = 0 )

Sets the button's label on over (eg: different colored text)

Parameters
tPointer to GuiText object
nIndex of label to set (optional, default is 0)

Definition at line 88 of file GuiButton.cpp.

◆ setSoundClick()

void GuiButton::setSoundClick ( GuiSound * s)

Sets the sound to play on click.

Parameters
sPointer to GuiSound object

Definition at line 132 of file GuiButton.cpp.

◆ setSoundHold()

void GuiButton::setSoundHold ( GuiSound * s)

Sets the sound to play on hold.

Parameters
sPointer to GuiSound object

Definition at line 128 of file GuiButton.cpp.

◆ setSoundOver()

void GuiButton::setSoundOver ( GuiSound * s)

Sets the sound to play on over.

Parameters
sPointer to GuiSound object

Definition at line 124 of file GuiButton.cpp.

◆ setState()

void GuiButton::setState ( STATE s,
int c = -1 )
overridevirtual

Sets the state and mirrors it into the button's images and icons, so a state-aware element such as GuiShape can restyle itself.

Reimplemented from GuiElement.

Definition at line 106 of file GuiButton.cpp.

◆ update()

void GuiButton::update ( InputController * c)
virtual

Constantly called to allow the GuiButton to respond to updated input data.

Parameters
cPointer to a InputController, containing the current input data

Reimplemented from GuiElement.

Definition at line 191 of file GuiButton.cpp.

Member Data Documentation

◆ icon

GuiElement* GuiButton::icon
protected

Button icon (drawn after button image)

Definition at line 87 of file GuiButton.h.

◆ iconClick

GuiElement* GuiButton::iconClick
protected

Button icon for STATE::CLICKED.

Definition at line 90 of file GuiButton.h.

◆ iconHold

GuiElement* GuiButton::iconHold
protected

Button icon for STATE::HELD.

Definition at line 89 of file GuiButton.h.

◆ iconOver

GuiElement* GuiButton::iconOver
protected

Button icon for STATE::SELECTED.

Definition at line 88 of file GuiButton.h.

◆ image

GuiElement* GuiButton::image
protected

Button image (default): a GuiImage, GuiShape or any element.

Definition at line 83 of file GuiButton.h.

◆ imageClick

GuiElement* GuiButton::imageClick
protected

Button image for STATE::CLICKED.

Definition at line 86 of file GuiButton.h.

◆ imageHold

GuiElement* GuiButton::imageHold
protected

Button image for STATE::HELD.

Definition at line 85 of file GuiButton.h.

◆ imageOver

GuiElement* GuiButton::imageOver
protected

Button image for STATE::SELECTED.

Definition at line 84 of file GuiButton.h.

◆ label

GuiText* GuiButton::label[MAX_BTN_LABELS]
protected

Label(s) to display (default)

Definition at line 91 of file GuiButton.h.

◆ labelClick

GuiText* GuiButton::labelClick[MAX_BTN_LABELS]
protected

Label(s) to display for STATE::CLICKED.

Definition at line 94 of file GuiButton.h.

◆ labelHold

GuiText* GuiButton::labelHold[MAX_BTN_LABELS]
protected

Label(s) to display for STATE::HELD.

Definition at line 93 of file GuiButton.h.

◆ labelOver

GuiText* GuiButton::labelOver[MAX_BTN_LABELS]
protected

Label(s) to display for STATE::SELECTED.

Definition at line 92 of file GuiButton.h.

◆ soundClick

GuiSound* GuiButton::soundClick
protected

Sound to play for STATE::CLICKED.

Definition at line 97 of file GuiButton.h.

◆ soundHold

GuiSound* GuiButton::soundHold
protected

Sound to play for STATE::HELD.

Definition at line 96 of file GuiButton.h.

◆ soundOver

GuiSound* GuiButton::soundOver
protected

Sound to play for STATE::SELECTED.

Definition at line 95 of file GuiButton.h.


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