aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/facade/SDLContext.cpp
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-14 13:49:40 +0100
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-14 13:49:40 +0100
commitc17233b10bd8e35bead60c5f44bb8a14836d755f (patch)
tree5031d3ac2761bf6a00e3e1696daed93d8f74f045 /src/crepe/facade/SDLContext.cpp
parent2389b23459cf5b01c6ea1cbbcfeb2043e26e0a0c (diff)
keyboard state working
Diffstat (limited to 'src/crepe/facade/SDLContext.cpp')
-rw-r--r--src/crepe/facade/SDLContext.cpp13
1 files changed, 3 insertions, 10 deletions
diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp
index bb65e3b..e5b0284 100644
--- a/src/crepe/facade/SDLContext.cpp
+++ b/src/crepe/facade/SDLContext.cpp
@@ -6,7 +6,6 @@
#include <SDL2/SDL_rect.h>
#include <SDL2/SDL_render.h>
#include <SDL2/SDL_surface.h>
-#include <SDL2/SDL_video.h>
#include <array>
#include <cmath>
#include <cstddef>
@@ -82,22 +81,18 @@ Keycode SDLContext::sdl_to_keycode(SDL_Scancode sdl_key) {
return LOOKUP_TABLE.at(sdl_key);
}
-const keyboard_state_t& SDLContext::get_keyboard_state() const{
- return this->keyboard_state;
-}
-
-void SDLContext::update_keyboard_state() {
- // Array to hold the key states (true if pressed, false if not)
+const keyboard_state_t& SDLContext::get_keyboard_state(){
SDL_PumpEvents();
const Uint8 * current_state = SDL_GetKeyboardState(nullptr);
for (int i = 0; i < SDL_NUM_SCANCODES; ++i) {
+
Keycode key = sdl_to_keycode(static_cast<SDL_Scancode>(i));
-
if (key != Keycode::NONE) {
this->keyboard_state[key] = current_state[i] != 0;
}
}
+ return this->keyboard_state;
}
MouseButton SDLContext::sdl_to_mousebutton(Uint8 sdl_button) {
@@ -289,7 +284,6 @@ std::vector<EventData> SDLContext::get_events() {
event_list.push_back({.event_type = EventType::SHUTDOWN});
break;
case SDL_KEYDOWN:
- this->update_keyboard_state();
event_list.push_back(EventData{
.event_type = EventType::KEY_DOWN,
.data = {
@@ -302,7 +296,6 @@ std::vector<EventData> SDLContext::get_events() {
break;
case SDL_KEYUP:
- this->update_keyboard_state();
event_list.push_back(EventData{
.event_type = EventType::KEY_UP,
.data = {