galaxy 1.0.0
Real-Time C++23 Game Programming Framework. Built on data-driven design principles and agile software engineering.
Loading...
Searching...
No Matches
Keyboard.cpp
Go to the documentation of this file.
1
7
8#include "Keyboard.hpp"
9
10namespace galaxy
11{
14 {
15 }
16
18 {
19 }
20
21 void Keyboard::begin_text_input(const SDL_TextInputType input_type, const SDL_Capitalization capitals, const bool multiline) const noexcept
22 {
23 if (!SDL_TextInputActive(m_window))
24 {
25 const auto props = SDL_CreateProperties();
26 SDL_SetNumberProperty(props, SDL_PROP_TEXTINPUT_TYPE_NUMBER, input_type);
27 SDL_SetNumberProperty(props, SDL_PROP_TEXTINPUT_CAPITALIZATION_NUMBER, capitals);
28 SDL_SetBooleanProperty(props, SDL_PROP_TEXTINPUT_AUTOCORRECT_BOOLEAN, false);
29 SDL_SetBooleanProperty(props, SDL_PROP_TEXTINPUT_MULTILINE_BOOLEAN, multiline);
30
31 SDL_StartTextInputWithProperties(m_window, props);
32 SDL_DestroyProperties(props);
33 }
34 }
35
36 bool Keyboard::is_text_input_active() const noexcept
37 {
38 return SDL_TextInputActive(m_window);
39 }
40
41 void Keyboard::end_text_input() const noexcept
42 {
43 SDL_StopTextInput(m_window);
44 }
45
46 void Keyboard::clear_state() const noexcept
47 {
48 SDL_ResetKeyboard();
49 }
50
51 bool Keyboard::has_keyboard() const noexcept
52 {
53 return SDL_HasKeyboard();
54 }
55
56 bool Keyboard::has_onscreen_keyboard() const noexcept
57 {
58 return SDL_HasScreenKeyboardSupport();
59 }
60
62 {
63 return SDL_ScreenKeyboardShown(m_window);
64 }
65
66 bool Keyboard::is_key_mod_down(const KeyMods modifier) const noexcept
67 {
68 const auto mod = static_cast<SDL_Keymod>(modifier);
69 return SDL_GetModState() & mod;
70 }
71
72 bool Keyboard::is_key_down(const Keys key) const noexcept
73 {
74 const auto keys = SDL_GetKeyboardState(nullptr);
75 return keys[static_cast<SDL_Keycode>(key)];
76 }
77
78 SDL_Scancode Keyboard::get_scancode(const Keys key, const KeyMods modifier) const noexcept
79 {
80 if (modifier == KeyMods::MOD_NONE)
81 {
82 return SDL_GetScancodeFromKey(static_cast<SDL_Keycode>(key), nullptr);
83 }
84 else
85 {
86 auto mod = static_cast<SDL_Keymod>(modifier);
87 return SDL_GetScancodeFromKey(static_cast<SDL_Keycode>(key), &mod);
88 }
89 }
90} // namespace galaxy
Keyboard() noexcept
Constructor.
Definition Keyboard.cpp:12
void clear_state() const noexcept
Will clear any existing keyboard state.
Definition Keyboard.cpp:46
void end_text_input() const noexcept
Disable text input.
Definition Keyboard.cpp:41
bool onscreen_keyboard_active() const noexcept
Check if onscreen keyboard is shown.
Definition Keyboard.cpp:61
SDL_Scancode get_scancode(const Keys key, const KeyMods modifier=KeyMods::MOD_NONE) const noexcept
Get key scancode.
Definition Keyboard.cpp:78
bool is_key_mod_down(const KeyMods modifier) const noexcept
See if a key mod is being held down.
Definition Keyboard.cpp:66
~Keyboard() noexcept
Destructor.
Definition Keyboard.cpp:17
bool has_keyboard() const noexcept
Check if there is a keyboard connected.
Definition Keyboard.cpp:51
bool is_text_input_active() const noexcept
Is text input active?
Definition Keyboard.cpp:36
void begin_text_input(const SDL_TextInputType input_type, const SDL_Capitalization capitals, const bool multiline) const noexcept
Enable window to begin processing text input.
Definition Keyboard.cpp:21
bool is_key_down(const Keys key) const noexcept
See if a key is being held down.
Definition Keyboard.cpp:72
bool has_onscreen_keyboard() const noexcept
Check if an onscreen keyboard is supported.
Definition Keyboard.cpp:56
WindowBindable() noexcept
Constructor.
SDL_Window * m_window
Pointer to SDL_Window handle.
Tag.cpp galaxy.
Definition Tag.cpp:13
Keys
Enum class representing keys.
Definition Keys.hpp:23
KeyMods
Enum class for key modifiers.
Definition Keys.hpp:286