aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/facade
diff options
context:
space:
mode:
Diffstat (limited to 'src/crepe/facade')
-rw-r--r--src/crepe/facade/SDLContext.cpp72
-rw-r--r--src/crepe/facade/SDLContext.h5
2 files changed, 38 insertions, 39 deletions
diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp
index 6e47561..7c7d58e 100644
--- a/src/crepe/facade/SDLContext.cpp
+++ b/src/crepe/facade/SDLContext.cpp
@@ -1,4 +1,3 @@
-#include <iostream>
#include <SDL2/SDL.h>
#include <SDL2/SDL_blendmode.h>
#include <SDL2/SDL_image.h>
@@ -86,7 +85,6 @@ Keycode SDLContext::sdl_to_keycode(SDL_Scancode sdl_key) {
}
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();
const Uint8 * current_state = SDL_GetKeyboardState(nullptr);
@@ -284,8 +282,6 @@ std::vector<SDLContext::EventData> SDLContext::get_events() {
ivec2 mouse_pos;
mouse_pos.x = (event.button.x - cam.bar_size.x) / cam.render_scale.x;
mouse_pos.y = (event.button.y - cam.bar_size.y) / cam.render_scale.y;
- std::cout << "SDL mousePos X: " << mouse_pos.x << std::endl;
- std::cout << "SDL mousePos Y: " << mouse_pos.y << std::endl;
switch (event.type) {
case SDL_QUIT:
event_list.push_back({.event_type = SDLContext::EventType::SHUTDOWN});
@@ -357,44 +353,52 @@ std::vector<SDLContext::EventData> SDLContext::get_events() {
};
event_list.push_back(transfer_event);
} break;
+ case SDL_WINDOWEVENT:
+ handle_window_event(event.window, event_list);
+ break;
}
}
return event_list;
}
-// Separate function for SDL_WINDOWEVENT subtypes
void SDLContext::handle_window_event(const SDL_WindowEvent & window_event,
std::vector<SDLContext::EventData> & event_list) {
- // switch (window_event.event) {
- // case SDL_WINDOWEVENT_EXPOSED:
- // event_list.push_back({SDLContext::EventType::WINDOW_EXPOSE, {}, {}, {}});
- // break;
- // case SDL_WINDOWEVENT_RESIZED:
- // event_list.push_back({SDLContext::EventType::WINDOW_RESIZE,
- // {},
- // {},
- // {{}, {window_event.data1, window_event.data2}}});
- // break;
- // case SDL_WINDOWEVENT_MOVED:
- // event_list.push_back({SDLContext::EventType::WINDOW_MOVE,
- // {},
- // {},
- // {{window_event.data1, window_event.data2}, {}}});
- // break;
- // case SDL_WINDOWEVENT_MINIMIZED:
- // event_list.push_back({SDLContext::EventType::WINDOW_MINIMIZE, {}, {}, {}});
- // break;
- // case SDL_WINDOWEVENT_MAXIMIZED:
- // event_list.push_back({SDLContext::EventType::WINDOW_MAXIMIZE, {}, {}, {}});
- // break;
- // case SDL_WINDOWEVENT_FOCUS_GAINED:
- // event_list.push_back({SDLContext::EventType::WINDOW_FOCUS_GAIN, {}, {}, {}});
- // break;
- // case SDL_WINDOWEVENT_FOCUS_LOST:
- // event_list.push_back({SDLContext::EventType::WINDOW_FOCUS_LOST, {}, {}, {}});
- // break;
- // }
+ switch (window_event.event) {
+ case SDL_WINDOWEVENT_EXPOSED:
+ event_list.push_back(EventData{SDLContext::EventType::WINDOW_EXPOSE});
+ break;
+ case SDL_WINDOWEVENT_RESIZED: {
+ EventData transfer_event;
+ transfer_event.event_type = SDLContext::EventType::WINDOW_RESIZE;
+ transfer_event.data.window_data = WindowData{
+ .resize_dimension = {window_event.data1, window_event.data2}
+ };
+ event_list.push_back(transfer_event);
+ break;
+ }
+ case SDL_WINDOWEVENT_MOVED: {
+ EventData transfer_event;
+ transfer_event.event_type = SDLContext::EventType::WINDOW_MOVE;
+ transfer_event.data.window_data = WindowData{
+ .move_delta = {window_event.data1, window_event.data2}
+ };
+ event_list.push_back(transfer_event);
+ break;
+ }
+ case SDL_WINDOWEVENT_MINIMIZED:
+ event_list.push_back(EventData{SDLContext::EventType::WINDOW_MINIMIZE});
+ break;
+ case SDL_WINDOWEVENT_MAXIMIZED:
+ event_list.push_back(EventData{SDLContext::EventType::WINDOW_MAXIMIZE});
+ break;
+ case SDL_WINDOWEVENT_FOCUS_GAINED:
+ event_list.push_back(EventData{SDLContext::EventType::WINDOW_FOCUS_GAIN});
+ break;
+ case SDL_WINDOWEVENT_FOCUS_LOST:
+ event_list.push_back(EventData{SDLContext::EventType::WINDOW_FOCUS_LOST});
+ break;
+ }
}
void SDLContext::set_color_texture(const Texture & texture, const Color & color) {
diff --git a/src/crepe/facade/SDLContext.h b/src/crepe/facade/SDLContext.h
index b10bcfe..e56d531 100644
--- a/src/crepe/facade/SDLContext.h
+++ b/src/crepe/facade/SDLContext.h
@@ -116,11 +116,6 @@ public:
EventDataUnion() {}
~EventDataUnion() {}
} data;
-
- // Helper functions
- // bool isKeyEvent() const { return event_type == SDLContext::EventType::KEYDOWN || event_type == SDLContext::EventType::KEYUP; }
- // bool isMouseEvent() const { return event_type == SDLContext::EventType::MOUSEDOWN || event_type == SDLContext::EventType::MOUSEUP || event_type == SDLContext::EventType::MOUSEMOVE; }
- // bool isWindowEvent() const { return event_type == SDLContext::EventType::WINDOW_MINIMIZE || event_type == SDLContext::EventType::WINDOW_RESIZE; }
};
/**
* \brief Retrieves the current state of the keyboard.