From f2136f836f9b9e9a6a6698f7bc6fba85a27ebebf Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Mon, 28 Oct 2024 11:34:43 +0100 Subject: iKeyListener test and iMouseListener test working --- mwe/events/src/event.cpp | 24 +++++++++++++++++++++--- mwe/events/src/keyListenerTest.cpp | 17 +++++++++++++++++ mwe/events/src/main.cpp | 11 +++++++---- mwe/events/src/mouseListenerTest.cpp | 25 +++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 7 deletions(-) create mode 100644 mwe/events/src/keyListenerTest.cpp create mode 100644 mwe/events/src/mouseListenerTest.cpp (limited to 'mwe/events/src') diff --git a/mwe/events/src/event.cpp b/mwe/events/src/event.cpp index 2509088..fc8eec9 100644 --- a/mwe/events/src/event.cpp +++ b/mwe/events/src/event.cpp @@ -53,10 +53,28 @@ Collision CollisionEvent::getCollisionData() const return this->collisionData; } -TextSubmitEvent::TextSubmitEvent(std::string text) : Event("TextSubmitEvent"){ +TextSubmitEvent::TextSubmitEvent(std::string text) + : text(text), Event("TextSubmitEvent") {} +std::string TextSubmitEvent::getText() const { + return this->text; } -std::string TextSubmitEvent::getText() const{ - return this->text; + +MouseReleasedEvent::MouseReleasedEvent(int x, int y, MouseButton button) : mouseX(x), mouseY(y), button(button),Event("MouseReleased"){ + +} +std::pair MouseReleasedEvent::getMousePosition() const{ + return {mouseX,mouseY}; +} +MouseClickEvent::MouseClickEvent(int x,int y,MouseButton button) : mouseX(x), mouseY(y), button(button),Event("MouseClickEvent"){ + } +MouseMovedEvent::MouseMovedEvent(int x, int y) : mouseX(x), mouseY(y),Event("MouseMovedEvent"){ +} +std::pair MouseClickEvent::getMousePosition() const { + return {mouseX, mouseY}; +} +std::pair MouseMovedEvent::getMousePosition() const { + return {mouseX, mouseY}; +} diff --git a/mwe/events/src/keyListenerTest.cpp b/mwe/events/src/keyListenerTest.cpp new file mode 100644 index 0000000..90b92a5 --- /dev/null +++ b/mwe/events/src/keyListenerTest.cpp @@ -0,0 +1,17 @@ +#include "keyListenerTest.h" + +KeyListenerTest::KeyListenerTest(int listenerId) { + subscribeEvents(listenerId); +} + +KeyListenerTest::~KeyListenerTest() { + unsubscribeEvents(); +} + +void KeyListenerTest::onKeyPressed(const KeyPressedEvent& event) { + std::cout << "Key pressed: " << event.getKeyCode() << std::endl; +} + +void KeyListenerTest::onKeyReleased(const KeyReleasedEvent& event) { + std::cout << "Key released: " << event.getKeyCode() << std::endl; +} diff --git a/mwe/events/src/main.cpp b/mwe/events/src/main.cpp index d056f85..03dff16 100644 --- a/mwe/events/src/main.cpp +++ b/mwe/events/src/main.cpp @@ -6,6 +6,10 @@ #include "loopManager.h" #include "event.h" #include "customTypes.h" +#include "iKeyListener.h" +#include "iMouseListener.h" +#include "keyListenerTest.h" +#include "mouseListenerTest.h" class PlayerDamagedEvent : public Event { public: PlayerDamagedEvent(int damage, int playerID) @@ -46,10 +50,9 @@ void testCollisionEvent() { } int main(int argc, char * args[]) { LoopManager gameLoop; - // Create an event handler for KeyPressedEvent - // EventHandler callback = [](const KeyPressedEvent& e) { - // onKeyPressed(e); - // }; + int testListenerId = 0; + KeyListenerTest keyListener(testListenerId); + MouseListenerTest mouseListener(testListenerId); // custom event class poc subscribe(onPlayerDamaged); triggerEvent(PlayerDamagedEvent(50, 1)); diff --git a/mwe/events/src/mouseListenerTest.cpp b/mwe/events/src/mouseListenerTest.cpp new file mode 100644 index 0000000..4b3aa3e --- /dev/null +++ b/mwe/events/src/mouseListenerTest.cpp @@ -0,0 +1,25 @@ +#include "mouseListenerTest.h" + +MouseListenerTest::MouseListenerTest(int listenerId) { + subscribeEvents(listenerId); +} + +MouseListenerTest::~MouseListenerTest() { + unsubscribeEvents(); +} + +void MouseListenerTest::onMouseClicked(const MouseClickEvent& event) { + std::cout << "Mouse clicked at: (" << event.getMousePosition().first << ", " << event.getMousePosition().second << ")" << std::endl; +} + +void MouseListenerTest::onMousePressed(const MousePressedEvent& event) { + std::cout << "Mouse button pressed at: (" << event.getMousePosition().first << ", " << event.getMousePosition().second << ")" << std::endl; +} + +void MouseListenerTest::onMouseReleased(const MouseReleasedEvent& event) { + std::cout << "Mouse button released at: (" << event.getMousePosition().first << ", " << event.getMousePosition().second << ")" << std::endl; +} + +void MouseListenerTest::onMouseMoved(const MouseMovedEvent& event) { + std::cout << "Mouse moved to: (" << event.getMousePosition().first << ", " << event.getMousePosition().second << ")" << std::endl; +} -- cgit v1.2.3