diff options
Diffstat (limited to 'mwe/events/include')
-rw-r--r-- | mwe/events/include/event.h | 13 | ||||
-rw-r--r-- | mwe/events/include/iKeyListener.h | 2 | ||||
-rw-r--r-- | mwe/events/include/iMouseListener.h | 26 | ||||
-rw-r--r-- | mwe/events/include/keyListenerTest.h | 12 | ||||
-rw-r--r-- | mwe/events/include/mouseListenerTest.h | 14 |
5 files changed, 37 insertions, 30 deletions
diff --git a/mwe/events/include/event.h b/mwe/events/include/event.h index 8968c6c..65560a1 100644 --- a/mwe/events/include/event.h +++ b/mwe/events/include/event.h @@ -67,15 +67,14 @@ public: class MouseClickEvent : public Event { public: MouseClickEvent(int x, int y, MouseButton button); - + REGISTER_EVENT_TYPE("KeyClickedEvent"); - int getX() const { return x; } - int getY() const { return y; } + std::pair<int, int> getMousePosition() const; MouseButton getButton() const { return button; } private: - int x; - int y; + int mouseX = 0; + int mouseY = 0; MouseButton button; }; // KeyReleasedEvent class @@ -147,9 +146,7 @@ public: REGISTER_EVENT_TYPE(TextSubmitEvent) - std::string getText() const { - return text; - } + std::string getText() const; private: std::string text; diff --git a/mwe/events/include/iKeyListener.h b/mwe/events/include/iKeyListener.h index 87ee1d5..5f39ece 100644 --- a/mwe/events/include/iKeyListener.h +++ b/mwe/events/include/iKeyListener.h @@ -11,6 +11,8 @@ public: protected: void subscribeEvents(int listenerId = 0); void unsubscribeEvents(int listenerId = 0); + void activate(int listenerId = 0) { subscribeEvents(listenerId); } + void deactivate(int listenerId = 0) { unsubscribeEvents(listenerId); } private: EventHandler<KeyPressedEvent> keyPressedHandler; diff --git a/mwe/events/include/iMouseListener.h b/mwe/events/include/iMouseListener.h index 7ae371c..03fd4c3 100644 --- a/mwe/events/include/iMouseListener.h +++ b/mwe/events/include/iMouseListener.h @@ -1,36 +1,18 @@ +#pragma once #include "event.h" #include "eventManager.h" #include "eventHandler.h" class IMouseListener { public: - virtual ~IMouseListener() { - unsubscribeEvents(); - } + virtual ~IMouseListener(); virtual void onMouseClicked(const MouseClickEvent& event) = 0; virtual void onMousePressed(const MousePressedEvent& event) = 0; virtual void onMouseReleased(const MouseReleasedEvent& event) = 0; virtual void onMouseMoved(const MouseMovedEvent& event) = 0; - protected: - void subscribeEvents(int listenerId = 0) { - 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 unsubscribeEvents(int listenerId = 0) { - unsubscribe<MouseClickEvent>(mouseClickHandler, listenerId); - unsubscribe<MousePressedEvent>(mousePressHandler, listenerId); - unsubscribe<MouseReleasedEvent>(mouseReleaseHandler, listenerId); - unsubscribe<MouseMovedEvent>(mouseMoveHandler, listenerId); - } + void subscribeEvents(int listenerId = 0); + void unsubscribeEvents(int listenerId = 0); private: EventHandler<MouseClickEvent> mouseClickHandler; diff --git a/mwe/events/include/keyListenerTest.h b/mwe/events/include/keyListenerTest.h new file mode 100644 index 0000000..5990cd1 --- /dev/null +++ b/mwe/events/include/keyListenerTest.h @@ -0,0 +1,12 @@ +#pragma once +#include "iKeyListener.h" +#include <iostream> + +class KeyListenerTest : public IKeyListener { +public: + KeyListenerTest(int listenerId); + ~KeyListenerTest(); + + void onKeyPressed(const KeyPressedEvent& event) override; + void onKeyReleased(const KeyReleasedEvent& event) override; +}; diff --git a/mwe/events/include/mouseListenerTest.h b/mwe/events/include/mouseListenerTest.h new file mode 100644 index 0000000..dae04f5 --- /dev/null +++ b/mwe/events/include/mouseListenerTest.h @@ -0,0 +1,14 @@ +#pragma once +#include "iMouseListener.h" +#include <iostream> + +class MouseListenerTest : public IMouseListener { +public: + MouseListenerTest(int listenerId); + ~MouseListenerTest(); + + void onMouseClicked(const MouseClickEvent& event) override; + void onMousePressed(const MousePressedEvent& event) override; + void onMouseReleased(const MouseReleasedEvent& event) override; + void onMouseMoved(const MouseMovedEvent& event) override; +}; |