The Battle for Wesnoth  1.19.5+dev
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:

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 overridden 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 36 of file hotkey_item.hpp.

Constructor & Destructor Documentation

◆ hotkey_base()

hotkey::hotkey_base::hotkey_base ( )
inline

Initialises a new empty hotkey that will be disabled.

Definition at line 42 of file hotkey_item.hpp.

◆ ~hotkey_base()

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

Definition at line 178 of file hotkey_item.hpp.

Member Function Documentation

◆ active()

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

Definition at line 139 of file hotkey_item.hpp.

References command_.

Referenced by matches().

◆ bindings_equal()

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 84 of file hotkey_item.cpp.

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

◆ bindings_equal_helper()

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_void, hotkey::hotkey_mouse, and hotkey::hotkey_keyboard.

Referenced by bindings_equal().

◆ clear()

void hotkey::hotkey_base::clear ( )
inline

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

Definition at line 119 of file hotkey_item.hpp.

References command_.

◆ disable()

void hotkey::hotkey_base::disable ( )
inline

Definition at line 107 of file hotkey_item.hpp.

References is_disabled_.

◆ enable()

void hotkey::hotkey_base::enable ( )
inline

Definition at line 111 of file hotkey_item.hpp.

References is_disabled_.

◆ get_command()

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 63 of file hotkey_item.hpp.

References command_.

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

◆ get_description()

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

Returns the translated description.

Todo:
unused
Returns
internationalised description of the command.

◆ get_name()

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 49 of file hotkey_item.cpp.

References get_name_helper(), and mod_.

◆ get_name_helper()

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().

◆ hidden()

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 79 of file hotkey_item.hpp.

◆ is_default()

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 89 of file hotkey_item.hpp.

References is_default_.

◆ is_disabled()

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

Definition at line 103 of file hotkey_item.hpp.

References is_disabled_.

Referenced by matches(), and save().

◆ matches()

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 101 of file hotkey_item.cpp.

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

◆ 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_keyboard, and hotkey::hotkey_void.

Referenced by matches().

◆ null()

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 128 of file hotkey_item.hpp.

References command_.

◆ save()

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 110 of file hotkey_item.cpp.

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

◆ save_helper()

virtual void hotkey::hotkey_base::save_helper ( config cfg) const
protectedpure virtual

◆ set_command()

void hotkey::hotkey_base::set_command ( const std::string &  command)
inline

Definition at line 45 of file hotkey_item.hpp.

References command_.

◆ set_mods()

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

Set keyboard modifiers.

Parameters
modsBitmask of SDL_Keymod.

Definition at line 54 of file hotkey_item.hpp.

References mod_.

◆ unset_default()

void hotkey::hotkey_base::unset_default ( )
inline

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

Definition at line 98 of file hotkey_item.hpp.

References is_default_.

◆ valid()

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

◆ command_

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

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

Definition at line 206 of file hotkey_item.hpp.

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

◆ is_default_

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 212 of file hotkey_item.hpp.

Referenced by is_default(), and unset_default().

◆ is_disabled_

bool hotkey::hotkey_base::is_disabled_
protected

Definition at line 220 of file hotkey_item.hpp.

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

◆ mod_

unsigned int hotkey::hotkey_base::mod_
protected

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