The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
hotkey_command.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2016 by David White <[email protected]>
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 #ifndef HOTKEY_COMMAND_HPP_INCLUDED
16 #define HOTKEY_COMMAND_HPP_INCLUDED
17 
18 #include "tooltips.hpp"
19 #include "tstring.hpp"
20 #include <boost/ptr_container/ptr_vector.hpp>
21 
22 #include <bitset>
23 class config;
24 
25 namespace hotkey {
26 
27 /**
28  * Available hotkey scopes. The scope is used to allow command from
29  * non-overlapping areas of the game share the same key
30  */
31 enum scope {
36 };
37 
56 
57  // Replay
63 
64  // Controls
67 
68  // Camera movement
70 
71  // Dialog control
73 
74  // Whiteboard commands
80 
81  // Misc.
87 
88  // Minimap
91 
92  /* Gui2 specific hotkeys. */
105 
107 
108  /* Editor commands */
111 
112  // Palette
115 
121 
122  // Unit
126 
127  // Brushes
130 
131  // Tools
136 
137  // Select
139  // Clipboard
143  // Selection
149 
150  // Map
159 
160  // Transitions
163 
164  // Refresh
167 
168  // Draw
170 
171  // Side
175 
176  // Area
181 
182  // Scenario
186 
187  /* This item must stay at the end since it is used as terminator for iterating. */
189 };
190 
191 typedef std::bitset<SCOPE_COUNT> hk_scopes;
192 
193 /// Stores all information related to functions that can be bound to hotkeys.
194 /// this is currently a semi struct: it haves a constructor, but only const-public members.
196 public:
197  /// the compiler want me to make a default constructor
198  /// since most member are const, calling the default constructor is normally no use.
199  hotkey_command();
201  /// the names are strange: the "hotkey::HOTKEY_COMMAND" is named id, and the string to identify the object is called "command"
202  /// there is some inconstancy with that names in this file.
203  /// This binds the command to a function. Does not need to be unique.
205  /// The command is unique.
207  // since the wml_menu hotkey_command s can have different textdomains we need t_string now.
209  /// If hidden then don't show the command in the hotkey preferences.
210  const bool hidden;
211  /// The visibility scope of the command.
213 
215 
216  /// checks weather this is the null hotkey_command
217  bool null() const;
218  /// returns the command that is treated as null
219  static const hotkey_command& null_command();
220  /// the execute_command argument was changed from HOTKEY_COMMAND to hotkey_command,
221  /// to be able to call it with HOTKEY_COMMAND, this function was created
223 };
224 
225 /// Do not use this outside hotkeys.cpp.
226 /// hotkey_command uses t_string which might cause bugs when used at program startup, so use this for the hotkey_list_ (and only there).
229 
230  const char* command;
231  /// description, tooltip are untranslated
232  const char* description;
233 
234  bool hidden;
235 
237 
238  const char* tooltip;
239 };
240 
242 public:
243  scope_changer();
244  ~scope_changer();
245 private:
247 };
248 typedef boost::ptr_vector<hotkey_command> t_hotkey_command_list;
249 /// returns a container that contains all currently active hotkey_commands.
250 /// everything that wants a hotkey, must be in this container.
251 const boost::ptr_vector<hotkey_command>& get_hotkey_commands();
252 
253 /// returns the hotkey_command with the given name
254 const hotkey_command& get_hotkey_command(const std::string& command);
255 
256 /// returns the hotkey_command that is treated as null.
258 
259 void deactivate_all_scopes();
260 void set_scope_active(scope s, bool set = true);
261 void set_active_scopes(hk_scopes s);
262 bool is_scope_active(hk_scopes s);
263 
264 ///
265 bool has_hotkey_command(const std::string& id);
266 
267 /// adds a new wml hotkey to the list, but only if there is no hotkey with that id yet on the list.
268 /// the object that is created here will be deleted in "delete_all_wml_hotkeys()"
269 void add_wml_hotkey(const std::string& id, const t_string& description, const config& default_hotkey);
270 
271 /// deletes all wml hotkeys, should be called after a game has ended
273 ///removes a wml hotkey with the given id, returns true if the deletion was successful
274 bool remove_wml_hotkey(const std::string& id);
275 
276 const std::string& get_description(const std::string& command);
277 const std::string& get_tooltip(const std::string& command);
278 
279 void init_hotkey_commands();
280 
281 void clear_hotkey_commands();
282 
283 /// returns get_hotkey_command(command).id
284 HOTKEY_COMMAND get_id(const std::string& command);
285 }
286 
287 #endif
bool null() const
checks weather this is the null hotkey_command
void set(CURSOR_TYPE type)
Use the default parameter to reset cursors.
Definition: cursor.cpp:154
boost::ptr_vector< hotkey_command > t_hotkey_command_list
scope
Available hotkey scopes.
void set_scope_active(scope s, bool set)
void add_wml_hotkey(const std::string &id, const t_string &description, const config &default_hotkey)
adds a new wml hotkey to the list, but only if there is no hotkey with that id yet on the list...
static const hotkey_command & null_command()
returns the command that is treated as null
bool is_scope_active(hk_scopes s)
Stores all information related to functions that can be bound to hotkeys.
void clear_hotkey_commands()
void set_active_scopes(hk_scopes s)
Keyboard shortcuts for game actions.
const std::string & get_tooltip(const std::string &command)
const t_string description
std::bitset< SCOPE_COUNT > hk_scopes
const char * description
description, tooltip are untranslated
void init_hotkey_commands()
const boost::ptr_vector< hotkey_command > & get_hotkey_commands()
returns a container that contains all currently active hotkey_commands.
const hotkey::hk_scopes scope
The visibility scope of the command.
void deactivate_all_scopes()
Do not use this outside hotkeys.cpp.
const std::string command
The command is unique.
hotkey_command()
the compiler want me to make a default constructor since most member are const, calling the default c...
const std::string & get_description(const std::string &command)
const hotkey_command & get_hotkey_null()
returns the hotkey_command that is treated as null.
const hotkey::HOTKEY_COMMAND id
the names are strange: the "hotkey::HOTKEY_COMMAND" is named id, and the string to identify the objec...
bool has_hotkey_command(const std::string &id)
hotkey::HOTKEY_COMMAND id
const bool hidden
If hidden then don't show the command in the hotkey preferences.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
GLdouble s
Definition: glew.h:1358
const hotkey_command & get_hotkey_command(const std::string &command)
returns the hotkey_command with the given name
void delete_all_wml_hotkeys()
deletes all wml hotkeys, should be called after a game has ended
bool remove_wml_hotkey(const std::string &id)
removes a wml hotkey with the given id, returns true if the deletion was successful ...
GLsizei const GLcharARB ** string
Definition: glew.h:4503
HOTKEY_COMMAND get_id(const std::string &command)
returns get_hotkey_command(command).id
static const hotkey_command & get_command_by_command(HOTKEY_COMMAND command)
the execute_command argument was changed from HOTKEY_COMMAND to hotkey_command, to be able to call it...