aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/facade/SDLContext.cpp
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-11-25 10:38:18 +0100
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-11-25 10:38:18 +0100
commit327154fd428e0798eea544d9f073f8e1293aa158 (patch)
tree0bf5ea14a33cf54ab6bbddd22bce5e72f9398cb0 /src/crepe/facade/SDLContext.cpp
parent987fc16a8ae124548e2074d6f46806387c03e161 (diff)
most test working
Diffstat (limited to 'src/crepe/facade/SDLContext.cpp')
-rw-r--r--src/crepe/facade/SDLContext.cpp86
1 files changed, 6 insertions, 80 deletions
diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp
index 1ef222c..f87cc61 100644
--- a/src/crepe/facade/SDLContext.cpp
+++ b/src/crepe/facade/SDLContext.cpp
@@ -76,75 +76,6 @@ SDLContext::~SDLContext() {
SDL_Quit();
}
-void SDLContext::handle_events(bool &running) {
- EventManager& event_manager = EventManager::get_instance();
- SDL_Event event;
-
- while (SDL_PollEvent(&event)) {
- switch (event.type) {
- case SDL_QUIT:
- running = false;
- event_manager.trigger_event(ShutDownEvent{});
- break;
- case SDL_KEYDOWN:
- event_manager.trigger_event<KeyPressEvent>(KeyPressEvent{
- .repeat = (!event.key.repeat == 0),
- .key = this->sdl_to_keycode(event.key.keysym.scancode)
- });
- break;
-
- case SDL_KEYUP:
- event_manager.trigger_event<KeyReleaseEvent>(KeyReleaseEvent{
- .key = this->sdl_to_keycode(event.key.keysym.scancode),
- });
- break;
-
- case SDL_MOUSEBUTTONDOWN:
- {
- int x, y;
- SDL_GetMouseState(&x, &y);
- event_manager.trigger_event<MousePressEvent>(MousePressEvent{
- .mouse_x = x,
- .mouse_y = y,
- .button = this->sdl_to_mousebutton(event.button.button)
- });
- }
- break;
-
- case SDL_MOUSEBUTTONUP:
- {
- int x, y;
- SDL_GetMouseState(&x, &y);
- event_manager.trigger_event<MouseReleaseEvent>(MouseReleaseEvent{
- .mouse_x = x,
- .mouse_y = y,
- .button = this->sdl_to_mousebutton(event.button.button)
- });
- }
- break;
-
- case SDL_MOUSEMOTION:
- event_manager.trigger_event<MouseMoveEvent>(MouseMoveEvent{
- .mouse_x = event.motion.x,
- .mouse_y = event.motion.y,
- .rel_x = event.motion.xrel,
- .rel_y = event.motion.yrel
- });
- break;
-
- case SDL_MOUSEWHEEL:
- event_manager.trigger_event<MouseScrollEvent>(MouseScrollEvent{
- .scroll_x = event.wheel.x,
- .scroll_y = event.wheel.y,
- .direction = (event.wheel.direction == SDL_MOUSEWHEEL_FLIPPED ? -1 : 1)
- });
- break;
- }
- }
-}
-
-
-
Keycode SDLContext::sdl_to_keycode(SDL_Keycode sdl_key) {
static const std::array<Keycode, SDL_NUM_SCANCODES> LOOKUP_TABLE = [] {
std::array<Keycode, SDL_NUM_SCANCODES> table{};
@@ -259,8 +190,8 @@ Keycode SDLContext::sdl_to_keycode(SDL_Keycode sdl_key) {
return LOOKUP_TABLE[sdl_key];
}
MouseButton SDLContext::sdl_to_mousebutton(Uint8 sdl_button) {
- static const std::array<MouseButton, 8> MOUSE_BUTTON_LOOKUP_TABLE = [] {
- std::array<MouseButton, 8> table{};
+ static const std::array<MouseButton, 5> MOUSE_BUTTON_LOOKUP_TABLE = [] {
+ std::array<MouseButton, 5> table{};
table.fill(MouseButton::NONE);
table[SDL_BUTTON_LEFT] = MouseButton::LEFT_MOUSE;
@@ -409,7 +340,7 @@ std::vector<SDLContext::EventData> SDLContext::get_events(){
event_list.push_back(EventData{
.event_type = SDLContext::Event::MOUSEDOWN,
.mouse_button = sdl_to_mousebutton(event.button.button),
- .mouse_position = {x,y},
+ .mouse_position = {event.button.x,event.button.y},
});
}
break;
@@ -420,32 +351,27 @@ std::vector<SDLContext::EventData> SDLContext::get_events(){
event_list.push_back(EventData{
.event_type = SDLContext::Event::MOUSEUP,
.mouse_button = sdl_to_mousebutton(event.button.button),
- .mouse_position = {x,y},
+ .mouse_position = {event.button.x,event.button.y},
});
}
break;
case SDL_MOUSEMOTION:
{
- int x,y;
- SDL_GetMouseState(&x, &y);
event_list.push_back(EventData{
.event_type = SDLContext::Event::MOUSEMOVE,
- .mouse_position = {x,y},
+ .mouse_position = {event.button.x,event.button.y},
});
}
break;
case SDL_MOUSEWHEEL:
{
- int x, y;
- SDL_GetMouseState(&x, &y);
-
event_list.push_back(EventData{
.event_type = SDLContext::Event::MOUSEWHEEL,
.mouse_position = {event.motion.x,event.motion.y},
.wheel_delta = event.wheel.y,
- .rel_mouse_move {event.motion.yrel,event.motion.xrel},
+ .rel_mouse_move = {event.motion.yrel,event.motion.xrel},
});
}
break;