aboutsummaryrefslogtreecommitdiff
path: root/mwe/events/src/event.cpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-11-04 08:28:18 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-11-04 08:28:18 +0100
commit06f65659fc6ffde7cabd2135040cbfbf089e5a24 (patch)
treee3570bea52b87b6919550ee81d17927ccbc11cc5 /mwe/events/src/event.cpp
parent128969619a22dfc17a9ea35335c0d21c6ad0c954 (diff)
parent6aa8fdd04728b6a499f526de727514ae3d0490b4 (diff)
merge `origin/master` into `master`
Diffstat (limited to 'mwe/events/src/event.cpp')
-rw-r--r--mwe/events/src/event.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/mwe/events/src/event.cpp b/mwe/events/src/event.cpp
new file mode 100644
index 0000000..c9201d0
--- /dev/null
+++ b/mwe/events/src/event.cpp
@@ -0,0 +1,52 @@
+#include "event.h"
+#include "keyCodes.h"
+// 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) {
+ eventData[key] = value;
+}
+
+std::variant<int, std::string, float>
+Event::getArgument(const std::string & key) const {
+ return eventData.at(key);
+}
+
+std::string Event::getType() const {
+ return std::get<std::string>(eventData.at("eventType"));
+}
+std::string Event::toString() const { return std::to_string(getEventType()); }
+bool Event::getHandled() const { return isHandled; }
+
+void Event::markHandled() { isHandled = true; }
+
+// KeyPressedEvent class methods
+KeyPressedEvent::KeyPressedEvent(int keycode)
+ : Event("KeyPressedEvent"), key(keycode), repeatCount(0) {}
+
+Keycode KeyPressedEvent::getKeyCode() const { return key; }
+
+int KeyPressedEvent::getRepeatCount() const { return repeatCount; }
+
+// KeyReleasedEvent class methods
+KeyReleasedEvent::KeyReleasedEvent(int keycode)
+ : Event("KeyReleasedEvent"), key(keycode) {}
+
+Keycode KeyReleasedEvent::getKeyCode() const { return key; }
+
+// MousePressedEvent class methods
+MousePressedEvent::MousePressedEvent(int mouseX, int mouseY)
+ : Event("MousePressedEvent"), mouseX(mouseX), mouseY(mouseY) {}
+
+std::pair<int, int> MousePressedEvent::getMousePosition() const {
+ return {mouseX, mouseY};
+}
+
+//Collision event
+CollisionEvent::CollisionEvent(Collision collision)
+ : collisionData(collision), Event("CollisionEvent") {}
+
+Collision CollisionEvent::getCollisionData() const {
+ return this->collisionData;
+}