VenomEngine
Cross-Platform Modern Graphics Engine
Loading...
Searching...
No Matches
GUI.h
Go to the documentation of this file.
1
8#pragma once
10
13
15
16// Check https://fonts.google.com/icons?icon.set=Material+Symbols
17#include <IconsMaterialSymbols.h>
18
19namespace venom
20{
21namespace common
22{
24class VenomEngine;
25
26class Model;
27class Texture;
28class Transform3D;
29
30typedef void(*GUIDrawCallback)();
31typedef void * GUIViewport;
32class VENOM_COMMON_API GUI : public GraphicsPluginObject
33{
34public:
35 GUI();
36 ~GUI() override;
37
38 void SetGraphicsApplication(GraphicsApplication * app);
39
40 vc::Error Initialize();
41 vc::Error Reset();
42
43 inline void DrawCallback() { if (s_guiDrawCallback) s_guiDrawCallback(); }
44 static inline void SetGUIDrawCallback(GUIDrawCallback guiDrawCallback) { s_guiDrawCallback = guiDrawCallback; }
45#if defined(VENOM_PLATFORM_MOBILE)
46 static inline void ToggleGUIDraw() { s_guiDraw = false; }
47#else
48 static inline void ToggleGUIDraw() { s_guiDraw = !s_guiDraw; }
49#endif
50 static inline bool IsGUIDraw() { return s_guiDraw; }
51 static inline bool & IsGUIDrawRef() { return s_guiDraw; }
52
53 void Render();
54
55 static inline GUI * Get() { return s_gui; }
56
57 static void AddFont(const char * fontPath, float fontSize, const uint16_t * glyphRanges);
58 static void AddFont(const char * fontPath, float fontSize);
59 static void ClearFonts();
60
61 static inline void SetNextWindowPos(const vcm::Vec2 & pos, GUICond cond = GUICondBits::GUICond_None, const vcm::Vec2 & pivot = vcm::Vec2(0, 0)) { s_gui->_SetNextWindowPos(pos, cond, pivot); }
62 static inline void SetNextWindowSize(const vcm::Vec2 & size, GUICond cond = GUICondBits::GUICond_None) { s_gui->_SetNextWindowSize(size, cond); }
63 static inline void SetNextWindowViewport(GUIViewport viewport) { s_gui->_SetNextWindowViewport(viewport); }
64
65 static inline vcm::Vec2 GetContentRegionAvail() { return s_gui->_GetContentRegionAvail(); }
66
67 static inline GUIViewport GetMainViewport() { return s_gui->_GetMainViewport(); }
68 static inline vcm::Vec2 GetWindowSize() { return s_gui->_GetWindowSize(); }
69 static inline vcm::Vec2 GetWindowPos() { return s_gui->_GetWindowPos(); }
70 static inline void NewFrame() { s_gui->_NewFrame(); }
71 static inline void Begin(const char * name, bool * p_open = nullptr, GUIWindowFlags flags = 0) { s_gui->_Begin(name, p_open, flags); }
72 static inline void End() { s_gui->_End(); }
73 static inline void Text(const char* fmt, ...) { va_list args; va_start(args, fmt); s_gui->_Text(fmt, args); va_end(args); }
74 static inline void TextColored(const vcm::Vec4 & col, const char* fmt, ...) { va_list args; va_start(args, fmt); s_gui->_TextColored(col, fmt, args); va_end(args); }
75 static inline void LabelText(const char* label, const char* fmt, ...) { va_list args; va_start(args, fmt); s_gui->_LabelText(label, fmt, args); va_end(args); }
76
77 static inline void Image(const vc::Texture * texture, const vcm::Vec2 & size, bool centering = true) { s_gui->_Image(texture, size, centering); }
78 static inline void Image(const vc::RenderTarget * renderTarget, const vcm::Vec2 & size, bool centering = true) { s_gui->_Image(renderTarget->GetTexture(), size, centering); }
79
80 static inline bool InputText(const char* label, char* buf, size_t buf_size, GUIInputTextFlags flags = 0) { return s_gui->_InputText(label, buf, buf_size, flags); }
81
82 static inline bool TreeNode(const char* label) { return s_gui->_TreeNode(label); }
83 static inline void TreePop() { s_gui->_TreePop(); }
84 static inline void TreePush(const char* str_id) { s_gui->_TreePush(str_id); }
85
86 static inline void SeparatorText(const char* text) { s_gui->_SeparatorText(text); }
87 static inline void Separator() { s_gui->_Separator(); }
88 static inline void Spacing() { s_gui->_Spacing(); }
89 static inline void Dummy(const vcm::Vec2 & size) { s_gui->_Dummy(size); }
90
91 static inline bool SliderFloat(const char* label, float* v, float v_min, float v_max, const char* format = "%.3f") { return s_gui->_SliderFloat(label, v, v_min, v_max, format); }
92 static inline bool SliderFloat3(const char* label, float v[3], float v_min, float v_max, const char* format = "%.3f") { return s_gui->_SliderFloat3(label, v, v_min, v_max, format); }
93
94 static inline bool InputFloat(const char* label, float* v, float step = 0.0f, float step_fast = 0.0f, const char* format = "%.3f", GUIColorEditFlags flags = 0) { return s_gui->_InputFloat(label, v, step, step_fast, format, flags); }
95 static inline bool InputFloat3(const char* label, float v[3], const char* format = "%.3f", GUIColorEditFlags flags = 0) { return s_gui->_InputFloat3(label, v, format, flags); }
96
97 static inline void ColorEdit3(const char* label, float col[3], GUIColorEditFlags flags = 0) { s_gui->_ColorEdit3(label, col, flags); }
98
99 static inline bool CollapsingHeader(const char* label, GUITreeNodeFlags flags = 0) { return s_gui->_CollapsingHeader(label, flags); }
100
101 static inline bool Button(const char* label, const vcm::Vec2 & size = vcm::Vec2(0, 0)) { return s_gui->_Button(label, size); }
102 static inline bool Checkbox(const char* label, bool* v) { return s_gui->_Checkbox(label, v); }
103 static inline void ProgressBar(float fraction, const vcm::Vec2 & size_arg = vcm::Vec2(-1, 0), const char* overlay = nullptr) { s_gui->_ProgressBar(fraction, size_arg, overlay); }
104
105 static inline bool Selectable(const char* label, bool selected, GUISelectableFlags flags = 0, const vcm::Vec2 & size = vcm::Vec2(0, 0)) { return s_gui->_Selectable(label, selected, flags, size); }
106
107 static inline bool BeginCombo(const char* label, const char* preview_value, GUIComboFlags flags = 0) { return s_gui->_BeginCombo(label, preview_value, flags); }
108 static inline void EndCombo() { s_gui->_EndCombo(); }
109
110 static inline bool BeginMenu(const char* label, bool enabled = true) { return s_gui->_BeginMenu(label, enabled); }
111 static inline void EndMenu() { s_gui->_EndMenu(); }
112
113 static inline bool BeginMainMenuBar() { return s_gui->_BeginMainMenuBar(); }
114 static inline void EndMainMenuBar() { s_gui->_EndMainMenuBar(); }
115
116 static inline bool BeginMenuBar() { return s_gui->_BeginMenuBar(); }
117 static inline void EndMenuBar() { s_gui->_EndMenuBar(); }
118
119 static inline bool BeginChild(const char* str_id, const vcm::Vec2 & size, GUIChildFlags childFlags, GUIWindowFlags extraFlags = 0) { return s_gui->_BeginChild(str_id, size, childFlags, extraFlags); }
120 static inline void EndChild() { s_gui->_EndChild(); }
121
122 static inline bool MenuItem(const char* str, const char* text = nullptr) { return s_gui->_MenuItem(str, text); }
123
124 static inline void SetNextItemWidth(float item_width) { s_gui->_SetNextItemWidth(item_width); }
125 static inline void SetItemDefaultFocus() { s_gui->_SetItemDefaultFocus(); }
126
127 static inline void SameLine(float offset_from_start_x = 0.0f, float spacing = -1.0f) { s_gui->_SameLine(offset_from_start_x, spacing); }
128
129 static inline void PushItemWidth(float item_width) { s_gui->_PushItemWidth(item_width); }
130 static inline void PopItemWidth() { s_gui->_PopItemWidth(); }
131
132 static inline void PushButtonTextAlign(const vcm::Vec2 & padding) { s_gui->_PushButtonTextAlign(padding); }
133 static inline void PushWindowPadding(const vcm::Vec2 & padding) { s_gui->_PushWindowPadding(padding); }
134 static inline void PopStyleVar() { s_gui->_PopStyleVar(); }
135
136 static inline GUIId DockSpace(GUIId id, const vcm::Vec2 & size, GUIDockNodeFlags flags) { return s_gui->_DockSpace(id, size, flags); }
137 static inline GUIId DockSpace(const char * id, const vcm::Vec2 & size, GUIDockNodeFlags flags) { return s_gui->_DockSpace(id, size, flags); }
138 static inline GUIId DockSpaceOverViewport() { return s_gui->_DockSpaceOverViewport(); }
139 static inline GUIId DockSpaceAddNode(GUIId id, GUIDockNodeFlags flags) { return s_gui->_DockSpaceAddNode(id, flags); }
140 static inline void DockSpaceRemoveNode(GUIId id) { s_gui->_DockSpaceRemoveNode(id); }
141 static inline void DockSpaceSetNodeSize(GUIId id, const vcm::Vec2 & size) { s_gui->_DockSpaceSetNodeSize(id, size); }
142 static inline GUIId DockSpaceSplitNode(GUIId id, GUIDir split_dir, float size_ratio, GUIId * out_id_at_dir, GUIId * out_id_at_opposite_dir) { return s_gui->_DockSpaceSplitNode(id, split_dir, size_ratio, out_id_at_dir, out_id_at_opposite_dir); }
143 static inline void DockWindow(const char * str_id, GUIId id) { s_gui->_DockWindow(str_id, id); }
144 static inline void DockFinish(GUIId id) { s_gui->_DockFinish(id); }
145
146 static inline void OpenPopup(const char * str_id, GUIPopupFlags flags = 0) { s_gui->_OpenPopup(str_id, flags); }
147 static inline bool BeginPopup(const char * str_id, GUIWindowFlags flags = 0) { return s_gui->_BeginPopup(str_id, flags); }
148 static inline bool BeginPopupModal(const char * name, bool * p_open = nullptr, GUIWindowFlags flags = 0) { return s_gui->_BeginPopupModal(name, p_open, flags); }
149 static inline bool BeginPopupContextItem(const char * str_id = nullptr, GUIPopupFlags flags = 0) { return s_gui->_BeginPopupContextItem(str_id, flags); }
150 static inline void EndPopup() { s_gui->_EndPopup(); }
151 static inline void CloseCurrentPopup() { s_gui->_CloseCurrentPopup(); }
152
153 static bool isFirstFrame();
154 static bool isFirstInitialization();
155
156 static inline GUIId GetID(const char * str_id) { return s_gui->_GetID(str_id); }
157
158 static inline void Test() { s_gui->_Test(); }
159
160 static void GraphicsSettingsCollaspingHeader();
161
162 static void EntitiesListCollapsingHeader();
163
164 static bool EditableTexture(vc::Texture * texture, vc::String & path);
165 static bool EditableModel(vc::Model * model, vc::String & path);
166
170 static void EntityGuizmo(const vcm::Vec2 & renderingSize);
171
172private:
173 static void __EntityPropertiesWindow();
174 static void __EntityGuizmo(const vcm::Vec2 & renderingSize);
175
176protected:
177 virtual void _EntityGuizmo(vc::Transform3D * transform3D, const vcm::Vec2 & renderingSize) = 0;
178
179 virtual vc::Error _Initialize() = 0;
180 virtual vc::Error _Reset() = 0;
181
182 virtual void _ClearFonts() = 0;
183 virtual void _AddFont(const char * fontPath, float fontSize, const uint16_t * glyphRanges) = 0;
184 virtual void _AddFont(const char * fontPath, float fontSize) = 0;
185
186 virtual void _SetNextWindowPos(const vcm::Vec2 & pos, GUICond cond, const vcm::Vec2 & pivot) = 0;
187 virtual void _SetNextWindowSize(const vcm::Vec2 & size, GUICond cond) = 0;
188 virtual void _SetNextWindowViewport(GUIViewport viewport) = 0;
189
190 virtual vcm::Vec2 _GetContentRegionAvail() = 0;
191
192 virtual vcm::Vec2 _GetWindowSize() = 0;
193 virtual vcm::Vec2 _GetWindowPos() = 0;
194 virtual GUIViewport _GetMainViewport() = 0;
195
196 virtual void _NewFrame() = 0;
197 virtual void _Begin(const char * name, bool * p_open, GUIWindowFlags flags) = 0;
198 virtual void _End() = 0;
199 virtual void _Text(const char* fmt, va_list args) = 0;
200 virtual void _TextColored(const vcm::Vec4 & col, const char* fmt, va_list args) = 0;
201 virtual void _LabelText(const char* label, const char* fmt, va_list args) = 0;
202
203 virtual void _Image(const vc::Texture * texture, const vcm::Vec2 & size, bool centering) = 0;
204
205 virtual bool _InputText(const char* label, char* buf, size_t buf_size, GUIInputTextFlags flags) = 0;
206
207 virtual bool _TreeNode(const char* label) = 0;
208 virtual void _TreePop() = 0;
209 virtual void _TreePush(const char* str_id) = 0;
210
211 virtual void _SeparatorText(const char* text) = 0;
212 virtual void _Separator() = 0;
213 virtual void _Spacing() = 0;
214 virtual void _Dummy(const vcm::Vec2 & size) = 0;
215
216 virtual bool _SliderFloat(const char* label, float* v, float v_min, float v_max, const char* format) = 0;
217 virtual bool _SliderFloat3(const char* label, float v[3], float v_min, float v_max, const char* format) = 0;
218
219 virtual bool _InputFloat(const char* label, float* v, float step, float step_fast, const char* format, GUIColorEditFlags flags) = 0;
220 virtual bool _InputFloat3(const char* label, float v[3], const char* format, GUIColorEditFlags flags) = 0;
221
222 virtual void _ColorEdit3(const char* label, float col[3], GUIColorEditFlags flags) = 0;
223
224 virtual bool _CollapsingHeader(const char* label, GUITreeNodeFlags flags) = 0;
225
226 virtual bool _Button(const char* label, const vcm::Vec2 & size) = 0;
227 virtual bool _Checkbox(const char* label, bool* v) = 0;
228 virtual void _ProgressBar(float fraction, const vcm::Vec2 & size_arg, const char* overlay) = 0;
229
230 virtual bool _Selectable(const char* label, bool selected, GUISelectableFlags flags, const vcm::Vec2 & size) = 0;
231
232 virtual bool _BeginCombo(const char* label, const char* preview_value, GUIComboFlags flags) = 0;
233 virtual void _EndCombo() = 0;
234
235 virtual bool _BeginMenu(const char* label, bool enabled) = 0;
236 virtual void _EndMenu() = 0;
237
238 virtual bool _BeginMainMenuBar() = 0;
239 virtual void _EndMainMenuBar() = 0;
240
241 virtual bool _BeginMenuBar() = 0;
242 virtual void _EndMenuBar() = 0;
243
244 virtual bool _BeginChild(const char* str_id, const vcm::Vec2 & size, GUIChildFlags childFlags, GUIWindowFlags extra_flags) = 0;
245 virtual void _EndChild() = 0;
246
247 virtual bool _MenuItem(const char* str, const char* text) = 0;
248
249 virtual void _SetNextItemWidth(float item_width) = 0;
250 virtual void _SetItemDefaultFocus() = 0;
251
252 virtual void _SameLine(float offset_from_start_x, float spacing) = 0;
253
254 virtual void _PushItemWidth(float item_width) = 0;
255 virtual void _PopItemWidth() = 0;
256
257 virtual void _PushButtonTextAlign(const vcm::Vec2 & padding) = 0;
258 virtual void _PushWindowPadding(const vcm::Vec2 & padding) = 0;
259 virtual void _PopStyleVar() = 0;
260
261 virtual GUIId _DockSpace(GUIId id, const vcm::Vec2 & size, GUIDockNodeFlags flags) = 0;
262 virtual GUIId _DockSpace(const char * id, const vcm::Vec2 & size, GUIDockNodeFlags flags) = 0;
263 virtual GUIId _DockSpaceOverViewport() = 0;
264 virtual GUIId _DockSpaceAddNode(GUIId id, GUIDockNodeFlags flags) = 0;
265 virtual void _DockSpaceRemoveNode(GUIId id) = 0;
266 virtual void _DockSpaceSetNodeSize(GUIId id, const vcm::Vec2 & size) = 0;
267 virtual GUIId _DockSpaceSplitNode(GUIId id, GUIDir split_dir, float size_ratio, GUIId * out_id_at_dir, GUIId * out_id_at_opposite_dir) = 0;
268 virtual void _DockWindow(const char * str_id, GUIId id) = 0;
269 virtual void _DockFinish(GUIId id) = 0;
270
271 virtual void _OpenPopup(const char * str_id, GUIPopupFlags flags) = 0;
272 virtual bool _BeginPopup(const char * str_id, GUIWindowFlags flags) = 0;
273 virtual bool _BeginPopupModal(const char * name, bool * p_open, GUIWindowFlags flags) = 0;
274 virtual bool _BeginPopupContextItem(const char * str_id, GUIPopupFlags flags) = 0;
275 virtual void _EndPopup() = 0;
276 virtual void _CloseCurrentPopup() = 0;
277
278 virtual GUIId _GetID(const char * str_id) = 0;
279
280 virtual void _Render() = 0;
281 virtual vc::Error _PreUpdate() = 0;
282
283 virtual void _Test() = 0;
284
285protected:
286 GraphicsApplication * _app;
287 struct FontData
288 {
289 const vc::String path;
290 float size;
291 const uint16_t * glyphRanges;
292 };
293 vc::Vector<FontData> _fonts;
294
295private:
300 vc::Error __PreUpdate();
301
302protected:
303 bool _firstInit;
304private:
305 static GUI * s_gui;
306 bool __firstFrame;
307
308private:
309 static GUIDrawCallback s_guiDrawCallback;
310 static bool s_guiDraw;
311
312 friend class VenomEngine;
313};
314}
315}
static void EntityGuizmo(const vcm::Vec2 &renderingSize)
Definition GUI.cc:281
Definition GraphicsApplication.h:28
Contains all the mesh's data and is the main high-level interface for the user.
Definition Model.h:55
Definition RenderTarget.h:59
Definition Texture.h:178
Definition Transform3D.h:18
Main class of the engine This class will be the main entry point of the engine. It will contain all t...
Definition VenomEngine.h:43
High-Level Frontend of the VenomEngine project. It also contains all the code shared between every AP...
Definition Callback.h:15
Contains the entirety of the code of the VenomEngine project.
Definition Callback.h:13
Definition GUI.h:288