aboutsummaryrefslogtreecommitdiff
path: root/mwe/events/include
diff options
context:
space:
mode:
Diffstat (limited to 'mwe/events/include')
-rw-r--r--mwe/events/include/event.h20
-rw-r--r--mwe/events/include/eventHandler.h4
-rw-r--r--mwe/events/include/gameObject.h14
-rw-r--r--mwe/events/include/iMouseListener.h3
-rw-r--r--mwe/events/include/inputSystem.h16
-rw-r--r--mwe/events/include/loopManager.h7
-rw-r--r--mwe/events/include/uiObject.h17
-rw-r--r--mwe/events/include/uiRenderer.h17
-rw-r--r--mwe/events/include/window.h28
9 files changed, 98 insertions, 28 deletions
diff --git a/mwe/events/include/event.h b/mwe/events/include/event.h
index 65560a1..b1b6867 100644
--- a/mwe/events/include/event.h
+++ b/mwe/events/include/event.h
@@ -7,7 +7,6 @@
#include <variant>
#include "keyCodes.h"
#include "customTypes.h"
-
class UUIDGenerator {
public:
static std::uint32_t getUniqueID() {
@@ -151,3 +150,22 @@ public:
private:
std::string text;
};
+class ShutDownEvent : public Event {
+public:
+ ShutDownEvent() : Event("ShutDownEvent"){};
+
+ REGISTER_EVENT_TYPE(ShutDownEvent)
+
+private:
+};
+// class ButtonClickEvent : public Event {
+// public:
+// ButtonClickEvent(int x,int y,int width,int height);
+
+// REGISTER_EVENT_TYPE(TextSubmitEvent)
+
+// std::string getText() const;
+
+// private:
+// std::string text;
+// };
diff --git a/mwe/events/include/eventHandler.h b/mwe/events/include/eventHandler.h
index 7414801..7d8f20a 100644
--- a/mwe/events/include/eventHandler.h
+++ b/mwe/events/include/eventHandler.h
@@ -1,9 +1,9 @@
#pragma once
-
#include "event.h"
-
#include <functional>
#include <iostream>
+
+
template <typename EventType>
using EventHandler = std::function<void(const EventType & e)>;
diff --git a/mwe/events/include/gameObject.h b/mwe/events/include/gameObject.h
index 70d4517..de5f3fe 100644
--- a/mwe/events/include/gameObject.h
+++ b/mwe/events/include/gameObject.h
@@ -3,14 +3,14 @@
#include <string>
class GameObject {
public:
- GameObject(std::uint32_t id, std::string name, std::string tag, int layer);
+ GameObject(){}
- template <typename... Args>
- void addSpriteComponent(Args &&... args);
- template <typename... Args>
- void addRigidbodyComponent(Args &&... args);
- template <typename... Args>
- void addColiderComponent(Args &&... args);
+ // template <typename... Args>
+ // void addSpriteComponent(Args &&... args);
+ // template <typename... Args>
+ // void addRigidbodyComponent(Args &&... args);
+ // template <typename... Args>
+ // void addColiderComponent(Args &&... args);
std::uint32_t mId;
std::string mName;
diff --git a/mwe/events/include/iMouseListener.h b/mwe/events/include/iMouseListener.h
index 03fd4c3..7d840c1 100644
--- a/mwe/events/include/iMouseListener.h
+++ b/mwe/events/include/iMouseListener.h
@@ -1,7 +1,8 @@
#pragma once
#include "event.h"
-#include "eventManager.h"
#include "eventHandler.h"
+#include "eventManager.h"
+
class IMouseListener {
public:
virtual ~IMouseListener();
diff --git a/mwe/events/include/inputSystem.h b/mwe/events/include/inputSystem.h
new file mode 100644
index 0000000..06db74c
--- /dev/null
+++ b/mwe/events/include/inputSystem.h
@@ -0,0 +1,16 @@
+#pragma once
+#include <vector>
+#include "uiObject.h"
+#include "event.h"
+#include "keyCodes.h"
+#include "eventManager.h"
+class InputSystem {
+public:
+ InputSystem();
+ void registerButton(Button* button);
+ void processInput();
+
+private:
+ std::vector<Button*> buttons;
+ void processMouseClick(int mouseX, int mouseY);
+};
diff --git a/mwe/events/include/loopManager.h b/mwe/events/include/loopManager.h
index baffb94..289ff0f 100644
--- a/mwe/events/include/loopManager.h
+++ b/mwe/events/include/loopManager.h
@@ -6,6 +6,10 @@
#include "eventHandler.h"
#include "eventManager.h"
#include "loopManager.h"
+#include "uiRenderer.h"
+#include "uiObject.h"
+#include "inputSystem.h"
+#include <memory>
class LoopManager {
public:
LoopManager();
@@ -19,6 +23,7 @@ private:
void lateUpdate();
void fixedUpdate();
void render();
+ void onShutdown(const ShutDownEvent& e);
bool gameRunning = false;
WindowManager window;
int timeScale = 1;
@@ -26,4 +31,6 @@ private:
double currentTime;
double t = 0.0;
double dt = 0.01;
+ std::unique_ptr<InputSystem> inputSystem;
+ EventHandler<ShutDownEvent> shutdownHandler;
};
diff --git a/mwe/events/include/uiObject.h b/mwe/events/include/uiObject.h
index 46d32be..720d5c2 100644
--- a/mwe/events/include/uiObject.h
+++ b/mwe/events/include/uiObject.h
@@ -1,8 +1,10 @@
+#pragma once
#include "gameObject.h"
#include <SDL2/SDL.h>
#include <SDL_ttf.h>
#include "event.h"
#include "eventHandler.h"
+#include <functional>
struct Alignment {
enum class Horizontal { LEFT, CENTER, RIGHT };
enum class Vertical { TOP, MIDDLE, BOTTOM };
@@ -21,28 +23,29 @@ struct Alignment {
int marginRight = 0;
};
struct RGBColor{
- int red,
- int green,
- int blue
+ int red;
+ int green;
+ int blue;
};
class UIObject : public GameObject{
public:
UIObject(int width,int height);
- private:
+ virtual ~UIObject() {}
int width;
int height;
+ int x;
+ int y;
};
class Button : public UIObject{
public:
Button(int width,int height);
- EventHandler<KeyPressedEvent> onKeyPressed;
- EventHandler<KeyReleasedEvent> onKeyReleased;
+ RGBColor color;
+ std::function<void()> onClick;
};
class Text : public UIObject{
public:
Text(int width,int height);
- private:
std::string text;
int size;
Alignment alignment;
diff --git a/mwe/events/include/uiRenderer.h b/mwe/events/include/uiRenderer.h
new file mode 100644
index 0000000..286ac1f
--- /dev/null
+++ b/mwe/events/include/uiRenderer.h
@@ -0,0 +1,17 @@
+#pragma once
+#include <SDL2/SDL.h>
+#include <SDL2/SDL_ttf.h>
+#include "uiObject.h"
+
+class UIRenderer {
+public:
+ UIRenderer(SDL_Renderer* renderer);
+ void render(UIObject* uiObject);
+
+private:
+ SDL_Renderer* renderer;
+
+ void renderButton(Button* button);
+ void renderText(Text* text);
+ void renderTextInput(TextInput* textInput);
+};
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 <SDL2/SDL.h>
-#include <iostream>
#include <vector>
+#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<UIObject*> uiObjects;
};