The Battle for Wesnoth  1.13.10+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 - 2017 by Fabian Mueller <fabianmueller5@gmx.de>
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 {
26 IMPLEMENT_ACTION(select)
27 
28 void editor_action_select::extend(const editor_map& /*map*/, const std::set<map_location>& locs)
29 {
30  for(const map_location& loc : locs) {
31  LOG_ED << "Extending by " << loc << "\n";
32  area_.insert(loc);
33  }
34 }
35 
37 {
38  std::set<map_location> undo_locs;
39  for(const map_location& loc : area_) {
40  undo_locs.insert(loc);
41  mc.add_changed_location(loc);
42  }
43 
45  return new editor_action_select(undo_locs);
46 }
47 
49 {
50  for(const map_location& loc : area_) {
51  mc.get_map().add_to_selection(loc);
52  mc.add_changed_location(loc);
53  }
54 }
55 
56 IMPLEMENT_ACTION(deselect)
57 
58 void editor_action_deselect::extend(const editor_map& map, const std::set<map_location>& locs)
59 {
60  for(const map_location& loc : locs) {
61  LOG_ED << "Checking " << loc << "\n";
62  if(!map.in_selection(loc)) {
63  LOG_ED << "Extending by " << loc << "\n";
64  area_.insert(loc);
65  }
66  }
67 }
68 
70 {
71  std::set<map_location> undo_locs;
72  for(const map_location& loc : area_) {
73  if(mc.get_map().in_selection(loc)) {
74  undo_locs.insert(loc);
75  mc.add_changed_location(loc);
76  }
77  }
78 
80  return new editor_action_select(undo_locs);
81 }
82 
84 {
85  for(const map_location& loc : area_) {
87  mc.add_changed_location(loc);
88  }
89 }
90 
91 IMPLEMENT_ACTION(select_all)
92 
94 {
95  std::set<map_location> current = mc.get_map().selection();
96  mc.get_map().select_all();
97 
98  std::set<map_location> all = mc.get_map().selection();
99  std::set<map_location> undo_locs;
100 
101  std::set_difference(
102  all.begin(), all.end(), current.begin(), current.end(), std::inserter(undo_locs, undo_locs.begin()));
103 
104  mc.set_everything_changed();
105  return new editor_action_select(undo_locs);
106 }
107 
109 {
110  mc.get_map().select_all();
112 }
113 
114 IMPLEMENT_ACTION(select_none)
115 
117 {
118  std::set<map_location> current = mc.get_map().selection();
119  mc.get_map().clear_selection();
120  mc.set_everything_changed();
121  return new editor_action_select(current);
122 }
123 
125 {
126  mc.get_map().clear_selection();
128 }
129 
130 IMPLEMENT_ACTION(select_inverse)
131 
133 {
134  perform_without_undo(mc);
135  return new editor_action_select_inverse();
136 }
137 
139 {
140  mc.get_map().invert_selection();
142 }
143 
144 } // 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.
void set(CURSOR_TYPE type)
Use the default parameter to reset cursors.
Definition: cursor.cpp:154
editor_action * perform(map_context &mc) const
Perform the action, returning an undo action that, when performed, shall reverse any effects of this ...
#define LOG_ED
STL namespace.
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:161
void invert_selection()
Invert the selection, i.e.
Definition: editor_map.cpp:191
editor_map & get_map()
Map accessor.
Definition: map_context.hpp:92
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:29
bool add_to_selection(const map_location &loc)
Add a location to the selection.
Definition: editor_map.cpp:166
Encapsulates the map of the game.
Definition: location.hpp:40
This class adds extra editor-specific functionality to a normal gamemap.
Definition: editor_map.hpp:69
Base class for all editor actions.
Definition: action_base.hpp:40
void clear_selection()
Clear the selection.
Definition: editor_map.cpp:186
This class wraps around a map to provide a concise interface for the editor to work with...
Definition: map_context.hpp:55
editor_action * perform(map_context &mc) const
Perform the action, returning an undo action that, when performed, shall reverse any effects of this ...
void select_all()
Select all map hexes.
Definition: editor_map.cpp:204
#define IMPLEMENT_ACTION(id)
Helper macro to implement common action methods.
Deselect the given locations.
std::set< map_location > area_
Definition: action.hpp:249
Editor action classes.
bool remove_from_selection(const map_location &loc)
Remove a location to the selection.
Definition: editor_map.cpp:181