The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
action_select.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2016 by Fabian Mueller <[email protected]>
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 
15 /**
16  * @file
17  * Editor label action classes
18  */
19 #define GETTEXT_DOMAIN "wesnoth-editor"
20 
23 
24 namespace editor {
25 
27 {
28  return new editor_action_select(*this);
29 }
30 
31 void editor_action_select::extend(const editor_map& /*map*/, const std::set<map_location>& locs)
32 {
33  for (const map_location& loc : locs) {
34  LOG_ED << "Extending by " << loc << "\n";
35  area_.insert(loc);
36  }
37 }
38 
40 {
41  std::set<map_location> undo_locs;
42  for (const map_location& loc : area_) {
43  undo_locs.insert(loc);
44  mc.add_changed_location(loc);
45  }
47  return new editor_action_select(undo_locs);
48 }
49 
51 {
52  for (const map_location& loc : area_) {
53 
54  mc.get_map().add_to_selection(loc);
55  mc.add_changed_location(loc);
56  }
57 }
58 
60 {
61  return new editor_action_deselect(*this);
62 }
63 
64 void editor_action_deselect::extend(const editor_map& map, const std::set<map_location>& locs)
65 {
66  for (const map_location& loc : locs) {
67  LOG_ED << "Checking " << loc << "\n";
68  if (!map.in_selection(loc)) {
69  LOG_ED << "Extending by " << loc << "\n";
70  area_.insert(loc);
71  }
72  }
73 }
74 
76 {
77  std::set<map_location> undo_locs;
78  for (const map_location& loc : area_) {
79  if (mc.get_map().in_selection(loc)) {
80  undo_locs.insert(loc);
81  mc.add_changed_location(loc);
82  }
83  }
85  return new editor_action_select(undo_locs);
86 }
87 
89 {
90  for (const map_location& loc : area_) {
92  mc.add_changed_location(loc);
93  }
94 }
95 
97 {
98  return new editor_action_select_all(*this);
99 }
100 
102 {
103  std::set<map_location> current = mc.get_map().selection();
104  mc.get_map().select_all();
105  std::set<map_location> all = mc.get_map().selection();
106  std::set<map_location> undo_locs;
107  std::set_difference(all.begin(), all.end(),
108  current.begin(), current.end(),
109  std::inserter(undo_locs, undo_locs.begin()));
111  return new editor_action_select(undo_locs);
112 }
113 
115 {
116  mc.get_map().select_all();
118 }
119 
121 {
122  return new editor_action_select_none(*this);
123 }
124 
126 {
127  std::set<map_location> current = mc.get_map().selection();
128  mc.get_map().clear_selection();
130  return new editor_action_select(current);
131 }
132 
134 {
135  mc.get_map().clear_selection();
137 }
138 
140 {
141  return new editor_action_select_inverse(*this);
142 }
143 
145 {
147  return new editor_action_select_inverse();
148 }
149 
151 {
152  mc.get_map().invert_selection();
154 }
155 
156 
157 } //end namespace editor
void perform_without_undo(map_context &mc) const
Perform the action without creating an undo action.
void add_changed_location(const map_location &loc)
void perform_without_undo(map_context &mc) const
Perform the action without creating an undo action.
Select the entire map.
editor_action_select_inverse * clone() const
Action cloning.
editor_action * perform(map_context &mc) const
Perform the action, returning an undo action that, when performed, shall reverse any effects of this ...
editor_action_deselect * clone() const
Action cloning.
#define LOG_ED
editor_action_deselect(const std::set< map_location > &area)
void perform_without_undo(map_context &mc) const
Perform the action without creating an undo action.
void perform_without_undo(map_context &mc) const
Perform the action without creating an undo action.
editor_action_select(const std::set< map_location > &area)
bool in_selection(const map_location &loc) const
Definition: editor_map.cpp:171
void invert_selection()
Invert the selection, i.e.
Definition: editor_map.cpp:201
editor_action_select_all * clone() const
Action cloning.
editor_map & get_map()
Map accessor.
Definition: map_context.hpp:75
Select the given locations.
void perform_without_undo(map_context &mc) const
Perform the action without creating an undo action.
Manage the empty-palette in the editor.
Definition: action.cpp:28
bool add_to_selection(const map_location &loc)
Add a location to the selection.
Definition: editor_map.cpp:176
Encapsulates the map of the game.
Definition: location.hpp:38
This class adds extra editor-specific functionality to a normal gamemap.
Definition: editor_map.hpp:70
Base class for all editor actions.
Definition: action_base.hpp:41
void clear_selection()
Clear the selection.
Definition: editor_map.cpp:196
editor_action_select * clone() const
Action cloning.
editor_action_select_none * clone() const
Action cloning.
This class wraps around a map to provide a concise interface for the editor to work with...
Definition: map_context.hpp:41
const std::set< map_location > & selection() const
Return the selection set.
Definition: editor_map.hpp:150
editor_action * perform(map_context &mc) const
Perform the action, returning an undo action that, when performed, shall reverse any effects of this ...
void extend(const editor_map &map, const std::set< map_location > &locs)
The crux of the extendable contract.
void select_all()
Select all map hexes.
Definition: editor_map.cpp:214
editor_action_select_inverse * perform(map_context &mc) const
Perform the action, returning an undo action that, when performed, shall reverse any effects of this ...
void extend(const editor_map &map, const std::set< map_location > &locs)
The crux of the extendable contract.
editor_action_select * perform(map_context &mc) const
Perform the action, returning an undo action that, when performed, shall reverse any effects of this ...
Deselect the given locations.
std::set< map_location > area_
Definition: action.hpp:218
Editor action classes.
editor_action_select * perform(map_context &mc) const
Perform the action, returning an undo action that, when performed, shall reverse any effects of this ...
bool remove_from_selection(const map_location &loc)
Remove a location to the selection.
Definition: editor_map.cpp:191