2021-05-26 18:39:40 +04:30
|
|
|
#include "ltpch.h"
|
2021-05-27 10:41:32 +04:30
|
|
|
#include "UserInterface.h"
|
2021-05-27 18:55:30 +04:30
|
|
|
#include "OpenGL/glUserInterface.h"
|
2021-05-27 10:41:32 +04:30
|
|
|
|
2021-06-02 17:20:15 +04:30
|
|
|
#ifdef LIGHT_PLATFORM_WINDOWS
|
|
|
|
#include "DirectX/dxUserInterface.h"
|
2021-06-19 15:12:42 +04:30
|
|
|
#include "DirectX/dxSharedContext.h"
|
2021-06-02 17:20:15 +04:30
|
|
|
#endif
|
|
|
|
|
2021-05-27 18:55:30 +04:30
|
|
|
#include "Events/Event.h"
|
2021-05-27 12:51:39 +04:30
|
|
|
#include "Events/MouseEvents.h"
|
2021-05-27 18:55:30 +04:30
|
|
|
#include "Events/KeyboardEvents.h"
|
2021-05-27 12:51:39 +04:30
|
|
|
|
2021-07-29 17:12:13 +04:30
|
|
|
#include "Graphics/GraphicsContext.h"
|
|
|
|
|
2021-05-27 12:51:39 +04:30
|
|
|
#include <imgui.h>
|
|
|
|
|
2021-05-26 18:39:40 +04:30
|
|
|
namespace Light {
|
|
|
|
|
2021-07-26 11:43:37 +04:30
|
|
|
Scope<UserInterface> UserInterface::Create(GLFWwindow* windowHandle, Ref<SharedContext> sharedContext)
|
2021-05-26 18:39:40 +04:30
|
|
|
{
|
2021-05-27 10:41:32 +04:30
|
|
|
switch (GraphicsContext::GetGraphicsAPI())
|
|
|
|
{
|
|
|
|
case GraphicsAPI::OpenGL:
|
2021-07-26 11:43:37 +04:30
|
|
|
return CreateScope<glUserInterface>(windowHandle);
|
2021-05-27 19:54:05 +04:30
|
|
|
|
2021-06-02 17:20:15 +04:30
|
|
|
case GraphicsAPI::DirectX: LT_WIN(
|
2021-07-26 11:43:37 +04:30
|
|
|
return CreateScope<dxUserInterface>(windowHandle, std::dynamic_pointer_cast<dxSharedContext>(sharedContext));)
|
2021-06-02 17:20:15 +04:30
|
|
|
|
2021-05-27 19:54:05 +04:30
|
|
|
default:
|
2021-07-01 19:25:46 +04:30
|
|
|
LT_ENGINE_ASSERT(false, "UserInterface::Create: invalid/unsupported 'GraphicsAPI' {}", GraphicsContext::GetGraphicsAPI());
|
2021-05-27 19:54:05 +04:30
|
|
|
return nullptr;
|
2021-05-27 10:41:32 +04:30
|
|
|
}
|
|
|
|
}
|
2021-05-26 18:39:40 +04:30
|
|
|
|
2021-05-27 12:51:39 +04:30
|
|
|
void UserInterface::OnInput(const Event& inputEvent)
|
|
|
|
{
|
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
|
|
switch (inputEvent.GetEventType())
|
|
|
|
{
|
2021-07-29 17:12:13 +04:30
|
|
|
/* mouse events */
|
2021-05-27 12:51:39 +04:30
|
|
|
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;
|
|
|
|
}
|
2021-06-19 15:12:42 +04:30
|
|
|
case EventType::WheelScrolled:
|
|
|
|
{
|
|
|
|
const WheelScrolledEvent& event = (const WheelScrolledEvent&)inputEvent;
|
|
|
|
ImGui::GetIO().MouseWheel = event.GetOffset();
|
|
|
|
return;
|
|
|
|
}
|
2021-07-29 17:12:13 +04:30
|
|
|
/* keyboard events */
|
2021-05-27 12:51:39 +04:30
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-26 18:39:40 +04:30
|
|
|
}
|