SDOM - Simple SDL Document Object Model
A lightweight, extensible Document Object Model for SDL-based applications.
Loading...
Searching...
No Matches
SDOM_IPanelObject.hpp
Go to the documentation of this file.
1// SDOM_IPanelObject.hpp
2
3#pragma once
4
7
8namespace SDOM
9{
10 class IFontObject;
11 class AssetHandle;
12
13 enum class PanelBaseIndex
14 {
15 ButtonUp = 0,
17 ButtonDown = 18,
19 Frame = 36,
20 Group = 45,
21 // // Individual Indices
22 // Hamburger = 54,
23 // Left_Arrow_Raised,
24 // Right_Arrow_Raised,
25 // Up_Arrow_Raised,
26 // Down_Arrow_Raised,
27 // Left_Arrow_Depressed,
28 // Right_Arrow_Depressed,
29 // Up_Arrow_Depressed,
30 // Down_Arrow_Depressed,
31 // Horizontal_Knob,
32 // Vertical_Knob,
33 // Slider_Tick,
34 // HSlider_Rail,
35 // VSlider_Rail,
36 // Empty_Checkbox,
37 // Checked_Checkbox,
38 // X_Checkbox,
39 // Unselected_Radio,
40 // Selected_Radio,
41 // Left_HProgress,
42 // Empty_HProgress,
43 // Thumb_HProgress,
44 // Right_HProgress,
45 // Top_VProgress,
46 // Empty_VProgress,
47 // Thumb_VProgress,
48 // Bottom_VProgress
49 };
50 inline static const std::unordered_map<std::string, PanelBaseIndex> stringToPanelBaseIndex_ =
51 {
52 { "button_up", PanelBaseIndex::ButtonUp },
53 { "button_up_selected", PanelBaseIndex::ButtonUpSelected },
54 { "button_down", PanelBaseIndex::ButtonDown },
55 { "button_down_selected", PanelBaseIndex::ButtonDownSelected },
56 { "frame", PanelBaseIndex::Frame },
57 { "group", PanelBaseIndex::Group }
58 };
59 inline static const std::unordered_map<PanelBaseIndex, std::string> panelBaseIndexToString_ =
60 {
61 { PanelBaseIndex::ButtonUp, "button_up" },
62 { PanelBaseIndex::ButtonUpSelected, "button_up_selected" },
63 { PanelBaseIndex::ButtonDown, "button_down" },
64 { PanelBaseIndex::ButtonDownSelected, "button_down_selected" },
65 { PanelBaseIndex::Frame, "frame" },
66 { PanelBaseIndex::Group, "group" }
67 };
68
69 enum class PanelTileOffset
70 {
71 TopLeft = 0,
72 TopCenter = 1,
73 TopRight = 2,
74 LeftCenter = 3,
75 Center = 4,
76 RightCenter = 5,
77 BottomLeft = 6,
78 BottomCenter = 7,
79 BottomRight = 8
80 };
81 inline static const std::unordered_map<std::string, PanelTileOffset> stringToPanelTileOffset_ =
82 {
83 { "top_left", PanelTileOffset::TopLeft },
84 { "top_center", PanelTileOffset::TopCenter },
85 { "top_right", PanelTileOffset::TopRight },
86 { "left_center", PanelTileOffset::LeftCenter },
87 { "center", PanelTileOffset::Center },
88 { "right_center", PanelTileOffset::RightCenter },
89 { "bottom_left", PanelTileOffset::BottomLeft },
90 { "bottom_center",PanelTileOffset::BottomCenter },
91 { "bottom_right", PanelTileOffset::BottomRight }
92 };
93 inline static const std::unordered_map<PanelTileOffset, std::string> panelTileOffsetToString_ =
94 {
95 { PanelTileOffset::TopLeft, "top_left" },
96 { PanelTileOffset::TopCenter, "top_center" },
97 { PanelTileOffset::TopRight, "top_right" },
98 { PanelTileOffset::LeftCenter, "left_center" },
99 { PanelTileOffset::Center, "center" },
100 { PanelTileOffset::RightCenter, "right_center" },
101 { PanelTileOffset::BottomLeft, "bottom_left" },
102 { PanelTileOffset::BottomCenter, "bottom_center" },
103 { PanelTileOffset::BottomRight, "bottom_right" }
104 };
105
107 {
108 using SUPER = IDisplayObject;
109
110 public:
111 // --- Type Info --- //
112 static constexpr const char* TypeName = "IPanelObject";
113
114 // --- Initialization Struct --- //
116 {
118 {
119 name = TypeName;
120 type = TypeName;
121 color = {96, 0, 96, 255}; // panel color
122 }
124 std::string icon_resource = "internal_icon_8x8"; // Default to internal 8x8 sprite sheet
125 int icon_width = 8; // default icon width is 8
126 int icon_height = 8; // default icon height is 8
127 std::string font_resource = "internal_font_8x8"; // Default to internal 8x8 font
128 int font_width = 8; // default font width is 8
129 int font_height = 8; // default font height is 8
130 };
131
132 protected:
133 // --- Constructors --- //
134 IPanelObject(const InitStruct& init);
135 IPanelObject(const sol::table& config);
136
137 // IPanelObject();
138
139 public:
140
141 // // --- Static Factory Methods --- //
142 // static std::unique_ptr<IDisplayObject> CreateFromLua(const sol::table& config) {
143 // return std::unique_ptr<IDisplayObject>(new IPanelObject(config));
144 // }
145 // static std::unique_ptr<IDisplayObject> CreateFromInitStruct(const IDisplayObject::InitStruct& baseInit) {
146 // const auto& panelInit = static_cast<const IPanelObject::InitStruct&>(baseInit);
147 // return std::unique_ptr<IDisplayObject>(new IPanelObject(panelInit));
148 // }
149
150 virtual ~IPanelObject() = default;
151
152 // --- Virtual Methods --- //
153 virtual bool onInit() override; // Called when the display object is initialized
154 virtual void onRender() override; // Called to render the display object
155 virtual void onQuit() override; // Called when the display object is being destroyed
156 virtual void onUpdate(float fElapsedTime)=0; // Called every frame to update the display object
157 virtual void onEvent(const Event& event)=0; // Called when an event occurs
158
159 // --- Helper Methods --- //
160 void renderPanel(); // render nine-panel based on the base_index_;
161
164 std::string getIconResourceName() const { return icon_resource_; }
165 std::string getFontResourceName() const { return font_resource_; }
166 int getIconWidth() const { return icon_width_; }
167 int getIconHeight() const { return icon_height_; }
168 int getFontWidth() const { return font_width_; }
169 int getFontHeight() const { return font_height_; }
171
172 protected:
173 // std::string name_; // Name for this panel object (inherited from IDisplayObject)
174 AssetHandle spriteSheetAsset_; // icon based sprite sheet, default: `internal_icon_8x8`
175 AssetHandle fontAsset_; // IFontObject based font resource, default: `internal_font_8x8`
176 std::string icon_resource_ = "internal_icon_8x8"; // Default to internal 8x8 sprite sheet
177 std::string font_resource_ = "internal_font_8x8"; // Default to internal 8x8 font
178 int icon_width_ = 8; // default icon width is 8
179 int icon_height_ = 8; // default icon height is 8
180 int font_width_ = 8; // default font width is 8
181 int font_height_ = 8; // default font height is 8
184
185 // --- Lua Registration --- //
186 virtual void _registerLuaBindings(const std::string& typeName, sol::state_view lua);
187 }; // END: IPanelObject : public IDisplayObject
188
189} // namespace SDOM
190// END SDOM_IPanelObject.hpp
Definition SDOM_AssetHandle.hpp:13
Definition SDOM_Event.hpp:55
Definition SDOM_Frame.hpp:10
Definition SDOM_Group.hpp:10
Definition SDOM_IDisplayObject.hpp:153
Definition SDOM_IPanelObject.hpp:107
int getFontHeight() const
Definition SDOM_IPanelObject.hpp:169
int getIconWidth() const
Definition SDOM_IPanelObject.hpp:166
PanelBaseIndex getBaseIndex() const
Definition SDOM_IPanelObject.hpp:170
int font_width_
Definition SDOM_IPanelObject.hpp:180
AssetHandle spriteSheetAsset_
Definition SDOM_IPanelObject.hpp:174
int getIconHeight() const
Definition SDOM_IPanelObject.hpp:167
virtual bool onInit() override
Definition SDOM_IPanelObject.cpp:86
int icon_width_
Definition SDOM_IPanelObject.hpp:178
virtual void onEvent(const Event &event)=0
virtual void onUpdate(float fElapsedTime)=0
AssetHandle fontAsset_
Definition SDOM_IPanelObject.hpp:175
virtual void _registerLuaBindings(const std::string &typeName, sol::state_view lua)
Definition SDOM_IPanelObject.cpp:243
int font_height_
Definition SDOM_IPanelObject.hpp:181
virtual void onQuit() override
Definition SDOM_IPanelObject.cpp:157
std::string getIconResourceName() const
Definition SDOM_IPanelObject.hpp:164
int getFontWidth() const
Definition SDOM_IPanelObject.hpp:168
int icon_height_
Definition SDOM_IPanelObject.hpp:179
static constexpr const char * TypeName
Definition SDOM_IPanelObject.hpp:112
virtual void onRender() override
Definition SDOM_IPanelObject.cpp:170
std::string getFontResourceName() const
Definition SDOM_IPanelObject.hpp:165
PanelBaseIndex base_index_
Definition SDOM_IPanelObject.hpp:182
void renderPanel()
Definition SDOM_IPanelObject.cpp:177
AssetHandle getFontAsset() const
Definition SDOM_IPanelObject.hpp:163
std::string font_resource_
Definition SDOM_IPanelObject.hpp:177
std::string icon_resource_
Definition SDOM_IPanelObject.hpp:176
AssetHandle getSpriteSheet() const
Definition SDOM_IPanelObject.hpp:162
virtual ~IPanelObject()=default
PanelBaseIndex last_base_index_
Definition SDOM_IPanelObject.hpp:183
Contains all core classes and utilities for the SDOM library.
Definition lua_BindHelpers.hpp:7
PanelTileOffset
Definition SDOM_IPanelObject.hpp:70
static const std::unordered_map< PanelTileOffset, std::string > panelTileOffsetToString_
Definition SDOM_IPanelObject.hpp:93
PanelBaseIndex
Definition SDOM_IPanelObject.hpp:14
static const std::unordered_map< std::string, PanelBaseIndex > stringToPanelBaseIndex_
Definition SDOM_IPanelObject.hpp:50
static const std::unordered_map< std::string, PanelTileOffset > stringToPanelTileOffset_
Definition SDOM_IPanelObject.hpp:81
static const std::unordered_map< PanelBaseIndex, std::string > panelBaseIndexToString_
Definition SDOM_IPanelObject.hpp:59
Definition SDOM_IDisplayObject.hpp:187
std::string type
Definition SDOM_IDisplayObject.hpp:189
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
InitStruct()
Definition SDOM_IPanelObject.hpp:117
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