diff --git a/Dependencies/GLFW b/Dependencies/GLFW index 7222944..23f9926 160000 --- a/Dependencies/GLFW +++ b/Dependencies/GLFW @@ -1 +1 @@ -Subproject commit 72229440a46f607a325fa430ef0c9c14c7ec1218 +Subproject commit 23f99263cdb8db054db5202f605e5730aec4e3c3 diff --git a/Dependencies/imgui b/Dependencies/imgui index 04fd507..6fb2e27 160000 --- a/Dependencies/imgui +++ b/Dependencies/imgui @@ -1 +1 @@ -Subproject commit 04fd5072fbc635cc7a8814b8543d40836248d3a7 +Subproject commit 6fb2e276cbee262fed50d9c9acf98fa314f624f8 diff --git a/Engine/src/Engine/Core/Application.cpp b/Engine/src/Engine/Core/Application.cpp index cf761e0..7dd213f 100644 --- a/Engine/src/Engine/Core/Application.cpp +++ b/Engine/src/Engine/Core/Application.cpp @@ -41,9 +41,12 @@ namespace Light { void Application::OnEvent(const Event& event) { - if (event.IsInCategory(WindowEventCategory)) + if (event.HasCategory(WindowEventCategory)) m_Window->OnEvent(event); + if (event.HasCategory(InputEventCategory)) + m_Window->GetGfxContext()->GetUserInterface()->OnInput(event); + m_LayerStack.OnEvent(event); } diff --git a/Engine/src/Engine/Events/Event.h b/Engine/src/Engine/Events/Event.h index 3d041a0..9eaf948 100644 --- a/Engine/src/Engine/Events/Event.h +++ b/Engine/src/Engine/Events/Event.h @@ -31,14 +31,14 @@ namespace Light { }; #define EVENT_TYPE(type) EventType GetEventType() const override { return EventType::##type; } -#define EVENT_CATEGORY(eCategory) inline bool IsInCategory(EventCategory category) const override { return (eCategory) & category; } +#define EVENT_CATEGORY(eCategory) inline bool HasCategory(EventCategory category) const override { return (eCategory) & category; } class Event { public: virtual EventType GetEventType() const = 0; virtual std::string GetInfoLog() const = 0; - virtual bool IsInCategory(EventCategory category) const = 0; + virtual bool HasCategory(EventCategory category) const = 0; friend std::ostream & operator<<(std::ostream & os, const Event& e) { diff --git a/Engine/src/Engine/UserInterface/UserInterface.cpp b/Engine/src/Engine/UserInterface/UserInterface.cpp index 91abcf9..a9b1707 100644 --- a/Engine/src/Engine/UserInterface/UserInterface.cpp +++ b/Engine/src/Engine/UserInterface/UserInterface.cpp @@ -2,9 +2,13 @@ #include "UserInterface.h" #include "Graphics/GraphicsContext.h" - #include "OpenGL/glUserInterface.h" +#include "Events/KeyboardEvents.h" +#include "Events/MouseEvents.h" + +#include + namespace Light { UserInterface* UserInterface::Create(GLFWwindow* windowHandle) @@ -16,4 +20,50 @@ namespace Light { } } + void UserInterface::OnInput(const Event& inputEvent) + { + ImGuiIO& io = ImGui::GetIO(); + switch (inputEvent.GetEventType()) + { + case EventType::MouseMoved: + { + const MouseMovedEvent& event = (const MouseMovedEvent&)inputEvent; + ImGui::GetIO().MousePos = ImVec2(event.GetX(), event.GetY()); + return; + } + + case EventType::ButtonPressed: + { + const ButtonPressedEvent& event = (const ButtonPressedEvent&)inputEvent; + ImGui::GetIO().MouseDown[event.GetButton()] = true; + return; + } + case EventType::ButtonReleased: + { + const ButtonReleasedEvent& event = (const ButtonReleasedEvent&)inputEvent; + ImGui::GetIO().MouseDown[event.GetButton()] = false; + return; + } + + case EventType::KeyPressed: + { + const KeyPressedEvent& event = (const KeyPressedEvent&)inputEvent; + ImGui::GetIO().MouseDown[event.GetKey()] = true; + return; + } + case EventType::KeyReleased: + { + const KeyReleasedEvent& event = (const KeyReleasedEvent&)inputEvent; + ImGui::GetIO().MouseDown[event.GetKey()] = false; + return; + } + case EventType::WheelScrolled: + { + const WheelScrolledEvent& event = (const WheelScrolledEvent&)inputEvent; + ImGui::GetIO().MouseWheel = event.GetOffset(); + return; + } + } + } + } \ No newline at end of file diff --git a/Engine/src/Engine/UserInterface/UserInterface.h b/Engine/src/Engine/UserInterface/UserInterface.h index facd72e..b43ca38 100644 --- a/Engine/src/Engine/UserInterface/UserInterface.h +++ b/Engine/src/Engine/UserInterface/UserInterface.h @@ -2,6 +2,8 @@ #include "Base.h" +#include "Events/Event.h" + struct GLFWwindow; namespace Light { @@ -12,6 +14,8 @@ namespace Light { public: static UserInterface* Create(GLFWwindow* windowHandle); + void OnInput(const Event& inputEvent); + virtual void Begin() = 0; virtual void End() = 0; }; diff --git a/Engine/src/Platform/GraphicsAPI/OpenGL/glUserInterface.cpp b/Engine/src/Platform/GraphicsAPI/OpenGL/glUserInterface.cpp index 762c4ec..7149f34 100644 --- a/Engine/src/Platform/GraphicsAPI/OpenGL/glUserInterface.cpp +++ b/Engine/src/Platform/GraphicsAPI/OpenGL/glUserInterface.cpp @@ -1,6 +1,9 @@ #include "ltpch.h" #include "glUserInterface.h" +#include "Events/KeyboardEvents.h" +#include "Events/MouseEvents.h" + #include #include #include @@ -16,7 +19,7 @@ namespace Light { ImGui::StyleColorsDark(); - ImGui_ImplGlfw_InitForOpenGL(windowHandle, true); + ImGui_ImplGlfw_InitForOpenGL(windowHandle, false); ImGui_ImplOpenGL3_Init(); } diff --git a/Engine/src/Platform/GraphicsAPI/OpenGL/glUserInterface.h b/Engine/src/Platform/GraphicsAPI/OpenGL/glUserInterface.h index a246dc7..28bd89b 100644 --- a/Engine/src/Platform/GraphicsAPI/OpenGL/glUserInterface.h +++ b/Engine/src/Platform/GraphicsAPI/OpenGL/glUserInterface.h @@ -3,6 +3,8 @@ #include "Base.h" #include "UserInterface/UserInterface.h" +#include "Events/Event.h" + namespace Light { class glUserInterface : public UserInterface diff --git a/Sandbox/imgui.ini b/Sandbox/imgui.ini index b6eba40..c404be8 100644 --- a/Sandbox/imgui.ini +++ b/Sandbox/imgui.ini @@ -4,7 +4,75 @@ Size=400,400 Collapsed=0 [Window][Dear ImGui Demo] -Pos=219,40 +Pos=248,45 Size=550,536 Collapsed=0 +[Table][0xC9935533,3] +Column 0 Weight=1.0000 +Column 1 Weight=1.0000 +Column 2 Weight=1.0000 + +[Table][0x64418101,3] +RefScale=13 +Column 0 Width=63 +Column 1 Width=63 +Column 2 Width=63 + +[Table][0x47600645,3] +RefScale=13 +Column 0 Width=63 +Column 1 Width=63 +Column 2 Weight=1.0000 + +[Table][0xDE6957FF,6] +RefScale=13 +Column 0 Width=63 +Column 1 Width=63 +Column 2 Width=-1 +Column 3 Weight=1.0000 +Column 4 Weight=1.0000 +Column 5 Weight=-1.0000 + +[Table][0x861D378E,3] +Column 0 Weight=1.0000 +Column 1 Weight=1.0000 +Column 2 Weight=1.0000 + +[Table][0x1F146634,3] +RefScale=13 +Column 0 Width=63 +Column 1 Width=63 +Column 2 Width=63 + +[Table][0x8DFA6E86,2] +Column 0 Weight=1.0000 +Column 1 Weight=1.0000 + +[Table][0xFABAAEF7,2] +Column 0 Weight=1.0000 +Column 1 Weight=1.0000 + +[Table][0xA43C3885,3] +RefScale=13 +Column 0 Width=56 +Column 1 Width=56 +Column 2 Width=56 + +[Table][0x49F8DCEA,3] +RefScale=13 +Column 0 Weight=1.0000 +Column 1 Width=84 +Column 2 Width=126 + +[Table][0x82CBB907,3] +Column 0 Weight=1.0000 +Column 1 Weight=1.0000 +Column 2 Weight=1.0000 + +[Table][0x49D11DC0,3] +RefScale=13 +Column 0 Width=86 +Column 1 Width=86 +Column 2 Width=86 +