aboutsummaryrefslogtreecommitdiff
path: root/mwe/events
diff options
context:
space:
mode:
Diffstat (limited to 'mwe/events')
-rw-r--r--mwe/events/include/event.h4
-rw-r--r--mwe/events/include/eventHandler.h7
-rw-r--r--mwe/events/include/eventManager.h25
-rw-r--r--mwe/events/src/event.cpp5
-rw-r--r--mwe/events/src/eventManager.cpp5
-rw-r--r--mwe/events/src/loopManager.cpp6
-rw-r--r--mwe/events/src/uiObject.cpp6
-rw-r--r--mwe/events/src/window.cpp6
8 files changed, 38 insertions, 26 deletions
diff --git a/mwe/events/include/event.h b/mwe/events/include/event.h
index ee1bf52..6df98ee 100644
--- a/mwe/events/include/event.h
+++ b/mwe/events/include/event.h
@@ -27,8 +27,8 @@ public:
virtual ~Event() = default;
virtual std::uint32_t getEventType() const = 0;
virtual std::string toString() const;
- void addArgument(const std::string & key,
- const std::variant<int, std::string, float> & value);
+ void
+ addArgument(const std::string & key, const std::variant<int, std::string, float> & value);
std::variant<int, std::string, float> getArgument(const std::string & key) const;
diff --git a/mwe/events/include/eventHandler.h b/mwe/events/include/eventHandler.h
index 3a83b15..8598cee 100644
--- a/mwe/events/include/eventHandler.h
+++ b/mwe/events/include/eventHandler.h
@@ -22,8 +22,9 @@ private:
template <typename EventType>
class EventHandlerWrapper : public IEventHandlerWrapper {
public:
- explicit EventHandlerWrapper(const EventHandler<EventType> & handler,
- const bool destroyOnSuccess = false)
+ explicit EventHandlerWrapper(
+ const EventHandler<EventType> & handler, const bool destroyOnSuccess = false
+ )
: m_handler(handler),
m_handlerType(m_handler.target_type().name()),
m_destroyOnSuccess(destroyOnSuccess) {
@@ -42,5 +43,5 @@ private:
EventHandler<EventType> m_handler;
const std::string m_handlerType;
- bool m_destroyOnSuccess{false};
+ bool m_destroyOnSuccess {false};
};
diff --git a/mwe/events/include/eventManager.h b/mwe/events/include/eventManager.h
index 30e927f..43906e8 100644
--- a/mwe/events/include/eventManager.h
+++ b/mwe/events/include/eventManager.h
@@ -18,8 +18,8 @@ public:
}
void shutdown();
- void subscribe(int eventType, std::unique_ptr<IEventHandlerWrapper> && handler,
- int eventId);
+ void
+ subscribe(int eventType, std::unique_ptr<IEventHandlerWrapper> && handler, int eventId);
void unsubscribe(int eventType, const std::string & handlerName, int eventId);
void triggerEvent(const Event & event_, int eventId);
void queueEvent(std::unique_ptr<Event> && event_, int eventId);
@@ -35,19 +35,23 @@ private:
};
template <typename EventType>
-inline void subscribe(const EventHandler<EventType> & callback, int eventId = 0,
- const bool unsubscribeOnSuccess = false) {
+inline void subscribe(
+ const EventHandler<EventType> & callback, int eventId = 0,
+ const bool unsubscribeOnSuccess = false
+) {
std::unique_ptr<IEventHandlerWrapper> handler
= std::make_unique<EventHandlerWrapper<EventType>>(callback, unsubscribeOnSuccess);
- EventManager::getInstance().subscribe(EventType::getStaticEventType(), std::move(handler),
- eventId);
+ EventManager::getInstance().subscribe(
+ EventType::getStaticEventType(), std::move(handler), eventId
+ );
}
template <typename EventType>
inline void unsubscribe(const EventHandler<EventType> & callback, int eventId = 0) {
const std::string handlerName = callback.target_type().name();
- EventManager::getInstance().unsubscribe(EventType::getStaticEventType(), handlerName,
- eventId);
+ EventManager::getInstance().unsubscribe(
+ EventType::getStaticEventType(), handlerName, eventId
+ );
}
inline void triggerEvent(const Event & triggeredEvent, int eventId = 0) {
@@ -55,6 +59,7 @@ inline void triggerEvent(const Event & triggeredEvent, int eventId = 0) {
}
inline void queueEvent(std::unique_ptr<Event> && queuedEvent, int eventId = 0) {
- EventManager::getInstance().queueEvent(std::forward<std::unique_ptr<Event>>(queuedEvent),
- eventId);
+ EventManager::getInstance().queueEvent(
+ std::forward<std::unique_ptr<Event>>(queuedEvent), eventId
+ );
}
diff --git a/mwe/events/src/event.cpp b/mwe/events/src/event.cpp
index 0040c73..5177199 100644
--- a/mwe/events/src/event.cpp
+++ b/mwe/events/src/event.cpp
@@ -3,8 +3,9 @@
// Event class methods
Event::Event(std::string eventType) { eventData["eventType"] = eventType; }
-void Event::addArgument(const std::string & key,
- const std::variant<int, std::string, float> & value) {
+void Event::addArgument(
+ const std::string & key, const std::variant<int, std::string, float> & value
+) {
eventData[key] = value;
}
diff --git a/mwe/events/src/eventManager.cpp b/mwe/events/src/eventManager.cpp
index 9e7d880..b77a0a3 100644
--- a/mwe/events/src/eventManager.cpp
+++ b/mwe/events/src/eventManager.cpp
@@ -2,8 +2,9 @@
void EventManager::shutdown() { subscribers.clear(); }
-void EventManager::subscribe(int eventType, std::unique_ptr<IEventHandlerWrapper> && handler,
- int eventId) {
+void EventManager::subscribe(
+ int eventType, std::unique_ptr<IEventHandlerWrapper> && handler, int eventId
+) {
if (eventId) {
std::unordered_map<
int, std::unordered_map<int, std::vector<std::unique_ptr<IEventHandlerWrapper>>>>::
diff --git a/mwe/events/src/loopManager.cpp b/mwe/events/src/loopManager.cpp
index c58a5e7..7be10df 100644
--- a/mwe/events/src/loopManager.cpp
+++ b/mwe/events/src/loopManager.cpp
@@ -51,8 +51,10 @@ void onKey(const KeyPressedEvent & e) {
std::cout << "keycode pressed: " << keyCode << std::endl;
}
void onMouse(const MousePressedEvent & e) {
- fprintf(stderr, "mouse Position X: %d Y: %d\n", e.getMousePosition().first,
- e.getMousePosition().second);
+ fprintf(
+ stderr, "mouse Position X: %d Y: %d\n", e.getMousePosition().first,
+ e.getMousePosition().second
+ );
}
void LoopManager::setup() {
gameRunning = window.initWindow();
diff --git a/mwe/events/src/uiObject.cpp b/mwe/events/src/uiObject.cpp
index 947d1a2..6b5b326 100644
--- a/mwe/events/src/uiObject.cpp
+++ b/mwe/events/src/uiObject.cpp
@@ -10,7 +10,7 @@ Text::Text(int width, int height)
: UIObject(width, height),
size(12),
font(nullptr),
- color{255, 255, 255} { // Default size and color
+ color {255, 255, 255} { // Default size and color
alignment.horizontal = Alignment::Horizontal::CENTER;
alignment.vertical = Alignment::Vertical::MIDDLE;
alignment.mode = Alignment::PositioningMode::RELATIVE;
@@ -21,8 +21,8 @@ TextInput::TextInput(int width, int height)
textBuffer(""),
placeholder(""),
isActive(false),
- textColor{255, 255, 255},
- backgroundColor{0, 0, 0},
+ textColor {255, 255, 255},
+ backgroundColor {0, 0, 0},
maxLength(100),
font(nullptr) {
alignment.horizontal = Alignment::Horizontal::LEFT;
diff --git a/mwe/events/src/window.cpp b/mwe/events/src/window.cpp
index af2b627..5cdd425 100644
--- a/mwe/events/src/window.cpp
+++ b/mwe/events/src/window.cpp
@@ -11,8 +11,10 @@ bool WindowManager::initWindow() {
return false;
}
- window = SDL_CreateWindow("SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
- SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
+ window = SDL_CreateWindow(
+ "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH,
+ SCREEN_HEIGHT, SDL_WINDOW_SHOWN
+ );
if (!window) {
std::cerr << "Error creating SDL Window.\n";
return false;