cangine
Loading...
Searching...
No Matches
button_object.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <functional>
4#include <string>
5#include <vector>
6
7#include "./label_object.hpp"
8#include "../../../platform/mouse.hpp"
9#include "../../../render/texture.hpp"
10
11namespace cangine {
12 class ButtonComponent;
19 class Button : public Label {
20 private:
21 std::vector<std::function<void(const MouseEvent*)>> onClickHandlers;
23
28 void onClick(const MouseEvent* e);
29 friend class ButtonComponent;
30 public:
40 Button(
41 std::string text,
42 Vector3 position = Vector3(0, 0, 0),
44 Color hoverColor = Colors::GRAY,
45 Color focusColor = Colors::DARK_GRAY,
46 Color backgroundColor = Colors::WHITE
47 );
48
53 inline void registerOnClickEvent(std::function<void(const MouseEvent*)> handler) {
54 onClickHandlers.push_back(handler);
55 }
56
67 };
68}
Component providing clickable-button behavior and visuals.
Definition button_component.hpp:16
Clickable button game object with a text label.
Definition button_object.hpp:19
ButtonComponent * btnComponent
Component driving button behavior.
Definition button_object.hpp:22
void registerOnClickEvent(std::function< void(const MouseEvent *)> handler)
Registers a callback invoked when the button is clicked.
Definition button_object.hpp:53
void onClick(const MouseEvent *e)
Invokes all registered click handlers.
Definition button_object.cpp:6
Texture * getTexture()
Returns the button's background texture.
Definition button_object.cpp:35
void setTexture(Texture *textureIn)
Sets the button's background texture.
Definition button_object.cpp:31
std::vector< std::function< void(const MouseEvent *)> > onClickHandlers
Registered click callbacks.
Definition button_object.hpp:21
T * getComponent()
Returns the first attached component of a type.
Definition game_object.hpp:93
Convenience game object that displays a line of text.
Definition label_object.hpp:23
Wraps an OpenGL texture object.
Definition texture.hpp:12
const Color WHITE(255, 255, 255)
White.
const Color DARK_GRAY(99, 99, 99)
Dark gray.
const Color GRAY(128, 128, 128)
Medium gray.
const Color BLACK(0, 0, 0)
Black.
Definition audiomanager.cpp:4
RGBA color stored as normalized floating-point components.
Definition color.hpp:12
A mouse event carrying its type, button, position and scroll offset.
Definition mouse.hpp:37
Three-component floating-point vector.
Definition vector3.hpp:13