From 5e833bba513d97c39f4e0d26b45a9095c32812a6 Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Mon, 28 Oct 2024 17:58:53 +0100 Subject: button working --- mwe/events/include/window.h | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'mwe/events/include/window.h') diff --git a/mwe/events/include/window.h b/mwe/events/include/window.h index 9020b1a..3c34d4c 100644 --- a/mwe/events/include/window.h +++ b/mwe/events/include/window.h @@ -1,19 +1,27 @@ #pragma once #include -#include #include +#include "uiObject.h" +#include "uiRenderer.h" + class WindowManager { public: - WindowManager(); - virtual ~WindowManager(); - bool initWindow(); - void destroyWindow(); + WindowManager(); + virtual ~WindowManager(); + + bool initWindow(); + void destroyWindow(); + SDL_Renderer* getRenderer(); - SDL_Renderer * getRenderer(); + void addUIObject(UIObject* uiObject); + void renderUIObjects(); private: - const int SCREEN_WIDTH = 800; - const int SCREEN_HEIGHT = 600; - SDL_Window * window = NULL; - SDL_Renderer * renderer = NULL; + const int SCREEN_WIDTH = 800; + const int SCREEN_HEIGHT = 600; + SDL_Window* window = nullptr; + SDL_Renderer* renderer = nullptr; + + UIRenderer* uiRenderer; + std::vector uiObjects; }; -- cgit v1.2.3 From 2585dc3cab48ccad0cfa0c63354662d656c86c46 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Sun, 3 Nov 2024 13:34:27 +0100 Subject: `make format` --- mwe/audio/miniaudio/main.cpp | 6 +- mwe/events/include/event.h | 26 ++--- mwe/events/include/eventHandler.h | 1 - mwe/events/include/gameObject.h | 2 +- mwe/events/include/iKeyListener.h | 19 ++-- mwe/events/include/iMouseListener.h | 23 ++--- mwe/events/include/inputSystem.h | 27 +++--- mwe/events/include/keyCodes.h | 16 ++-- mwe/events/include/keyListenerTest.h | 8 +- mwe/events/include/loopManager.h | 6 +- mwe/events/include/mouseListenerTest.h | 12 +-- mwe/events/include/uiObject.h | 74 +++++++------- mwe/events/include/uiRenderer.h | 18 ++-- mwe/events/include/window.h | 30 +++--- mwe/events/src/event.cpp | 29 +++--- mwe/events/src/iKeyListener.cpp | 19 ++-- mwe/events/src/iMouseListener.cpp | 35 ++++--- mwe/events/src/inputSystem.cpp | 162 +++++++++++++++---------------- mwe/events/src/keyListenerTest.cpp | 14 ++- mwe/events/src/loopManager.cpp | 22 ++--- mwe/events/src/main.cpp | 13 +-- mwe/events/src/mouseListenerTest.cpp | 26 ++--- mwe/events/src/uiObject.cpp | 30 +++--- mwe/events/src/uiRenderer.cpp | 170 +++++++++++++++++---------------- mwe/events/src/window.cpp | 72 +++++++------- mwe/gameloop/include/loopManager.h | 2 +- mwe/gameloop/src/loopManager.cpp | 9 +- src/crepe/api/Transform.cpp | 3 +- src/example/audio_internal.cpp | 6 +- src/example/log.cpp | 4 +- src/example/script.cpp | 12 ++- 31 files changed, 435 insertions(+), 461 deletions(-) (limited to 'mwe/events/include/window.h') diff --git a/mwe/audio/miniaudio/main.cpp b/mwe/audio/miniaudio/main.cpp index bf31898..5c4f667 100644 --- a/mwe/audio/miniaudio/main.cpp +++ b/mwe/audio/miniaudio/main.cpp @@ -33,12 +33,10 @@ int main() { ma_sound_start(&sfx[2]); ma_sound_start(&bgm); // this actually resumes now this_thread::sleep_for(500ms); - for (unsigned i = 0; i < 3; i++) - ma_sound_seek_to_pcm_frame(&sfx[i], 0); + for (unsigned i = 0; i < 3; i++) ma_sound_seek_to_pcm_frame(&sfx[i], 0); // 5. play all samples simultaniously - for (unsigned i = 0; i < 3; i++) - ma_sound_start(&sfx[i]); + for (unsigned i = 0; i < 3; i++) ma_sound_start(&sfx[i]); this_thread::sleep_for(1000ms); ma_engine_uninit(&engine); diff --git a/mwe/events/include/event.h b/mwe/events/include/event.h index 62d8974..16c75bf 100644 --- a/mwe/events/include/event.h +++ b/mwe/events/include/event.h @@ -6,8 +6,6 @@ #include #include #include -#include "keyCodes.h" -#include "customTypes.h" class UUIDGenerator { public: static std::uint32_t getUniqueID() { @@ -66,16 +64,16 @@ public: }; class MouseClickEvent : public Event { public: - MouseClickEvent(int x, int y, MouseButton button); - + MouseClickEvent(int x, int y, MouseButton button); + REGISTER_EVENT_TYPE("KeyClickedEvent"); std::pair getMousePosition() const; - MouseButton getButton() const { return button; } + MouseButton getButton() const { return button; } private: - int mouseX = 0; + int mouseX = 0; int mouseY = 0; - MouseButton button; + MouseButton button; }; // KeyReleasedEvent class class KeyReleasedEvent : public Event { @@ -112,6 +110,7 @@ public: std::pair getMousePosition() const; MouseButton getMouseButton() const; + private: int mouseX = 0; int mouseY = 0; @@ -124,6 +123,7 @@ public: REGISTER_EVENT_TYPE(MouseMovedEvent) std::pair getMousePosition() const; + private: int mouseX = 0; int mouseY = 0; @@ -141,20 +141,20 @@ private: }; class TextSubmitEvent : public Event { public: - TextSubmitEvent(std::string submittedText); + TextSubmitEvent(std::string submittedText); - REGISTER_EVENT_TYPE(TextSubmitEvent) + REGISTER_EVENT_TYPE(TextSubmitEvent) - std::string getText() const; + std::string getText() const; private: - std::string text; + std::string text; }; class ShutDownEvent : public Event { public: - ShutDownEvent() : Event("ShutDownEvent"){}; + ShutDownEvent() : Event("ShutDownEvent") {}; - REGISTER_EVENT_TYPE(ShutDownEvent) + REGISTER_EVENT_TYPE(ShutDownEvent) private: }; diff --git a/mwe/events/include/eventHandler.h b/mwe/events/include/eventHandler.h index 7d8f20a..aa8f63b 100644 --- a/mwe/events/include/eventHandler.h +++ b/mwe/events/include/eventHandler.h @@ -3,7 +3,6 @@ #include #include - template using EventHandler = std::function; diff --git a/mwe/events/include/gameObject.h b/mwe/events/include/gameObject.h index de5f3fe..48e239b 100644 --- a/mwe/events/include/gameObject.h +++ b/mwe/events/include/gameObject.h @@ -3,7 +3,7 @@ #include class GameObject { public: - GameObject(){} + GameObject() {} // template // void addSpriteComponent(Args &&... args); diff --git a/mwe/events/include/iKeyListener.h b/mwe/events/include/iKeyListener.h index 5f39ece..5fee2eb 100644 --- a/mwe/events/include/iKeyListener.h +++ b/mwe/events/include/iKeyListener.h @@ -1,21 +1,20 @@ #pragma once #include "event.h" -#include "eventManager.h" #include "eventHandler.h" +#include "eventManager.h" class IKeyListener { public: - virtual ~IKeyListener(); - virtual void onKeyPressed(const KeyPressedEvent& event) = 0; - virtual void onKeyReleased(const KeyReleasedEvent& event) = 0; + virtual ~IKeyListener(); + virtual void onKeyPressed(const KeyPressedEvent & event) = 0; + virtual void onKeyReleased(const KeyReleasedEvent & event) = 0; protected: - void subscribeEvents(int listenerId = 0); - void unsubscribeEvents(int listenerId = 0); + void subscribeEvents(int listenerId = 0); + void unsubscribeEvents(int listenerId = 0); void activate(int listenerId = 0) { subscribeEvents(listenerId); } - void deactivate(int listenerId = 0) { unsubscribeEvents(listenerId); } + void deactivate(int listenerId = 0) { unsubscribeEvents(listenerId); } private: - EventHandler keyPressedHandler; - EventHandler keyReleasedHandler; + EventHandler keyPressedHandler; + EventHandler keyReleasedHandler; }; - diff --git a/mwe/events/include/iMouseListener.h b/mwe/events/include/iMouseListener.h index 7d840c1..5b1181c 100644 --- a/mwe/events/include/iMouseListener.h +++ b/mwe/events/include/iMouseListener.h @@ -5,19 +5,20 @@ class IMouseListener { public: - virtual ~IMouseListener(); + 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; - 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); - void unsubscribeEvents(int listenerId = 0); + void subscribeEvents(int listenerId = 0); + void unsubscribeEvents(int listenerId = 0); private: - EventHandler mouseClickHandler; - EventHandler mousePressHandler; - EventHandler mouseReleaseHandler; - EventHandler mouseMoveHandler; + EventHandler mouseClickHandler; + EventHandler mousePressHandler; + EventHandler mouseReleaseHandler; + EventHandler mouseMoveHandler; }; diff --git a/mwe/events/include/inputSystem.h b/mwe/events/include/inputSystem.h index c20562d..3e53b7c 100644 --- a/mwe/events/include/inputSystem.h +++ b/mwe/events/include/inputSystem.h @@ -1,24 +1,23 @@ #pragma once -#include -#include "uiObject.h" #include "event.h" -#include "keyCodes.h" #include "eventManager.h" +#include "keyCodes.h" +#include "uiObject.h" +#include class InputSystem { public: - InputSystem(); - void registerButton(Button* button); - void registerText(Text* label); - void registerTextInput(TextInput* input); - void processInput(); + InputSystem(); + void registerButton(Button * button); + void registerText(Text * label); + void registerTextInput(TextInput * input); + void processInput(); private: - std::vector buttons; - std::vector textInputs; - std::vector texts; - void processMouseClick(int mouseX, int mouseY); + std::vector