The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
hotkey::hotkey_base Class Referenceabstract

This is the base class for hotkey event matching. More...

#include <hotkey_item.hpp>

Inheritance diagram for hotkey::hotkey_base:
Inheritance graph

Public Member Functions

 hotkey_base ()
 Initialises a new empty hotkey that will be disabled. More...
 
void set_command (const std::string &command)
 
void set_mods (unsigned int mods)
 Set keyboard modifiers. More...
 
const std::string & get_command () const
 Returns the string name of the HOTKEY_COMMAND. More...
 
const std::string get_description () const
 Returns the translated description. More...
 
virtual bool hidden () const
 This controls whether the item should appear in the hotkey preferences. More...
 
bool is_default () const
 This indicates whether a hotkey is from the default config or if it's from the user preferences. More...
 
void unset_default ()
 Used to indicate that a hotkey is overriden and should be treated as a user-set hotkey. More...
 
bool is_disabled () const
 
void disable ()
 
void enable ()
 
void clear ()
 Unbind this hotkey by linking it to the null-command. More...
 
bool null () const
 Returns whether this hotkey points to the null-command. More...
 
bool active () const
 
virtual bool valid () const =0
 Evaluates whether the hotkey bindings are valid. More...
 
void save (config &cfg) const
 Save the hotkey into the configuration object. More...
 
const std::string get_name () const
 Return "name" of hotkey. More...
 
bool matches (const SDL_Event &event) const
 Used to evaluate whether: More...
 
virtual bool bindings_equal (hotkey_ptr other)
 Checks whether the hotkey bindings and scope are equal. More...
 
virtual ~hotkey_base ()
 

Protected Member Functions

virtual const std::string get_name_helper () const =0
 This is invoked by hotkey_base::get_name and must be implemented by subclasses. More...
 
virtual bool matches_helper (const SDL_Event &event) const =0
 This is invoked by hotkey_base::matches as a helper for the concrete classes. More...
 
virtual void save_helper (config &cfg) const =0
 
virtual bool bindings_equal_helper (hotkey_ptr other) const =0
 This is invoked by hotkey_base::bindings_equal as a helper for the concrete classes. More...
 

Protected Attributes

std::string command_
 The command that should be executed, or "null". More...
 
bool is_default_
 is_default_ is true if the hot-key is part of the default hot-key list defined in data/core/hotkeys.cfg. More...
 
bool is_disabled_
 
unsigned int mod_
 

Detailed Description

This is the base class for hotkey event matching.

Definition at line 41 of file hotkey_item.hpp.

Constructor & Destructor Documentation

hotkey::hotkey_base::hotkey_base ( )
inline

Initialises a new empty hotkey that will be disabled.

Definition at line 47 of file hotkey_item.hpp.

virtual hotkey::hotkey_base::~hotkey_base ( )
inlinevirtual

Definition at line 183 of file hotkey_item.hpp.

Member Function Documentation

bool hotkey::hotkey_base::active ( ) const
inline

Definition at line 144 of file hotkey_item.hpp.

References command_.

Referenced by matches().

bool hotkey::hotkey_base::bindings_equal ( hotkey_ptr  other)
virtual

Checks whether the hotkey bindings and scope are equal.

Parameters
otherthe hokey bindings to compare against.
Returns
true if other has same scope and bindings.

Definition at line 103 of file hotkey_item.cpp.

References bindings_equal_helper(), get_command(), hotkey::get_hotkey_command(), mod_, and hotkey::hotkey_command::scope.

virtual bool hotkey::hotkey_base::bindings_equal_helper ( hotkey_ptr  other) const
protectedpure virtual

This is invoked by hotkey_base::bindings_equal as a helper for the concrete classes.

Implementing classes should only check their parts of the hotkey.

Parameters
otherThe other hotkey the check against. Not guaranteed to be the same subclass.
Returns
true if they match, false otherwise.

Implemented in hotkey::hotkey_mouse, hotkey::hotkey_void, and hotkey::hotkey_keyboard.

Referenced by bindings_equal().

void hotkey::hotkey_base::clear ( )
inline

Unbind this hotkey by linking it to the null-command.

Definition at line 124 of file hotkey_item.hpp.

References command_.

void hotkey::hotkey_base::disable ( )
inline

Definition at line 112 of file hotkey_item.hpp.

References is_disabled_.

void hotkey::hotkey_base::enable ( )
inline

Definition at line 116 of file hotkey_item.hpp.

References is_disabled_.

const std::string& hotkey::hotkey_base::get_command ( ) const
inline

Returns the string name of the HOTKEY_COMMAND.

Returns
The unique string for a hotkey command.

Definition at line 68 of file hotkey_item.hpp.

References command_.

Referenced by bindings_equal(), matches(), hotkey::hotkey_keyboard::matches_helper(), and save().

const std::string hotkey::hotkey_base::get_description ( ) const

Returns the translated description.

Todo:
unused
Returns
internationalised description of the command.
const std::string hotkey::hotkey_base::get_name ( ) const

Return "name" of hotkey.

Example :"ctrl+alt+g"

Returns
The string representation of the keybindings

Definition at line 68 of file hotkey_item.cpp.

References filesystem::ends_with(), get_name_helper(), and mod_.

virtual const std::string hotkey::hotkey_base::get_name_helper ( ) const
protectedpure virtual

This is invoked by hotkey_base::get_name and must be implemented by subclasses.

Keyboard modifiers are handled in this class, other hotkeys in the respective classes

Implemented in hotkey::hotkey_mouse, hotkey::hotkey_void, and hotkey::hotkey_keyboard.

Referenced by get_name().

virtual bool hotkey::hotkey_base::hidden ( ) const
inlinevirtual

This controls whether the item should appear in the hotkey preferences.

Returns
true if the item should be hidden

Definition at line 84 of file hotkey_item.hpp.

bool hotkey::hotkey_base::is_default ( ) const
inline

This indicates whether a hotkey is from the default config or if it's from the user preferences.

Returns
true if from the default configurations, false otherwise

Definition at line 94 of file hotkey_item.hpp.

References is_default_.

bool hotkey::hotkey_base::is_disabled ( ) const
inline

Definition at line 108 of file hotkey_item.hpp.

References is_disabled_.

Referenced by matches(), and save().

bool hotkey::hotkey_base::matches ( const SDL_Event &  event) const

Used to evaluate whether:

  1. The hotkey is valid in the current scope.
  2. The Keyboard modifiers and SDL_Event mathes this hotkey.
Parameters
eventThe SDL_Event that has triggered and is being evaluated.

Definition at line 119 of file hotkey_item.cpp.

References active(), get_command(), hotkey::get_hotkey_command(), is_disabled(), hotkey::is_scope_active(), and matches_helper().

virtual bool hotkey::hotkey_base::matches_helper ( const SDL_Event &  event) const
protectedpure virtual

This is invoked by hotkey_base::matches as a helper for the concrete classes.

Implementing classes should only check their parts of the hotkey.

Parameters
eventThe SDL_Event being generated.
Returns
true if they match, false otherwise.

Implemented in hotkey::hotkey_mouse, hotkey::hotkey_void, and hotkey::hotkey_keyboard.

Referenced by matches().

bool hotkey::hotkey_base::null ( ) const
inline

Returns whether this hotkey points to the null-command.

Returns
true if it points to the null-command, false otherwise.

Definition at line 133 of file hotkey_item.hpp.

References command_.

void hotkey::hotkey_base::save ( config cfg) const

Save the hotkey into the configuration object.

Parameters
cfgThe configuration object to save into.

Definition at line 129 of file hotkey_item.cpp.

References get_command(), is_disabled(), mod_, and save_helper().

virtual void hotkey::hotkey_base::save_helper ( config cfg) const
protectedpure virtual
void hotkey::hotkey_base::set_command ( const std::string &  command)
inline

Definition at line 50 of file hotkey_item.hpp.

References command_.

void hotkey::hotkey_base::set_mods ( unsigned int  mods)
inline

Set keyboard modifiers.

Parameters
modsBitmask of SDL_Keymod.

Definition at line 59 of file hotkey_item.hpp.

References mod_.

void hotkey::hotkey_base::unset_default ( )
inline

Used to indicate that a hotkey is overriden and should be treated as a user-set hotkey.

Definition at line 103 of file hotkey_item.hpp.

References is_default_.

virtual bool hotkey::hotkey_base::valid ( ) const
pure virtual

Evaluates whether the hotkey bindings are valid.

Returns
true if they are valid, false otherwise.

Implemented in hotkey::hotkey_mouse, hotkey::hotkey_void, and hotkey::hotkey_keyboard.

Member Data Documentation

std::string hotkey::hotkey_base::command_
protected

The command that should be executed, or "null".

Definition at line 211 of file hotkey_item.hpp.

Referenced by active(), clear(), get_command(), null(), and set_command().

bool hotkey::hotkey_base::is_default_
protected

is_default_ is true if the hot-key is part of the default hot-key list defined in data/core/hotkeys.cfg.

is_default_ is false if it is not, in which case it would be defined in the user's preferences file.

Definition at line 217 of file hotkey_item.hpp.

Referenced by is_default(), and unset_default().

bool hotkey::hotkey_base::is_disabled_
protected

Definition at line 225 of file hotkey_item.hpp.

Referenced by disable(), enable(), and is_disabled().

unsigned int hotkey::hotkey_base::mod_
protected

The documentation for this class was generated from the following files: