lxgui
gui_check_button.cpp
1 #include "lxgui/gui_check_button.hpp"
2 
3 #include "lxgui/gui_frame.hpp"
4 #include "lxgui/gui_manager.hpp"
5 #include "lxgui/gui_out.hpp"
6 #include "lxgui/gui_region_tpl.hpp"
7 #include "lxgui/gui_texture.hpp"
8 
9 namespace lxgui::gui {
10 
12  utils::control_block& block, manager& mgr, const frame_core_attributes& attr) :
13  button(block, mgr, attr) {
14 
15  initialize_(*this, attr);
16 }
17 
18 std::string check_button::serialize(const std::string& tab) const {
19  return base::serialize(tab);
20 }
21 
22 void check_button::copy_from(const region& obj) {
23  base::copy_from(obj);
24 
25  const check_button* button_obj = down_cast<check_button>(&obj);
26  if (!button_obj)
27  return;
28 
29  if (const texture* checked_texture = button_obj->get_checked_texture().get()) {
31  attr.name = checked_texture->get_raw_name();
32  attr.inheritance = {button_obj->get_checked_texture()};
33 
34  auto tex = this->create_layered_region<texture>(
35  checked_texture->get_draw_layer(), std::move(attr));
36 
37  if (tex) {
38  tex->set_manually_inherited(true);
39  tex->notify_loaded();
40  this->set_checked_texture(tex);
41  }
42  }
43 
44  if (const texture* disabled_texture = button_obj->get_disabled_checked_texture().get()) {
46  attr.name = disabled_texture->get_raw_name();
47  attr.inheritance = {button_obj->get_disabled_checked_texture()};
48 
49  auto tex = this->create_layered_region<texture>(
50  disabled_texture->get_draw_layer(), std::move(attr));
51 
52  if (tex) {
53  tex->set_manually_inherited(true);
54  tex->notify_loaded();
56  }
57  }
58 }
59 
61  if (is_checked_)
62  return;
63 
64  if (state_ == state::disabled) {
67  else if (checked_texture_)
68  checked_texture_->show();
69  } else {
70  if (checked_texture_)
71  checked_texture_->show();
72  }
73 
74  is_checked_ = true;
75 }
76 
78  if (!is_checked_)
79  return;
80 
83 
84  if (checked_texture_)
85  checked_texture_->hide();
86 
87  is_checked_ = false;
88 }
89 
91  base::disable();
92 
94  if (checked_texture_)
95  checked_texture_->hide();
96 
98  }
99 }
100 
102  base::enable();
103 
105  if (checked_texture_)
106  checked_texture_->show();
107 
109  }
110 }
111 
113  base::release();
114 
115  if (is_checked())
116  uncheck();
117  else
118  check();
119 }
120 
122  return is_checked_;
123 }
124 
125 void check_button::set_checked_texture(utils::observer_ptr<texture> tex) {
126  checked_texture_ = std::move(tex);
127  if (!checked_texture_)
128  return;
129 
130  checked_texture_->set_shown(
132 }
133 
134 void check_button::set_disabled_checked_texture(utils::observer_ptr<texture> tex) {
135  disabled_checked_texture_ = std::move(tex);
137  return;
138 
139  if (checked_texture_) {
140  checked_texture_->set_shown(
142  }
143 
145 }
146 
147 const std::vector<std::string>& check_button::get_type_list_() const {
148  return get_type_list_impl_<check_button>();
149 }
150 
151 } // namespace lxgui::gui
A frame with a button that can be clicked.
Definition: gui_button.hpp:52
std::string serialize(const std::string &tab) const override
Prints all relevant information about this region in a string.
Definition: gui_button.cpp:22
virtual void disable()
Disables this button.
Definition: gui_button.cpp:291
bool is_enabled() const
Checks if this button is enabled.
Definition: gui_button.cpp:358
virtual void release()
Releases this button.
Definition: gui_button.cpp:380
virtual void enable()
Enables this button.
Definition: gui_button.cpp:328
void copy_from(const region &obj) override
Copies a region's parameters into this button (inheritance).
Definition: gui_button.cpp:86
A button with two additional states: checked and unchecked.
const utils::observer_ptr< texture > & get_disabled_checked_texture()
Returns this button's disabled checked texture.
const std::vector< std::string > & get_type_list_() const override
utils::observer_ptr< texture > disabled_checked_texture_
void set_disabled_checked_texture(utils::observer_ptr< texture > tex)
Sets this button's disabled checked texture.
virtual void uncheck()
UnChecks this button.
const utils::observer_ptr< texture > & get_checked_texture()
Returns this button's checked texture.
virtual void check()
Checks this button.
check_button(utils::control_block &block, manager &mgr, const frame_core_attributes &attr)
Constructor.
void disable() override
Disables this check button.
void enable() override
Enables this check button.
void copy_from(const region &obj) override
Copies a region's parameters into this check button (inheritance).
std::string serialize(const std::string &tab) const override
Prints all relevant information about this region in a string.
void release() override
Releases this check button.
utils::observer_ptr< texture > checked_texture_
void set_checked_texture(utils::observer_ptr< texture > tex)
Sets this button's checked texture.
bool is_checked() const
Checks if this check button is checked.
Manages the user interface.
Definition: gui_manager.hpp:44
The base class of all elements in the GUI.
Definition: gui_region.hpp:161
void initialize_(T &self, const region_core_attributes &attr)
Set up function to call in all derived class constructors.
A layered_region that can draw images and colored rectangles.
Definition: gui_texture.hpp:23
Struct holding all the core information about a frame necessary for its creation.
Struct holding all the core information about a region necessary for its creation.
std::vector< utils::observer_ptr< const region > > inheritance