lxgui
gui_status_bar_parser.cpp
1 #include "lxgui/gui_layout_node.hpp"
2 #include "lxgui/gui_out.hpp"
3 #include "lxgui/gui_parser_common.hpp"
4 #include "lxgui/gui_status_bar.hpp"
5 #include "lxgui/gui_texture.hpp"
6 
7 namespace lxgui::gui {
8 
11 
12  if (const auto attr = node.try_get_attribute_value<float>("minValue"))
13  set_min_value(attr.value());
14  if (const auto attr = node.try_get_attribute_value<float>("maxValue"))
15  set_max_value(attr.value());
16  if (const auto attr = node.try_get_attribute_value<float>("defaultValue"))
17  set_value(attr.value());
18  if (const auto attr = node.try_get_attribute_value<layer>("drawLayer"))
19  set_bar_draw_layer(attr.value());
20  if (const auto attr = node.try_get_attribute_value<orientation>("orientation"))
21  set_orientation(attr.value());
22  if (const auto attr = node.try_get_attribute_value<bool>("reversed"))
23  set_reversed(attr.value());
24 }
25 
28 
29  const layout_node* texture_node = node.try_get_child("BarTexture");
30  const layout_node* color_node = node.try_get_child("BarColor");
31  if (color_node && texture_node) {
33  << ": StatusBar can only contain one of BarTexture or BarColor, but not both. "
34  "BarColor ignored."
35  << std::endl;
36  }
37 
38  if (texture_node) {
39  layout_node defaulted = *texture_node;
40  defaulted.get_or_set_attribute_value("name", "$parentBarTexture");
41 
42  auto bar_texture = parse_region_(defaulted, "ARTWORK", "Texture");
43  if (bar_texture) {
44  bar_texture->set_manually_inherited(true);
45  set_bar_texture(utils::static_pointer_cast<texture>(bar_texture));
46  }
47 
48  warn_for_not_accessed_node(defaulted);
49  texture_node->bypass_access_check();
50  } else if (color_node) {
51  set_bar_color(parse_color_node_(*color_node));
52  }
53 }
54 
55 } // namespace lxgui::gui
virtual void parse_all_nodes_before_children_(const layout_node &node)
void parse_attributes_(const layout_node &node) override
utils::observer_ptr< layered_region > parse_region_(const layout_node &node, const std::string &layer_name, const std::string &type)
std::string_view get_location() const noexcept
Returns this node's location in the file as {file}:{line}.
void bypass_access_check() const noexcept
Flag this node as "fully accessed" for later warnings; no check will be done.
An node in a layout file.
std::optional< std::string_view > try_get_attribute_value(std::string_view name) const noexcept
Returns the value of the attribute with the provided name, nullopt if not found.
std::string_view get_or_set_attribute_value(std::string_view name, std::string_view value)
Returns the value of the attribute with the provided name, or set it if none.
const layout_node * try_get_child(std::string_view name) const noexcept
Returns the first child with a given name, or null if none.
color parse_color_node_(const layout_node &node)
void set_value(float value)
Sets this status_bar's value.
void set_orientation(orientation orient)
Sets this status_bar's orientation.
void set_min_value(float min_value)
Sets this status_bar's minimum value.
void parse_all_nodes_before_children_(const layout_node &node) override
void set_bar_draw_layer(layer bar_layer)
Sets the draw layer of this status_bar's bar texture.
void set_reversed(bool reversed)
Reverses this status_bar.
void parse_attributes_(const layout_node &node) override
void set_max_value(float max_value)
Sets this status_bar's maximum value.
void set_bar_texture(utils::observer_ptr< texture > bar_texture)
Sets this status_bar's bar texture.
void set_bar_color(const color &bar_color)
Sets this status_bar's bar color.
layer
ID of a layer for rendering inside a frame.
std::ostream out
const std::string warning
Definition: gui_out.cpp:6
void warn_for_not_accessed_node(const layout_node &node)
Emit a warning if this node (or any of its attributes/children) was not read.