diff options
Diffstat (limited to 'src/crepe/facade')
-rw-r--r-- | src/crepe/facade/EventData.h | 89 | ||||
-rw-r--r-- | src/crepe/facade/SDLContext.cpp | 9 | ||||
-rw-r--r-- | src/crepe/facade/SDLContext.h | 8 |
3 files changed, 51 insertions, 55 deletions
diff --git a/src/crepe/facade/EventData.h b/src/crepe/facade/EventData.h index d0ca07f..a7526b4 100644 --- a/src/crepe/facade/EventData.h +++ b/src/crepe/facade/EventData.h @@ -3,53 +3,52 @@ #include "../types.h" namespace crepe { //! EventType enum for passing eventType - enum EventType { - NONE = 0, - MOUSE_DOWN, - MOUSE_UP, - MOUSE_MOVE, - MOUSE_WHEEL, - KEY_UP, - KEY_DOWN, - SHUTDOWN, - WINDOW_MINIMIZE, - WINDOW_MAXIMIZE, - WINDOW_FOCUS_GAIN, - WINDOW_FOCUS_LOST, - WINDOW_MOVE, - WINDOW_RESIZE, - WINDOW_EXPOSE, - }; +enum EventType { + NONE = 0, + MOUSE_DOWN, + MOUSE_UP, + MOUSE_MOVE, + MOUSE_WHEEL, + KEY_UP, + KEY_DOWN, + SHUTDOWN, + WINDOW_MINIMIZE, + WINDOW_MAXIMIZE, + WINDOW_FOCUS_GAIN, + WINDOW_FOCUS_LOST, + WINDOW_MOVE, + WINDOW_RESIZE, + WINDOW_EXPOSE, +}; - //! Struct for storing key data. - struct KeyData { - Keycode key = Keycode::NONE; - bool key_repeat = false; - }; +//! Struct for storing key data. +struct KeyData { + Keycode key = Keycode::NONE; + bool key_repeat = false; +}; - //! Struct for storing mouse data. - struct MouseData { - MouseButton mouse_button = MouseButton::NONE; - ivec2 mouse_position = {-1, -1}; - int scroll_direction = -1; - float scroll_delta = INFINITY; - ivec2 rel_mouse_move = {-1, -1}; - }; +//! Struct for storing mouse data. +struct MouseData { + MouseButton mouse_button = MouseButton::NONE; + ivec2 mouse_position = {-1, -1}; + int scroll_direction = -1; + float scroll_delta = INFINITY; + ivec2 rel_mouse_move = {-1, -1}; +}; - //! Struct for storing window data. - struct WindowData { - ivec2 move_delta; - ivec2 resize_dimension; - }; - - //! EventData struct for passing event data from facade - struct EventData { - EventType event_type = EventType::NONE; - union { - KeyData key_data; - MouseData mouse_data; - WindowData window_data; - } data; +//! Struct for storing window data. +struct WindowData { + ivec2 move_delta; + ivec2 resize_dimension; +}; - }; +//! EventData struct for passing event data from facade +struct EventData { + EventType event_type = EventType::NONE; + union { + KeyData key_data; + MouseData mouse_data; + WindowData window_data; + } data; +}; } // namespace crepe diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index e5b0284..7ccc243 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -75,18 +75,17 @@ SDLContext::~SDLContext() { } Keycode SDLContext::sdl_to_keycode(SDL_Scancode sdl_key) { - if (!LOOKUP_TABLE.contains(sdl_key)) - return Keycode::NONE; + if (!LOOKUP_TABLE.contains(sdl_key)) return Keycode::NONE; return LOOKUP_TABLE.at(sdl_key); } -const keyboard_state_t& SDLContext::get_keyboard_state(){ +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; @@ -283,7 +282,7 @@ std::vector<EventData> SDLContext::get_events() { case SDL_QUIT: event_list.push_back({.event_type = EventType::SHUTDOWN}); break; - case SDL_KEYDOWN: + case SDL_KEYDOWN: event_list.push_back(EventData{ .event_type = EventType::KEY_DOWN, .data = { diff --git a/src/crepe/facade/SDLContext.h b/src/crepe/facade/SDLContext.h index 3531680..8f4760e 100644 --- a/src/crepe/facade/SDLContext.h +++ b/src/crepe/facade/SDLContext.h @@ -5,19 +5,18 @@ #include <SDL2/SDL_rect.h> #include <SDL2/SDL_render.h> #include <SDL2/SDL_video.h> -#include <array> #include <cmath> #include <functional> #include <memory> #include <string> #include <unordered_map> +#include "../types.h" #include "api/Camera.h" #include "api/Color.h" #include "api/KeyCodes.h" #include "api/Sprite.h" #include "api/Transform.h" -#include "../types.h" #include "EventData.h" @@ -71,7 +70,6 @@ public: }; public: - /** * \brief Gets the singleton instance of SDLContext. * \return Reference to the SDLContext instance. @@ -146,8 +144,8 @@ public: * \return A constant reference to the `keyboard_state_t`, which holds the state * of each key (true = pressed, false = not pressed). */ - const keyboard_state_t& get_keyboard_state(); - + const keyboard_state_t & get_keyboard_state(); + public: /** * \brief Gets the current SDL ticks since the program started. |