The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
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
25namespace editor
26{
27IMPLEMENT_ACTION(select)
28
29void 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
36std::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
56
57IMPLEMENT_ACTION(deselect)
58
59void 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
68std::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
88
89IMPLEMENT_ACTION(select_all)
90
91std::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
103
104IMPLEMENT_ACTION(select_none)
105
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
118
119IMPLEMENT_ACTION(select_inverse)
120
122{
123 perform_without_undo(mc);
124 return std::make_unique<editor_action_select_inverse>();
125}
126
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.
This class adds extra editor-specific functionality to a normal gamemap.
bool add_to_selection(const map_location &loc)
Add a location to the selection.
void invert_selection()
Invert the selection, i.e.
void select_all()
Select all map hexes.
bool in_selection(const map_location &loc) const
bool remove_from_selection(const map_location &loc)
Remove a location to the selection.
void clear_selection()
Clear the selection.
This class wraps around a map to provide a concise interface for the editor to work with.
virtual const editor_map & map() const override
Const map accessor.
void add_changed_location(const map_location &loc)
Manage the empty-palette in the editor.
Definition action.cpp:31
STL namespace.
Encapsulates the map of the game.
Definition location.hpp:46