The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
brush.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2017 by Tomasz Sniatowski <kailoran@gmail.com>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 #define GETTEXT_DOMAIN "wesnoth-editor"
15 
16 #include "editor/toolkit/brush.hpp"
17 #include "editor/editor_common.hpp"
18 
19 #include "pathutils.hpp"
20 
21 namespace editor {
22 
23 /*WIKI
24  * @page = EditorWML
25  * @order = 1_header
26  *
27  * {{AutogeneratedWML}}
28  *
29  * = Brush =
30  *
31  * Each brush tag defines one brush. (0,0) is the hotspot, that is, the brush
32  * is always moved so the mouse is over the brush's (0,0) coordinate. The
33  * following keys and tags are recognized:
34  *
35  * (Note the 1.5 version and the mandatory image are for testing only.)
36  *
37  * @begin{description}{wml_reference}
38  * name & string & "" & &
39  * Name for the brush (will possibly show up in the tooltip for the
40  * brush). $
41  * image & filename & "" & &
42  * Icon for the brush to de displayed on the toolbar. $
43  * radius & integer & 0 & &
44  * Include in the brushall hexes that are this or closer to the center
45  * of the brush, excluding the (0,0) point. $
46  * [relative] & node & 1 & & Include in the brush a single hex with
47  * coordinates relative from the center of the brush. $
48  *
49  * @begin{description}{wml_reference}
50  * x & int & 0 & & The relative x coordinate. $
51  * y & int & 0 & & The relative y coordinate. $
52  * @end{description}
53  *
54  * @end{description}
55  * A brush that has neither a radius nor any [relative] hexes will be empty
56  * which is not desired and a warning or error is to be expected.
57  */
58 
60  : relative_tiles_()
61  , name_()
62  , id_()
63 {
64 }
65 
66 brush::brush(const config& cfg)
67  : relative_tiles_()
68  , name_(cfg["name"])
69  , id_(cfg["id"])
70 {
71  int radius = cfg["radius"];
72  if (radius > 0) {
73  std::vector<map_location> in_radius;
74  get_tiles_in_radius(map_location(0, 0), radius, in_radius);
75  for (map_location& loc : in_radius) {
76  add_relative_location(loc.x, loc.y);
77  }
78  }
79  for (const config &relative : cfg.child_range("relative"))
80  {
81  int x = relative["x"];
82  int y = relative["y"];
84  }
85  if (relative_tiles_.empty()) {
86  WRN_ED << "Empty brush definition, name=" << name_ << std::endl;
87  }
88 }
89 
90 void brush::add_relative_location(int relative_x, int relative_y)
91 {
92  relative_tiles_.insert(map_location(relative_x, relative_y));
93 }
94 
95 std::set<map_location> brush::project(const map_location& hotspot) const
96 {
97  std::set<map_location> result;
98  for (const map_location& relative : relative_tiles_) {
99  result.insert(relative.vector_sum(hotspot));
100  }
101  return result;
102 }
103 
104 
105 } //end namespace editor
void get_tiles_in_radius(const map_location &center, const int radius, std::vector< map_location > &result)
Function that will add to result all locations within radius tiles of center (excluding center itself...
Definition: pathutils.cpp:54
child_itors child_range(config_key_type key)
Definition: config.cpp:343
std::string name_
Definition: brush.hpp:65
#define WRN_ED
brush()
Construct a default (empty) brush.
Definition: brush.cpp:59
Manage the empty-palette in the editor.
Definition: action.cpp:29
Encapsulates the map of the game.
Definition: location.hpp:40
Main (common) editor header.
std::set< map_location > relative_tiles_
The relative locations of the brush.
Definition: brush.hpp:63
void add_relative_location(int relative_x, int relative_y)
Add a location to the brush.
Definition: brush.cpp:90
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:93
std::set< map_location > project(const map_location &hotspot) const
Get a set of locations affected (i.e.
Definition: brush.cpp:95