The Battle for Wesnoth  1.19.18+dev
action_select.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2025
3  by Fabian Mueller <fabianmueller5@gmx.de>
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 /**
17  * @file
18  * Editor label action classes
19  */
20 #define GETTEXT_DOMAIN "wesnoth-editor"
21 
24 
25 namespace editor
26 {
27 IMPLEMENT_ACTION(select)
28 
29 void editor_action_select::extend(const editor_map& /*map*/, const std::set<map_location>& locs)
30 {
31  for(const map_location& loc : locs) {
32  area_.insert(loc);
33  }
34 }
35 
36 std::unique_ptr<editor_action> editor_action_select::perform(map_context& mc) const
37 {
38  std::set<map_location> undo_locs;
39  for(const map_location& loc : area_) {
40  if(!mc.map().in_selection(loc)) {
41  undo_locs.insert(loc);
42  }
43  }
44 
46  return std::make_unique<editor_action_deselect>(undo_locs);
47 }
48 
50 {
51  for(const map_location& loc : area_) {
52  mc.map().add_to_selection(loc);
54  }
55 }
56 
57 IMPLEMENT_ACTION(deselect)
58 
59 void editor_action_deselect::extend(const editor_map& map, const std::set<map_location>& locs)
60 {
61  for(const map_location& loc : locs) {
62  if(!map.in_selection(loc)) {
63  area_.insert(loc);
64  }
65  }
66 }
67 
68 std::unique_ptr<editor_action> editor_action_deselect::perform(map_context& mc) const
69 {
70  std::set<map_location> undo_locs;
71  for(const map_location& loc : area_) {
72  if(mc.map().in_selection(loc)) {
73  undo_locs.insert(loc);
74  }
75  }
76 
78  return std::make_unique<editor_action_select>(undo_locs);
79 }
80 
82 {
83  for(const map_location& loc : area_) {
86  }
87 }
88 
89 IMPLEMENT_ACTION(select_all)
90 
91 std::unique_ptr<editor_action> editor_action_select_all::perform(map_context& mc) const
92 {
93  std::set<map_location> undo_locs = mc.map().selection_inverse();
94  perform_without_undo(mc);
95  return std::make_unique<editor_action_deselect>(undo_locs);
96 }
97 
99 {
100  mc.map().select_all();
102 }
103 
104 IMPLEMENT_ACTION(select_none)
105 
106 std::unique_ptr<editor_action> editor_action_select_none::perform(map_context& mc) const
107 {
108  std::set<map_location> current = mc.map().selection();
109  perform_without_undo(mc);
110  return std::make_unique<editor_action_select>(current);
111 }
112 
114 {
115  mc.map().clear_selection();
117 }
118 
119 IMPLEMENT_ACTION(select_inverse)
120 
121 std::unique_ptr<editor_action> editor_action_select_inverse::perform(map_context& mc) const
122 {
123  perform_without_undo(mc);
124  return std::make_unique<editor_action_select_inverse>();
125 }
126 
128 {
129  mc.map().invert_selection();
131 }
132 
133 } // end namespace editor
#define IMPLEMENT_ACTION(id)
Helper macro to implement common action methods.
Editor action classes.
map_location loc
Definition: move.cpp:172
std::set< map_location > area_
Definition: action.hpp:236
Deselect the given locations.
std::unique_ptr< editor_action > perform(map_context &mc) const override
Perform the action, returning an undo action that, when performed, shall reverse any effects of this ...
void perform_without_undo(map_context &mc) const override
Perform the action without creating an undo action.
void perform_without_undo(map_context &mc) const override
Perform the action without creating an undo action.
void perform_without_undo(map_context &mc) const override
Perform the action without creating an undo action.
void perform_without_undo(map_context &mc) const override
Perform the action without creating an undo action.
Select the given locations.
std::unique_ptr< editor_action > perform(map_context &mc) const override
Perform the action, returning an undo action that, when performed, shall reverse any effects of this ...
void perform_without_undo(map_context &mc) const override
Perform the action without creating an undo action.
Base class for all editor actions.
Definition: action_base.hpp:42
This class adds extra editor-specific functionality to a normal gamemap.
Definition: editor_map.hpp:70
bool add_to_selection(const map_location &loc)
Add a location to the selection.
Definition: editor_map.cpp:127
void invert_selection()
Invert the selection, i.e.
Definition: editor_map.cpp:160
void select_all()
Select all map hexes.
Definition: editor_map.cpp:165
bool in_selection(const map_location &loc) const
Definition: editor_map.cpp:122
bool remove_from_selection(const map_location &loc)
Remove a location to the selection.
Definition: editor_map.cpp:150
void clear_selection()
Clear the selection.
Definition: editor_map.cpp:155
This class wraps around a map to provide a concise interface for the editor to work with.
Definition: map_context.hpp:64
virtual const editor_map & map() const override
Const map accessor.
void add_changed_location(const map_location &loc)
void set(CURSOR_TYPE type)
Use the default parameter to reset cursors.
Definition: cursor.cpp:178
Manage the empty-palette in the editor.
Definition: action.cpp:31
Encapsulates the map of the game.
Definition: location.hpp:46