SDOM - Simple SDL Document Object Model
A lightweight, extensible Document Object Model for SDL-based applications.
Loading...
Searching...
No Matches
SDOM_Button.hpp
Go to the documentation of this file.
1// SDOM_Button.hpp
2#pragma once
3
6
7namespace SDOM
8{
9
10 class Button : public IPanelObject, public IButtonObject
11 {
13
14 public:
15 // --- Type Info --- //
16 static constexpr const char* TypeName = "Button";
17
18 // --- Initialization Struct --- //
20 {
22 {
23 // from IDisplayObject
24 name = TypeName;
25 type = TypeName;
26 color = {96, 0, 96, 255}; // panel color
27 tabEnabled = true; // buttons are tab-enabled by default
28 // from IPanelObject
30 icon_resource = "internal_icon_8x8"; // Default to internal 8x8 sprite sheet
31 icon_width = 8; // default icon width is 8
32 icon_height = 8; // default icon height is 8
33 font_resource = "internal_font_8x8"; // Default to internal 8x8 font
34 font_width = 8; // default font width is 8
35 font_height = 8; // default font height is 8
36 }
37 std::string text = "Button"; // default button text
38 int font_size = 8; // default font size is 8
39 SDL_Color label_color = {255, 255, 255, 255}; // default label color is white
40
41 }; // END: InitStruct
42 protected:
43 // --- Constructors --- //
44 Button(const InitStruct& init);
45 Button(const sol::table& config);
46
47 public:
48
49 // --- Static Factory Methods --- //
50 static std::unique_ptr<IDisplayObject> CreateFromLua(const sol::table& config) {
51 return std::unique_ptr<IDisplayObject>(new Button(config));
52 }
53 static std::unique_ptr<IDisplayObject> CreateFromInitStruct(const IDisplayObject::InitStruct& baseInit) {
54 const auto& buttonInit = static_cast<const Button::InitStruct&>(baseInit);
55 return std::unique_ptr<IDisplayObject>(new Button(buttonInit));
56 }
57
58 Button() = default;
59 virtual ~Button() = default;
60
61 // --- Virtual Methods --- //
62 virtual bool onInit() override; // Called when the display object is initialized
63 virtual void onRender() override; // Called to render the display object
64 virtual void onQuit() override; // Called when the display object is being destroyed
65 virtual void onUpdate(float fElapsedTime) override; // Called every frame to update the display object
66 virtual void onEvent(const Event& event) override; // Called when an event occurs
67
69 std::string getText() const { return text_; }
70 void setText(const std::string& newText);
71
72 protected:
73 DisplayHandle labelObject_; // internal label object for button text
74 std::string text_; // initialized label text
75 std::string font_resource_name_ = "internal_font_8x8"; // default font resource name
76 int font_size_ = 8; // default font size
77 int font_width_ = 8; // default font width
78 int font_height_ = 8; // default font height
79 SDL_Color label_color_ = {255, 255, 255, 255}; // default label color is white
80
81 // --- Lua Registration --- //
82 virtual void _registerLuaBindings(const std::string& typeName, sol::state_view lua);
83
84 }; // END: class Button : public IPanelObject
85
86} // END namespace SDOM
Definition SDOM_Button.hpp:11
int font_height_
Definition SDOM_Button.hpp:78
virtual void onUpdate(float fElapsedTime) override
Definition SDOM_Button.cpp:165
SDL_Color label_color_
Definition SDOM_Button.hpp:79
std::string font_resource_name_
Definition SDOM_Button.hpp:75
static std::unique_ptr< IDisplayObject > CreateFromLua(const sol::table &config)
Definition SDOM_Button.hpp:50
virtual void _registerLuaBindings(const std::string &typeName, sol::state_view lua)
Definition SDOM_Button.cpp:247
void setText(const std::string &newText)
Definition SDOM_Button.cpp:224
DisplayHandle labelObject_
Definition SDOM_Button.hpp:73
virtual ~Button()=default
int font_width_
Definition SDOM_Button.hpp:77
virtual bool onInit() override
Definition SDOM_Button.cpp:111
Button()=default
DisplayHandle getLabelObject() const
Definition SDOM_Button.hpp:68
std::string getText() const
Definition SDOM_Button.hpp:69
virtual void onRender() override
Definition SDOM_Button.cpp:158
virtual void onQuit() override
Definition SDOM_Button.cpp:152
static constexpr const char * TypeName
Definition SDOM_Button.hpp:16
std::string text_
Definition SDOM_Button.hpp:74
static std::unique_ptr< IDisplayObject > CreateFromInitStruct(const IDisplayObject::InitStruct &baseInit)
Definition SDOM_Button.hpp:53
int font_size_
Definition SDOM_Button.hpp:76
virtual void onEvent(const Event &event) override
Definition SDOM_Button.cpp:170
Definition SDOM_DisplayHandle.hpp:24
Definition SDOM_Event.hpp:55
Definition SDOM_IButtonObject.hpp:125
Definition SDOM_IPanelObject.hpp:107
Contains all core classes and utilities for the SDOM library.
Definition lua_BindHelpers.hpp:7
Definition SDOM_Button.hpp:20
int font_size
Definition SDOM_Button.hpp:38
SDL_Color label_color
Definition SDOM_Button.hpp:39
InitStruct()
Definition SDOM_Button.hpp:21
std::string text
Definition SDOM_Button.hpp:37
Definition SDOM_IDisplayObject.hpp:187
std::string type
Definition SDOM_IDisplayObject.hpp:189
bool tabEnabled
Definition SDOM_IDisplayObject.hpp:212
std::string name
Definition SDOM_IDisplayObject.hpp:188
SDL_Color color
Definition SDOM_IDisplayObject.hpp:194
Definition SDOM_IPanelObject.hpp:116
std::string font_resource
Definition SDOM_IPanelObject.hpp:127
std::string icon_resource
Definition SDOM_IPanelObject.hpp:124
int font_height
Definition SDOM_IPanelObject.hpp:129
PanelBaseIndex base_index
Definition SDOM_IPanelObject.hpp:123
int font_width
Definition SDOM_IPanelObject.hpp:128
int icon_height
Definition SDOM_IPanelObject.hpp:126
int icon_width
Definition SDOM_IPanelObject.hpp:125