lxgui
Loading...
Searching...
No Matches
gui_frame_renderer.hpp
1#ifndef LXGUI_GUI_FRAME_RENDERER_HPP
2#define LXGUI_GUI_FRAME_RENDERER_HPP
3
4#include "lxgui/gui_strata.hpp"
5#include "lxgui/lxgui.hpp"
6#include "lxgui/utils.hpp"
7#include "lxgui/utils_observer.hpp"
8#include "lxgui/utils_sorted_vector.hpp"
9
10#include <functional>
11#include <magic_enum/magic_enum.hpp>
12
13namespace lxgui::gui {
14
15class frame;
16class font;
17class color;
18
21public:
24
26 virtual ~frame_renderer() = default;
27
28 // Non-copiable, non-movable
33
35 virtual void notify_strata_needs_redraw(strata strata_id);
36
42 virtual void notify_rendered_frame(const utils::observer_ptr<frame>& obj, bool rendered);
43
50 virtual void notify_strata_changed(
51 const utils::observer_ptr<frame>& obj, strata old_strata_id, strata new_strata_id);
52
59 virtual void
60 notify_level_changed(const utils::observer_ptr<frame>& obj, int old_level, int new_level);
61
66 virtual vector2f get_target_dimensions() const = 0;
67
73 utils::observer_ptr<const frame>
74 find_topmost_frame(const std::function<bool(const frame&)>& predicate) const;
75
81 utils::observer_ptr<frame>
82 find_topmost_frame(const std::function<bool(const frame&)>& predicate) {
83 return utils::const_pointer_cast<frame>(
84 const_cast<const frame_renderer*>(this)->find_topmost_frame(predicate));
85 }
86
92 int get_highest_level(strata strata_id) const;
93
94protected:
95 void clear_strata_list_();
96 bool has_strata_list_changed_() const;
98
99 void render_strata_(const strata_data& strata_obj) const;
100
102 bool operator()(const frame* f1, const frame* f2) const;
103 };
104
107
108 std::pair<std::size_t, std::size_t> get_strata_range_(strata strata_id) const;
109
110 static constexpr std::size_t num_strata = magic_enum::enum_count<strata>();
111
112 std::array<strata_data, num_strata> strata_list_;
115};
116
117} // namespace lxgui::gui
118
119#endif
Abstract class for layering and rendering frames.
virtual void notify_strata_changed(const utils::observer_ptr< frame > &obj, strata old_strata_id, strata new_strata_id)
Tells this renderer that a frame has changed strata.
virtual void notify_strata_needs_redraw(strata strata_id)
Tells this renderer that one of its region requires redraw.
frame_renderer(frame_renderer &&)=delete
int get_highest_level(strata strata_id) const
Returns the highest level on the provided strata.
virtual void notify_level_changed(const utils::observer_ptr< frame > &obj, int old_level, int new_level)
Tells this renderer that a frame has changed level.
frame_renderer(const frame_renderer &)=delete
frame_renderer & operator=(const frame_renderer &)=delete
void render_strata_(const strata_data &strata_obj) const
virtual ~frame_renderer()=default
Destructor.
frame_list_type::iterator frame_list_iterator
utils::observer_ptr< frame > find_topmost_frame(const std::function< bool(const frame &)> &predicate)
Find the top-most frame matching the provided predicate.
std::array< strata_data, num_strata > strata_list_
virtual void notify_rendered_frame(const utils::observer_ptr< frame > &obj, bool rendered)
Tells this renderer that it should (or not) render another frame.
utils::observer_ptr< const frame > find_topmost_frame(const std::function< bool(const frame &)> &predicate) const
Find the top-most frame matching the provided predicate.
frame_renderer & operator=(frame_renderer &&)=delete
static constexpr std::size_t num_strata
virtual vector2f get_target_dimensions() const =0
Returns the width and height of of this renderer's main render target (e.g., screen).
std::pair< std::size_t, std::size_t > get_strata_range_(strata strata_id) const
frame_renderer()
Default constructor.
A region that can contain other regions and react to events.
bool operator()(const frame *f1, const frame *f2) const
Contains frames sorted by level.