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 static inline void ToggleGUIDraw() { s_guiDraw = !s_guiDraw; }
46 static inline bool IsGUIDraw() { return s_guiDraw; }
47 static inline bool & IsGUIDrawRef() { return s_guiDraw; }
48
49 void Render();
50
51 static inline GUI * Get() { return s_gui; }
52
53 static void AddFont(const char * fontPath, float fontSize, const uint16_t * glyphRanges);
54 static void AddFont(const char * fontPath, float fontSize);
55 static void ClearFonts();
56
57 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); }
58 static inline void SetNextWindowSize(const vcm::Vec2 & size, GUICond cond = GUICondBits::GUICond_None) { s_gui->_SetNextWindowSize(size, cond); }
59 static inline void SetNextWindowViewport(GUIViewport viewport) { s_gui->_SetNextWindowViewport(viewport); }
60
61 static inline vcm::Vec2 GetContentRegionAvail() { return s_gui->_GetContentRegionAvail(); }
62
63 static inline GUIViewport GetMainViewport() { return s_gui->_GetMainViewport(); }
64 static inline vcm::Vec2 GetWindowSize() { return s_gui->_GetWindowSize(); }
65 static inline vcm::Vec2 GetWindowPos() { return s_gui->_GetWindowPos(); }
66 static inline void NewFrame() { s_gui->_NewFrame(); }
67 static inline void Begin(const char * name, bool * p_open = nullptr, GUIWindowFlags flags = 0) { s_gui->_Begin(name, p_open, flags); }
68 static inline void End() { s_gui->_End(); }
69 static inline void Text(const char* fmt, ...) { va_list args; va_start(args, fmt); s_gui->_Text(fmt, args); va_end(args); }
70 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); }
71 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); }
72
73 static inline void Image(const vc::Texture * texture, const vcm::Vec2 & size, bool centering = true) { s_gui->_Image(texture, size, centering); }
74 static inline void Image(const vc::RenderTarget * renderTarget, const vcm::Vec2 & size, bool centering = true) { s_gui->_Image(renderTarget->GetTexture(), size, centering); }
75
76 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); }
77
78 static inline bool TreeNode(const char* label) { return s_gui->_TreeNode(label); }
79 static inline void TreePop() { s_gui->_TreePop(); }
80 static inline void TreePush(const char* str_id) { s_gui->_TreePush(str_id); }
81
82 static inline void SeparatorText(const char* text) { s_gui->_SeparatorText(text); }
83 static inline void Separator() { s_gui->_Separator(); }
84 static inline void Spacing() { s_gui->_Spacing(); }
85 static inline void Dummy(const vcm::Vec2 & size) { s_gui->_Dummy(size); }
86
87 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); }
88 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); }
89
90 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); }
91 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); }
92
93 static inline void ColorEdit3(const char* label, float col[3], GUIColorEditFlags flags = 0) { s_gui->_ColorEdit3(label, col, flags); }
94
95 static inline bool CollapsingHeader(const char* label, GUITreeNodeFlags flags = 0) { return s_gui->_CollapsingHeader(label, flags); }
96
97 static inline bool Button(const char* label, const vcm::Vec2 & size = vcm::Vec2(0, 0)) { return s_gui->_Button(label, size); }
98 static inline bool Checkbox(const char* label, bool* v) { return s_gui->_Checkbox(label, v); }
99 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); }
100
101 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); }
102
103 static inline bool BeginCombo(const char* label, const char* preview_value, GUIComboFlags flags = 0) { return s_gui->_BeginCombo(label, preview_value, flags); }
104 static inline void EndCombo() { s_gui->_EndCombo(); }
105
106 static inline bool BeginMenu(const char* label, bool enabled = true) { return s_gui->_BeginMenu(label, enabled); }
107 static inline void EndMenu() { s_gui->_EndMenu(); }
108
109 static inline bool BeginMainMenuBar() { return s_gui->_BeginMainMenuBar(); }
110 static inline void EndMainMenuBar() { s_gui->_EndMainMenuBar(); }
111
112 static inline bool BeginMenuBar() { return s_gui->_BeginMenuBar(); }
113 static inline void EndMenuBar() { s_gui->_EndMenuBar(); }
114
115 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); }
116 static inline void EndChild() { s_gui->_EndChild(); }
117
118 static inline bool MenuItem(const char* str, const char* text = nullptr) { return s_gui->_MenuItem(str, text); }
119
120 static inline void SetNextItemWidth(float item_width) { s_gui->_SetNextItemWidth(item_width); }
121 static inline void SetItemDefaultFocus() { s_gui->_SetItemDefaultFocus(); }
122
123 static inline void SameLine(float offset_from_start_x = 0.0f, float spacing = -1.0f) { s_gui->_SameLine(offset_from_start_x, spacing); }
124
125 static inline void PushItemWidth(float item_width) { s_gui->_PushItemWidth(item_width); }
126 static inline void PopItemWidth() { s_gui->_PopItemWidth(); }
127
128 static inline void PushButtonTextAlign(const vcm::Vec2 & padding) { s_gui->_PushButtonTextAlign(padding); }
129 static inline void PushWindowPadding(const vcm::Vec2 & padding) { s_gui->_PushWindowPadding(padding); }
130 static inline void PopStyleVar() { s_gui->_PopStyleVar(); }
131
132 static inline GUIId DockSpace(GUIId id, const vcm::Vec2 & size, GUIDockNodeFlags flags) { return s_gui->_DockSpace(id, size, flags); }
133 static inline GUIId DockSpace(const char * id, const vcm::Vec2 & size, GUIDockNodeFlags flags) { return s_gui->_DockSpace(id, size, flags); }
134 static inline GUIId DockSpaceOverViewport() { return s_gui->_DockSpaceOverViewport(); }
135 static inline GUIId DockSpaceAddNode(GUIId id, GUIDockNodeFlags flags) { return s_gui->_DockSpaceAddNode(id, flags); }
136 static inline void DockSpaceRemoveNode(GUIId id) { s_gui->_DockSpaceRemoveNode(id); }
137 static inline void DockSpaceSetNodeSize(GUIId id, const vcm::Vec2 & size) { s_gui->_DockSpaceSetNodeSize(id, size); }
138 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); }
139 static inline void DockWindow(const char * str_id, GUIId id) { s_gui->_DockWindow(str_id, id); }
140 static inline void DockFinish(GUIId id) { s_gui->_DockFinish(id); }
141
142 static inline void OpenPopup(const char * str_id, GUIPopupFlags flags = 0) { s_gui->_OpenPopup(str_id, flags); }
143 static inline bool BeginPopup(const char * str_id, GUIWindowFlags flags = 0) { return s_gui->_BeginPopup(str_id, flags); }
144 static inline bool BeginPopupModal(const char * name, bool * p_open = nullptr, GUIWindowFlags flags = 0) { return s_gui->_BeginPopupModal(name, p_open, flags); }
145 static inline bool BeginPopupContextItem(const char * str_id = nullptr, GUIPopupFlags flags = 0) { return s_gui->_BeginPopupContextItem(str_id, flags); }
146 static inline void EndPopup() { s_gui->_EndPopup(); }
147 static inline void CloseCurrentPopup() { s_gui->_CloseCurrentPopup(); }
148
149 static bool isFirstFrame();
150 static bool isFirstInitialization();
151
152 static inline GUIId GetID(const char * str_id) { return s_gui->_GetID(str_id); }
153
154 static inline void Test() { s_gui->_Test(); }
155
156 static void GraphicsSettingsCollaspingHeader();
157
158 static void EntitiesListCollapsingHeader();
159
160 static bool EditableTexture(vc::Texture * texture, vc::String & path);
161 static bool EditableModel(vc::Model * model, vc::String & path);
162
166 static void EntityGuizmo(const vcm::Vec2 & renderingSize);
167
168private:
169 static void __EntityPropertiesWindow();
170 static void __EntityGuizmo(const vcm::Vec2 & renderingSize);
171
172protected:
173 virtual void _EntityGuizmo(vc::Transform3D * transform3D, const vcm::Vec2 & renderingSize) = 0;
174
175 virtual vc::Error _Initialize() = 0;
176 virtual vc::Error _Reset() = 0;
177
178 virtual void _AddFont(const char * fontPath, float fontSize, const uint16_t * glyphRanges) = 0;
179 virtual void _AddFont(const char * fontPath, float fontSize) = 0;
180
181 virtual void _SetNextWindowPos(const vcm::Vec2 & pos, GUICond cond, const vcm::Vec2 & pivot) = 0;
182 virtual void _SetNextWindowSize(const vcm::Vec2 & size, GUICond cond) = 0;
183 virtual void _SetNextWindowViewport(GUIViewport viewport) = 0;
184
185 virtual vcm::Vec2 _GetContentRegionAvail() = 0;
186
187 virtual vcm::Vec2 _GetWindowSize() = 0;
188 virtual vcm::Vec2 _GetWindowPos() = 0;
189 virtual GUIViewport _GetMainViewport() = 0;
190
191 virtual void _NewFrame() = 0;
192 virtual void _Begin(const char * name, bool * p_open, GUIWindowFlags flags) = 0;
193 virtual void _End() = 0;
194 virtual void _Text(const char* fmt, va_list args) = 0;
195 virtual void _TextColored(const vcm::Vec4 & col, const char* fmt, va_list args) = 0;
196 virtual void _LabelText(const char* label, const char* fmt, va_list args) = 0;
197
198 virtual void _Image(const vc::Texture * texture, const vcm::Vec2 & size, bool centering) = 0;
199
200 virtual bool _InputText(const char* label, char* buf, size_t buf_size, GUIInputTextFlags flags) = 0;
201
202 virtual bool _TreeNode(const char* label) = 0;
203 virtual void _TreePop() = 0;
204 virtual void _TreePush(const char* str_id) = 0;
205
206 virtual void _SeparatorText(const char* text) = 0;
207 virtual void _Separator() = 0;
208 virtual void _Spacing() = 0;
209 virtual void _Dummy(const vcm::Vec2 & size) = 0;
210
211 virtual bool _SliderFloat(const char* label, float* v, float v_min, float v_max, const char* format) = 0;
212 virtual bool _SliderFloat3(const char* label, float v[3], float v_min, float v_max, const char* format) = 0;
213
214 virtual bool _InputFloat(const char* label, float* v, float step, float step_fast, const char* format, GUIColorEditFlags flags) = 0;
215 virtual bool _InputFloat3(const char* label, float v[3], const char* format, GUIColorEditFlags flags) = 0;
216
217 virtual void _ColorEdit3(const char* label, float col[3], GUIColorEditFlags flags) = 0;
218
219 virtual bool _CollapsingHeader(const char* label, GUITreeNodeFlags flags) = 0;
220
221 virtual bool _Button(const char* label, const vcm::Vec2 & size) = 0;
222 virtual bool _Checkbox(const char* label, bool* v) = 0;
223 virtual void _ProgressBar(float fraction, const vcm::Vec2 & size_arg, const char* overlay) = 0;
224
225 virtual bool _Selectable(const char* label, bool selected, GUISelectableFlags flags, const vcm::Vec2 & size) = 0;
226
227 virtual bool _BeginCombo(const char* label, const char* preview_value, GUIComboFlags flags) = 0;
228 virtual void _EndCombo() = 0;
229
230 virtual bool _BeginMenu(const char* label, bool enabled) = 0;
231 virtual void _EndMenu() = 0;
232
233 virtual bool _BeginMainMenuBar() = 0;
234 virtual void _EndMainMenuBar() = 0;
235
236 virtual bool _BeginMenuBar() = 0;
237 virtual void _EndMenuBar() = 0;
238
239 virtual bool _BeginChild(const char* str_id, const vcm::Vec2 & size, GUIChildFlags childFlags, GUIWindowFlags extra_flags) = 0;
240 virtual void _EndChild() = 0;
241
242 virtual bool _MenuItem(const char* str, const char* text) = 0;
243
244 virtual void _SetNextItemWidth(float item_width) = 0;
245 virtual void _SetItemDefaultFocus() = 0;
246
247 virtual void _SameLine(float offset_from_start_x, float spacing) = 0;
248
249 virtual void _PushItemWidth(float item_width) = 0;
250 virtual void _PopItemWidth() = 0;
251
252 virtual void _PushButtonTextAlign(const vcm::Vec2 & padding) = 0;
253 virtual void _PushWindowPadding(const vcm::Vec2 & padding) = 0;
254 virtual void _PopStyleVar() = 0;
255
256 virtual GUIId _DockSpace(GUIId id, const vcm::Vec2 & size, GUIDockNodeFlags flags) = 0;
257 virtual GUIId _DockSpace(const char * id, const vcm::Vec2 & size, GUIDockNodeFlags flags) = 0;
258 virtual GUIId _DockSpaceOverViewport() = 0;
259 virtual GUIId _DockSpaceAddNode(GUIId id, GUIDockNodeFlags flags) = 0;
260 virtual void _DockSpaceRemoveNode(GUIId id) = 0;
261 virtual void _DockSpaceSetNodeSize(GUIId id, const vcm::Vec2 & size) = 0;
262 virtual GUIId _DockSpaceSplitNode(GUIId id, GUIDir split_dir, float size_ratio, GUIId * out_id_at_dir, GUIId * out_id_at_opposite_dir) = 0;
263 virtual void _DockWindow(const char * str_id, GUIId id) = 0;
264 virtual void _DockFinish(GUIId id) = 0;
265
266 virtual void _OpenPopup(const char * str_id, GUIPopupFlags flags) = 0;
267 virtual bool _BeginPopup(const char * str_id, GUIWindowFlags flags) = 0;
268 virtual bool _BeginPopupModal(const char * name, bool * p_open, GUIWindowFlags flags) = 0;
269 virtual bool _BeginPopupContextItem(const char * str_id, GUIPopupFlags flags) = 0;
270 virtual void _EndPopup() = 0;
271 virtual void _CloseCurrentPopup() = 0;
272
273 virtual GUIId _GetID(const char * str_id) = 0;
274
275 virtual void _Render() = 0;
276 virtual vc::Error _PreUpdate() = 0;
277
278 virtual void _Test() = 0;
279
280protected:
281 GraphicsApplication * _app;
282 struct FontData
283 {
284 const vc::String path;
285 float size;
286 const uint16_t * glyphRanges;
287 };
288 vc::Vector<FontData> _fonts;
289
290private:
295 vc::Error __PreUpdate();
296
297protected:
298 bool _firstInit;
299private:
300 static GUI * s_gui;
301 bool __firstFrame;
302
303private:
304 static GUIDrawCallback s_guiDrawCallback;
305 static bool s_guiDraw;
306
307 friend class VenomEngine;
308};
309}
310}
static void EntityGuizmo(const vcm::Vec2 &renderingSize)
Definition GUI.cc:272
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:179
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:283