OpenTTD Source 20260206-master-g4d4e37dbf1
hotkeys.h File Reference

Hotkey related functions. More...

#include "gfx_type.h"
#include "window_type.h"
#include "string_type.h"

Go to the source code of this file.

Data Structures

struct  Hotkey
 All data for a single hotkey. More...
struct  HotkeyList
 List of hotkeys for a window. More...

Enumerations

enum class  SpecialListHotkeys : int { PreviousItem = 1 << SPECIAL_HOTKEY_BIT , NextItem , FirstItem , LastItem }
 Indexes for special hotkeys to navigate in lists. More...

Functions

bool IsQuitKey (uint16_t keycode)
 Does the given keycode match one of the keycodes bound to 'quit game'?
void LoadHotkeysFromConfig ()
 Load the hotkeys from the config file.
void SaveHotkeysToConfig ()
 Save the hotkeys to the config file.
void HandleGlobalHotkeys (char32_t key, uint16_t keycode)
bool IsSpecialHotkey (const int &hotkey)
 Checks if hotkey index is special or not.
template<class ItemType, class ListType>
std::tuple< size_t, size_t > GetListIndexStep (SpecialListHotkeys hotkey, const ListType &list, const ItemType &current_item)
 Gets the first index in the list for given hotkey and the step to look for another if first is invalid.

Variables

static constexpr int SPECIAL_HOTKEY_BIT = 30
 Bit which denotes that hotkey isn't bound to UI button.

Detailed Description

Hotkey related functions.

Definition in file hotkeys.h.

Enumeration Type Documentation

◆ SpecialListHotkeys

enum class SpecialListHotkeys : int
strong

Indexes for special hotkeys to navigate in lists.

Values have to have SPECIAL_HOTKEY_BIT set.

Enumerator
PreviousItem 

Hotkey to select previous item in the list.

NextItem 

Hotkey to select next item in the list.

FirstItem 

Hotkey to select first item in the list.

LastItem 

Hotkey to select last item in the list.

Definition at line 83 of file hotkeys.h.

Function Documentation

◆ GetListIndexStep()

template<class ItemType, class ListType>
std::tuple< size_t, size_t > GetListIndexStep ( SpecialListHotkeys hotkey,
const ListType & list,
const ItemType & current_item )

Gets the first index in the list for given hotkey and the step to look for another if first is invalid.

Template Parameters
ItemTypeThe type of items stored in the list.
ListTypeThe type of the list. For example: std::vector<ItemType>, std::list<ItemType>.
Parameters
hotkeyThe special hotkey to get the index and step for.
listThe list containing items.
current_itemThe item that is currently chosen, used for next and previous hotkeys.
Returns
Tuple containing index as first element and step as second. The step for backward direction has positive value, use % list.size() to remain in bounds.

Definition at line 100 of file hotkeys.h.

References FirstItem, LastItem, NextItem, and PreviousItem.

Referenced by BuildRailToolbarWindow::ChangeRailTypeOnHotkey(), and BuildRoadToolbarWindow::ChangeRoadTypeOnHotkey().

◆ HandleGlobalHotkeys()

void HandleGlobalHotkeys ( char32_t key,
uint16_t keycode )

Definition at line 343 of file hotkeys.cpp.

◆ IsQuitKey()

bool IsQuitKey ( uint16_t keycode)

Does the given keycode match one of the keycodes bound to 'quit game'?

Parameters
keycodeThe keycode that was pressed by the user.
Returns
True iff the keycode matches one of the hotkeys for 'quit'.

Definition at line 541 of file main_gui.cpp.

Referenced by EndGameHighScoreBaseWindow::OnKeyPress().

◆ IsSpecialHotkey()

bool IsSpecialHotkey ( const int & hotkey)
inline

Checks if hotkey index is special or not.

Parameters
hotkeyHotkey index to check.
Returns
True iff the index is for special hotkey.

Definition at line 74 of file hotkeys.h.

References HasBit(), and SPECIAL_HOTKEY_BIT.

Referenced by BuildRailToolbarWindow::OnHotkey(), and BuildRoadToolbarWindow::OnHotkey().

◆ LoadHotkeysFromConfig()

void LoadHotkeysFromConfig ( )

Load the hotkeys from the config file.

Definition at line 332 of file hotkeys.cpp.

Referenced by AfterNewGRFScan::OnNewGRFsScanned().

◆ SaveHotkeysToConfig()

void SaveHotkeysToConfig ( )

Save the hotkeys to the config file.

Definition at line 338 of file hotkeys.cpp.

Variable Documentation

◆ SPECIAL_HOTKEY_BIT

int SPECIAL_HOTKEY_BIT = 30
staticconstexpr

Bit which denotes that hotkey isn't bound to UI button.

Definition at line 67 of file hotkeys.h.

Referenced by IsSpecialHotkey().