The Battle for Wesnoth  1.19.7+dev
brush.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2024
3  by Tomasz Sniatowski <kailoran@gmail.com>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #define GETTEXT_DOMAIN "wesnoth-editor"
17 
18 #include "editor/toolkit/brush.hpp"
19 #include "editor/editor_common.hpp"
20 
21 #include "pathutils.hpp"
22 
23 namespace editor {
24 
26  : relative_tiles_()
27  , name_()
28  , id_()
29 {
30 }
31 
32 brush::brush(const config& cfg)
33  : relative_tiles_()
34  , name_(cfg["name"])
35  , id_(cfg["id"])
36 {
37  int radius = cfg["radius"].to_int();
38  if (radius > 0) {
39  std::vector<map_location> in_radius;
40  get_tiles_in_radius(map_location(0, 0), radius, in_radius);
41  for (map_location& loc : in_radius) {
43  }
44  }
45  for (const config &relative : cfg.child_range("relative"))
46  {
47  int x = relative["x"].to_int();
48  int y = relative["y"].to_int();
50  }
51  if (relative_tiles_.empty()) {
52  WRN_ED << "Empty brush definition, name=" << name_;
53  }
54 }
55 
56 void brush::add_relative_location(int relative_x, int relative_y)
57 {
58  relative_tiles_.insert(map_location(relative_x, relative_y));
59 }
60 
61 std::set<map_location> brush::project(const map_location& hotspot) const
62 {
63  std::set<map_location> result;
64  for (const map_location& relative : relative_tiles_) {
65  result.insert(relative.vector_sum(hotspot));
66  }
67  return result;
68 }
69 
70 
71 } //end namespace editor
map_location loc
Definition: move.cpp:172
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:172
child_itors child_range(config_key_type key)
Definition: config.cpp:272
brush()
Construct a default (empty) brush.
Definition: brush.cpp:25
void add_relative_location(int relative_x, int relative_y)
Add a location to the brush.
Definition: brush.cpp:56
std::set< map_location > relative_tiles_
The relative locations of the brush.
Definition: brush.hpp:64
std::string name_
Definition: brush.hpp:66
std::set< map_location > project(const map_location &hotspot) const
Get a set of locations affected (i.e.
Definition: brush.cpp:61
Main (common) editor header.
#define WRN_ED
Manage the empty-palette in the editor.
Definition: action.cpp:31
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:56
Encapsulates the map of the game.
Definition: location.hpp:45