diff options
Diffstat (limited to 'mwe/events/src')
-rw-r--r-- | mwe/events/src/event.cpp | 8 | ||||
-rw-r--r-- | mwe/events/src/iKeyListener.cpp | 18 | ||||
-rw-r--r-- | mwe/events/src/iMouseListener.cpp | 23 | ||||
-rw-r--r-- | mwe/events/src/uiObject.cpp | 28 |
4 files changed, 77 insertions, 0 deletions
diff --git a/mwe/events/src/event.cpp b/mwe/events/src/event.cpp index 38ff62a..2509088 100644 --- a/mwe/events/src/event.cpp +++ b/mwe/events/src/event.cpp @@ -52,3 +52,11 @@ Collision CollisionEvent::getCollisionData() const { return this->collisionData; } + +TextSubmitEvent::TextSubmitEvent(std::string text) : Event("TextSubmitEvent"){ + +} +std::string TextSubmitEvent::getText() const{ + return this->text; +} + diff --git a/mwe/events/src/iKeyListener.cpp b/mwe/events/src/iKeyListener.cpp new file mode 100644 index 0000000..59cc89a --- /dev/null +++ b/mwe/events/src/iKeyListener.cpp @@ -0,0 +1,18 @@ +#include "iKeyListener.h" + +IKeyListener::~IKeyListener() { + unsubscribeEvents(); +} + +void IKeyListener::subscribeEvents(int listenerId) { + keyPressedHandler = [this](const KeyPressedEvent& event) { this->onKeyPressed(event); }; + keyReleasedHandler = [this](const KeyReleasedEvent& event) { this->onKeyReleased(event); }; + + subscribe<KeyPressedEvent>(keyPressedHandler, listenerId); + subscribe<KeyReleasedEvent>(keyReleasedHandler, listenerId); +} + +void IKeyListener::unsubscribeEvents(int listenerId) { + unsubscribe<KeyPressedEvent>(keyPressedHandler, listenerId); + unsubscribe<KeyReleasedEvent>(keyReleasedHandler, listenerId); +} diff --git a/mwe/events/src/iMouseListener.cpp b/mwe/events/src/iMouseListener.cpp new file mode 100644 index 0000000..3239304 --- /dev/null +++ b/mwe/events/src/iMouseListener.cpp @@ -0,0 +1,23 @@ +#include "iMouseListener.h" +IMouseListener::~IMouseListener() { + unsubscribeEvents(); +} + +void IMouseListener::subscribeEvents(int listenerId) { + mouseClickHandler = [this](const MouseClickEvent& event) { this->onMouseClicked(event); }; + mousePressHandler = [this](const MousePressedEvent& event) { this->onMousePressed(event); }; + mouseReleaseHandler = [this](const MouseReleasedEvent& event) { this->onMouseReleased(event); }; + mouseMoveHandler = [this](const MouseMovedEvent& event) { this->onMouseMoved(event); }; + + subscribe<MouseClickEvent>(mouseClickHandler, listenerId); + subscribe<MousePressedEvent>(mousePressHandler, listenerId); + subscribe<MouseReleasedEvent>(mouseReleaseHandler, listenerId); + subscribe<MouseMovedEvent>(mouseMoveHandler, listenerId); +} + +void IMouseListener::unsubscribeEvents(int listenerId) { + unsubscribe<MouseClickEvent>(mouseClickHandler, listenerId); + unsubscribe<MousePressedEvent>(mousePressHandler, listenerId); + unsubscribe<MouseReleasedEvent>(mouseReleaseHandler, listenerId); + unsubscribe<MouseMovedEvent>(mouseMoveHandler, listenerId); +} diff --git a/mwe/events/src/uiObject.cpp b/mwe/events/src/uiObject.cpp new file mode 100644 index 0000000..b941858 --- /dev/null +++ b/mwe/events/src/uiObject.cpp @@ -0,0 +1,28 @@ +#include "uiObject.h" + +// Constructor for UIObject +UIObject::UIObject(int width, int height) + : width(width), height(height) { + + } + +// Constructor for Button +Button::Button(int width, int height) + : UIObject(width, height) { +} + +Text::Text(int width, int height) + : UIObject(width, height), size(12), font(nullptr), color{255, 255, 255} { // Default size and color + alignment.horizontal = Alignment::Horizontal::CENTER; + alignment.vertical = Alignment::Vertical::MIDDLE; + alignment.mode = Alignment::PositioningMode::RELATIVE; +} + +TextInput::TextInput(int width, int height) + : UIObject(width, height), textBuffer(""), placeholder(""), caretPosition(0), + isActive(false), textColor{255, 255, 255}, backgroundColor{0, 0, 0}, maxLength(100), font(nullptr) { + alignment.horizontal = Alignment::Horizontal::LEFT; + alignment.vertical = Alignment::Vertical::TOP; + alignment.mode = Alignment::PositioningMode::RELATIVE; +} + |