Refactoring tcontrol_definition.

Moved it to gui/auxiliary/widget_definition.* and put the template
function in the header so more parts of gui/widgets/settings.* can be
moved in seperate files.
This commit is contained in:
Mark de Wever 2010-01-04 20:48:21 +00:00
parent 1c0891ea0c
commit 6c2a47c8e9
4 changed files with 67 additions and 67 deletions

View file

@ -16,9 +16,10 @@
#include "gui/auxiliary/widget_definition.hpp"
#include "config.hpp"
#include "gettext.hpp"
#include "gui/auxiliary/log.hpp"
#include "gui/widgets/helper.hpp"
#include "wml_exception.hpp"
namespace gui2 {
@ -96,5 +97,46 @@ tresolution_definition_::tresolution_definition_(const config& cfg) :
<< window_width << ", " << window_height << '\n';
}
tcontrol_definition::tcontrol_definition(const config& cfg) :
id(cfg["id"]),
description(cfg["description"]),
resolutions()
{
/*WIKI
* @page = GUIWidgetDefinitionWML
* @order = 1
*
* THIS PAGE IS AUTOMATICALLY GENERATED, DO NOT MODIFY DIRECTLY !!!
*
* = Widget definition =
*
* This page describes the definition of all widgets in the toolkit. Every
* widget has some parts in common, first of all every definition has the
* following fields.
*
* @start_table = config
* id (string) Unique id for this gui (theme).
* description (t_string) Unique translatable name for this gui.
*
* resolution (section) The definitions of the widget in various
* resolutions.
* @end_table
*
*/
VALIDATE(!id.empty(), missing_mandatory_wml_key("gui", "id"));
VALIDATE(!description.empty()
, missing_mandatory_wml_key("gui", "description"));
/*
* Do this validation here instead of in load_resolutions so the
* translatable string is not in the header and we don't need to pull in
* extra header dependencies.
*/
config::const_child_itors itors = cfg.child_range("resolution");
VALIDATE(itors.first != itors.second, _("No resolution defined."));
}
} // namespace gui2

View file

@ -15,10 +15,10 @@
#ifndef GUI_AUXILIARY_WIDGET_DEFINITION_HPP_INCLUDED
#define GUI_AUXILIARY_WIDGET_DEFINITION_HPP_INCLUDED
#include "config.hpp"
#include "foreach.hpp"
#include "gui/auxiliary/canvas.hpp"
class config;
namespace gui2 {
/**
@ -70,6 +70,28 @@ typedef
boost::intrusive_ptr<const tresolution_definition_>
tresolution_definition_const_ptr;
struct tcontrol_definition
: public reference_counted_object
{
tcontrol_definition(const config& cfg);
template<class T>
void load_resolutions(const config &cfg)
{
config::const_child_itors itors = cfg.child_range("resolution");
foreach (const config &r, itors) {
resolutions.push_back(new T(r));
}
}
std::string id;
t_string description;
std::vector<tresolution_definition_ptr> resolutions;
};
typedef boost::intrusive_ptr<tcontrol_definition> tcontrol_definition_ptr;
} // namespace gui2
#endif

View file

@ -415,49 +415,6 @@ void tgui_definition::load_definitions(
!= control_definition[definition_type].end(), msg);
}
tcontrol_definition::tcontrol_definition(const config& cfg) :
id(cfg["id"]),
description(cfg["description"]),
resolutions()
{
/*WIKI
* @page = GUIWidgetDefinitionWML
* @order = 1
*
* THIS PAGE IS AUTOMATICALLY GENERATED, DO NOT MODIFY DIRECTLY !!!
*
* = Widget definition =
*
* This page describes the definition of all widgets in the toolkit. Every
* widget has some parts in common, first of all every definition has the
* following fields.
*
* @start_table = config
* id (string) Unique id for this gui (theme).
* description (t_string) Unique translatable name for this gui.
*
* resolution (section) The definitions of the widget in various
* resolutions.
* @end_table
*
*/
VALIDATE(!id.empty(), missing_mandatory_wml_key("gui", "id"));
VALIDATE(!description.empty(), missing_mandatory_wml_key("gui", "description"));
}
template<class T>
void tcontrol_definition::load_resolutions(const config &cfg)
{
config::const_child_itors itors = cfg.child_range("resolution");
VALIDATE(itors.first != itors.second, _("No resolution defined."));
foreach (const config &r, itors) {
resolutions.push_back(new T(r));
}
}
tstate_definition::tstate_definition(const config &cfg) :
canvas()

View file

@ -85,27 +85,6 @@ enum twindow_type {
const std::string& get_id(const twindow_type window_type);
struct tcontrol_definition : public reference_counted_object
{
private:
tcontrol_definition();
public:
tcontrol_definition(const config& cfg);
template<class T>
void load_resolutions(const config &resolution_list);
std::string id;
t_string description;
std::vector<tresolution_definition_ptr> resolutions;
};
typedef boost::intrusive_ptr<tcontrol_definition> tcontrol_definition_ptr;
struct tbutton_definition : public tcontrol_definition
{
tbutton_definition(const config& cfg);