Binds global actions to key presses.
More...
#include <gui_key_binder.hpp>
|
using | function_type = signal_type::function_type |
| Type of a keybinding callback.
|
|
|
| key_binder ()=default |
| Constructor.
|
|
| key_binder (const key_binder &)=delete |
|
| key_binder (key_binder &&)=delete |
|
key_binder & | operator= (const key_binder &)=delete |
|
key_binder & | operator= (key_binder &&)=delete |
|
utils::connection | register_key_binding (std::string_view name, sol::protected_function lua_function) |
| Registers an action as a possible key binding.
|
|
utils::connection | register_key_binding (std::string_view name, function_type function) |
| Registers an action as a possible key binding.
|
|
void | set_key_binding (std::string_view name, std::string_view key_name) |
| Binds an action to a key.
|
|
void | set_key_binding (std::string_view name, input::key key_id, bool shift_is_pressed, bool ctrl_is_pressed, bool alt_is_pressed) |
| Binds an action to a key.
|
|
void | remove_key_binding (std::string_view name) |
| Unbinds an action.
|
|
bool | on_key_down (input::key key_id, bool shift_is_pressed, bool ctrl_is_pressed, bool alt_is_pressed) |
| Called when a key is pressed.
|
|
Binds global actions to key presses.
Definition at line 17 of file gui_key_binder.hpp.
◆ function_type
◆ key_binder() [1/3]
lxgui::gui::key_binder::key_binder |
( |
| ) |
|
|
default |
◆ key_binder() [2/3]
lxgui::gui::key_binder::key_binder |
( |
const key_binder & |
| ) |
|
|
delete |
◆ key_binder() [3/3]
lxgui::gui::key_binder::key_binder |
( |
key_binder && |
| ) |
|
|
delete |
◆ on_key_down()
bool lxgui::gui::key_binder::on_key_down |
( |
input::key |
key_id, |
|
|
bool |
shift_is_pressed, |
|
|
bool |
ctrl_is_pressed, |
|
|
bool |
alt_is_pressed |
|
) |
| |
Called when a key is pressed.
- Parameters
-
key_id | The key that is pressed |
shift_is_pressed | Is the Shift key pressed |
ctrl_is_pressed | Is the Ctrl key pressed |
alt_is_pressed | Is the Alt key pressed |
- Returns
- 'true' if a key binding was found matching this key combination, 'false' otherwise.
Definition at line 115 of file gui_key_binder.cpp.
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ register_key_binding() [1/2]
Registers an action as a possible key binding.
- Parameters
-
name | The name of the key binding (e.g., "JUMP") |
function | The C++ function that will be executed |
- Note
- The name of the key binding can be anything, but it must be unique. This only registers the action as "available" for a key binding. You must then call set_key_binding() to actually bind it to a key.
- Returns
- A connection object representing the registered callback function, can be used to gracefully disconnect the callback.
Definition at line 28 of file gui_key_binder.cpp.
◆ register_key_binding() [2/2]
utils::connection lxgui::gui::key_binder::register_key_binding |
( |
std::string_view |
name, |
|
|
sol::protected_function |
lua_function |
|
) |
| |
Registers an action as a possible key binding.
- Parameters
-
name | The name of the key binding (e.g., "JUMP") |
lua_function | The Lua function that will be executed |
- Note
- The name of the key binding can be anything, but it must be unique. This only registers the action as "available" for a key binding. You must then call set_key_binding() to actually bind it to a key.
- Returns
- A connection object representing the registered callback function, can be used to gracefully disconnect the callback.
Definition at line 14 of file gui_key_binder.cpp.
◆ remove_key_binding()
void lxgui::gui::key_binder::remove_key_binding |
( |
std::string_view |
name | ) |
|
◆ set_key_binding() [1/2]
void lxgui::gui::key_binder::set_key_binding |
( |
std::string_view |
name, |
|
|
input::key |
key_id, |
|
|
bool |
shift_is_pressed, |
|
|
bool |
ctrl_is_pressed, |
|
|
bool |
alt_is_pressed |
|
) |
| |
Binds an action to a key.
- Parameters
-
name | The action to bind |
key_id | The key to bind |
shift_is_pressed | 'true' if the Shift key must be pressed |
ctrl_is_pressed | 'true' if the Ctrl key must be pressed |
alt_is_pressed | 'true' if the Alt key must be pressed |
Definition at line 46 of file gui_key_binder.cpp.
◆ set_key_binding() [2/2]
void lxgui::gui::key_binder::set_key_binding |
( |
std::string_view |
name, |
|
|
std::string_view |
key_name |
|
) |
| |
Binds an action to a key.
- Parameters
-
name | The action to bind |
key_name | The key to bind it to (e.g., "Shift-T") |
- Note
- The format of the
key_name
parameter is any key name as returned from input::get_key_codename(), preceded by optional modifiers (any combination of "Shift-", "Ctrl-", "Alt-"). This corresponds to the key name given to frames in the "OnKeyDown", "OnKeyRepeat", and "OnKeyUp" scripts.
Definition at line 69 of file gui_key_binder.cpp.
The documentation for this class was generated from the following files: