cangine
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
cangine::Button Class Reference

Clickable button game object with a text label. More...

#include <button_object.hpp>

Inheritance diagram for cangine::Button:
Inheritance graph
[legend]
Collaboration diagram for cangine::Button:
Collaboration graph
[legend]

Public Member Functions

 Button (std::string text, Vector3 position=Vector3(0, 0, 0), Color foreColor=Colors::BLACK, Color hoverColor=Colors::GRAY, Color focusColor=Colors::DARK_GRAY, Color backgroundColor=Colors::WHITE)
 Constructs a button.
 
void registerOnClickEvent (std::function< void(const MouseEvent *)> handler)
 Registers a callback invoked when the button is clicked.
 
void setTexture (Texture *textureIn)
 Sets the button's background texture.
 
Texture * getTexture ()
 Returns the button's background texture.
 
- Public Member Functions inherited from cangine::Label
 Label (std::string text="Label", Vector3 position=Vector3(0, 0, 80))
 Constructs a label.
 
std::string getText ()
 Returns the current text.
 
Vector2 getSize ()
 Returns the rendered size of the text.
 
int getFontHeight ()
 Returns the font pixel height.
 
void setText (std::string text)
 Sets the displayed text.
 
void setFontHeight (int heightIn)
 Sets the font pixel height.
 
void setColor (Color colorIn)
 Sets the text color.
 
void setBackgroundColor (Color colorIn)
 Sets the background color behind the text.
 
TextRendererComponent * getTextRendererComponent ()
 Returns the underlying text renderer component.
 
- Public Member Functions inherited from cangine::GameObject
 GameObject ()
 
virtual ~GameObject ()
 
virtual void onUpdate (double deltaTime)
 Per-frame update hook.
 
virtual void onMouseEvent (const MouseEvent *e)
 Mouse event hook.
 
virtual void onDisable ()
 Called when the object becomes inactive.
 
virtual void onEnable ()
 Called when the object becomes active.
 
void destroy ()
 Marks the object for destruction by the ObjectManager.
 
template<typename T >
void appendComponent (T *component)
 Attaches an existing component to this object.
 
template<typename T >
void destroyComponent ()
 Destroys and removes the first component of a type.
 
template<typename T >
T * getComponent ()
 Returns the first attached component of a type.
 
template<typename T >
std::vector< T * > getComponents ()
 Returns all attached components of a type.
 
template<typename T , typename... Args>
T * newComponent (Args &&... args)
 Constructs a component in place and attaches it.
 
void setActive (bool a)
 Activates or deactivates the object.
 
bool isActive ()
 Reports whether the object is active.
 

Private Member Functions

void onClick (const MouseEvent *e)
 Invokes all registered click handlers.
 

Private Attributes

std::vector< std::function< void(const MouseEvent *)> > onClickHandlers
 Registered click callbacks.
 
ButtonComponent * btnComponent
 Component driving button behavior.
 

Friends

class ButtonComponent
 

Detailed Description

Clickable button game object with a text label.

Extends Label with a ButtonComponent for hover/press visuals and lets callers register click handlers.

Constructor & Destructor Documentation

◆ Button()

cangine::Button::Button ( std::string  text,
Vector3  position = Vector3(0, 0, 0),
Color  foreColor = Colors::BLACK,
Color  hoverColor = Colors::GRAY,
Color  focusColor = Colors::DARK_GRAY,
Color  backgroundColor = Colors::WHITE 
)

Constructs a button.

Parameters
textButton label text.
positionPosition of the button (z is the layer).
foreColorLabel text color.
hoverColorBackground color while hovered.
focusColorBackground color while pressed.
backgroundColorDefault background color.

Member Function Documentation

◆ getTexture()

Texture * cangine::Button::getTexture ( )

Returns the button's background texture.

Returns
The current texture.

◆ onClick()

void cangine::Button::onClick ( const MouseEvent *  e)
private

Invokes all registered click handlers.

Parameters
eMouse event that triggered the click.

◆ registerOnClickEvent()

void cangine::Button::registerOnClickEvent ( std::function< void(const MouseEvent *)>  handler)
inline

Registers a callback invoked when the button is clicked.

Parameters
handlerClick handler to add.

◆ setTexture()

void cangine::Button::setTexture ( Texture *  textureIn)

Sets the button's background texture.

Parameters
textureInTexture to use.

Friends And Related Symbol Documentation

◆ ButtonComponent

Member Data Documentation

◆ btnComponent

ButtonComponent* cangine::Button::btnComponent
private

Component driving button behavior.

◆ onClickHandlers

std::vector<std::function<void(const MouseEvent*)> > cangine::Button::onClickHandlers
private

Registered click callbacks.


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