ImGui Events
This commit is contained in:
parent
4621f86cb2
commit
d4a9a0366f
9 changed files with 138 additions and 8 deletions
2
Dependencies/GLFW
vendored
2
Dependencies/GLFW
vendored
|
@ -1 +1 @@
|
|||
Subproject commit 72229440a46f607a325fa430ef0c9c14c7ec1218
|
||||
Subproject commit 23f99263cdb8db054db5202f605e5730aec4e3c3
|
2
Dependencies/imgui
vendored
2
Dependencies/imgui
vendored
|
@ -1 +1 @@
|
|||
Subproject commit 04fd5072fbc635cc7a8814b8543d40836248d3a7
|
||||
Subproject commit 6fb2e276cbee262fed50d9c9acf98fa314f624f8
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -2,9 +2,13 @@
|
|||
#include "UserInterface.h"
|
||||
|
||||
#include "Graphics/GraphicsContext.h"
|
||||
|
||||
#include "OpenGL/glUserInterface.h"
|
||||
|
||||
#include "Events/KeyboardEvents.h"
|
||||
#include "Events/MouseEvents.h"
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
#include "ltpch.h"
|
||||
#include "glUserInterface.h"
|
||||
|
||||
#include "Events/KeyboardEvents.h"
|
||||
#include "Events/MouseEvents.h"
|
||||
|
||||
#include <imgui.h>
|
||||
#include <imgui_impl_glfw.h>
|
||||
#include <imgui_impl_opengl3.h>
|
||||
|
@ -16,7 +19,7 @@ namespace Light {
|
|||
|
||||
ImGui::StyleColorsDark();
|
||||
|
||||
ImGui_ImplGlfw_InitForOpenGL(windowHandle, true);
|
||||
ImGui_ImplGlfw_InitForOpenGL(windowHandle, false);
|
||||
ImGui_ImplOpenGL3_Init();
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
#include "Base.h"
|
||||
#include "UserInterface/UserInterface.h"
|
||||
|
||||
#include "Events/Event.h"
|
||||
|
||||
namespace Light {
|
||||
|
||||
class glUserInterface : public UserInterface
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue