The Battle for Wesnoth  1.15.12+dev
action_select.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2018 by Fabian Mueller <fabianmueller5@gmx.de>
3  Part of the Battle for Wesnoth Project https://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 action classes. Some important points:
18  * - This is a polymorphic hierarchy of classes, so actions are usually passed around
19  * as editor_action pointers
20  * - The pointers can, in general, be null. Always check for null before doing anything.
21  * The helper functions perform_ that take a pointer do that.
22  * - The perform() functions can throw when an error occurs. Use smart pointers if you
23  * need to ensure the pointer is deleted.
24  */
25 
26 #pragma once
27 
28 #include "editor/action/action.hpp"
29 
30 namespace editor
31 {
32 /**
33  * Select the given locations
34  */
36 {
37 public:
38  editor_action_select(const std::set<map_location>& area)
39  : editor_action_area(area)
40  {
41  }
42 
43  std::unique_ptr<editor_action> clone() const override;
44  void extend(const editor_map& map, const std::set<map_location>& locs) override;
45  std::unique_ptr<editor_action> perform(map_context& mc) const override;
46  void perform_without_undo(map_context& mc) const override;
47  const std::string& get_name() const override;
48 };
49 
50 /**
51  * Deselect the given locations
52  */
54 {
55 public:
56  editor_action_deselect(const std::set<map_location>& area)
57  : editor_action_area(area)
58  {
59  }
60 
61  std::unique_ptr<editor_action> clone() const override;
62  void extend(const editor_map& map, const std::set<map_location>& locs) override;
63  std::unique_ptr<editor_action> perform(map_context& mc) const override;
64  void perform_without_undo(map_context& mc) const override;
65  const std::string& get_name() const override;
66 };
67 
68 /**
69  * Select the entire map
70  */
72 {
73 public:
75  {
76  }
77 
78  std::unique_ptr<editor_action> clone() const override;
79  std::unique_ptr<editor_action> perform(map_context& mc) const override;
80  void perform_without_undo(map_context& mc) const override;
81  const std::string& get_name() const override;
82 };
83 
84 /**
85  * Clear selection
86  */
88 {
89 public:
91  {
92  }
93 
94  std::unique_ptr<editor_action> clone() const override;
95  std::unique_ptr<editor_action> perform(map_context& mc) const override;
96  void perform_without_undo(map_context& mc) const override;
97  const std::string& get_name() const override;
98 };
99 
100 /**
101  * Invert the selection
102  */
104 {
105 public:
107  {
108  }
109 
110  std::unique_ptr<editor_action> clone() const override;
111  std::unique_ptr<editor_action> perform(map_context& mc) const override;
112  void perform_without_undo(map_context& mc) const override;
113  const std::string& get_name() const override;
114 };
115 
116 } // end namespace editor
Select the entire map.
Base class for area-affecting actions.
Definition: action.hpp:218
void extend(const editor_map &map, const std::set< map_location > &locs) override
The crux of the extendable contract.
editor_action_deselect(const std::set< map_location > &area)
editor_action_select(const std::set< map_location > &area)
Select the given locations.
Editor action classes.
void perform_without_undo(map_context &mc) const override
Perform the action without creating an undo action.
Manage the empty-palette in the editor.
Definition: action.cpp:29
std::unique_ptr< editor_action > clone() const override
Action cloning.
This class adds extra editor-specific functionality to a normal gamemap.
Definition: editor_map.hpp:69
const std::string & get_name() const override
Base class for all editor actions.
Definition: action_base.hpp:40
This class wraps around a map to provide a concise interface for the editor to work with...
Definition: map_context.hpp:59
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 ...