lxgui
gui_backdrop.hpp
1 #ifndef LXGUI_GUI_BACKDROP_HPP
2 #define LXGUI_GUI_BACKDROP_HPP
3 
4 #include "lxgui/gui_bounds2.hpp"
5 #include "lxgui/gui_material.hpp"
6 #include "lxgui/gui_quad.hpp"
7 #include "lxgui/gui_vertex_cache.hpp"
8 #include "lxgui/lxgui.hpp"
9 #include "lxgui/utils.hpp"
10 
11 #include <string>
12 
13 namespace lxgui::gui {
14 
15 class frame;
16 
18 class backdrop {
19 public:
24  explicit backdrop(frame& parent);
25 
27  backdrop(const backdrop&) = delete;
28 
30  backdrop(backdrop&&) = delete;
31 
33  backdrop& operator=(const backdrop&) = delete;
34 
36  backdrop& operator=(backdrop&&) = delete;
37 
42  void copy_from(const backdrop& other);
43 
48  void set_background(const std::string& background_file);
49 
54  const std::string& get_background_file() const;
55 
62  void set_background_color(const color& c);
63 
69 
74  void set_background_tilling(bool is_tilling);
75 
80  bool is_background_tilling() const;
81 
87  void set_tile_size(float tile_size);
88 
93  float get_tile_size() const;
94 
99  void set_background_insets(const bounds2f& insets);
100 
105  const bounds2f& get_background_insets() const;
106 
111  void set_edge_insets(const bounds2f& insets);
112 
117  const bounds2f& get_edge_insets() const;
118 
133  void set_edge(const std::string& edge_file);
134 
139  const std::string& get_edge_file() const;
140 
147  void set_edge_color(const color& c);
148 
153  color get_edge_color() const;
154 
160  void set_edge_size(float edge_size);
161 
166  float get_edge_size() const;
167 
172  void set_vertex_color(const color& c);
173 
175  void render() const;
176 
178  void notify_borders_updated() const;
179 
180 private:
181  void update_cache_() const;
182  void update_background_(color c) const;
183  void update_edge_(color c) const;
184 
185  frame& parent_;
186 
187  std::string background_file_;
188  color background_color_ = color::empty;
189  std::shared_ptr<material> background_texture_;
190  bool is_background_tilling_ = false;
191  float tile_size_ = 0.0f;
192  float original_tile_size_ = 0.0f;
193  bounds2f background_insets_;
194 
195  std::string edge_file_;
196  color edge_color_ = color::empty;
197  std::shared_ptr<material> edge_texture_;
198  bounds2f edge_insets_;
199  float edge_size_ = 0.0f;
200  float original_edge_size_ = 0.0f;
201 
202  color vertex_color_ = color::white;
203 
204  mutable bool is_cache_dirty_ = true;
205  mutable float cache_alpha_ = std::numeric_limits<float>::quiet_NaN();
206  mutable std::vector<std::array<vertex, 4>> background_quads_;
207  mutable std::shared_ptr<vertex_cache> background_cache_;
208  mutable std::vector<std::array<vertex, 4>> edge_quads_;
209  mutable std::shared_ptr<vertex_cache> edge_cache_;
210 };
211 
212 } // namespace lxgui::gui
213 
214 #endif
Draws borders and background of a frame.
bool is_background_tilling() const
Checks if tilling is enabled for the background texture.
backdrop(const backdrop &)=delete
Non-copiable.
float get_tile_size() const
Returns this backdrop's tile size.
color get_edge_color() const
Returns the edge color.
void set_tile_size(float tile_size)
Sets the apparent tile size.
void set_edge_color(const color &c)
Sets the edge color.
const bounds2f & get_edge_insets() const
Returns this backdrop's edge insets.
float get_edge_size() const
Returns this backdrop's edge size.
void set_edge_size(float edge_size)
Sets the apparent edge size.
void set_vertex_color(const color &c)
Sets the color to be multiplied to all drawn vertices.
const bounds2f & get_background_insets() const
Returns this backdrop's background insets.
const std::string & get_edge_file() const
Returns this backdrop's edge file.
void set_edge_insets(const bounds2f &insets)
Sets insets for the edge texture.
backdrop(frame &parent)
Constructor.
backdrop & operator=(const backdrop &)=delete
Non-copiable.
color get_background_color() const
Returns the background color.
void set_background_insets(const bounds2f &insets)
Sets insets for the background texture.
void copy_from(const backdrop &other)
Copies a backdrop's parameters into this one (inheritance).
void set_edge(const std::string &edge_file)
Sets the edge/corner texture.
const std::string & get_background_file() const
Returns this backdrop's background file.
void set_background(const std::string &background_file)
Sets the background texture.
backdrop(backdrop &&)=delete
Non-movable.
backdrop & operator=(backdrop &&)=delete
Non-movable.
void set_background_tilling(bool is_tilling)
Enables tilling for the background texture.
void set_background_color(const color &c)
Sets the background color.
void notify_borders_updated() const
Tells this backdrop that its parent frame has changed dimensions.
void render() const
Renders this backdrop on the current render target.
Holds a single color (float RGBA, 128 bits)
Definition: gui_color.hpp:12
static const color white
Definition: gui_color.hpp:43
static const color empty
Definition: gui_color.hpp:42
A region that can contain other regions and react to events.
Definition: gui_frame.hpp:255