From d4c91450d9df5fb6a61fec54bbb454dd163de161 Mon Sep 17 00:00:00 2001 From: binaryDiv Date: Wed, 26 Nov 2025 02:07:27 +0100 Subject: [PATCH] Wrap SDL event type enum (partially) --- src/core/engine.cppm | 2 +- src/game/game.cppm | 4 ++-- src/wrappers/sdl/events.cppm | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/core/engine.cppm b/src/core/engine.cppm index fda4019..0978cdf 100644 --- a/src/core/engine.cppm +++ b/src/core/engine.cppm @@ -83,7 +83,7 @@ export namespace core // Handles an SDL event. Returns true if the event has been handled. bool handle_event(const sdl::Event* event) { - if (event->type == SDL_EVENT_QUIT) { + if (event->type == sdl::EventType::Quit) { // Exit the application keep_running_ = false; return true; diff --git a/src/game/game.cppm b/src/game/game.cppm index 04f43f5..7f7eab0 100644 --- a/src/game/game.cppm +++ b/src/game/game.cppm @@ -62,7 +62,7 @@ export namespace game // Handles an SDL event. Returns true if the event has been handled. bool handle_event(const sdl::Event* event) { - if (event->type == SDL_EVENT_MOUSE_MOTION) { + if (event->type == sdl::EventType::MouseMotion) { player_sprite_.move( event->motion.x - 50, event->motion.y - 50 @@ -70,7 +70,7 @@ export namespace game return true; } - if (event->type == SDL_EVENT_MOUSE_BUTTON_UP) { + if (event->type == sdl::EventType::MouseButtonUp) { sprites_.emplace_back( engine_.get_render_server().load_texture("assets/neofox.png"), sdl::FRect{ diff --git a/src/wrappers/sdl/events.cppm b/src/wrappers/sdl/events.cppm index a168af0..7bb2e61 100644 --- a/src/wrappers/sdl/events.cppm +++ b/src/wrappers/sdl/events.cppm @@ -8,4 +8,23 @@ export namespace sdl { // Simple alias for SDL_Event union using Event = SDL_Event; + + // Alias for EventType enum + using EventType_t = SDL_EventType; + + /** + * Wrapper for the SDL_EventType enum. + * + * We're using a namespace here to emulate an enum-like interface, without having to copy the entire enum. + * More constants can be added on demand. + */ + namespace EventType + { + constexpr EventType_t Quit = SDL_EVENT_QUIT; + constexpr EventType_t KeyDown = SDL_EVENT_KEY_DOWN; + constexpr EventType_t KeyUp = SDL_EVENT_KEY_UP; + constexpr EventType_t MouseMotion = SDL_EVENT_MOUSE_MOTION; + constexpr EventType_t MouseButtonUp = SDL_EVENT_MOUSE_BUTTON_UP; + constexpr EventType_t MouseButtonDown = SDL_EVENT_MOUSE_BUTTON_DOWN; + } }