Skip to content

Commit

Permalink
Move linked group definition to a shared location
Browse files Browse the repository at this point in the history
@Vultraz suggested this change.
  • Loading branch information
jyrkive committed Jan 31, 2017
1 parent 63d6dce commit 575326c
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 71 deletions.
9 changes: 9 additions & 0 deletions projectfiles/VC12/wesnoth.vcxproj
Expand Up @@ -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>
Expand Down Expand Up @@ -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" />
Expand Down
6 changes: 6 additions & 0 deletions projectfiles/VC12/wesnoth.vcxproj.filters
Expand Up @@ -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">
Expand Down Expand Up @@ -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">
Expand Down
1 change: 1 addition & 0 deletions source_lists/wesnoth
Expand Up @@ -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
Expand Down
54 changes: 54 additions & 0 deletions src/gui/core/linked_group_definition.cpp
@@ -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;
}

}
47 changes: 47 additions & 0 deletions src/gui/core/linked_group_definition.hpp
@@ -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
25 changes: 1 addition & 24 deletions src/gui/core/widget_definition.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 2 additions & 12 deletions src/gui/core/widget_definition.hpp
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
24 changes: 1 addition & 23 deletions src/gui/core/window_builder.cpp
Expand Up @@ -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"])
Expand Down
14 changes: 2 additions & 12 deletions src/gui/core/window_builder.hpp
Expand Up @@ -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"

Expand Down Expand Up @@ -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_group> linked_groups;
std::vector<linked_group_definition> linked_groups;

/** Helper struct to store information about the tips. */
struct tooltip_info
Expand Down

0 comments on commit 575326c

Please sign in to comment.