aboutsummaryrefslogtreecommitdiff
path: root/mwe/events/include
diff options
context:
space:
mode:
Diffstat (limited to 'mwe/events/include')
-rw-r--r--mwe/events/include/event.h26
-rw-r--r--mwe/events/include/eventHandler.h1
-rw-r--r--mwe/events/include/gameObject.h2
-rw-r--r--mwe/events/include/iKeyListener.h19
-rw-r--r--mwe/events/include/iMouseListener.h23
-rw-r--r--mwe/events/include/inputSystem.h27
-rw-r--r--mwe/events/include/keyCodes.h16
-rw-r--r--mwe/events/include/keyListenerTest.h8
-rw-r--r--mwe/events/include/loopManager.h6
-rw-r--r--mwe/events/include/mouseListenerTest.h12
-rw-r--r--mwe/events/include/uiObject.h74
-rw-r--r--mwe/events/include/uiRenderer.h18
-rw-r--r--mwe/events/include/window.h30
13 files changed, 129 insertions, 133 deletions
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 <string>
#include <unordered_map>
#include <variant>
-#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<int, int> 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<int, int> getMousePosition() const;
MouseButton getMouseButton() const;
+
private:
int mouseX = 0;
int mouseY = 0;
@@ -124,6 +123,7 @@ public:
REGISTER_EVENT_TYPE(MouseMovedEvent)
std::pair<int, int> 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 <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 de5f3fe..48e239b 100644
--- a/mwe/events/include/gameObject.h
+++ b/mwe/events/include/gameObject.h
@@ -3,7 +3,7 @@
#include <string>
class GameObject {
public:
- GameObject(){}
+ GameObject() {}
// template <typename... Args>
// 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<KeyPressedEvent> keyPressedHandler;
- EventHandler<KeyReleasedEvent> keyReleasedHandler;
+ EventHandler<KeyPressedEvent> keyPressedHandler;
+ EventHandler<KeyReleasedEvent> 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<MouseClickEvent> mouseClickHandler;
- EventHandler<MousePressedEvent> mousePressHandler;
- EventHandler<MouseReleasedEvent> mouseReleaseHandler;
- EventHandler<MouseMovedEvent> mouseMoveHandler;
+ EventHandler<MouseClickEvent> mouseClickHandler;
+ EventHandler<MousePressedEvent> mousePressHandler;
+ EventHandler<MouseReleasedEvent> mouseReleaseHandler;
+ EventHandler<MouseMovedEvent> 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 <vector>
-#include "uiObject.h"
#include "event.h"
-#include "keyCodes.h"
#include "eventManager.h"
+#include "keyCodes.h"
+#include "uiObject.h"
+#include <vector>
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<Button*> buttons;
- std::vector<TextInput*> textInputs;
- std::vector<Text*> texts;
- void processMouseClick(int mouseX, int mouseY);
+ std::vector<Button *> buttons;
+ std::vector<TextInput *> textInputs;
+ std::vector<Text *> texts;
+ void processMouseClick(int mouseX, int mouseY);
void processInputField(int mouseX, int mouseY);
void processKeyPress(Keycode);
- void processTextInput(const std::string& text);
-
+ void processTextInput(const std::string & text);
};
diff --git a/mwe/events/include/keyCodes.h b/mwe/events/include/keyCodes.h
index 61deba2..73ba1cd 100644
--- a/mwe/events/include/keyCodes.h
+++ b/mwe/events/include/keyCodes.h
@@ -4,14 +4,14 @@
#include <unordered_map>
using Keycode = uint16_t;
enum class MouseButton {
- None = 0,
- Left_Mouse = 1,
- Right_Mouse = 2,
- Middle_Mouse = 3,
- X1_Mouse = 4,
- X2_Mouse = 5,
- Scroll_Up = 6,
- Scroll_Down = 7,
+ None = 0,
+ Left_Mouse = 1,
+ Right_Mouse = 2,
+ Middle_Mouse = 3,
+ X1_Mouse = 4,
+ X2_Mouse = 5,
+ Scroll_Up = 6,
+ Scroll_Down = 7,
};
enum : Keycode {
// From glfw3.h
diff --git a/mwe/events/include/keyListenerTest.h b/mwe/events/include/keyListenerTest.h
index 5990cd1..08f3feb 100644
--- a/mwe/events/include/keyListenerTest.h
+++ b/mwe/events/include/keyListenerTest.h
@@ -4,9 +4,9 @@
class KeyListenerTest : public IKeyListener {
public:
- KeyListenerTest(int listenerId);
- ~KeyListenerTest();
+ KeyListenerTest(int listenerId);
+ ~KeyListenerTest();
- void onKeyPressed(const KeyPressedEvent& event) override;
- void onKeyReleased(const KeyReleasedEvent& event) override;
+ void onKeyPressed(const KeyPressedEvent & event) override;
+ void onKeyReleased(const KeyReleasedEvent & event) override;
};
diff --git a/mwe/events/include/loopManager.h b/mwe/events/include/loopManager.h
index 289ff0f..9959c94 100644
--- a/mwe/events/include/loopManager.h
+++ b/mwe/events/include/loopManager.h
@@ -5,10 +5,10 @@
//#include "combinedEvent.h"
#include "eventHandler.h"
#include "eventManager.h"
+#include "inputSystem.h"
#include "loopManager.h"
-#include "uiRenderer.h"
#include "uiObject.h"
-#include "inputSystem.h"
+#include "uiRenderer.h"
#include <memory>
class LoopManager {
public:
@@ -23,7 +23,7 @@ private:
void lateUpdate();
void fixedUpdate();
void render();
- void onShutdown(const ShutDownEvent& e);
+ void onShutdown(const ShutDownEvent & e);
bool gameRunning = false;
WindowManager window;
int timeScale = 1;
diff --git a/mwe/events/include/mouseListenerTest.h b/mwe/events/include/mouseListenerTest.h
index dae04f5..ca9afc5 100644
--- a/mwe/events/include/mouseListenerTest.h
+++ b/mwe/events/include/mouseListenerTest.h
@@ -4,11 +4,11 @@
class MouseListenerTest : public IMouseListener {
public:
- MouseListenerTest(int listenerId);
- ~MouseListenerTest();
+ 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;
+ void onMouseClicked(const MouseClickEvent & event) override;
+ void onMousePressed(const MousePressedEvent & event) override;
+ void onMouseReleased(const MouseReleasedEvent & event) override;
+ void onMouseMoved(const MouseMovedEvent & event) override;
};
diff --git a/mwe/events/include/uiObject.h b/mwe/events/include/uiObject.h
index 893232d..23efe44 100644
--- a/mwe/events/include/uiObject.h
+++ b/mwe/events/include/uiObject.h
@@ -1,70 +1,68 @@
#pragma once
+#include "event.h"
+#include "eventHandler.h"
#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 };
- enum class PositioningMode { RELATIVE, STATIC,ABSOLUTE };
+ enum class Horizontal { LEFT, CENTER, RIGHT };
+ enum class Vertical { TOP, MIDDLE, BOTTOM };
+ enum class PositioningMode { RELATIVE, STATIC, ABSOLUTE };
- Horizontal horizontal = Horizontal::CENTER;
- Vertical vertical = Vertical::MIDDLE;
- PositioningMode mode = PositioningMode::RELATIVE;
+ Horizontal horizontal = Horizontal::CENTER;
+ Vertical vertical = Vertical::MIDDLE;
+ PositioningMode mode = PositioningMode::RELATIVE;
- int staticX = 0;
- int staticY = 0;
+ int staticX = 0;
+ int staticY = 0;
- int marginTop = 0;
- int marginBottom = 0;
- int marginLeft = 0;
- int marginRight = 0;
+ int marginTop = 0;
+ int marginBottom = 0;
+ int marginLeft = 0;
+ int marginRight = 0;
};
-struct RGBColor{
+struct RGBColor {
int red;
int green;
int blue;
};
-class UIObject : public GameObject{
- public:
- UIObject(int width,int height);
+class UIObject : public GameObject {
+public:
+ UIObject(int width, int height);
virtual ~UIObject() {}
int width;
int height;
int x;
int y;
};
-class Button : public UIObject{
- public:
- Button(int width,int height);
+class Button : public UIObject {
+public:
+ Button(int width, int height);
RGBColor color;
std::function<void()> onClick;
-
};
-class Text : public UIObject{
- public:
- Text(int width,int height);
+class Text : public UIObject {
+public:
+ Text(int width, int height);
std::string text;
int size;
Alignment alignment;
//font resource
- TTF_Font *font;
+ TTF_Font * font;
RGBColor color;
};
class TextInput : public UIObject {
public:
- TextInput(int width, int height);
- std::string textBuffer;
- std::string placeholder;
- bool isActive = false;
- RGBColor textColor;
- RGBColor backgroundColor;
- size_t maxLength = 100;
- Alignment alignment;
- TTF_Font* font = nullptr;
- std::function<void()> onSubmit;
- std::function<void()> onFocus;
+ TextInput(int width, int height);
+ std::string textBuffer;
+ std::string placeholder;
+ bool isActive = false;
+ RGBColor textColor;
+ RGBColor backgroundColor;
+ size_t maxLength = 100;
+ Alignment alignment;
+ TTF_Font * font = nullptr;
+ std::function<void()> onSubmit;
+ std::function<void()> onFocus;
};
-
diff --git a/mwe/events/include/uiRenderer.h b/mwe/events/include/uiRenderer.h
index 32acecf..8f22fdf 100644
--- a/mwe/events/include/uiRenderer.h
+++ b/mwe/events/include/uiRenderer.h
@@ -1,21 +1,21 @@
#pragma once
+#include "uiObject.h"
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
#include <string>
-#include "uiObject.h"
class UIRenderer {
public:
- UIRenderer(SDL_Renderer* renderer);
- ~UIRenderer();
+ UIRenderer(SDL_Renderer * renderer);
+ ~UIRenderer();
- void render(UIObject* uiObject);
+ void render(UIObject * uiObject);
private:
- SDL_Renderer* renderer;
- TTF_Font* font;
+ SDL_Renderer * renderer;
+ TTF_Font * font;
- void renderButton(Button* button);
- void renderText(Text* text);
- void renderTextInput(TextInput* textInput);
+ 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 3c34d4c..bd75c4a 100644
--- a/mwe/events/include/window.h
+++ b/mwe/events/include/window.h
@@ -1,27 +1,27 @@
#pragma once
-#include <SDL2/SDL.h>
-#include <vector>
#include "uiObject.h"
#include "uiRenderer.h"
+#include <SDL2/SDL.h>
+#include <vector>
class WindowManager {
public:
- WindowManager();
- virtual ~WindowManager();
+ WindowManager();
+ virtual ~WindowManager();
- bool initWindow();
- void destroyWindow();
- SDL_Renderer* getRenderer();
+ bool initWindow();
+ void destroyWindow();
+ SDL_Renderer * getRenderer();
- void addUIObject(UIObject* uiObject);
- void renderUIObjects();
+ void addUIObject(UIObject * uiObject);
+ void renderUIObjects();
private:
- const int SCREEN_WIDTH = 800;
- const int SCREEN_HEIGHT = 600;
- SDL_Window* window = nullptr;
- SDL_Renderer* renderer = nullptr;
+ const int SCREEN_WIDTH = 800;
+ const int SCREEN_HEIGHT = 600;
+ SDL_Window * window = nullptr;
+ SDL_Renderer * renderer = nullptr;
- UIRenderer* uiRenderer;
- std::vector<UIObject*> uiObjects;
+ UIRenderer * uiRenderer;
+ std::vector<UIObject *> uiObjects;
};