The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
action_select.hpp
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 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  /** Inherited from editor_action, implemented by IMPLEMENT_ACTION. */
44  editor_action_select* clone() const;
45 
46  void extend(const editor_map& map, const std::set<map_location>& locs);
47 
48  editor_action* perform(map_context& mc) const;
49 
50  void perform_without_undo(map_context& mc) const;
51 
52  /** Inherited from editor_action, implemented by IMPLEMENT_ACTION. */
53  const std::string& get_name() const;
54 };
55 
56 /**
57  * Deselect the given locations
58  */
60 {
61 public:
62  editor_action_deselect(const std::set<map_location>& area)
63  : editor_action_area(area)
64  {
65  }
66 
67  /** Inherited from editor_action, implemented by IMPLEMENT_ACTION. */
69 
70  void extend(const editor_map& map, const std::set<map_location>& locs);
71 
72  editor_action* perform(map_context& mc) const;
73 
74  void perform_without_undo(map_context& mc) const;
75 
76  /** Inherited from editor_action, implemented by IMPLEMENT_ACTION. */
77  const std::string& get_name() const;
78 };
79 
80 /**
81  * Select the entire map
82  */
84 {
85 public:
87  {
88  }
89 
90  /** Inherited from editor_action, implemented by IMPLEMENT_ACTION. */
92 
94 
95  void perform_without_undo(map_context& mc) const;
96 
97  /** Inherited from editor_action, implemented by IMPLEMENT_ACTION. */
98  const std::string& get_name() const;
99 };
100 
101 /**
102  * Clear selection
103  */
105 {
106 public:
108  {
109  }
110 
111  /** Inherited from editor_action, implemented by IMPLEMENT_ACTION. */
113 
115 
116  void perform_without_undo(map_context& mc) const;
117 
118  /** Inherited from editor_action, implemented by IMPLEMENT_ACTION. */
119  const std::string& get_name() const;
120 };
121 
122 /**
123  * Invert the selection
124  */
126 {
127 public:
129  {
130  }
131 
132  /** Inherited from editor_action, implemented by IMPLEMENT_ACTION. */
134 
136 
137  void perform_without_undo(map_context& mc) const;
138 
139  /** Inherited from editor_action, implemented by IMPLEMENT_ACTION. */
140  const std::string& get_name() const;
141 };
142 
143 } // end namespace editor
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.
std::vector< char_t > string
Select the entire map.
editor_action_select_all * clone() const
Inherited from editor_action, implemented by IMPLEMENT_ACTION.
editor_action * perform(map_context &mc) const
Perform the action, returning an undo action that, when performed, shall reverse any effects of this ...
const std::string & get_name() const
Inherited from editor_action, implemented by IMPLEMENT_ACTION.
const std::string & get_name() const
Inherited from editor_action, implemented by IMPLEMENT_ACTION.
Base class for area-affecting actions.
Definition: action.hpp:232
editor_action_deselect * clone() const
Inherited from editor_action, implemented by IMPLEMENT_ACTION.
editor_action_select * clone() const
Inherited from editor_action, implemented by IMPLEMENT_ACTION.
editor_action_deselect(const std::set< map_location > &area)
const std::string & get_name() const
Inherited from editor_action, implemented by IMPLEMENT_ACTION.
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)
Select the given locations.
Editor action classes.
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
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
This class wraps around a map to provide a concise interface for the editor to work with...
Definition: map_context.hpp:55
const std::string & get_name() const
Inherited from editor_action, implemented by IMPLEMENT_ACTION.
editor_action_select_inverse * clone() const
Inherited from editor_action, implemented by IMPLEMENT_ACTION.
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.
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.
editor_action_select_none * clone() const
Inherited from editor_action, implemented by IMPLEMENT_ACTION.
const std::string & get_name() const
Inherited from editor_action, implemented by IMPLEMENT_ACTION.
editor_action_select * perform(map_context &mc) const
Perform the action, returning an undo action that, when performed, shall reverse any effects of this ...