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

Component providing clickable-button behavior and visuals. More...

#include <button_component.hpp>

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

Public Member Functions

void firstFrame () override
 Called once before the first frame update.
 
void onMouseEvent (const MouseEvent *e) override
 Called when a mouse event is dispatched to the owning object.
 
void setTexture (Texture *textureIn)
 Sets the button's background texture.
 
Texture * getTexture ()
 Returns the button's background texture.
 
- Public Member Functions inherited from cangine::IComponent
 IComponent (GameObject *gameObject=nullptr)
 Constructs the component, optionally bound to a game object.
 
virtual ~IComponent ()
 
GameObject * getGameObject () const
 Returns the game object this component is attached to.
 
virtual void frame (double deltaTime)
 Called every frame to update the component.
 

Public Attributes

Color hoverColor = Colors::GRAY
 Background color while hovered.
 
Color focusColor = Colors::DARK_GRAY
 Background color while pressed.
 
Color backgroundColor = Colors::WHITE
 Default background color.
 
- Public Attributes inherited from cangine::IComponent
bool isUnique = true
 If true, only one of this component type may exist per object.
 

Private Attributes

bool mouseHover = false
 Whether the cursor is over the button.
 
bool mousePressed = false
 Whether the button is currently pressed.
 
Button * button
 Owning button object.
 
TextRendererComponent * trc = nullptr
 Label text renderer, if present.
 

Detailed Description

Component providing clickable-button behavior and visuals.

Tracks hover/press state from mouse events and swaps the background color accordingly. Attaches to a Button game object.

Member Function Documentation

◆ firstFrame()

void cangine::ButtonComponent::firstFrame ( )
overridevirtual

Called once before the first frame update.

Reimplemented from cangine::IComponent.

◆ getTexture()

Texture * cangine::ButtonComponent::getTexture ( )

Returns the button's background texture.

Returns
The current texture.

◆ onMouseEvent()

void cangine::ButtonComponent::onMouseEvent ( const MouseEvent *  e)
overridevirtual

Called when a mouse event is dispatched to the owning object.

Parameters
eThe mouse event.

Reimplemented from cangine::IComponent.

◆ setTexture()

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

Sets the button's background texture.

Parameters
textureInTexture to use.

Member Data Documentation

◆ backgroundColor

Color cangine::ButtonComponent::backgroundColor = Colors::WHITE

Default background color.

◆ button

Button* cangine::ButtonComponent::button
private

Owning button object.

◆ focusColor

Color cangine::ButtonComponent::focusColor = Colors::DARK_GRAY

Background color while pressed.

◆ hoverColor

Color cangine::ButtonComponent::hoverColor = Colors::GRAY

Background color while hovered.

◆ mouseHover

bool cangine::ButtonComponent::mouseHover = false
private

Whether the cursor is over the button.

◆ mousePressed

bool cangine::ButtonComponent::mousePressed = false
private

Whether the button is currently pressed.

◆ trc

TextRendererComponent* cangine::ButtonComponent::trc = nullptr
private

Label text renderer, if present.


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