1 #include "lxgui/gui_frame_renderer.hpp"
3 #include "lxgui/gui_frame.hpp"
4 #include "lxgui/gui_out.hpp"
5 #include "lxgui/utils_range.hpp"
6 #include "lxgui/utils_string.hpp"
12 gui::out <<
"----------" << std::endl;
13 for (
auto iter = list.begin(); iter != list.end(); ++iter) {
14 gui::out <<
" - " << (*iter)->get_name() <<
": "
15 << utils::to_string((*iter)->get_effective_strata()) <<
", "
16 << (*iter)->get_level() << std::endl;
18 if (iter != list.begin()) {
19 gui::out <<
" is greater than last? " << list.comparator()(*(iter - 1), *iter)
23 gui::out <<
"----------" << std::endl;
25 if (!std::is_sorted(list.begin(), list.end(), list.comparator())) {
30 struct strata_comparator {
32 using int_type = std::underlying_type_t<strata>;
33 const auto strata_id1 =
static_cast<int_type
>(s1);
34 const auto strata_id2 =
static_cast<int_type
>(s2);
35 return strata_id1 < strata_id2;
38 bool operator()(
const frame* f1,
strata s2)
const {
39 return operator()(f1->get_effective_strata(), s2);
42 bool operator()(
strata s1,
const frame* f2)
const {
43 return operator()(s1, f2->get_effective_strata());
46 bool operator()(
const frame* f1,
const frame* f2)
const {
47 return operator()(f1->get_effective_strata(), f2->get_effective_strata());
52 using int_type = std::underlying_type_t<strata>;
56 if (strata_id1 < strata_id2)
58 if (strata_id1 > strata_id2)
79 strata_list_[
static_cast<std::size_t
>(strata_id)].redraw_flag =
true;
89 throw gui::exception(
"frame_renderer",
"Frame was already in this renderer");
94 throw gui::exception(
"frame_renderer",
"Could not find frame in this renderer");
104 const auto strata_id = obj->get_effective_strata();
111 const utils::observer_ptr<frame>& ,
strata old_strata_id,
strata new_strata_id) {
126 auto range = std::equal_range(
133 const utils::observer_ptr<frame>& obj,
int ,
int ) {
135 const auto strata_id = obj->get_effective_strata();
137 auto& strata_obj =
strata_list_[
static_cast<std::size_t
>(strata_id)];
148 utils::observer_ptr<const frame>
152 if (obj->is_visible()) {
153 if (
auto topmost = obj->find_topmost_frame(predicate))
162 auto range =
strata_list_[
static_cast<std::size_t
>(strata_id)].range;
168 return (*last)->get_level();
178 for (
auto iter = begin; iter != end; ++iter) {
Exception to be thrown by GUI code.
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.
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.
void reset_strata_list_changed_flag_()
void render_strata_(const strata_data &strata_obj) const
frame_list_type sorted_frame_list_
std::array< strata_data, num_strata > strata_list_
bool has_strata_list_changed_() const
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.
void clear_strata_list_()
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.
int get_level() const
Returns this frame's level.
strata get_effective_strata() const
Returns this frame's effective strata.
iterator find(const Key &k)
Find an object in this vector by its key. The key can be a copy of the element itself,...
std::pair< iterator, bool > insert(U &&t)
Insert the provided object in the vector, only if no object exists with the same key.
iterator erase(iterator iter)
Erase an element from this vector.
Cmp & comparator()
Return the comparator object.
void check_sorted(const T &list)
range_impl::reverse_range< T > reverse(T &container)
Reverse traversal.
bool operator()(const frame *f1, const frame *f2) const
Contains frames sorted by level.
std::pair< std::size_t, std::size_t > range