From 575326c74d79d117cebed0ef1e708df413dbfdec Mon Sep 17 00:00:00 2001 From: Jyrki Vesterinen Date: Tue, 31 Jan 2017 20:29:02 +0200 Subject: [PATCH] Move linked group definition to a shared location @Vultraz suggested this change. --- projectfiles/VC12/wesnoth.vcxproj | 9 ++++ projectfiles/VC12/wesnoth.vcxproj.filters | 6 +++ source_lists/wesnoth | 1 + src/gui/core/linked_group_definition.cpp | 54 +++++++++++++++++++++++ src/gui/core/linked_group_definition.hpp | 47 ++++++++++++++++++++ src/gui/core/widget_definition.cpp | 25 +---------- src/gui/core/widget_definition.hpp | 14 +----- src/gui/core/window_builder.cpp | 24 +--------- src/gui/core/window_builder.hpp | 14 +----- 9 files changed, 123 insertions(+), 71 deletions(-) create mode 100644 src/gui/core/linked_group_definition.cpp create mode 100644 src/gui/core/linked_group_definition.hpp diff --git a/projectfiles/VC12/wesnoth.vcxproj b/projectfiles/VC12/wesnoth.vcxproj index dacc6302c552..09883cfc7a7d 100644 --- a/projectfiles/VC12/wesnoth.vcxproj +++ b/projectfiles/VC12/wesnoth.vcxproj @@ -1572,6 +1572,14 @@ $(IntDir)Gui\Core\Event\ $(IntDir)Gui\Core\Event\ + + $(IntDir)Gui\Core\ + $(IntDir)Gui\Core\ + $(IntDir)Gui\Core\ + $(IntDir)Gui\Core\ + $(IntDir)Gui\Core\ + $(IntDir)Gui\Core\ + $(IntDir)Gui\Core\ $(IntDir)Gui\Core\ @@ -4112,6 +4120,7 @@ + diff --git a/projectfiles/VC12/wesnoth.vcxproj.filters b/projectfiles/VC12/wesnoth.vcxproj.filters index ed0193efe3bc..6378f0051ceb 100644 --- a/projectfiles/VC12/wesnoth.vcxproj.filters +++ b/projectfiles/VC12/wesnoth.vcxproj.filters @@ -1522,6 +1522,9 @@ Font + + Gui\Core + @@ -2955,6 +2958,9 @@ Font\Pango + + Gui\Core + diff --git a/source_lists/wesnoth b/source_lists/wesnoth index 26bd8360e8d1..c47cc9d03703 100644 --- a/source_lists/wesnoth +++ b/source_lists/wesnoth @@ -151,6 +151,7 @@ gui/core/canvas.cpp gui/core/event/dispatcher.cpp gui/core/event/distributor.cpp gui/core/event/handler.cpp +gui/core/linked_group_definition.cpp gui/core/log.cpp gui/core/placer.cpp gui/core/placer/horizontal_list.cpp diff --git a/src/gui/core/linked_group_definition.cpp b/src/gui/core/linked_group_definition.cpp new file mode 100644 index 000000000000..84ced45b16ff --- /dev/null +++ b/src/gui/core/linked_group_definition.cpp @@ -0,0 +1,54 @@ +/* + Copyright (C) 2008 - 2017 by Mark de Wever + Part of the Battle for Wesnoth Project http://www.wesnoth.org/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY. + + See the COPYING file for more details. +*/ + +#include "linked_group_definition.hpp" + +#include "formula/string_utils.hpp" +#include "serialization/string_utils.hpp" +#include "wml_exception.hpp" + +namespace gui2 +{ + +std::vector parse_linked_group_definitions(const config& cfg) +{ + std::vector definitions; + + for(const auto & lg : cfg.child_range("linked_group")) { + linked_group_definition linked_group; + linked_group.id = lg["id"].str(); + linked_group.fixed_width = lg["fixed_width"].to_bool(); + linked_group.fixed_height = lg["fixed_height"].to_bool(); + + VALIDATE(!linked_group.id.empty(), + missing_mandatory_wml_key("linked_group", "id")); + + if(!(linked_group.fixed_width || linked_group.fixed_height)) { + utils::string_map symbols; + symbols["id"] = linked_group.id; + t_string msg + = vgettext("Linked '$id' group needs a 'fixed_width' or " + "'fixed_height' key.", + symbols); + + FAIL(msg); + } + + definitions.push_back(linked_group); + } + + return definitions; +} + +} diff --git a/src/gui/core/linked_group_definition.hpp b/src/gui/core/linked_group_definition.hpp new file mode 100644 index 000000000000..8e8aa3f170ac --- /dev/null +++ b/src/gui/core/linked_group_definition.hpp @@ -0,0 +1,47 @@ +/* + Copyright (C) 2008 - 2017 by Mark de Wever + Part of the Battle for Wesnoth Project http://www.wesnoth.org/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY. + + See the COPYING file for more details. +*/ + +#ifndef GUI_CORE_LINKED_GROUP_DEFINITION_HPP_INCLUDED +#define GUI_CORE_LINKED_GROUP_DEFINITION_HPP_INCLUDED + +#include "config.hpp" +#include +#include + +namespace gui2 +{ + +struct linked_group_definition +{ + linked_group_definition() : id(), fixed_width(false), fixed_height(false) + { + } + + linked_group_definition(const linked_group_definition& other) + : id(other.id) + , fixed_width(other.fixed_width) + , fixed_height(other.fixed_height) + { + } + + std::string id; + bool fixed_width; + bool fixed_height; +}; + +std::vector parse_linked_group_definitions(const config& cfg); + +} + +#endif diff --git a/src/gui/core/widget_definition.cpp b/src/gui/core/widget_definition.cpp index 95e26b4d2ff4..2f800c2920d1 100644 --- a/src/gui/core/widget_definition.cpp +++ b/src/gui/core/widget_definition.cpp @@ -16,11 +16,9 @@ #include "gui/core/widget_definition.hpp" -#include "formula/string_utils.hpp" #include "gettext.hpp" #include "gui/core/log.hpp" #include "gui/widgets/helper.hpp" -#include "serialization/string_utils.hpp" #include "wml_exception.hpp" namespace gui2 @@ -111,28 +109,7 @@ resolution_definition::resolution_definition(const config& cfg) DBG_GUI_P << "Parsing resolution " << window_width << ", " << window_height << '\n'; - for(const config& lg : cfg.child_range("linked_group")) { - linked_group linked_group; - linked_group.id = lg["id"].str(); - linked_group.fixed_width = lg["fixed_width"].to_bool(); - linked_group.fixed_height = lg["fixed_height"].to_bool(); - - VALIDATE(!linked_group.id.empty(), - missing_mandatory_wml_key("linked_group", "id")); - - if(!(linked_group.fixed_width || linked_group.fixed_height)) { - utils::string_map symbols; - symbols["id"] = linked_group.id; - t_string msg - = vgettext("Linked '$id' group needs a 'fixed_width' or " - "'fixed_height' key.", - symbols); - - FAIL(msg); - } - - linked_groups.push_back(linked_group); - } + linked_groups = parse_linked_group_definitions(cfg); } /*WIKI diff --git a/src/gui/core/widget_definition.hpp b/src/gui/core/widget_definition.hpp index 5e3c34b8c992..2d5ea3e331c4 100644 --- a/src/gui/core/widget_definition.hpp +++ b/src/gui/core/widget_definition.hpp @@ -19,6 +19,7 @@ #include "font/font_options.hpp" #include "font/text.hpp" #include "gui/core/canvas.hpp" +#include "gui/core/linked_group_definition.hpp" #include namespace gui2 @@ -56,18 +57,7 @@ struct resolution_definition unsigned max_width; unsigned max_height; - struct linked_group - { - linked_group() : id(), fixed_width(false), fixed_height(false) - { - } - - std::string id; - bool fixed_width; - bool fixed_height; - }; - - std::vector linked_groups; + std::vector linked_groups; unsigned text_extra_width; unsigned text_extra_height; diff --git a/src/gui/core/window_builder.cpp b/src/gui/core/window_builder.cpp index 1a8422d23019..90e61fdce52b 100644 --- a/src/gui/core/window_builder.cpp +++ b/src/gui/core/window_builder.cpp @@ -422,29 +422,7 @@ builder_window::window_resolution::window_resolution(const config& cfg) definition = "default"; } - for(const auto & lg : cfg.child_range("linked_group")) - { - linked_group linked_group; - linked_group.id = lg["id"].str(); - linked_group.fixed_width = lg["fixed_width"].to_bool(); - linked_group.fixed_height = lg["fixed_height"].to_bool(); - - VALIDATE(!linked_group.id.empty(), - missing_mandatory_wml_key("linked_group", "id")); - - if(!(linked_group.fixed_width || linked_group.fixed_height)) { - utils::string_map symbols; - symbols["id"] = linked_group.id; - t_string msg - = vgettext("Linked '$id' group needs a 'fixed_width' or " - "'fixed_height' key.", - symbols); - - FAIL(msg); - } - - linked_groups.push_back(linked_group); - } + linked_groups = parse_linked_group_definitions(cfg); } builder_window::window_resolution::tooltip_info::tooltip_info(const config& cfg, const std::string& tagname) : id(cfg["id"]) diff --git a/src/gui/core/window_builder.hpp b/src/gui/core/window_builder.hpp index 1d800c96a8a5..ce43f222552b 100644 --- a/src/gui/core/window_builder.hpp +++ b/src/gui/core/window_builder.hpp @@ -16,6 +16,7 @@ #define GUI_AUXILIARY_WINDOW_BUILDER_HPP_INCLUDED #include "gui/auxiliary/typed_formula.hpp" +#include "gui/core/linked_group_definition.hpp" #include "gui/widgets/grid.hpp" #include "color.hpp" @@ -184,18 +185,7 @@ class builder_window std::string definition; - struct linked_group - { - linked_group() : id(), fixed_width(false), fixed_height(false) - { - } - - std::string id; - bool fixed_width; - bool fixed_height; - }; - - std::vector linked_groups; + std::vector linked_groups; /** Helper struct to store information about the tips. */ struct tooltip_info