The Battle for Wesnoth  1.15.12+dev
brush.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2018 by Tomasz Sniatowski <kailoran@gmail.com>
3  Part of the Battle for Wesnoth Project https://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 
24  : relative_tiles_()
25  , name_()
26  , id_()
27 {
28 }
29 
30 brush::brush(const config& cfg)
31  : relative_tiles_()
32  , name_(cfg["name"])
33  , id_(cfg["id"])
34 {
35  int radius = cfg["radius"];
36  if (radius > 0) {
37  std::vector<map_location> in_radius;
38  get_tiles_in_radius(map_location(0, 0), radius, in_radius);
39  for (map_location& loc : in_radius) {
40  add_relative_location(loc.x, loc.y);
41  }
42  }
43  for (const config &relative : cfg.child_range("relative"))
44  {
45  int x = relative["x"];
46  int y = relative["y"];
48  }
49  if (relative_tiles_.empty()) {
50  WRN_ED << "Empty brush definition, name=" << name_ << std::endl;
51  }
52 }
53 
54 void brush::add_relative_location(int relative_x, int relative_y)
55 {
56  relative_tiles_.insert(map_location(relative_x, relative_y));
57 }
58 
59 std::set<map_location> brush::project(const map_location& hotspot) const
60 {
61  std::set<map_location> result;
62  for (const map_location& relative : relative_tiles_) {
63  result.insert(relative.vector_sum(hotspot));
64  }
65  return result;
66 }
67 
68 
69 } //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:55
child_itors child_range(config_key_type key)
Definition: config.cpp:356
std::string id_
Definition: brush.hpp:66
std::string name_
Definition: brush.hpp:65
#define WRN_ED
std::set< map_location > project(const map_location &hotspot) const
Get a set of locations affected (i.e.
Definition: brush.cpp:59
brush()
Construct a default (empty) brush.
Definition: brush.cpp:23
Manage the empty-palette in the editor.
Definition: action.cpp:29
Encapsulates the map of the game.
Definition: location.hpp:37
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:54
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:59