Another refactoring patch making load_config() more generic.
This commit is contained in:
parent
f968eb3f3b
commit
ff14c3865b
11 changed files with 48 additions and 67 deletions
|
@ -126,18 +126,4 @@ void tbutton::set_state(tstate state)
|
|||
}
|
||||
}
|
||||
|
||||
void tbutton::load_config()
|
||||
{
|
||||
if(!config()) {
|
||||
set_config(get_control("button", definition()));
|
||||
|
||||
assert(canvas().size() == config()->state.size());
|
||||
for(size_t i = 0; i < canvas().size(); ++i) {
|
||||
canvas(i) = config()->state[i].canvas;
|
||||
}
|
||||
|
||||
set_canvas_text();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
|
|
@ -62,9 +62,6 @@ public:
|
|||
bool get_active() const;
|
||||
unsigned get_state() const { return state_; }
|
||||
|
||||
//! Inherited from twidget.
|
||||
void load_config();
|
||||
|
||||
protected:
|
||||
|
||||
private:
|
||||
|
@ -75,6 +72,10 @@ private:
|
|||
tstate state_;
|
||||
|
||||
int retval_;
|
||||
|
||||
//! Inherited from tcontrol.
|
||||
const std::string& get_control_type() const
|
||||
{ static const std::string type = "button"; return type; }
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -350,6 +350,22 @@ void tcontrol::restore_background(surface& dst)
|
|||
}
|
||||
}
|
||||
|
||||
void tcontrol::load_config()
|
||||
{
|
||||
if(!config()) {
|
||||
set_config(get_control(get_control_type(), definition()));
|
||||
|
||||
assert(canvas().size() == config()->state.size());
|
||||
for(size_t i = 0; i < canvas().size(); ++i) {
|
||||
canvas(i) = config()->state[i].canvas;
|
||||
}
|
||||
|
||||
set_canvas_text();
|
||||
|
||||
load_config_extra();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
|
||||
|
|
|
@ -87,6 +87,9 @@ public:
|
|||
tpoint get_best_size() const;
|
||||
tpoint get_maximum_size() const;
|
||||
|
||||
//! Inherited from twidget.
|
||||
void load_config();
|
||||
|
||||
private:
|
||||
//! Helpers
|
||||
tpoint get_single_line_best_size(const tpoint& config_size) const;
|
||||
|
@ -149,6 +152,15 @@ private:
|
|||
//! current resolution.
|
||||
tresolution_definition_* config_;
|
||||
|
||||
//! Once the config is loaded this function is called.
|
||||
virtual void load_config_extra() {}
|
||||
|
||||
//! The control_type parameter for tgui_definition::get_control()
|
||||
//! To keep the code more generic this type is required so the
|
||||
//! controls need to return the proper string here.
|
||||
//! Might be used at other parts as well the get the type of
|
||||
//! control involved.
|
||||
virtual const std::string& get_control_type() const = 0;
|
||||
};
|
||||
|
||||
} // namespace gui2
|
||||
|
|
|
@ -47,20 +47,6 @@ void tlabel::set_state(tstate state)
|
|||
}
|
||||
}
|
||||
|
||||
void tlabel::load_config()
|
||||
{
|
||||
if(!config()) {
|
||||
set_config(get_control("label", definition()));
|
||||
|
||||
assert(canvas().size() == config()->state.size());
|
||||
for(size_t i = 0; i < canvas().size(); ++i) {
|
||||
canvas(i) = config()->state[i].canvas;
|
||||
}
|
||||
|
||||
set_canvas_text();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
|
||||
|
|
|
@ -34,15 +34,16 @@ public:
|
|||
bool get_active() const { return state_ == ENABLED; }
|
||||
unsigned get_state() const { return state_; }
|
||||
|
||||
//! Inherited from twidget.
|
||||
void load_config();
|
||||
|
||||
private:
|
||||
//! Note the order of the states must be the same as defined in settings.hpp.
|
||||
enum tstate { ENABLED, DISABLED, COUNT };
|
||||
|
||||
void set_state(tstate state);
|
||||
tstate state_;
|
||||
|
||||
//! Inherited from tcontrol.
|
||||
const std::string& get_control_type() const
|
||||
{ static const std::string type = "label"; return type; }
|
||||
};
|
||||
|
||||
} // namespace gui2
|
||||
|
|
|
@ -438,20 +438,6 @@ void ttext_box::handle_key_clear_line(SDLMod /*modifier*/, bool& handled)
|
|||
set_text("");
|
||||
}
|
||||
|
||||
void ttext_box::load_config()
|
||||
{
|
||||
if(!config()) {
|
||||
set_config(get_control("text_box", definition()));
|
||||
|
||||
assert(canvas().size() == config()->state.size());
|
||||
for(size_t i = 0; i < canvas().size(); ++i) {
|
||||
canvas(i) = config()->state[i].canvas;
|
||||
}
|
||||
|
||||
set_canvas_text();
|
||||
}
|
||||
}
|
||||
|
||||
void ttext_box::handle_key_up_arrow(SDLMod /*modifier*/, bool& handled)
|
||||
{
|
||||
if (history_.get_enabled()) {
|
||||
|
|
|
@ -241,9 +241,6 @@ protected:
|
|||
void goto_end_of_line(const bool select = false) { goto_end_of_data(select); }
|
||||
void goto_start_of_line(const bool select = false) { goto_start_of_data(select); }
|
||||
|
||||
//! Inherited from twidget.
|
||||
void load_config();
|
||||
|
||||
private:
|
||||
|
||||
void handle_key_up_arrow(SDLMod modifier, bool& handled);
|
||||
|
@ -259,6 +256,10 @@ private:
|
|||
void calculate_char_offset();
|
||||
|
||||
ttext_history history_;
|
||||
|
||||
//! Inherited from tcontrol.
|
||||
const std::string& get_control_type() const
|
||||
{ static const std::string type = "text_box"; return type; }
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -38,19 +38,5 @@
|
|||
|
||||
namespace gui2 {
|
||||
|
||||
void ttooltip::load_config()
|
||||
{
|
||||
if(!config()) {
|
||||
set_config(get_control("tooltip", definition()));
|
||||
|
||||
assert(canvas().size() == config()->state.size());
|
||||
for(size_t i = 0; i < canvas().size(); ++i) {
|
||||
canvas(i) = config()->state[i].canvas;
|
||||
}
|
||||
|
||||
set_canvas_text();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
|
|
|
@ -33,8 +33,10 @@ public:
|
|||
bool get_active() const { return true; }
|
||||
unsigned get_state() const { return 0; }
|
||||
|
||||
//! Inherited from twidget.
|
||||
void load_config();
|
||||
private:
|
||||
//! Inherited from tcontrol.
|
||||
const std::string& get_control_type() const
|
||||
{ static const std::string type = "tooltip"; return type; }
|
||||
};
|
||||
|
||||
} // namespace gui2
|
||||
|
|
|
@ -139,6 +139,10 @@ private:
|
|||
|
||||
//! Widget for the help popup FIXME should be thelp_popup.
|
||||
ttooltip help_popup_;
|
||||
|
||||
//! Inherited from tcontrol.
|
||||
const std::string& get_control_type() const
|
||||
{ static const std::string type = "window"; return type; }
|
||||
};
|
||||
|
||||
} // namespace gui2
|
||||
|
|
Loading…
Add table
Reference in a new issue