aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/crepe/api/Event.h10
-rw-r--r--src/crepe/api/KeyCodes.h4
-rw-r--r--src/crepe/api/Script.cpp7
-rw-r--r--src/crepe/api/Script.h10
-rw-r--r--src/crepe/facade/EventData.h55
-rw-r--r--src/crepe/facade/SDLContext.cpp188
-rw-r--r--src/crepe/facade/SDLContext.h80
-rw-r--r--src/crepe/system/InputSystem.cpp51
-rw-r--r--src/crepe/system/InputSystem.h16
-rw-r--r--src/test/InputTest.cpp1
10 files changed, 228 insertions, 194 deletions
diff --git a/src/crepe/api/Event.h b/src/crepe/api/Event.h
index 17ae809..d353a5b 100644
--- a/src/crepe/api/Event.h
+++ b/src/crepe/api/Event.h
@@ -39,7 +39,7 @@ public:
*/
class MousePressEvent : public Event {
public:
- //! mouse position
+ //! mouse position in game units
vec2 mouse_pos = {0, 0};
//! The mouse button that was pressed.
@@ -51,7 +51,7 @@ public:
*/
class MouseClickEvent : public Event {
public:
- //! mouse position
+ //! mouse position in game units
vec2 mouse_pos = {0, 0};
//! The mouse button that was clicked.
@@ -63,7 +63,7 @@ public:
*/
class MouseReleaseEvent : public Event {
public:
- //! mouse position
+ //! mouse position in game units
vec2 mouse_pos = {0, 0};
//! The mouse button that was released.
@@ -75,7 +75,7 @@ public:
*/
class MouseMoveEvent : public Event {
public:
- //! new mouse position
+ //! mouse position in game units
vec2 mouse_pos = {0, 0};
//! The change in mouse position relative to the last position (in pixels).
ivec2 mouse_delta = {0, 0};
@@ -86,7 +86,7 @@ public:
*/
class MouseScrollEvent : public Event {
public:
- //! mouse position when the scroll happened.
+ //! mouse position in game units when the scroll happened.
vec2 mouse_pos = {0, 0};
//! scroll direction (-1 = down, 1 = up)
int scroll_direction = 0;
diff --git a/src/crepe/api/KeyCodes.h b/src/crepe/api/KeyCodes.h
index dc3219a..1b9573a 100644
--- a/src/crepe/api/KeyCodes.h
+++ b/src/crepe/api/KeyCodes.h
@@ -3,6 +3,7 @@
#include <unordered_map>
namespace crepe {
+
//! Enumeration for mouse button inputs, including standard and extended buttons.
enum class MouseButton {
NONE = 0, //!< No mouse button input.
@@ -154,5 +155,6 @@ enum class Keycode {
/// \}
MENU = 348, //!< Menu key.
};
-
+//! Typedef for keyboard state.
+typedef std::unordered_map<Keycode, bool> keyboard_state_t;
} // namespace crepe
diff --git a/src/crepe/api/Script.cpp b/src/crepe/api/Script.cpp
index 753a9e3..7b56f61 100644
--- a/src/crepe/api/Script.cpp
+++ b/src/crepe/api/Script.cpp
@@ -1,7 +1,7 @@
#include <string>
#include "../manager/SceneManager.h"
-
+#include "../facade/SDLContext.h"
#include "Script.h"
using namespace crepe;
@@ -25,3 +25,8 @@ void Script::set_next_scene(const string & name) {
}
SaveManager & Script::get_save_manager() const { return this->mediator->save_manager; }
+
+const keyboard_state_t& Script::get_keyboard_state() const{
+ SDLContext& sdl_context = this->mediator->sdl_context;
+ return sdl_context.get_keyboard_state();
+}
diff --git a/src/crepe/api/Script.h b/src/crepe/api/Script.h
index 668e5d1..4fbf344 100644
--- a/src/crepe/api/Script.h
+++ b/src/crepe/api/Script.h
@@ -6,6 +6,7 @@
#include "../manager/Mediator.h"
#include "../system/CollisionSystem.h"
#include "../types.h"
+#include "../api/KeyCodes.h"
#include "../util/OptionalRef.h"
namespace crepe {
@@ -134,7 +135,14 @@ protected:
//! Retrieve SaveManager reference
SaveManager & get_save_manager() const;
-
+ /**
+ * \brief Utility function to retrieve the keyboard state
+ * \see SDLContext::get_keyboard_state
+ *
+ * \return current keyboard state map with Keycode as key and bool as value(true = pressed, false = not pressed)
+ *
+ */
+ const keyboard_state_t& get_keyboard_state() const;
//! \}
private:
diff --git a/src/crepe/facade/EventData.h b/src/crepe/facade/EventData.h
new file mode 100644
index 0000000..d0ca07f
--- /dev/null
+++ b/src/crepe/facade/EventData.h
@@ -0,0 +1,55 @@
+#pragma once
+#include "../api/KeyCodes.h"
+#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,
+ };
+
+ //! 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 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 7e19ede..bb65e3b 100644
--- a/src/crepe/facade/SDLContext.cpp
+++ b/src/crepe/facade/SDLContext.cpp
@@ -76,13 +76,16 @@ SDLContext::~SDLContext() {
}
Keycode SDLContext::sdl_to_keycode(SDL_Scancode sdl_key) {
- auto it = LOOKUP_TABLE.find(sdl_key);
- if (it != LOOKUP_TABLE.end()) {
- return it->second;
- }
+ if (!LOOKUP_TABLE.contains(sdl_key))
+ return Keycode::NONE;
+
+ return LOOKUP_TABLE.at(sdl_key);
+}
- return Keycode::NONE;
+const keyboard_state_t& SDLContext::get_keyboard_state() const{
+ return this->keyboard_state;
}
+
void SDLContext::update_keyboard_state() {
// Array to hold the key states (true if pressed, false if not)
SDL_PumpEvents();
@@ -273,8 +276,8 @@ ivec2 SDLContext::get_size(const Texture & ctx) {
return size;
}
-std::vector<SDLContext::EventData> SDLContext::get_events() {
- std::vector<SDLContext::EventData> event_list;
+std::vector<EventData> SDLContext::get_events() {
+ std::vector<EventData> event_list;
SDL_Event event;
const CameraAuxiliaryData & cam = this->cam_aux_data;
while (SDL_PollEvent(&event)) {
@@ -283,77 +286,83 @@ std::vector<SDLContext::EventData> SDLContext::get_events() {
mouse_pos.y = (event.button.y - cam.bar_size.y) / cam.render_scale.y;
switch (event.type) {
case SDL_QUIT:
- event_list.push_back({.event_type = SDLContext::EventType::SHUTDOWN});
+ event_list.push_back({.event_type = EventType::SHUTDOWN});
break;
- case SDL_KEYDOWN: {
+ case SDL_KEYDOWN:
this->update_keyboard_state();
- EventData transfer_event;
- transfer_event.event_type = SDLContext::EventType::KEYDOWN;
- transfer_event.data.key_data = KeyData{
- .key = sdl_to_keycode(event.key.keysym.scancode),
- .key_repeat = event.key.repeat != 0,
- };
- event_list.push_back(transfer_event);
+ event_list.push_back(EventData{
+ .event_type = EventType::KEY_DOWN,
+ .data = {
+ .key_data = {
+ .key = this->sdl_to_keycode(event.key.keysym.scancode),
+ .key_repeat = event.key.repeat != 0,
+ },
+ },
+ });
break;
- }
- case SDL_KEYUP: {
+ case SDL_KEYUP:
this->update_keyboard_state();
- EventData transfer_event;
- transfer_event.event_type = SDLContext::EventType::KEYUP;
- transfer_event.data.key_data = KeyData{
- .key = sdl_to_keycode(event.key.keysym.scancode),
- .key_repeat = false,
- };
- event_list.push_back(transfer_event);
+ event_list.push_back(EventData{
+ .event_type = EventType::KEY_UP,
+ .data = {
+ .key_data = {
+ .key = this->sdl_to_keycode(event.key.keysym.scancode),
+ .key_repeat = event.key.repeat != 0,
+ },
+ },
+ });
break;
- }
-
- case SDL_MOUSEBUTTONDOWN: {
- EventData transfer_event;
- transfer_event.event_type = SDLContext::EventType::MOUSEDOWN;
- transfer_event.data.mouse_data = MouseData{
- .mouse_button = sdl_to_mousebutton(event.button.button),
- .mouse_position = mouse_pos,
- };
- event_list.push_back(transfer_event);
+
+ case SDL_MOUSEBUTTONDOWN:
+ event_list.push_back(EventData{
+ .event_type = EventType::MOUSE_DOWN,
+ .data = {
+ .mouse_data = {
+ .mouse_button = this->sdl_to_mousebutton(event.button.button),
+ .mouse_position = mouse_pos,
+ },
+ },
+ });
break;
- }
- case SDL_MOUSEBUTTONUP: {
- EventData transfer_event;
- transfer_event.event_type = SDLContext::EventType::MOUSEUP;
- transfer_event.data.mouse_data = MouseData{
- .mouse_button = sdl_to_mousebutton(event.button.button),
- .mouse_position = mouse_pos,
- };
- event_list.push_back(transfer_event);
+ case SDL_MOUSEBUTTONUP:
+ event_list.push_back(EventData{
+ .event_type = EventType::MOUSE_UP,
+ .data = {
+ .mouse_data = {
+ .mouse_button = this->sdl_to_mousebutton(event.button.button),
+ .mouse_position = mouse_pos,
+ },
+ },
+ });
break;
- }
-
- case SDL_MOUSEMOTION: {
- EventData transfer_event;
- transfer_event.event_type = SDLContext::EventType::MOUSEMOVE;
- transfer_event.data.mouse_data = MouseData{
- .mouse_position = mouse_pos,
- .rel_mouse_move = {event.motion.xrel, event.motion.yrel},
- };
- event_list.push_back(transfer_event);
+
+ case SDL_MOUSEMOTION:
+ event_list.push_back(EventData{
+ .event_type = EventType::MOUSE_MOVE,
+ .data = {
+ .mouse_data = {
+ .mouse_position = mouse_pos,
+ .rel_mouse_move = {event.motion.xrel, event.motion.yrel},
+ },
+ },
+ });
break;
- }
-
- case SDL_MOUSEWHEEL: {
- EventData transfer_event;
- transfer_event.event_type = SDLContext::EventType::MOUSEWHEEL;
- transfer_event.data.mouse_data = MouseData{
- .mouse_position = mouse_pos,
- .scroll_direction = event.wheel.y < 0 ? -1 : 1,
- .scroll_delta = event.wheel.preciseY,
- };
- event_list.push_back(transfer_event);
+
+ case SDL_MOUSEWHEEL:
+ event_list.push_back(EventData{
+ .event_type = EventType::MOUSE_WHEEL,
+ .data = {
+ .mouse_data = {
+ .mouse_position = mouse_pos,
+ .scroll_direction = event.wheel.y < 0 ? -1 : 1,
+ .scroll_delta = event.wheel.preciseY,
+ },
+ },
+ });
break;
- }
case SDL_WINDOWEVENT:
- handle_window_event(event.window, event_list);
+ this->handle_window_event(event.window, event_list);
break;
}
}
@@ -362,38 +371,43 @@ std::vector<SDLContext::EventData> SDLContext::get_events() {
}
void SDLContext::handle_window_event(const SDL_WindowEvent & window_event,
- std::vector<SDLContext::EventData> & event_list) {
+ std::vector<EventData> & event_list) {
switch (window_event.event) {
case SDL_WINDOWEVENT_EXPOSED:
- event_list.push_back(EventData{SDLContext::EventType::WINDOW_EXPOSE});
+ event_list.push_back(EventData{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);
+ case SDL_WINDOWEVENT_RESIZED:
+ event_list.push_back(EventData{
+ .event_type = EventType::WINDOW_RESIZE,
+ .data = {
+ .window_data = {
+ .resize_dimension = {window_event.data1, window_event.data2}
+ },
+ },
+ });
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);
+ case SDL_WINDOWEVENT_MOVED:
+ event_list.push_back(EventData{
+ .event_type = EventType::WINDOW_MOVE,
+ .data = {
+ .window_data = {
+ .move_delta = {window_event.data1, window_event.data2}
+ },
+ },
+ });
break;
- }
+
case SDL_WINDOWEVENT_MINIMIZED:
- event_list.push_back(EventData{SDLContext::EventType::WINDOW_MINIMIZE});
+ event_list.push_back(EventData{EventType::WINDOW_MINIMIZE});
break;
case SDL_WINDOWEVENT_MAXIMIZED:
- event_list.push_back(EventData{SDLContext::EventType::WINDOW_MAXIMIZE});
+ event_list.push_back(EventData{EventType::WINDOW_MAXIMIZE});
break;
case SDL_WINDOWEVENT_FOCUS_GAINED:
- event_list.push_back(EventData{SDLContext::EventType::WINDOW_FOCUS_GAIN});
+ event_list.push_back(EventData{EventType::WINDOW_FOCUS_GAIN});
break;
case SDL_WINDOWEVENT_FOCUS_LOST:
- event_list.push_back(EventData{SDLContext::EventType::WINDOW_FOCUS_LOST});
+ event_list.push_back(EventData{EventType::WINDOW_FOCUS_LOST});
break;
}
}
diff --git a/src/crepe/facade/SDLContext.h b/src/crepe/facade/SDLContext.h
index 7ccefeb..34a4a09 100644
--- a/src/crepe/facade/SDLContext.h
+++ b/src/crepe/facade/SDLContext.h
@@ -17,11 +17,11 @@
#include "api/KeyCodes.h"
#include "api/Sprite.h"
#include "api/Transform.h"
+#include "../types.h"
-#include "types.h"
+#include "EventData.h"
namespace crepe {
-
class Texture;
class Mediator;
@@ -71,61 +71,7 @@ public:
};
public:
- //! EventType enum for passing eventType
- enum EventType {
- NONE = 0,
- MOUSEDOWN,
- MOUSEUP,
- MOUSEMOVE,
- MOUSEWHEEL,
- KEYUP,
- KEYDOWN,
- SHUTDOWN,
- WINDOW_MINIMIZE,
- WINDOW_MAXIMIZE,
- WINDOW_FOCUS_GAIN,
- WINDOW_FOCUS_LOST,
- WINDOW_MOVE,
- WINDOW_RESIZE,
- WINDOW_EXPOSE,
- };
- struct KeyData {
- Keycode key = Keycode::NONE;
- bool key_repeat = false;
- };
- 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 WindowData {
- ivec2 move_delta;
- ivec2 resize_dimension;
- };
- //! EventData struct for passing event data from facade
- struct EventData {
- SDLContext::EventType event_type = SDLContext::EventType::NONE;
-
- union EventDataUnion {
- KeyData key_data;
- MouseData mouse_data;
- WindowData window_data;
-
- EventDataUnion() {}
- ~EventDataUnion() {}
- } data;
- };
- /**
- * \brief Retrieves the current state of the keyboard.
- *
- * This method updates the state of all keys on the keyboard. Each element of the unordered map corresponds to a
- * specific key defined in the `Keycode` enum, and the value indicates whether
- * the key is currently pressed (true) or not pressed (false).
- *
- */
- void update_keyboard_state();
+
/**
* \brief Gets the singleton instance of SDLContext.
* \return Reference to the SDLContext instance.
@@ -161,7 +107,7 @@ public:
*
* \return Events that occurred since last call to `get_events()`
*/
- std::vector<SDLContext::EventData> get_events();
+ std::vector<EventData> get_events();
/**
* \brief Fills event_list with triggered window events
*
@@ -169,7 +115,7 @@ public:
*
*/
void handle_window_event(const SDL_WindowEvent & window_event,
- std::vector<SDLContext::EventData> & event_list);
+ std::vector<EventData> & event_list);
/**
* \brief Converts an SDL scan code to the custom Keycode type.
*
@@ -191,7 +137,8 @@ public:
* \return The corresponding `MouseButton` value or `MouseButton::NONE` if the key is unrecognized
*/
MouseButton sdl_to_mousebutton(Uint8 sdl_button);
-
+ const keyboard_state_t& get_keyboard_state() const;
+
public:
/**
* \brief Gets the current SDL ticks since the program started.
@@ -288,7 +235,18 @@ private:
CameraAuxiliaryData cam_aux_data;
private:
- std::unordered_map<Keycode, bool> keyboard_state;
+ /**
+ * \brief Retrieves the current state of the keyboard.
+ *
+ * This method updates the state of all keys on the keyboard. Each element of the unordered map corresponds to a
+ * specific key defined in the `Keycode` enum, and the value indicates whether
+ * the key is currently pressed (true) or not pressed (false).
+ *
+ */
+ void update_keyboard_state();
+ //! variable to store the state of each key (true = pressed, false = not pressed)
+ keyboard_state_t keyboard_state;
+ //! lookup table for converting SDL_SCANCODES to Keycodes
const std::unordered_map<SDL_Scancode, Keycode> LOOKUP_TABLE
= {{SDL_SCANCODE_SPACE, Keycode::SPACE},
{SDL_SCANCODE_APOSTROPHE, Keycode::APOSTROPHE},
diff --git a/src/crepe/system/InputSystem.cpp b/src/crepe/system/InputSystem.cpp
index 8de700b..1427adf 100644
--- a/src/crepe/system/InputSystem.cpp
+++ b/src/crepe/system/InputSystem.cpp
@@ -1,7 +1,7 @@
#include "../api/Button.h"
#include "../manager/ComponentManager.h"
#include "../manager/EventManager.h"
-#include "facade/SDLContext.h"
+#include "../facade/SDLContext.h"
#include "util/Log.h"
#include "InputSystem.h"
@@ -12,7 +12,7 @@ void InputSystem::update() {
ComponentManager & mgr = this->mediator.component_manager;
SDLContext & context = this->mediator.sdl_context;
- std::vector<SDLContext::EventData> event_list = context.get_events();
+ std::vector<EventData> event_list = context.get_events();
RefVector<Button> buttons = mgr.get_components_by_type<Button>();
RefVector<Camera> cameras = mgr.get_components_by_type<Camera>();
OptionalRef<Camera> curr_cam_ref;
@@ -33,9 +33,12 @@ void InputSystem::update() {
vec2 camera_origin = cam_transform.position + current_cam.data.postion_offset
- (current_cam.viewport_size / 2);
- for (const SDLContext::EventData & event : event_list) {
+ for (const EventData & event : event_list) {
// Only calculate mouse coordinates for relevant events
- if (this->is_mouse_event(event.event_type)) {
+ if (event.event_type == EventType::MOUSE_DOWN
+ || event.event_type == EventType::MOUSE_UP
+ || event.event_type == EventType::MOUSE_MOVE
+ || event.event_type == EventType::MOUSE_WHEEL) {
this->handle_mouse_event(event, camera_origin, current_cam);
} else {
@@ -44,7 +47,7 @@ void InputSystem::update() {
}
}
-void InputSystem::handle_mouse_event(const SDLContext::EventData & event,
+void InputSystem::handle_mouse_event(const EventData & event,
const vec2 & camera_origin, const Camera & current_cam) {
EventManager & event_mgr = this->mediator.event_manager;
vec2 adjusted_mouse;
@@ -59,7 +62,7 @@ void InputSystem::handle_mouse_event(const SDLContext::EventData & event,
// Handle mouse-specific events
switch (event.event_type) {
- case SDLContext::EventType::MOUSEDOWN:
+ case EventType::MOUSE_DOWN:
event_mgr.queue_event<MousePressEvent>({
.mouse_pos = adjusted_mouse,
.button = event.data.mouse_data.mouse_button,
@@ -68,7 +71,7 @@ void InputSystem::handle_mouse_event(const SDLContext::EventData & event,
this->last_mouse_button = event.data.mouse_data.mouse_button;
break;
- case SDLContext::EventType::MOUSEUP: {
+ case EventType::MOUSE_UP: {
event_mgr.queue_event<MouseReleaseEvent>({
.mouse_pos = adjusted_mouse,
.button = event.data.mouse_data.mouse_button,
@@ -87,7 +90,7 @@ void InputSystem::handle_mouse_event(const SDLContext::EventData & event,
break;
}
- case SDLContext::EventType::MOUSEMOVE:
+ case EventType::MOUSE_MOVE:
event_mgr.queue_event<MouseMoveEvent>({
.mouse_pos = adjusted_mouse,
.mouse_delta = event.data.mouse_data.rel_mouse_move,
@@ -95,7 +98,7 @@ void InputSystem::handle_mouse_event(const SDLContext::EventData & event,
this->handle_move(event, adjusted_mouse);
break;
- case SDLContext::EventType::MOUSEWHEEL:
+ case EventType::MOUSE_WHEEL:
event_mgr.queue_event<MouseScrollEvent>({
.mouse_pos = adjusted_mouse,
.scroll_direction = event.data.mouse_data.scroll_direction,
@@ -108,41 +111,41 @@ void InputSystem::handle_mouse_event(const SDLContext::EventData & event,
}
}
-void InputSystem::handle_non_mouse_event(const SDLContext::EventData & event) {
+void InputSystem::handle_non_mouse_event(const EventData & event) {
EventManager & event_mgr = this->mediator.event_manager;
switch (event.event_type) {
- case SDLContext::EventType::KEYDOWN:
+ case EventType::KEY_DOWN:
event_mgr.queue_event<KeyPressEvent>(
{.repeat = event.data.key_data.key_repeat, .key = event.data.key_data.key});
break;
- case SDLContext::EventType::KEYUP:
+ case EventType::KEY_UP:
event_mgr.queue_event<KeyReleaseEvent>({.key = event.data.key_data.key});
break;
- case SDLContext::EventType::SHUTDOWN:
+ case EventType::SHUTDOWN:
event_mgr.queue_event<ShutDownEvent>({});
break;
- case SDLContext::EventType::WINDOW_EXPOSE:
+ case EventType::WINDOW_EXPOSE:
event_mgr.queue_event<WindowExposeEvent>({});
break;
- case SDLContext::EventType::WINDOW_RESIZE:
+ case EventType::WINDOW_RESIZE:
event_mgr.queue_event<WindowResizeEvent>(
WindowResizeEvent{.dimensions = event.data.window_data.resize_dimension});
break;
- case SDLContext::EventType::WINDOW_MOVE:
+ case EventType::WINDOW_MOVE:
event_mgr.queue_event<WindowMoveEvent>(
{.delta_move = event.data.window_data.move_delta});
break;
- case SDLContext::EventType::WINDOW_MINIMIZE:
+ case EventType::WINDOW_MINIMIZE:
event_mgr.queue_event<WindowMinimizeEvent>({});
break;
- case SDLContext::EventType::WINDOW_MAXIMIZE:
+ case EventType::WINDOW_MAXIMIZE:
event_mgr.queue_event<WindowMaximizeEvent>({});
break;
- case SDLContext::EventType::WINDOW_FOCUS_GAIN:
+ case EventType::WINDOW_FOCUS_GAIN:
event_mgr.queue_event<WindowFocusGainEvent>({});
break;
- case SDLContext::EventType::WINDOW_FOCUS_LOST:
+ case EventType::WINDOW_FOCUS_LOST:
event_mgr.queue_event<WindowFocusLostEvent>({});
break;
default:
@@ -150,14 +153,8 @@ void InputSystem::handle_non_mouse_event(const SDLContext::EventData & event) {
}
}
-bool InputSystem::is_mouse_event(SDLContext::EventType event_type) {
- return (event_type == SDLContext::EventType::MOUSEDOWN
- || event_type == SDLContext::EventType::MOUSEUP
- || event_type == SDLContext::EventType::MOUSEMOVE
- || event_type == SDLContext::EventType::MOUSEWHEEL);
-}
-void InputSystem::handle_move(const SDLContext::EventData & event_data,
+void InputSystem::handle_move(const EventData & event_data,
const vec2 & mouse_pos) {
ComponentManager & mgr = this->mediator.component_manager;
diff --git a/src/crepe/system/InputSystem.h b/src/crepe/system/InputSystem.h
index 63dfae5..eefd9fe 100644
--- a/src/crepe/system/InputSystem.h
+++ b/src/crepe/system/InputSystem.h
@@ -1,7 +1,8 @@
#pragma once
#include "../api/Config.h"
-#include "../facade/SDLContext.h"
+#include "../facade/EventData.h"
+
#include "../types.h"
#include "../util/OptionalRef.h"
@@ -12,7 +13,6 @@ namespace crepe {
class Camera;
class Button;
class Transform;
-
/**
* \brief Handles the processing of input events created by SDLContext
*
@@ -38,12 +38,6 @@ private:
//! Stores the last mouse button pressed.
MouseButton last_mouse_button = MouseButton::NONE;
/**
- * \brief Determines whether the given event type is a mouse event.
- * \param event_type The event type to check.
- * \return True if the event type corresponds to a mouse event, false otherwise.
- */
- bool is_mouse_event(SDLContext::EventType event_type);
- /**
* \brief Handles mouse-related events.
* \param event The event data for the mouse event.
* \param camera_origin The origin position of the camera in world space.
@@ -52,7 +46,7 @@ private:
* This method processes mouse events, adjusts the mouse position to world coordinates,
* and triggers the appropriate mouse-specific event handling logic.
*/
- void handle_mouse_event(const SDLContext::EventData & event, const vec2 & camera_origin,
+ void handle_mouse_event(const EventData & event, const vec2 & camera_origin,
const Camera & current_cam);
/**
* \brief Handles non-mouse-related events.
@@ -61,7 +55,7 @@ private:
* This method processes events that do not involve the mouse, such as keyboard events,
* window events, and shutdown events, and triggers the corresponding event actions.
*/
- void handle_non_mouse_event(const SDLContext::EventData & event);
+ void handle_non_mouse_event(const EventData & event);
/**
* \brief Handles the mouse click event.
* \param mouse_button The mouse button involved in the click.
@@ -80,7 +74,7 @@ private:
*
* This method processes the mouse movement event and updates the button hover state.
*/
- void handle_move(const SDLContext::EventData & event_data, const vec2 & mouse_pos);
+ void handle_move(const EventData & event_data, const vec2 & mouse_pos);
/**
* \brief Checks if the mouse position is inside the bounds of the button.
diff --git a/src/test/InputTest.cpp b/src/test/InputTest.cpp
index 09163a6..a707444 100644
--- a/src/test/InputTest.cpp
+++ b/src/test/InputTest.cpp
@@ -13,6 +13,7 @@
#include <crepe/api/Camera.h>
#include <crepe/api/GameObject.h>
#include <crepe/api/Metadata.h>
+#include <crepe/facade/SDLContext.h>
#include <crepe/api/Transform.h>
#include <crepe/api/Vector2.h>
#include <gmock/gmock.h>