diff options
author | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-12-13 08:16:48 +0100 |
---|---|---|
committer | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-12-13 08:16:48 +0100 |
commit | 193d5bf4d9577e63202cec45b21ed85a76a89f09 (patch) | |
tree | f25e2f1d0efebcb72e3c411f380222a84459e37a /src/crepe/facade/SDLContext.cpp | |
parent | 6e2aa75019a28c298454f50b7bfb0dca100e0936 (diff) |
keyboard state implemented
Diffstat (limited to 'src/crepe/facade/SDLContext.cpp')
-rw-r--r-- | src/crepe/facade/SDLContext.cpp | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index d70a7bb..6e47561 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -84,7 +84,7 @@ Keycode SDLContext::sdl_to_keycode(SDL_Scancode sdl_key) { return Keycode::NONE; } -keyboard_state_t SDLContext::get_keyboard_state() { +void SDLContext::update_keyboard_state() { // Array to hold the key states (true if pressed, false if not) std::array<bool, Keycode::NUM_KEYCODES> keyState{}; SDL_PumpEvents(); @@ -94,11 +94,10 @@ keyboard_state_t SDLContext::get_keyboard_state() { Keycode key = sdl_to_keycode(static_cast<SDL_Scancode>(i)); if (key != Keycode::NONE) { - keyboard_state[key] = current_state[i] != 0; + this->keyboard_state[key] = current_state[i] != 0; } } - return keyboard_state; } MouseButton SDLContext::sdl_to_mousebutton(Uint8 sdl_button) { @@ -293,25 +292,24 @@ std::vector<SDLContext::EventData> SDLContext::get_events() { break; case SDL_KEYDOWN: { - + this->update_keyboard_state(); EventData transfer_event; transfer_event.event_type = SDLContext::EventType::KEYDOWN; transfer_event.data.key_data = KeyData{ .key = sdl_to_keycode(event.key.keysym.scancode), .key_repeat = event.key.repeat != 0, - .keyboard_state = this->get_keyboard_state(), }; event_list.push_back(transfer_event); } break; case SDL_KEYUP: { + this->update_keyboard_state(); EventData transfer_event; transfer_event.event_type = SDLContext::EventType::KEYUP; transfer_event.data.key_data = KeyData{ .key = sdl_to_keycode(event.key.keysym.scancode), .key_repeat = false, - .keyboard_state = this->get_keyboard_state(), }; event_list.push_back(transfer_event); } |