lxgui
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 
16 namespace sol {
17 
18 class state;
19 
20 }
24 namespace lxgui::input {
25 
26 class source;
27 class window;
28 class dispatcher;
29 class world_dispatcher;
30 
31 } // namespace lxgui::input
32 
33 namespace lxgui::gui {
34 
35 class renderer;
36 class localizer;
37 class factory;
38 class root;
39 class virtual_root;
40 class addon_registry;
41 class event_emitter;
42 
45 public:
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;
64  manager& operator=(manager&&) = delete;
65 
81  void set_interface_scaling_factor(float scaling_factor);
82 
88  float get_interface_scaling_factor() const;
89 
95  void enable_caching(bool enable_caching);
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 
395 private:
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
Loads and owns addons.
Generates events and keep tracks of registered callbacks.
Handles the creation of new UI objects.
Definition: gui_factory.hpp:39
Utility class to translate strings for display in GUI.
Manages the user interface.
Definition: gui_manager.hpp:44
manager(utils::control_block &block, std::unique_ptr< input::source > src, std::unique_ptr< renderer > rdr)
Constructor.
Definition: gui_manager.cpp:36
void add_localization_directory(const std::string &directory)
Adds a new directory to be parsed for localization.
renderer & get_renderer()
Returns the renderer implementation.
const event_emitter & get_event_emitter() const
Returns the gui event emitter.
manager(manager &&)=delete
manager(const manager &)=delete
void toggle_caching()
Toggles interface caching.
Definition: gui_manager.cpp:97
const localizer & get_localizer() const
Returns the object used for localizing strings.
localizer & get_localizer()
Returns the object used for localizing strings.
const root & get_root() const
Returns the UI root object, which contains root frames.
void set_interface_scaling_factor(float scaling_factor)
Sets the global UI scaling factor.
Definition: gui_manager.cpp:70
float get_interface_scaling_factor() const
Returns the current UI scaling factor.
Definition: gui_manager.cpp:87
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.
factory & get_factory()
Returns the UI object factory, which is used to create new objects.
manager & operator=(manager &&)=delete
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 input::dispatcher & get_input_dispatcher() const
Returns the input manager associated to this gui.
virtual_root & get_virtual_root()
Returns the UI root object, which contains root frames.
const addon_registry * get_addon_registry() const
Returns the addon registry, which keeps track of loaded addons.
void reload_ui_now()
Closes the UI and load it again (immediately).
addon_registry * get_addon_registry()
Returns the addon registry, which keeps track of loaded addons.
std::string print_ui() const
Prints debug information in the log file.
const input::window & get_window() const
Returns the window in which this gui is being displayed.
void close_ui()
Closes the UI safely (at the end of update_ui()).
const input::world_dispatcher & get_world_input_dispatcher() const
Returns the input manager associated to this gui.
input::dispatcher & get_input_dispatcher()
Returns the input manager associated to this gui.
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.
Definition: gui_manager.cpp:91
const renderer & get_renderer() const
Returns the renderer implementation.
input::window & get_window()
Returns the window in which this gui is being displayed.
void close_ui_now()
Closes the UI (immediately).
input::world_dispatcher & get_world_input_dispatcher()
Returns the input manager associated to this gui.
manager & operator=(const manager &)=delete
const virtual_root & get_virtual_root() const
Returns the UI root object, which contains root frames.
root & get_root()
Returns the UI root object, which contains root frames.
sol::state & get_lua()
Returns the GUI Lua state (sol wrapper).
void reload_ui()
Closes the UI and load it again safely (at the end of update_ui()).
const factory & get_factory() const
Returns the UI object factory, which is used to create new objects.
~manager() override
Destructor.
Definition: gui_manager.cpp:66
bool is_caching_enabled() const
Checks if interface caching is enabled.
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.
event_emitter & get_event_emitter()
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