diff --git a/CopiumEngine/CopiumEngine.vcxproj b/CopiumEngine/CopiumEngine.vcxproj
index d92d3b9..0429967 100644
--- a/CopiumEngine/CopiumEngine.vcxproj
+++ b/CopiumEngine/CopiumEngine.vcxproj
@@ -175,6 +175,16 @@
+
+
+
+
+
+
+
+
+
+
@@ -221,6 +231,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/CopiumEngine/CopiumEngine.vcxproj.filters b/CopiumEngine/CopiumEngine.vcxproj.filters
index 46a531e..16f1010 100644
--- a/CopiumEngine/CopiumEngine.vcxproj.filters
+++ b/CopiumEngine/CopiumEngine.vcxproj.filters
@@ -150,6 +150,36 @@
Source Files
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
@@ -293,5 +323,44 @@
Header Files
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
\ No newline at end of file
diff --git a/CopiumEngine/src/copium/core/Application.cpp b/CopiumEngine/src/copium/core/Application.cpp
index 8d67ec4..a2756d2 100644
--- a/CopiumEngine/src/copium/core/Application.cpp
+++ b/CopiumEngine/src/copium/core/Application.cpp
@@ -1,6 +1,13 @@
#include "copium/core/Application.h"
#include "copium/core/Vulkan.h"
+#include "copium/event/EventDispatcher.h"
+#include "copium/event/MouseMoveEvent.h"
+#include "copium/event/MouseScrollEvent.h"
+#include "copium/event/MousePressEvent.h"
+#include "copium/event/KeyPressEvent.h"
+#include "copium/event/WindowFocusEvent.h"
+#include "copium/event/WindowResizeEvent.h"
#include "copium/mesh/Vertex.h"
#include "copium/mesh/VertexPassthrough.h"
#include "copium/asset/AssetManager.h"
@@ -38,6 +45,7 @@ namespace Copium
Application::Application()
{
+ EventDispatcher::AddEventHandler(this);
InitializeFrameBuffer();
InitializeRenderer();
InitializeGraphicsPipeline();
@@ -55,6 +63,7 @@ namespace Copium
AssetManager::UnloadAsset(graphicsPipeline);
AssetManager::UnloadAsset(graphicsPipelinePassthrough);
AssetManager::UnloadAsset(framebuffer);
+ EventDispatcher::RemoveEventHandler(this);
}
bool Application::Update()
@@ -69,6 +78,58 @@ namespace Copium
return !glfwWindowShouldClose(Vulkan::GetWindow().GetWindow());
}
+ EventResult Application::OnEvent(const Event& event)
+ {
+ switch (event.GetType())
+ {
+ case EventType::WindowResize:
+ {
+ const WindowResizeEvent& windowResizeEvent = static_cast(event);
+ AssetManager::GetAsset(framebuffer).Resize(windowResizeEvent.GetWidth(), windowResizeEvent.GetHeight());
+ descriptorSetPassthrough->SetSampler(AssetManager::GetAsset(framebuffer).GetColorAttachment(), 0);
+
+ return EventResult::Continue;
+ }
+ case EventType::MouseMove:
+ {
+ const MouseMoveEvent& mouseMoveEvent = static_cast(event);
+ mousePos = {mouseMoveEvent.GetPos().x / Vulkan::GetSwapChain().GetExtent().width, mouseMoveEvent.GetPos().y / Vulkan::GetSwapChain().GetExtent().height};
+
+ return EventResult::Continue;
+ }
+ case EventType::MousePress:
+ {
+ const MousePressEvent& mousePressEvent = static_cast(event);
+ CP_INFO("%d", mousePressEvent.GetButton());
+
+ return EventResult::Focus;
+ }
+ case EventType::KeyPress:
+ {
+ const KeyPressEvent& keyPressEvent = static_cast(event);
+ CP_INFO("%d", keyPressEvent.GetButton());
+
+ return EventResult::Handled;
+ }
+ case EventType::MouseScroll:
+ {
+ const MouseScrollEvent& mouseScrollEvent = static_cast(event);
+ CP_INFO("%d %d", mouseScrollEvent.GetScrollX(), mouseScrollEvent.GetScrollY());
+
+ return EventResult::Continue;
+ }
+ case EventType::WindowFocus:
+ {
+ const WindowFocusEvent& windowFocusEvent = static_cast(event);
+ CP_INFO("Window Focused: %s", windowFocusEvent.IsFocused() ? "true" : "false");
+
+ return EventResult::Continue;
+ }
+ }
+
+ return EventResult::Continue;
+ }
+
void Application::InitializeFrameBuffer()
{
framebuffer = AssetManager::LoadAsset("framebuffer.meta");
@@ -143,6 +204,7 @@ namespace Copium
}
renderer->Quad(glm::vec2{-0.9, -0.4}, glm::vec2{0.8, 0.8}, AssetManager::GetAsset(texture2D));
renderer->Quad(glm::vec2{ 0.1, -0.4}, glm::vec2{0.8, 0.8}, AssetManager::GetAsset(texture2D2));
+ renderer->Quad(mousePos, glm::vec2{0.8, 0.8}, AssetManager::GetAsset(texture2D2));
renderer->End();
fb.Unbind(*commandBuffer);
diff --git a/CopiumEngine/src/copium/core/Application.h b/CopiumEngine/src/copium/core/Application.h
index ef38697..e2bb0e4 100644
--- a/CopiumEngine/src/copium/core/Application.h
+++ b/CopiumEngine/src/copium/core/Application.h
@@ -2,6 +2,7 @@
#include "copium/asset/AssetMeta.h"
#include "copium/buffer/Framebuffer.h"
+#include "copium/event/EventHandler.h"
#include "copium/mesh/Mesh.h"
#include "copium/pipeline/DescriptorPool.h"
#include "copium/pipeline/DescriptorSet.h"
@@ -10,7 +11,7 @@
namespace Copium
{
- class Application final
+ class Application final : EventHandler
{
CP_DELETE_COPY_AND_MOVE_CTOR(Application);
private:
@@ -27,12 +28,14 @@ namespace Copium
std::unique_ptr mesh;
std::unique_ptr meshPassthrough;
std::unique_ptr commandBuffer;
+ glm::vec2 mousePos;
public:
Application();
~Application();
bool Update();
+ EventResult OnEvent(const Event& event) override;
private:
void InitializeFrameBuffer();
void InitializeRenderer();
diff --git a/CopiumEngine/src/copium/core/Window.cpp b/CopiumEngine/src/copium/core/Window.cpp
index e525ffc..7405822 100644
--- a/CopiumEngine/src/copium/core/Window.cpp
+++ b/CopiumEngine/src/copium/core/Window.cpp
@@ -1,75 +1,120 @@
#include "copium/core/Window.h"
#include "copium/core/Vulkan.h"
+#include "copium/event/EventDispatcher.h"
+#include "copium/event/KeyPressEvent.h"
+#include "copium/event/KeyReleaseEvent.h"
+#include "copium/event/MouseMoveEvent.h"
+#include "copium/event/MousePressEvent.h"
+#include "copium/event/MouseReleaseEvent.h"
+#include "copium/event/MouseScrollEvent.h"
+#include "copium/event/WindowResizeEvent.h"
+#include "copium/event/WindowFocusEvent.h"
namespace Copium
{
- Window::Window(const std::string& windowName, int width, int height, Mode mode)
+ Window::Window(const std::string& windowName, int width, int height, Mode mode)
+ {
+ InitializeWindow(windowName, width, height, mode);
+ InitializeSurface();
+ }
+
+ Window::~Window()
+ {
+ vkDestroySurfaceKHR(Vulkan::GetInstance(), surface, nullptr);
+ glfwDestroyWindow(window);
+ }
+
+ VkSurfaceKHR Window::GetSurface() const
+ {
+ return surface;
+ }
+
+ GLFWwindow* Window::GetWindow()
+ {
+ return window;
+ }
+
+ void Window::InitializeWindow(const std::string& windowName, int width, int height, Mode mode)
+ {
+ glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
+
+ switch (mode)
{
- InitializeWindow(windowName, width, height, mode);
- InitializeSurface();
+ case Mode::Fullscreen:
+ {
+ GLFWmonitor* monitor = glfwGetPrimaryMonitor();
+ const GLFWvidmode* mode = glfwGetVideoMode(monitor);
+ window = glfwCreateWindow(mode->width, mode->height, windowName.c_str(), glfwGetPrimaryMonitor(), nullptr);
+ break;
+ }
+ case Mode::BorderlessWindowed:
+ {
+ GLFWmonitor* monitor = glfwGetPrimaryMonitor();
+ const GLFWvidmode* mode = glfwGetVideoMode(monitor);
+ window = glfwCreateWindow(mode->width, mode->height, windowName.c_str(), nullptr, nullptr);
+ glfwSetWindowMonitor(window, monitor, 0, 0, mode->width, mode->height, mode->refreshRate);
+ break;
+ }
+ case Mode::Windowed:
+ {
+ window = glfwCreateWindow(width, height, windowName.c_str(), nullptr, nullptr);
+ break;
+ }
+ default:
+ CP_ABORT("Unreachable switch case");
}
- Window::~Window()
- {
- vkDestroySurfaceKHR(Vulkan::GetInstance(), surface, nullptr);
- glfwDestroyWindow(window);
- }
+ CP_ASSERT(window, "Failed to initialize glfw window");
- VkSurfaceKHR Window::GetSurface() const
- {
- return surface;
- }
+ glfwSetWindowUserPointer(window, this);
+ glfwSetFramebufferSizeCallback(window, FramebufferResizeCallback);
+ glfwSetKeyCallback(window, KeyCallback);
+ glfwSetMouseButtonCallback(window, MouseButtonCallback);
+ glfwSetCursorPosCallback(window, MouseMoveCallback);
+ glfwSetWindowFocusCallback(window, WindowFocusCallback);
+ glfwSetScrollCallback(window, MouseScrollCallback);
+ }
- GLFWwindow* Window::GetWindow()
- {
- return window;
- }
+ void Window::InitializeSurface()
+ {
+ CP_VK_ASSERT(glfwCreateWindowSurface(Vulkan::GetInstance(), window, nullptr, &surface), "Failed to create Vulkan surface");
+ }
- void Window::InitializeWindow(const std::string& windowName, int width, int height, Mode mode)
- {
- glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
+ void Window::FramebufferResizeCallback(GLFWwindow* glfwWindow, int width, int height)
+ {
+ Vulkan::GetSwapChain().ResizeFramebuffer();
+ EventDispatcher::QueueEvent(WindowResizeEvent{width, height});
+ }
- switch (mode)
- {
- case Mode::Fullscreen:
- {
- GLFWmonitor* monitor = glfwGetPrimaryMonitor();
- const GLFWvidmode* mode = glfwGetVideoMode(monitor);
- window = glfwCreateWindow(mode->width, mode->height, windowName.c_str(), glfwGetPrimaryMonitor(), nullptr);
- break;
- }
- case Mode::BorderlessWindowed:
- {
- GLFWmonitor* monitor = glfwGetPrimaryMonitor();
- const GLFWvidmode* mode = glfwGetVideoMode(monitor);
- window = glfwCreateWindow(mode->width, mode->height, windowName.c_str(), nullptr, nullptr);
- glfwSetWindowMonitor(window, monitor, 0, 0, mode->width, mode->height, mode->refreshRate);
- break;
- }
- case Mode::Windowed:
- {
- window = glfwCreateWindow(width, height, windowName.c_str(), nullptr, nullptr);
- break;
- }
- default:
- CP_ABORT("Unreachable switch case");
- }
+ void Window::KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods)
+ {
+ if (action == GLFW_PRESS)
+ EventDispatcher::QueueEvent(KeyPressEvent(key));
+ else if (action == GLFW_RELEASE)
+ EventDispatcher::QueueEvent(KeyReleaseEvent(key));
+ }
- CP_ASSERT(window, "Failed to initialize glfw window");
+ void Window::MouseButtonCallback(GLFWwindow* window, int button, int action, int mods)
+ {
+ if (action == GLFW_PRESS)
+ EventDispatcher::QueueEvent(MousePressEvent{button});
+ else if (action == GLFW_RELEASE)
+ EventDispatcher::QueueEvent(MouseReleaseEvent{button});
+ }
- glfwSetWindowUserPointer(window, this);
- glfwSetFramebufferSizeCallback(window, FramebufferResizeCallback);
- }
+ void Window::MouseMoveCallback(GLFWwindow* window, double xpos, double ypos)
+ {
+ EventDispatcher::QueueEvent(MouseMoveEvent{glm::vec2{xpos, ypos}}); // TODO: Convert to Vulkan coordinates
+ }
- void Window::InitializeSurface()
- {
- CP_VK_ASSERT(glfwCreateWindowSurface(Vulkan::GetInstance(), window, nullptr, &surface), "Failed to create Vulkan surface");
- }
-
- void Window::FramebufferResizeCallback(GLFWwindow* glfwWindow, int width, int height)
- {
- Vulkan::GetSwapChain().ResizeFramebuffer(); // TODO: Should maybe be handled by an event system?
- }
+ void Window::WindowFocusCallback(GLFWwindow* window, int focused)
+ {
+ EventDispatcher::QueueEvent(WindowFocusEvent{focused == GLFW_TRUE});
+ }
+ void Window::MouseScrollCallback(GLFWwindow* window, double xoffset, double yoffset)
+ {
+ EventDispatcher::QueueEvent(MouseScrollEvent{(int)xoffset, (int)yoffset});
+ }
}
\ No newline at end of file
diff --git a/CopiumEngine/src/copium/core/Window.h b/CopiumEngine/src/copium/core/Window.h
index d02846a..25dd67a 100644
--- a/CopiumEngine/src/copium/core/Window.h
+++ b/CopiumEngine/src/copium/core/Window.h
@@ -28,7 +28,12 @@ namespace Copium
private:
void InitializeWindow(const std::string& windowName, int width, int height, Mode mode);
void InitializeSurface();
- static void FramebufferResizeCallback(GLFWwindow* glfwWindow, int width, int height);
+ static void FramebufferResizeCallback(GLFWwindow* glfwWindow, int width, int height);
+ static void KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
+ static void MouseButtonCallback(GLFWwindow* window, int button, int action, int mods);
+ static void MouseMoveCallback(GLFWwindow* window, double xpos, double ypos);
+ static void WindowFocusCallback(GLFWwindow* window, int focused);
+ static void MouseScrollCallback(GLFWwindow* window, double xoffset, double yoffset);
};
}
\ No newline at end of file
diff --git a/CopiumEngine/src/copium/event/Event.cpp b/CopiumEngine/src/copium/event/Event.cpp
new file mode 100644
index 0000000..f6a9067
--- /dev/null
+++ b/CopiumEngine/src/copium/event/Event.cpp
@@ -0,0 +1,14 @@
+#include "copium/event/Event.h"
+
+namespace Copium
+{
+
+ Event::Event(EventType type)
+ : type{type}
+ {}
+
+ EventType Event::GetType() const
+ {
+ return type;
+ }
+}
diff --git a/CopiumEngine/src/copium/event/Event.h b/CopiumEngine/src/copium/event/Event.h
new file mode 100644
index 0000000..5638caa
--- /dev/null
+++ b/CopiumEngine/src/copium/event/Event.h
@@ -0,0 +1,16 @@
+#pragma once
+
+#include "copium/event/EventType.h"
+
+namespace Copium
+{
+ class Event
+ {
+ private:
+ EventType type;
+ public:
+ Event(EventType type);
+
+ EventType GetType() const;
+ };
+}
diff --git a/CopiumEngine/src/copium/event/EventDispatcher.cpp b/CopiumEngine/src/copium/event/EventDispatcher.cpp
new file mode 100644
index 0000000..7ad1246
--- /dev/null
+++ b/CopiumEngine/src/copium/event/EventDispatcher.cpp
@@ -0,0 +1,60 @@
+#include "copium/event/EventDispatcher.h"
+
+#include "copium/util/Common.h"
+
+namespace Copium
+{
+ EventHandler* EventDispatcher::focusedEventHandler = nullptr;
+ std::vector EventDispatcher::eventHandlers;
+ std::queue> EventDispatcher::events;
+
+ void EventDispatcher::Dispatch()
+ {
+ while (!events.empty())
+ {
+ std::unique_ptr event = std::move(events.front());
+ events.pop();
+ if (focusedEventHandler)
+ {
+ EventResult result = focusedEventHandler->OnEvent(*event);
+ if (result == EventResult::Handled || result == EventResult::Focus)
+ return;
+ }
+ for (auto& eventHandler : eventHandlers)
+ {
+ if (eventHandler == focusedEventHandler)
+ continue;
+ EventResult result = eventHandler->OnEvent(*event);
+ switch (result)
+ {
+ case EventResult::Continue:
+ continue;
+ case EventResult::Handled:
+ return;
+ case EventResult::Focus:
+ focusedEventHandler = eventHandler;
+ return;
+ default:
+ CP_ABORT("Unreachable switch case");
+ }
+ }
+ }
+ }
+
+ void EventDispatcher::AddEventHandler(EventHandler* eventHandler)
+ {
+ eventHandlers.emplace_back(eventHandler);
+ }
+
+ void EventDispatcher::RemoveEventHandler(EventHandler* eventHandler)
+ {
+ for (auto it = eventHandlers.begin(); it != eventHandlers.end(); ++it)
+ {
+ if (*it == eventHandler)
+ {
+ eventHandlers.erase(it);
+ return;
+ }
+ }
+ }
+}
diff --git a/CopiumEngine/src/copium/event/EventDispatcher.h b/CopiumEngine/src/copium/event/EventDispatcher.h
new file mode 100644
index 0000000..5d03963
--- /dev/null
+++ b/CopiumEngine/src/copium/event/EventDispatcher.h
@@ -0,0 +1,28 @@
+#pragma once
+
+#include "copium/event/Event.h"
+#include "copium/event/EventHandler.h"
+
+#include
+#include
+#include
+
+namespace Copium
+{
+ class EventDispatcher
+ {
+ private:
+ static EventHandler* focusedEventHandler;
+ static std::vector eventHandlers;
+ static std::queue> events;
+ public:
+ template
+ static void QueueEvent(const EventType& event)
+ {
+ events.push(std::make_unique(event));
+ }
+ static void Dispatch();
+ static void AddEventHandler(EventHandler* eventHandler);
+ static void RemoveEventHandler(EventHandler* eventHandler);
+ };
+}
\ No newline at end of file
diff --git a/CopiumEngine/src/copium/event/EventHandler.h b/CopiumEngine/src/copium/event/EventHandler.h
new file mode 100644
index 0000000..f4c27e7
--- /dev/null
+++ b/CopiumEngine/src/copium/event/EventHandler.h
@@ -0,0 +1,13 @@
+#pragma once
+
+#include "copium/event/Event.h"
+#include "copium/event/EventResult.h"
+
+namespace Copium
+{
+ class EventHandler
+ {
+ public:
+ virtual EventResult OnEvent(const Event& event) = 0;
+ };
+}
\ No newline at end of file
diff --git a/CopiumEngine/src/copium/event/EventResult.h b/CopiumEngine/src/copium/event/EventResult.h
new file mode 100644
index 0000000..d02e142
--- /dev/null
+++ b/CopiumEngine/src/copium/event/EventResult.h
@@ -0,0 +1,8 @@
+#pragma once
+
+enum class EventResult
+{
+ Continue,
+ Handled,
+ Focus
+};
\ No newline at end of file
diff --git a/CopiumEngine/src/copium/event/EventType.h b/CopiumEngine/src/copium/event/EventType.h
new file mode 100644
index 0000000..44549e8
--- /dev/null
+++ b/CopiumEngine/src/copium/event/EventType.h
@@ -0,0 +1,11 @@
+#pragma once
+
+namespace Copium
+{
+ enum class EventType
+ {
+ MouseMove, MousePress, MouseRelease, MouseScroll,
+ KeyPress, KeyRelease,
+ WindowResize, WindowFocus,
+ };
+}
diff --git a/CopiumEngine/src/copium/event/KeyPressEvent.cpp b/CopiumEngine/src/copium/event/KeyPressEvent.cpp
new file mode 100644
index 0000000..384a4c6
--- /dev/null
+++ b/CopiumEngine/src/copium/event/KeyPressEvent.cpp
@@ -0,0 +1,13 @@
+#include "copium/event/KeyPressEvent.h"
+
+namespace Copium
+{
+ KeyPressEvent::KeyPressEvent(int button)
+ : Event{EventType::KeyPress}, button{button}
+ {}
+
+ int KeyPressEvent::GetButton() const
+ {
+ return button;
+ }
+}
\ No newline at end of file
diff --git a/CopiumEngine/src/copium/event/KeyPressEvent.h b/CopiumEngine/src/copium/event/KeyPressEvent.h
new file mode 100644
index 0000000..59ffdd4
--- /dev/null
+++ b/CopiumEngine/src/copium/event/KeyPressEvent.h
@@ -0,0 +1,16 @@
+#pragma once
+
+#include "copium/event/Event.h"
+
+namespace Copium
+{
+ class KeyPressEvent : public Event
+ {
+ private:
+ int button;
+ public:
+ KeyPressEvent(int button);
+
+ int GetButton() const;
+ };
+}
diff --git a/CopiumEngine/src/copium/event/KeyReleaseEvent.cpp b/CopiumEngine/src/copium/event/KeyReleaseEvent.cpp
new file mode 100644
index 0000000..e692ee9
--- /dev/null
+++ b/CopiumEngine/src/copium/event/KeyReleaseEvent.cpp
@@ -0,0 +1,13 @@
+#include "copium/event/KeyReleaseEvent.h"
+
+namespace Copium
+{
+ KeyReleaseEvent::KeyReleaseEvent(int button)
+ : Event{EventType::KeyRelease}, button{button}
+ {}
+
+ int KeyReleaseEvent::GetButton() const
+ {
+ return button;
+ }
+}
\ No newline at end of file
diff --git a/CopiumEngine/src/copium/event/KeyReleaseEvent.h b/CopiumEngine/src/copium/event/KeyReleaseEvent.h
new file mode 100644
index 0000000..9b98a13
--- /dev/null
+++ b/CopiumEngine/src/copium/event/KeyReleaseEvent.h
@@ -0,0 +1,16 @@
+#pragma once
+
+#include "copium/event/Event.h"
+
+namespace Copium
+{
+ class KeyReleaseEvent : public Event
+ {
+ private:
+ int button;
+ public:
+ KeyReleaseEvent(int button);
+
+ int GetButton() const;
+ };
+}
diff --git a/CopiumEngine/src/copium/event/MouseMoveEvent.cpp b/CopiumEngine/src/copium/event/MouseMoveEvent.cpp
new file mode 100644
index 0000000..82c13ed
--- /dev/null
+++ b/CopiumEngine/src/copium/event/MouseMoveEvent.cpp
@@ -0,0 +1,13 @@
+#include "copium/event/MouseMoveEvent.h"
+
+namespace Copium
+{
+ MouseMoveEvent::MouseMoveEvent(glm::vec2 pos)
+ : Event{EventType::MouseMove}, pos{pos}
+ {}
+
+ glm::vec2 MouseMoveEvent::GetPos() const
+ {
+ return pos;
+ }
+}
\ No newline at end of file
diff --git a/CopiumEngine/src/copium/event/MouseMoveEvent.h b/CopiumEngine/src/copium/event/MouseMoveEvent.h
new file mode 100644
index 0000000..6fcad4b
--- /dev/null
+++ b/CopiumEngine/src/copium/event/MouseMoveEvent.h
@@ -0,0 +1,18 @@
+#pragma once
+
+#include "copium/event/Event.h"
+
+#include
+
+namespace Copium
+{
+ class MouseMoveEvent : public Event
+ {
+ private:
+ glm::vec2 pos;
+ public:
+ MouseMoveEvent(glm::vec2 pos);
+
+ glm::vec2 GetPos() const;
+ };
+}
diff --git a/CopiumEngine/src/copium/event/MousePressEvent.cpp b/CopiumEngine/src/copium/event/MousePressEvent.cpp
new file mode 100644
index 0000000..33abb75
--- /dev/null
+++ b/CopiumEngine/src/copium/event/MousePressEvent.cpp
@@ -0,0 +1,13 @@
+#include "copium/event/MousePressEvent.h"
+
+namespace Copium
+{
+ MousePressEvent::MousePressEvent(int button)
+ : Event{EventType::MousePress}, button{button}
+ {}
+
+ int MousePressEvent::GetButton() const
+ {
+ return button;
+ }
+}
diff --git a/CopiumEngine/src/copium/event/MousePressEvent.h b/CopiumEngine/src/copium/event/MousePressEvent.h
new file mode 100644
index 0000000..a9f573b
--- /dev/null
+++ b/CopiumEngine/src/copium/event/MousePressEvent.h
@@ -0,0 +1,18 @@
+#pragma once
+
+#include "copium/event/Event.h"
+
+#include
+
+namespace Copium
+{
+ class MousePressEvent : public Event
+ {
+ private:
+ int button;
+ public:
+ MousePressEvent(int button);
+
+ int GetButton() const;
+ };
+}
\ No newline at end of file
diff --git a/CopiumEngine/src/copium/event/MouseReleaseEvent.cpp b/CopiumEngine/src/copium/event/MouseReleaseEvent.cpp
new file mode 100644
index 0000000..fb628f3
--- /dev/null
+++ b/CopiumEngine/src/copium/event/MouseReleaseEvent.cpp
@@ -0,0 +1,13 @@
+#include "copium/event/MouseReleaseEvent.h"
+
+namespace Copium
+{
+ MouseReleaseEvent::MouseReleaseEvent(int button)
+ : Event{EventType::MouseRelease}, button{button}
+ {}
+
+ int MouseReleaseEvent::GetButton() const
+ {
+ return button;
+ }
+}
diff --git a/CopiumEngine/src/copium/event/MouseReleaseEvent.h b/CopiumEngine/src/copium/event/MouseReleaseEvent.h
new file mode 100644
index 0000000..56e3006
--- /dev/null
+++ b/CopiumEngine/src/copium/event/MouseReleaseEvent.h
@@ -0,0 +1,18 @@
+#pragma once
+
+#include "copium/event/Event.h"
+
+#include
+
+namespace Copium
+{
+ class MouseReleaseEvent : public Event
+ {
+ private:
+ int button;
+ public:
+ MouseReleaseEvent(int button);
+
+ int GetButton() const;
+ };
+}
\ No newline at end of file
diff --git a/CopiumEngine/src/copium/event/MouseScrollEvent.cpp b/CopiumEngine/src/copium/event/MouseScrollEvent.cpp
new file mode 100644
index 0000000..37c441f
--- /dev/null
+++ b/CopiumEngine/src/copium/event/MouseScrollEvent.cpp
@@ -0,0 +1,18 @@
+#include "copium/event/MouseScrollEvent.h"
+
+namespace Copium
+{
+ MouseScrollEvent::MouseScrollEvent(int scrollX, int scrollY)
+ : Event{EventType::MouseScroll}, scrollX{scrollX}, scrollY{scrollY}
+ {}
+
+ int MouseScrollEvent::GetScrollX() const
+ {
+ return scrollX;
+ }
+
+ int MouseScrollEvent::GetScrollY() const
+ {
+ return scrollY;
+ }
+}
diff --git a/CopiumEngine/src/copium/event/MouseScrollEvent.h b/CopiumEngine/src/copium/event/MouseScrollEvent.h
new file mode 100644
index 0000000..a2ef4a4
--- /dev/null
+++ b/CopiumEngine/src/copium/event/MouseScrollEvent.h
@@ -0,0 +1,18 @@
+#pragma once
+
+#include "copium/event/Event.h"
+
+namespace Copium
+{
+ class MouseScrollEvent : public Event
+ {
+ private:
+ int scrollX;
+ int scrollY;
+ public:
+ MouseScrollEvent(int scrollX, int scrollY);
+
+ int GetScrollX() const;
+ int GetScrollY() const;
+ };
+}
diff --git a/CopiumEngine/src/copium/event/WindowFocusEvent.cpp b/CopiumEngine/src/copium/event/WindowFocusEvent.cpp
new file mode 100644
index 0000000..53d1c85
--- /dev/null
+++ b/CopiumEngine/src/copium/event/WindowFocusEvent.cpp
@@ -0,0 +1,13 @@
+#include "copium/event/WindowFocusEvent.h"
+
+namespace Copium
+{
+ WindowFocusEvent::WindowFocusEvent(bool focused)
+ : Event{EventType::WindowFocus}, focused{focused}
+ {}
+
+ bool WindowFocusEvent::IsFocused() const
+ {
+ return focused;
+ }
+}
diff --git a/CopiumEngine/src/copium/event/WindowFocusEvent.h b/CopiumEngine/src/copium/event/WindowFocusEvent.h
new file mode 100644
index 0000000..2469198
--- /dev/null
+++ b/CopiumEngine/src/copium/event/WindowFocusEvent.h
@@ -0,0 +1,16 @@
+#pragma once
+
+#include "copium/event/Event.h"
+
+namespace Copium
+{
+ class WindowFocusEvent : public Event
+ {
+ private:
+ bool focused;
+ public:
+ WindowFocusEvent(bool focused);
+
+ bool IsFocused() const;
+ };
+}
diff --git a/CopiumEngine/src/copium/event/WindowResizeEvent.cpp b/CopiumEngine/src/copium/event/WindowResizeEvent.cpp
new file mode 100644
index 0000000..67066c8
--- /dev/null
+++ b/CopiumEngine/src/copium/event/WindowResizeEvent.cpp
@@ -0,0 +1,18 @@
+#include "copium/event/WindowResizeEvent.h"
+
+namespace Copium
+{
+ WindowResizeEvent::WindowResizeEvent(int width, int height)
+ : Event{EventType::WindowResize}, width{width}, height{height}
+ {}
+
+ int WindowResizeEvent::GetWidth() const
+ {
+ return width;
+ }
+
+ int WindowResizeEvent::GetHeight() const
+ {
+ return height;
+ }
+}
diff --git a/CopiumEngine/src/copium/event/WindowResizeEvent.h b/CopiumEngine/src/copium/event/WindowResizeEvent.h
new file mode 100644
index 0000000..bd63103
--- /dev/null
+++ b/CopiumEngine/src/copium/event/WindowResizeEvent.h
@@ -0,0 +1,18 @@
+#pragma once
+
+#include "copium/event/Event.h"
+
+namespace Copium
+{
+ class WindowResizeEvent : public Event
+ {
+ private:
+ int width;
+ int height;
+ public:
+ WindowResizeEvent(int width, int height);
+
+ int GetWidth() const;
+ int GetHeight() const;
+ };
+}
diff --git a/CopiumEngine/src/copium/main.cpp b/CopiumEngine/src/copium/main.cpp
index ced70fc..4580fc9 100644
--- a/CopiumEngine/src/copium/main.cpp
+++ b/CopiumEngine/src/copium/main.cpp
@@ -1,5 +1,6 @@
#include "copium/core/Application.h"
#include "copium/core/Vulkan.h"
+#include "copium/event/EventDispatcher.h"
#include "copium/util/Common.h"
#include "copium/util/Timer.h"
@@ -17,6 +18,7 @@ int main(int argc, char** argv)
while (application.Update())
{
glfwPollEvents();
+ Copium::EventDispatcher::Dispatch();
if (timer.Elapsed() >= 1.0)
{
CP_DEBUG("%d fps", frames);