Move linked group definition to a shared location

@Vultraz suggested this change.
This commit is contained in:
Jyrki Vesterinen 2017-01-31 20:29:02 +02:00
parent 63d6dce285
commit 575326c74d
9 changed files with 123 additions and 71 deletions

View file

@ -1572,6 +1572,14 @@
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Test_Debug|Win32'">$(IntDir)Gui\Core\Event\</ObjectFileName>
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Test_Release|Win32'">$(IntDir)Gui\Core\Event\</ObjectFileName>
</ClCompile>
<ClCompile Include="..\..\src\gui\core\linked_group_definition.cpp">
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(IntDir)Gui\Core\</ObjectFileName>
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(IntDir)Gui\Core\</ObjectFileName>
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='ReleaseDEBUG|Win32'">$(IntDir)Gui\Core\</ObjectFileName>
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Test_Debug|Win32'">$(IntDir)Gui\Core\</ObjectFileName>
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Debug_with_VLD|Win32'">$(IntDir)Gui\Core\</ObjectFileName>
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Test_Release|Win32'">$(IntDir)Gui\Core\</ObjectFileName>
</ClCompile>
<ClCompile Include="..\..\src\gui\core\log.cpp">
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Debug_with_VLD|Win32'">$(IntDir)Gui\Core\</ObjectFileName>
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(IntDir)Gui\Core\</ObjectFileName>
@ -4112,6 +4120,7 @@
<ClInclude Include="..\..\src\gui\core\event\handler.hpp" />
<ClInclude Include="..\..\src\gui\core\event\message.hpp" />
<ClInclude Include="..\..\src\gui\core\layout_exception.hpp" />
<ClInclude Include="..\..\src\gui\core\linked_group_definition.hpp" />
<ClInclude Include="..\..\src\gui\core\log.hpp" />
<ClInclude Include="..\..\src\gui\core\notifiee.hpp" />
<ClInclude Include="..\..\src\gui\core\notifier.hpp" />

View file

@ -1522,6 +1522,9 @@
<ClCompile Include="..\..\src\font\text_surface.cpp">
<Filter>Font</Filter>
</ClCompile>
<ClCompile Include="..\..\src\gui\core\linked_group_definition.cpp">
<Filter>Gui\Core</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src\addon\client.hpp">
@ -2955,6 +2958,9 @@
<ClInclude Include="..\..\src\font\pango\stream_ops.hpp">
<Filter>Font\Pango</Filter>
</ClInclude>
<ClInclude Include="..\..\src\gui\core\linked_group_definition.hpp">
<Filter>Gui\Core</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="..\..\src\tests\test_sdl_utils.hpp">

View file

@ -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

View file

@ -0,0 +1,54 @@
/*
Copyright (C) 2008 - 2017 by Mark de Wever <koraq@xs4all.nl>
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<linked_group_definition> parse_linked_group_definitions(const config& cfg)
{
std::vector<linked_group_definition> 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;
}
}

View file

@ -0,0 +1,47 @@
/*
Copyright (C) 2008 - 2017 by Mark de Wever <koraq@xs4all.nl>
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 <string>
#include <vector>
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<linked_group_definition> parse_linked_group_definitions(const config& cfg);
}
#endif

View file

@ -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

View file

@ -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 <vector>
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_group> linked_groups;
std::vector<linked_group_definition> linked_groups;
unsigned text_extra_width;
unsigned text_extra_height;

View file

@ -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"])

View file

@ -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 @@ public:
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_group> linked_groups;
std::vector<linked_group_definition> linked_groups;
/** Helper struct to store information about the tips. */
struct tooltip_info