Author: mordante
Date: Sat Jun 21 17:06:45 2008
New Revision: 27374
URL: http://svn.gna.org/viewcvs/wesnoth?rev=27374&view=rev
Log:
Rewrote the listbox row adding code in order to make it more flexible.
* Renamed to add_row(s).
* Added set_members which allows to modify certain member with help of a map.
* Used the new set_members in favour of tlistbox::titem.
Modified:
trunk/src/gui/dialogs/language_selection.cpp
trunk/src/gui/dialogs/mp_connect.cpp
trunk/src/gui/widgets/control.cpp
trunk/src/gui/widgets/control.hpp
trunk/src/gui/widgets/listbox.cpp
trunk/src/gui/widgets/listbox.hpp
trunk/src/gui/widgets/toggle_button.cpp
trunk/src/gui/widgets/toggle_button.hpp
trunk/src/gui/widgets/window_builder.cpp
Modified: trunk/src/gui/dialogs/language_selection.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/dialogs/language_selection.cpp?rev=27374&r1=27373&r2=27374&view=diff
==============================================================================
--- trunk/src/gui/dialogs/language_selection.cpp (original)
+++ trunk/src/gui/dialogs/language_selection.cpp Sat Jun 21 17:06:45 2008
@@ -59,8 +59,11 @@
const std::vector<language_def>& languages = get_languages();
const language_def& current_language = get_language();
foreach(const language_def& lang, languages) {
+ std::map<std::string, t_string> item;
+ item.insert(std::make_pair("label", lang.language));
+ item.insert(std::make_pair("tooltip", lang.language));
- list->add_item(lang.language);
+ list->add_row(item);
if(lang == current_language) {
list->select_row(list->get_item_count() - 1);
}
Modified: trunk/src/gui/dialogs/mp_connect.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/dialogs/mp_connect.cpp?rev=27374&r1=27373&r2=27374&view=diff
==============================================================================
--- trunk/src/gui/dialogs/mp_connect.cpp (original)
+++ trunk/src/gui/dialogs/mp_connect.cpp Sat Jun 21 17:06:45 2008
@@ -89,12 +89,16 @@
foreach(const game_config::server_info& server, pref_servers) {
- std::map<std::string, tlistbox::titem> data;
- data.insert(std::make_pair("name", tlistbox::titem(server.name,
"")));
- data.insert(std::make_pair(
- "address", tlistbox::titem(server.address, "")));
-
- list->add_item(data);
+ std::map<std::string, std::map<std::string, t_string> > data;
+ std::map<std::string, t_string> item;
+
+ item["label"] = server.name;
+ data.insert(std::make_pair("name", item));
+
+ item["label"] = server.address;
+ data.insert(std::make_pair("address", item));
+
+ list->add_row(data);
}
window.recalculate_size();
Modified: trunk/src/gui/widgets/control.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/control.cpp?rev=27374&r1=27373&r2=27374&view=diff
==============================================================================
--- trunk/src/gui/widgets/control.cpp (original)
+++ trunk/src/gui/widgets/control.cpp Sat Jun 21 17:06:45 2008
@@ -56,6 +56,25 @@
restorer_(),
config_(0)
{
+}
+
+void tcontrol::set_members(const std::map<
+ std::string /* member id */, t_string /* member value */>& data)
+{
+ std::map<std::string, t_string>::const_iterator itor =
data.find("label");
+ if(itor != data.end()) {
+ set_label(itor->second);
+ }
+
+ itor = data.find("tooltip");
+ if(itor != data.end()) {
+ set_tooltip(itor->second);
+ }
+
+ itor = data.find("help");
+ if(itor != data.end()) {
+ set_help_message(itor->second);
+ }
}
void tcontrol::mouse_hover(tevent_handler& event)
Modified: trunk/src/gui/widgets/control.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/control.hpp?rev=27374&r1=27373&r2=27374&view=diff
==============================================================================
--- trunk/src/gui/widgets/control.hpp (original)
+++ trunk/src/gui/widgets/control.hpp Sat Jun 21 17:06:45 2008
@@ -32,6 +32,22 @@
tcontrol(const unsigned canvas_count);
virtual ~tcontrol() {}
+
+ /**
+ * Sets the members of the control.
+ *
+ * The map contains named members it can set, controls inheriting from
us
+ * can add additional members to set by this function. The following
+ * members can by the following key:
+ * * label_ label
+ * * tooltip_ tooltip
+ * * help_message_ help
+ *
+ *
+ * @param data Map with the key value pairs to set the
members.
+ */
+ virtual void set_members(const std::map<
+ std::string /* member id */, t_string /* member value */>&
data);
/***** ***** ***** ***** State handling ***** ***** ***** *****/
Modified: trunk/src/gui/widgets/listbox.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/listbox.cpp?rev=27374&r1=27373&r2=27374&view=diff
==============================================================================
--- trunk/src/gui/widgets/listbox.cpp (original)
+++ trunk/src/gui/widgets/listbox.cpp Sat Jun 21 17:06:45 2008
@@ -376,14 +376,18 @@
return result;
}
-void tlistbox::add_item(const titem& item)
-{
- std::map<std::string, titem> data;
+void tlistbox::add_row(const std::map<
+ std::string /* member id */, t_string /* member value */>& item)
+{
+ std::map<std::string /* widget id */, std::map<
+ std::string /* member id */, t_string /* member value */> >
data;
+
data.insert(std::make_pair("", item));
- add_item(data);
-}
-
-void tlistbox::add_item(const std::map<std::string, titem>& data)
+ add_row(data);
+}
+
+void tlistbox::add_row(const std::map<std::string /* widget id */, std::map<
+ std::string /* member id */, t_string /* member value */> >&
data)
{
assert(list_builder_);
@@ -401,21 +405,13 @@
set_scrollbar_button_status();
}
-void tlistbox::add_items(const std::vector< std::map<std::string, t_string> >&
data)
+void tlistbox::add_rows(const std::vector< std::map<std::string, t_string> >&
data)
{
// foreach(const std::map<std::string, t_string>& cell, data) {
// doesn't compile it sees 3 paramters instead of 2 so use a typedef.
typedef std::map<std::string, t_string> hack ;
foreach(const hack& cell, data) {
- std::map<std::string, t_string >::const_iterator itor =
cell.find("icon");
- assert(itor != cell.end());
- const t_string& icon = itor->second;
-
- itor = cell.find("label");
- assert(itor != cell.end());
- const std::string& label = itor->second;
-
- add_item(titem(label, icon));
+ add_row(cell);
}
}
@@ -497,7 +493,8 @@
}
tlistbox::trow::trow(const tbuilder_grid& list_builder_,
- const std::map<std::string, titem>& data) :
+ const std::map<std::string /* widget id */, std::map<
+ std::string /* member id */, t_string /* member value */> >&
data) :
grid_(dynamic_cast<tgrid*>(list_builder_.build())),
height_(0),
selected_(false)
@@ -507,7 +504,8 @@
}
void tlistbox::trow::init_in_grid(tgrid* grid,
- const std::map<std::string, titem>& data)
+ const std::map<std::string /* widget id */, std::map<
+ std::string /* member id */, t_string /* member value */> >&
data)
{
for(unsigned row = 0; row < grid->get_rows(); ++row) {
for(unsigned col = 0; col < grid->get_cols(); ++col) {
@@ -520,13 +518,15 @@
if(btn) {
btn->set_callback_mouse_left_click(callback_select_list_item);
- std::map<std::string, titem>::const_iterator
itor = data.find(btn->id());
+ std::map<std::string /* widget id */, std::map<
+ std::string /* member id */, t_string
/* member value */> >
+ ::const_iterator itor =
data.find(btn->id());
+
if(itor == data.end()) {
itor = data.find("");
}
if(itor != data.end()) {
- btn->set_label(itor->second.label);
- btn->set_icon_name(itor->second.icon);
+ btn->set_members(itor->second);
}
} else if(child_grid) {
init_in_grid(child_grid, data);
Modified: trunk/src/gui/widgets/listbox.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/listbox.hpp?rev=27374&r1=27373&r2=27374&view=diff
==============================================================================
--- trunk/src/gui/widgets/listbox.hpp (original)
+++ trunk/src/gui/widgets/listbox.hpp Sat Jun 21 17:06:45 2008
@@ -97,54 +97,48 @@
*/
/**
- * Listbox item definition.
- *
- * A row in a listbox can have one or more items (widgets) each of them
can
- * be defined from the code. Every wiget can have an item 'assigned'
which
- * means the fields in that widget get the values of the items set after
- * constructing.
- */
- struct titem {
-
- titem(const t_string& label, const std::string& icon = "") :
- label(label),
- icon(icon)
- {}
-
- /** The label for the widget. */
- t_string label;
-
- /** the filename of the icon for the widget. */
- std::string icon;
- };
-
- /**
- * Adds an item to the list.
- *
- * The widget added gets the item assigned to it.
- *
- * @param item The item to assign to the widget.
- */
- void add_item(const titem& item);
-
- /**
- * Adds an item to the list.
- *
- * An item is most of the time a row which contains one or more widgets.
- * This map contains the items to assign to those widgets. If a widget
with
- * the 'id' of a map exists then that widget gets that 'item' assigned.
Else if
- * there is an empty map 'id', that 'item' gets assigned.
- *
- * @param data Map with the items to assign to the row
items.
- */
- void add_item(const std::map<std::string /*id*/, titem /*item*/>& data);
-
- /**
- * Adds one or more items to the listbox.
- *
- * Just a proof-of-concept version to add a list of items to a listbox.
- */
- void add_items(const std::vector< std::map<std::string, t_string> >&
data);
+ * Adds a single row to the grid.
+ *
+ * This function expects a row to have only one widget or all widgets
need
+ * the same settings.
+ *
+ * @param item The data to send to set_members of the
+ * widget or to all the widgets.
+ */
+ void add_row(const std::map<
+ std::string /* member id */, t_string /* member value */>&
item);
+
+ /**
+ * Adds single row to the grid.
+ *
+ * This function expect a row to have multiple widgets (either multiple
+ * columns or one column with multiple widgets).
+ *
+ *
+ * @param data The data to send to the set_members of the
+ * widgets. If the member id is not an empty
+ * string it is only send to the widget that
has
+ * the wanted id (if any). If the member id
is an
+ * empty string, it is send to all members.
+ * Having both empty and non-empty id's gives
+ * undefined behaviour.
+ */
+ void add_row(const std::map<std::string /* widget id */, std::map<
+ std::string /* member id */, t_string /* member value */> >&
data);
+
+ /**
+ * Adds multiple rows to the grid.
+ *
+ * Small wrapper to void add_row(const std::map<std::string,
t_string>&).
+ * NOTE it's _not_ a wrapper to void add_row(const std::map<std::string,
+ * std::map<std::string, t_string> >&).
+ *
+ * @param data Vector with the number of rows, for every
row
+ * it calls add_row(std::map<std::string,
+ * t_string>&).
+ */
+ void add_rows(const std::vector<std::map<
+ std::string /* member id */, t_string /* member value */> >&
data);
unsigned get_item_count() const { return rows_.size(); }
@@ -251,7 +245,8 @@
public:
trow(const tbuilder_grid& list_builder_,
- const std::map<std::string, titem>& data);
+ const std::map<std::string /* widget id */, std::map<
+ std::string /* member id */, t_string /* member value
*/> >& data);
void select(const bool sel = true);
@@ -276,7 +271,8 @@
bool selected_;
void init_in_grid(tgrid* grid,
- const std::map<std::string, titem>& data);
+ const std::map<std::string /* widget id */, std::map<
+ std::string /* member id */, t_string /* member value
*/> >& data);
void select_in_grid(tgrid* grid, const bool sel);
};
Modified: trunk/src/gui/widgets/toggle_button.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/toggle_button.cpp?rev=27374&r1=27373&r2=27374&view=diff
==============================================================================
--- trunk/src/gui/widgets/toggle_button.cpp (original)
+++ trunk/src/gui/widgets/toggle_button.cpp Sat Jun 21 17:06:45 2008
@@ -41,6 +41,17 @@
namespace gui2 {
+
+void ttoggle_button::set_members(const std::map<std::string, t_string>& data)
+{
+ // Inherit
+ tcontrol::set_members(data);
+
+ std::map<std::string, t_string>::const_iterator itor =
data.find("icon");
+ if(itor != data.end()) {
+ set_icon_name(itor->second);
+ }
+}
void ttoggle_button::mouse_enter(tevent_handler&)
{
Modified: trunk/src/gui/widgets/toggle_button.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/toggle_button.hpp?rev=27374&r1=27373&r2=27374&view=diff
==============================================================================
--- trunk/src/gui/widgets/toggle_button.hpp (original)
+++ trunk/src/gui/widgets/toggle_button.hpp Sat Jun 21 17:06:45 2008
@@ -46,6 +46,14 @@
/** Inherted from tevent_executor. */
void mouse_left_button_click(tevent_handler&);
+
+ /**
+ * Inherited from tcontrol.
+ *
+ * Sets the additional member
+ * * icon_name_ icon
+ */
+ void set_members(const std::map<std::string, t_string>& data);
/** Inherited from tcontrol. */
void set_active(const bool active);
Modified: trunk/src/gui/widgets/window_builder.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/window_builder.cpp?rev=27374&r1=27373&r2=27374&view=diff
==============================================================================
--- trunk/src/gui/widgets/window_builder.cpp (original)
+++ trunk/src/gui/widgets/window_builder.cpp Sat Jun 21 17:06:45 2008
@@ -911,7 +911,7 @@
, 0);
if(!list_data.empty()) {
- listbox->add_items(list_data);
+ listbox->add_rows(list_data);
}
listbox->finalize_setup();
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits