aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-11-25 12:04:24 +0100
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-11-25 12:04:24 +0100
commitaaf1d8132b631b3c09672b27d6ca3141e875d71c (patch)
treec54d1a8fd4f6694af1540042ac0ca1c3364bead9
parentfd7dfd2202c9435b86ac10ed96c6515f2505daa8 (diff)
added enters
-rw-r--r--src/crepe/facade/SDLContext.cpp4
-rw-r--r--src/crepe/facade/SDLContext.h34
2 files changed, 33 insertions, 5 deletions
diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp
index 063be41..512e858 100644
--- a/src/crepe/facade/SDLContext.cpp
+++ b/src/crepe/facade/SDLContext.cpp
@@ -188,6 +188,7 @@ 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, 5> MOUSE_BUTTON_LOOKUP_TABLE = [] {
std::array<MouseButton, 5> table{};
@@ -209,7 +210,9 @@ MouseButton SDLContext::sdl_to_mousebutton(Uint8 sdl_button) {
return MOUSE_BUTTON_LOOKUP_TABLE[sdl_button];
}
+
void SDLContext::clear_screen() { SDL_RenderClear(this->game_renderer.get()); }
+
void SDLContext::present_screen() { SDL_RenderPresent(this->game_renderer.get()); }
SDL_Rect SDLContext::get_src_rect(const Sprite & sprite) const {
@@ -307,6 +310,7 @@ int SDLContext::get_height(const Texture & ctx) const {
SDL_QueryTexture(ctx.texture.get(), NULL, NULL, NULL, &h);
return h;
}
+
void SDLContext::delay(int ms) const { SDL_Delay(ms); }
std::vector<SDLContext::EventData> SDLContext::get_events() {
diff --git a/src/crepe/facade/SDLContext.h b/src/crepe/facade/SDLContext.h
index 5892d5c..dd288af 100644
--- a/src/crepe/facade/SDLContext.h
+++ b/src/crepe/facade/SDLContext.h
@@ -36,6 +36,7 @@ class InputSystem;
class SDLContext {
public:
+ //! EventType enum for passing eventType
enum EventType {
NONE = 0,
MOUSEDOWN,
@@ -47,6 +48,7 @@ public:
SHUTDOWN,
};
+ //! EventData struct for passing event data from facade
struct EventData {
SDLContext::EventType event_type = SDLContext::EventType::NONE;
Keycode key = Keycode::NONE;
@@ -68,17 +70,39 @@ public:
SDLContext & operator=(SDLContext &&) = delete;
private:
- //! will only use handle_events
+ //! will only use get_events
friend class InputSystem;
/**
- * \brief Handles SDL events such as window close and input.
- * \param running Reference to a boolean flag that controls the main loop.
+ * @brief Retrieves a list of all events from the SDL context.
+ *
+ * This method retrieves all the events from the SDL context that are currently
+ * available. It is primarily used by the InputSystem to process various
+ * input events such as mouse clicks, mouse movements, and keyboard presses.
+ *
+ * @return A vector of `SDLContext::EventData` containing the events.
*/
std::vector<SDLContext::EventData> get_events();
- Keycode get_key();
- Keycode get_mouse();
+ /**
+ * @brief Converts an SDL key code to the custom Keycode type.
+ *
+ * This method maps an SDL key code to the corresponding `Keycode` enum value,
+ * which is used internally by the system to identify the keys.
+ *
+ * @param sdlKey The SDL key code to convert.
+ * @return The corresponding `Keycode` value.
+ */
Keycode sdl_to_keycode(SDL_Keycode sdlKey);
+
+ /**
+ * @brief Converts an SDL mouse button code to the custom MouseButton type.
+ *
+ * This method maps an SDL mouse button code to the corresponding `MouseButton`
+ * enum value, which is used internally by the system to identify mouse buttons.
+ *
+ * @param sdl_button The SDL mouse button code to convert.
+ * @return The corresponding `MouseButton` value.
+ */
MouseButton sdl_to_mousebutton(Uint8 sdl_button);
private: