lxgui
Classes | Public Types | Public Member Functions | List of all members
lxgui::gui::key_binder Class Reference

Binds global actions to key presses. More...

#include <gui_key_binder.hpp>

Public Types

using function_type = signal_type::function_type
 Type of a keybinding callback. More...
 

Public Member Functions

 key_binder ()=default
 Constructor. More...
 
 key_binder (const key_binder &)=delete
 
 key_binder (key_binder &&)=delete
 
key_binderoperator= (const key_binder &)=delete
 
key_binderoperator= (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. More...
 
utils::connection register_key_binding (std::string_view name, function_type function)
 Registers an action as a possible key binding. More...
 
void set_key_binding (std::string_view name, std::string_view key_name)
 Binds an action to a key. More...
 
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. More...
 
void remove_key_binding (std::string_view name)
 Unbinds an action. More...
 
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. More...
 

Detailed Description

Binds global actions to key presses.

Definition at line 17 of file gui_key_binder.hpp.

Member Typedef Documentation

◆ function_type

using lxgui::gui::key_binder::function_type = signal_type::function_type

Type of a keybinding callback.

Definition at line 22 of file gui_key_binder.hpp.

Constructor & Destructor Documentation

◆ key_binder() [1/3]

lxgui::gui::key_binder::key_binder ( )
default

Constructor.

◆ 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

Member Function Documentation

◆ 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_idThe key that is pressed
shift_is_pressedIs the Shift key pressed
ctrl_is_pressedIs the Ctrl key pressed
alt_is_pressedIs 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]

key_binder& lxgui::gui::key_binder::operator= ( const key_binder )
delete

◆ operator=() [2/2]

key_binder& lxgui::gui::key_binder::operator= ( key_binder &&  )
delete

◆ register_key_binding() [1/2]

utils::connection lxgui::gui::key_binder::register_key_binding ( std::string_view  name,
function_type  function 
)

Registers an action as a possible key binding.

Parameters
nameThe name of the key binding (e.g., "JUMP")
functionThe 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
nameThe name of the key binding (e.g., "JUMP")
lua_functionThe 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)

Unbinds an action.

Parameters
nameThe action to unbind

Definition at line 89 of file gui_key_binder.cpp.

◆ 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
nameThe action to bind
key_idThe 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
nameThe action to bind
key_nameThe 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: