diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-24 10:53:02 +0200 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-24 10:53:02 +0200 |
commit | a8a7ff90dfd626ea76dd9e9fe00c7854a7b9f31f (patch) | |
tree | 2724ddce9d181770e7ca745900af76ed64194451 /mwe/events/src/event.cpp | |
parent | 39054829fa69bcfa2b468015dc3852a2f8deac9f (diff) | |
parent | b5e83d076f356c6d01b7bbc1f033db4850356c0d (diff) |
Merge branch 'wouter/events-poc' of github.com:lonkaars/crepe
Diffstat (limited to 'mwe/events/src/event.cpp')
-rw-r--r-- | mwe/events/src/event.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/mwe/events/src/event.cpp b/mwe/events/src/event.cpp new file mode 100644 index 0000000..fecae76 --- /dev/null +++ b/mwe/events/src/event.cpp @@ -0,0 +1,56 @@ +#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}; +} |