Brunot
Loading...
Searching...
No Matches
Button Class Reference

A class that can be "activated" to broadcast a message. More...

#include <Button.h>

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

Public Member Functions

 Button ()
 Button (const Button &)
auto operator= (const Button &) -> Button &=default
 ~Button () override=default
 Button (Button &&other) noexcept
auto operator= (Button &&other) noexcept -> Button &=default
auto clone () const -> std::unique_ptr< GameObject > override
 makes a copy a GameObject even if it's held polymorphically
auto componentShowMenu () -> void override
auto onUpdate (float dt) -> void override
 called once every frame.
auto endWindow () -> void override
 currently unused, but intended to but was assumed to be necessary for a proper ImGui editor
auto onRender () -> void override
 called every frame after update has been called for every object.
auto onEnterEngine () -> void override
 hook that is called when a GameObject enters the Engine tree.
auto load (Stream &stream) -> void override
 Implementations will load the state of a GameObject from a th::Json Object.
auto save (Stream &stream) const -> void override
 Implementations will load the state of a GameObject to a th::Json object.
auto select () -> void
 Selects a button (e.g. like clicking on it). Broadcasts an event that this button was selected.
auto highlight () const -> void
 Calls the buttons HighlightLambda. Intended to trigger when a selector moves onto it, but currently untested.
auto undoHighlight () const -> void
 Calls the buttons UndoHighlightLambda. Intended to trigger when a selector moves off of it, but currently untested.
auto setEvent (std::string newEvent) -> void
 Changes the event that this button broadcasts when selected.
auto setSelectLambda (std::string newSelect) -> void
 Changes the lambda that the button calls when it is selected, but before it broadcasts.
auto setHighlightLambda (std::string newHighlight) -> void
 Changes the buttons highlight lambda.
auto setUndoHighlightLambda (std::string newUndoHighlight) -> void
 Changes the buttons undo highlight lambda.
auto linkMessages () -> void
Public Member Functions inherited from Component
auto getType () const -> ComponentTypeEnum
auto getKey () const -> Key override
 Generates a unique Key that corresponds to the GameObject.
auto showMenu () -> void override
 Called before update each frame, for calling ImGui editor code relevant to the gameObject.
auto getEntityParent () const -> Entity *
 gets the parent as an Entity.
Public Member Functions inherited from GameObject
 GameObject (std::string typeName, gobj::Type parentType, gobj::Type type)
 constructor for gameobject.
virtual ~GameObject ()
 destructor for GameObject.
 GameObject (const GameObject &other)
 Copy Constructor.
auto operator= (const GameObject &other) -> GameObject &
 copy assignment operator
 GameObject (GameObject &&other) noexcept
 Move constructor.
auto operator= (GameObject &&other) noexcept -> GameObject &
 Move assignment operator.
virtual auto update (float dt) -> void
 called once every frame.
virtual auto render () -> void
 called every frame after update has been called for every object.
virtual auto destroy () -> void
 Marks an GameObject to be destroyed.
virtual auto for_each (std::function< void(GameObject &)> func) -> void
 applies a function to every child.
virtual auto for_each (std::function< void(const GameObject &)> func) const -> void
 applies a const function to every child.
virtual auto getParent () const -> GameObject *
 Gets the parent of a GameObject.
virtual auto parentTo (GameObject *newParent) -> bool
 Sets the GameObject as a child of another GameObject.
auto getInternalParent () const -> GameObject *
 returns the actual owning parent of the GameObject
virtual auto addChild (std::unique_ptr< GameObject > newChild) -> bool
 Adds a child to a GameObject.
auto destroyed () const -> bool
auto getUUID () const -> gobj::UUID
auto isUUID (gobj::UUID compareUUID) const -> bool
auto getName () const -> const std::string &
 Gets the type of the object as a string.
auto getNickname () const -> const std::string &
 Gets the nickname (custom, writable name) of a GameObject.
void calculateFormattedName () const
auto getFormattedName () const -> const std::string &
 combines a GameObjects Type, Nickname, and UUID into one string, for use with logging.
auto nameEquals (const std::string &compareString) const -> bool
 check whether a GameObjects typeName is equivilent to a given string.
auto isType (gobj::Type otherType) const -> bool
 check whether the GameObject is the same as a given type.
auto getObjectType () const -> gobj::Type
 gets the internal type of the GameObject, as an enum
auto setNickname (const std::string &newNickname) -> void
 sets the GameObjects nickname.
auto updates () const -> bool
auto renders () const -> bool
auto receivesMessages () const -> bool
auto isActive () const -> bool
virtual auto setShouldUpdate (const bool _shouldUpdate) -> void
 set whether the GameObject should update every frame, and whether all of it's children should update every frame
virtual auto setShouldRender (const bool _shouldRender) -> void
 set whether the GameObject should render every frame, and whether all of it's children should render every frame
virtual auto setShouldReceiveMessages (const bool _shouldReceiveMessages) -> void
 set whether the GameObject should Receive Messags, and whether all of it's children should receive messages
auto setActive (const bool shouldBeActive) -> void
 set the GameObject should update, render, and receive messages

Static Public Member Functions

static auto checkIfAnyButtonHasBeenPressed () -> bool
 Returns if any button has been pressed this frame.
static auto setIfAnyButtonHasBeenPressed (bool newState) -> void
 Sets the tracker of if any button has been pressed this frame.

Static Public Attributes

static constexpr auto DESIRED_BUTTON_SPEED = 500.f

Private Attributes

std::string buttonEvent
 The event that you want to broadcast when this button is selected.
std::string messageName
 The name of the message we want to create for broadcasting.
std::unique_ptr< MessagemessagePtr
 A pointer to the message that this button will broadcast when selected.
std::string selectLambdaName
std::string highlightLambdaName
std::string undoHighlightLambdaName
std::function< void(Entity *ent)> selectLambda
 Lambda called when the button is selected but BEFORE the message is broadcast. Intended for visual effects.
std::function< void(Entity *ent)> highlightLambda
 The Lambda called when the button is hovered over by a Selector. Intended for visual effects.
std::function< void(Entity *ent)> undoHighlightLambda
 The Lambda called when the button is no longer hovered over. Returns the button to its default state.

Static Private Attributes

static bool anyButtonHasTriggeredThisFrameAlready = false
 Bool to ensure only one button can activate than once a frame. Currently being updated by Input.

Friends

auto to_json (json &j, const Button &b) ->void
auto from_json (const json &j, Button &b) ->void

Additional Inherited Members

Public Types inherited from Component
enum  ComponentTypeEnum : unsigned short {
  cErrorType = 0 , cPhysics = 100 , cAnimation = 200 , cTransform = 300 ,
  cCollider = 400 , cSprite = 500 , cBehavior = 600 , cTable = 650 ,
  cCard = 700 , cDeck = 750 , cPlayer = 800 , cBoard = 850 ,
  cScene = 900 , cPauseScene = 915 , cMainScene = 920 , cMainMenuScene = 925 ,
  cConfirmDestructiveActionScene = 930 , cOptionsScene = 935 , cCreditsScene = 940 , cTutorialScene = 945 ,
  cBackground = 950 , cSplashScreenScene = 955 , cWinScreenScene = 960 , cFlags = 1000 ,
  cSelectable = 1100 , cMenu = 1200 , cActionProxy = 1300 , cEntityMover = 1400 ,
  cMenuItem = 1500 , cMenuPosition = 1525 , cSelector = 1600 , cButton = 1700
}
 This enum lists out every type of component we have. More...
Public Attributes inherited from GameObject
friend Entity
friend Node
friend ChildrenHandeler
friend Engine
Protected Member Functions inherited from Component
 Component (ComponentTypeEnum type, const char *typeName)
auto getComponentJson () const -> json
auto getChildren () const -> std::shared_ptr< std::vector< GameObject * > > override
 override for component to return a vector of no children
Protected Member Functions inherited from GameObject
auto setInternalParent (GameObject *parent) -> bool
 sets the internal parent of a GameObject directly, avoiding abstractions provided by ParentTo().
auto getGameObjectJson () const -> json
 Used for serializing GameObjects.
auto setGameObjectJson (const json &stream) -> void
 used for deserializing GameObjects
auto checkAddToSceneHook () -> void
 Determine if the GameObject was recently added to the engine, and if it was, call onEngineEnter.

Detailed Description

A class that can be "activated" to broadcast a message.

Designed to be used with a Selector, but can be selected without a Selector instance

Author
Ori Balashov (ori.b.nosp@m.alas.nosp@m.hov@d.nosp@m.igip.nosp@m.en.ed.nosp@m.u)
Date
2026 / 01 / 23

Constructor & Destructor Documentation

◆ Button() [1/3]

Button::Button ( )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Button() [2/3]

Button::Button ( const Button & other)
Here is the call graph for this function:

◆ ~Button()

Button::~Button ( )
overridedefault
Here is the call graph for this function:

◆ Button() [3/3]

Button::Button ( Button && other)
noexcept
Todo
: figure out how to move the std::string in button copy ctor
Here is the call graph for this function:

Member Function Documentation

◆ checkIfAnyButtonHasBeenPressed()

auto Button::checkIfAnyButtonHasBeenPressed ( ) ->bool
static

Returns if any button has been pressed this frame.

Here is the caller graph for this function:

◆ clone()

auto Button::clone ( ) const->std::unique_ptr< GameObject >
inlineoverridevirtual

makes a copy a GameObject even if it's held polymorphically

Warning
When overriding this function, make sure to set the parents object to this
Returns
a unique_ptr to a new stack allocated object that is a copy of the object

Implements GameObject.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ componentShowMenu()

auto Button::componentShowMenu ( ) ->void
overridevirtual

Reimplemented from Component.

Here is the call graph for this function:

◆ endWindow()

auto Button::endWindow ( ) ->void
inlineoverridevirtual

currently unused, but intended to but was assumed to be necessary for a proper ImGui editor

Implements GameObject.

◆ highlight()

auto Button::highlight ( ) const->void

Calls the buttons HighlightLambda. Intended to trigger when a selector moves onto it, but currently untested.

Here is the call graph for this function:

◆ linkMessages()

auto Button::linkMessages ( ) ->void
Here is the caller graph for this function:

◆ load()

auto Button::load ( Stream & stream) ->void
overridevirtual

Implementations will load the state of a GameObject from a th::Json Object.

Unimplemented in GameObject

Parameters
streamth::Json Object

Implements GameObject.

◆ onEnterEngine()

void Button::onEnterEngine ( ) ->void
overridevirtual

hook that is called when a GameObject enters the Engine tree.

The hook is called immedietly after a gameobject's parent is called. Functionality may not be correct if an object was removed from the engine then re-added

Reimplemented from GameObject.

Here is the call graph for this function:

◆ onRender()

auto Button::onRender ( ) ->void
overridevirtual

called every frame after update has been called for every object.

Generally used for rendering an object to the screen, when applicable. Unimplemented in GameObject

Implements GameObject.

◆ onUpdate()

auto Button::onUpdate ( float dt) ->void
overridevirtual

called once every frame.

Generally used for timers, movement, condition checks, etc. Unimplemented in GameObject

Parameters
dtthe time in seconds that has elapsed

Implements GameObject.

◆ operator=() [1/2]

auto Button::operator= ( Button && other) ->Button &=default
defaultnoexcept
Here is the call graph for this function:

◆ operator=() [2/2]

auto Button::operator= ( const Button & ) ->Button &=default
default
Here is the call graph for this function:

◆ save()

auto Button::save ( Stream & stream) const->void
overridevirtual

Implementations will load the state of a GameObject to a th::Json object.

Unimplemented in GameObject

Parameters
streamth::Json Object

Implements GameObject.

◆ select()

auto Button::select ( ) ->void

Selects a button (e.g. like clicking on it). Broadcasts an event that this button was selected.

Here is the call graph for this function:

◆ setEvent()

auto Button::setEvent ( std::string newEvent) ->void

Changes the event that this button broadcasts when selected.

◆ setHighlightLambda()

auto Button::setHighlightLambda ( std::string newHighlight) ->void

Changes the buttons highlight lambda.

Here is the call graph for this function:

◆ setIfAnyButtonHasBeenPressed()

auto Button::setIfAnyButtonHasBeenPressed ( bool newState) ->void
static

Sets the tracker of if any button has been pressed this frame.

Here is the caller graph for this function:

◆ setSelectLambda()

auto Button::setSelectLambda ( std::string newSelect) ->void

Changes the lambda that the button calls when it is selected, but before it broadcasts.

Here is the call graph for this function:

◆ setUndoHighlightLambda()

auto Button::setUndoHighlightLambda ( std::string newUndoHighlight) ->void

Changes the buttons undo highlight lambda.

Here is the call graph for this function:

◆ undoHighlight()

auto Button::undoHighlight ( ) const->void

Calls the buttons UndoHighlightLambda. Intended to trigger when a selector moves off of it, but currently untested.

Here is the call graph for this function:

◆ from_json

auto from_json ( const json & j,
Button & b )->void
friend

◆ to_json

auto to_json ( json & j,
const Button & b )->void
friend

Member Data Documentation

◆ anyButtonHasTriggeredThisFrameAlready

bool Button::anyButtonHasTriggeredThisFrameAlready = false
staticprivate

Bool to ensure only one button can activate than once a frame. Currently being updated by Input.

◆ buttonEvent

std::string Button::buttonEvent
private

The event that you want to broadcast when this button is selected.

◆ DESIRED_BUTTON_SPEED

auto Button::DESIRED_BUTTON_SPEED = 500.f
staticconstexpr

◆ highlightLambda

std::function<void(Entity* ent)> Button::highlightLambda
private

The Lambda called when the button is hovered over by a Selector. Intended for visual effects.

◆ highlightLambdaName

std::string Button::highlightLambdaName
private

◆ messageName

std::string Button::messageName
private

The name of the message we want to create for broadcasting.

◆ messagePtr

std::unique_ptr<Message> Button::messagePtr
private

A pointer to the message that this button will broadcast when selected.

◆ selectLambda

std::function<void(Entity* ent)> Button::selectLambda
private

Lambda called when the button is selected but BEFORE the message is broadcast. Intended for visual effects.

◆ selectLambdaName

std::string Button::selectLambdaName
private

◆ undoHighlightLambda

std::function<void(Entity* ent)> Button::undoHighlightLambda
private

The Lambda called when the button is no longer hovered over. Returns the button to its default state.

◆ undoHighlightLambdaName

std::string Button::undoHighlightLambdaName
private

The documentation for this class was generated from the following files:
  • /home/egrazil/sites/Brunot/The House/source/Component/Button.h
  • /home/egrazil/sites/Brunot/The House/source/Component/Button.cpp