lxgui
Loading...
Searching...
No Matches
gui_manager.hpp
1#ifndef LXGUI_GUI_MANAGER_HPP
2#define LXGUI_GUI_MANAGER_HPP
3
4#include "lxgui/input_keys.hpp"
5#include "lxgui/lxgui.hpp"
6#include "lxgui/utils_observer.hpp"
7#include "lxgui/utils_signal.hpp"
8
9#include <functional>
10#include <memory>
11#include <string>
12#include <vector>
13
16namespace sol {
17
18class state;
19
20}
24namespace lxgui::input {
25
26class source;
27class window;
28class dispatcher;
29class world_dispatcher;
30
31} // namespace lxgui::input
32
33namespace lxgui::gui {
34
35class renderer;
36class localizer;
37class factory;
38class root;
39class virtual_root;
40class addon_registry;
41class event_emitter;
42
45public:
52 manager(
53 utils::control_block& block,
54 std::unique_ptr<input::source> src,
55 std::unique_ptr<renderer> rdr);
56
58 ~manager() override;
59
60 // Non-copiable, non-movable
61 manager(const manager&) = delete;
62 manager(manager&&) = delete;
63 manager& operator=(const manager&) = delete;
65
81 void set_interface_scaling_factor(float scaling_factor);
82
88 float get_interface_scaling_factor() const;
89
96
104 void toggle_caching();
105
111 bool is_caching_enabled() const;
112
119 void add_addon_directory(const std::string& directory);
120
130
137 void add_localization_directory(const std::string& directory);
138
148
157 utils::signal<void(sol::state&)> on_create_lua;
158
163 std::string print_ui() const;
164
171 void load_ui();
172
179 void close_ui();
180
187 void close_ui_now();
188
195 void reload_ui();
196
203 void reload_ui_now();
204
209 bool is_loaded() const;
210
215 void render_ui() const;
216
221 void update_ui(float delta);
222
227 sol::state& get_lua();
228
233 const sol::state& get_lua() const;
234
239 const renderer& get_renderer() const {
240 return *renderer_;
241 }
242
248 return *renderer_;
249 }
250
255 const input::window& get_window() const {
256 return *window_;
257 }
258
264 return *window_;
265 }
266
272 return *input_dispatcher_;
273 }
274
280 return *input_dispatcher_;
281 }
282
288 return *world_input_dispatcher_;
289 }
290
296 return *world_input_dispatcher_;
297 }
298
304 return *event_emitter_;
305 }
306
312 return *event_emitter_;
313 }
314
320 return *localizer_;
321 }
322
327 const localizer& get_localizer() const {
328 return *localizer_;
329 }
330
336 return *root_;
337 }
338
343 const root& get_root() const {
344 return *root_;
345 }
346
352 return *virtual_root_;
353 }
354
360 return *virtual_root_;
361 }
362
368 return *factory_;
369 }
370
375 const factory& get_factory() const {
376 return *factory_;
377 }
378
384 return addon_registry_.get();
385 }
386
392 return addon_registry_.get();
393 }
394
395private:
402 void create_lua_();
403
412 void read_files_();
413
414 // Persistent state
415 float scaling_factor_ = 1.0f;
416 float base_scaling_factor_ = 1.0f;
417 bool enable_caching_ = false;
418 std::vector<std::string> localization_directory_list_;
419 std::vector<std::string> gui_directory_list_;
420
421 // Implementations
422 std::unique_ptr<input::source> input_source_;
423 std::unique_ptr<renderer> renderer_;
424
425 // IO
426 std::unique_ptr<input::window> window_;
427 std::unique_ptr<input::dispatcher> input_dispatcher_;
428 std::unique_ptr<input::world_dispatcher> world_input_dispatcher_;
429 std::unique_ptr<event_emitter> event_emitter_;
430
431 // UI state
432 std::unique_ptr<factory> factory_;
433 std::unique_ptr<localizer> localizer_;
434 std::unique_ptr<sol::state> lua_;
436 utils::owner_ptr<virtual_root> virtual_root_;
437 std::unique_ptr<addon_registry> addon_registry_;
438
439 bool is_loaded_ = false;
440 bool reload_ui_flag_ = false;
441 bool close_ui_flag_ = false;
442 bool is_first_iteration_ = true;
443};
444
445} // namespace lxgui::gui
446
447#endif
Generates events and keep tracks of registered callbacks.
Handles the creation of new UI objects.
Utility class to translate strings for display in GUI.
Manages the user interface.
manager & operator=(const manager &)=delete
void add_localization_directory(const std::string &directory)
Adds a new directory to be parsed for localization.
virtual_root & get_virtual_root()
Returns the UI root object, which contains root frames.
root & get_root()
Returns the UI root object, which contains root frames.
const virtual_root & get_virtual_root() const
Returns the UI root object, which contains root frames.
manager(manager &&)=delete
manager(const manager &)=delete
void toggle_caching()
Toggles interface caching.
addon_registry * get_addon_registry()
Returns the addon registry, which keeps track of loaded addons.
void set_interface_scaling_factor(float scaling_factor)
Sets the global UI scaling factor.
float get_interface_scaling_factor() const
Returns the current UI scaling factor.
renderer & get_renderer()
Returns the renderer implementation.
bool is_loaded() const
Checks if the UI has been loaded.
void load_ui()
Loads the UI.
void render_ui() const
Renders the UI into the current render target.
input::window & get_window()
Returns the window in which this gui is being displayed.
utils::signal< void(sol::state &)> on_create_lua
Triggers on each fresh Lua state (e.g., on startup or after a UI re-load).
const factory & get_factory() const
Returns the UI object factory, which is used to create new objects.
event_emitter & get_event_emitter()
Returns the gui event emitter.
void reload_ui_now()
Closes the UI and load it again (immediately).
factory & get_factory()
Returns the UI object factory, which is used to create new objects.
std::string print_ui() const
Prints debug information in the log file.
const renderer & get_renderer() const
Returns the renderer implementation.
void close_ui()
Closes the UI safely (at the end of update_ui()).
localizer & get_localizer()
Returns the object used for localizing strings.
const input::window & get_window() const
Returns the window in which this gui is being displayed.
const localizer & get_localizer() const
Returns the object used for localizing strings.
void clear_localization_directory_list()
Clears the localization directory list.
void clear_addon_directory_list()
Clears the addon directory list.
void enable_caching(bool enable_caching)
Enables or disables interface caching.
const addon_registry * get_addon_registry() const
Returns the addon registry, which keeps track of loaded addons.
void close_ui_now()
Closes the UI (immediately).
const input::world_dispatcher & get_world_input_dispatcher() const
Returns the input manager associated to this gui.
sol::state & get_lua()
Returns the GUI Lua state (sol wrapper).
input::dispatcher & get_input_dispatcher()
Returns the input manager associated to this gui.
void reload_ui()
Closes the UI and load it again safely (at the end of update_ui()).
~manager() override
Destructor.
bool is_caching_enabled() const
Checks if interface caching is enabled.
manager & operator=(manager &&)=delete
const input::dispatcher & get_input_dispatcher() const
Returns the input manager associated to this gui.
input::world_dispatcher & get_world_input_dispatcher()
Returns the input manager associated to this gui.
const root & get_root() const
Returns the UI root object, which contains root frames.
void add_addon_directory(const std::string &directory)
Adds a new directory to be parsed for UI addons.
void update_ui(float delta)
Updates this manager and its regions.
const event_emitter & get_event_emitter() const
Returns the gui event emitter.
Abstract type for implementation specific management.
Root of the UI object hierarchy.
Definition gui_root.hpp:39
Root of the virtual UI object hierarchy.
Handles inputs (keyboard and mouse)
Represents the window in which the UI is displayed.
Generates input events for the world, after filtering by the UI.
Generic class for observing and triggering events.
oup::enable_observer_from_this_sealed< T > enable_observer_from_this
oup::observable_sealed_ptr< T > owner_ptr