2021-06-02 17:20:15 +04:30
|
|
|
#include "ltpch.h"
|
|
|
|
#include "dxUserInterface.h"
|
|
|
|
#include "dxSharedContext.h"
|
|
|
|
|
2021-08-01 16:43:59 +04:30
|
|
|
#include "Input/KeyCodes.h"
|
|
|
|
|
2021-06-02 17:20:15 +04:30
|
|
|
#define GLFW_EXPOSE_NATIVE_WIN32
|
|
|
|
#include <glfw/glfw3.h>
|
|
|
|
#include <glfw/glfw3native.h>
|
|
|
|
|
2021-07-29 17:12:13 +04:30
|
|
|
#include <imgui.h>
|
|
|
|
#include <imgui_impl_win32.h>
|
|
|
|
#include <imgui_impl_dx11.h>
|
|
|
|
|
2021-06-02 17:20:15 +04:30
|
|
|
namespace Light {
|
|
|
|
|
2021-07-26 11:43:37 +04:30
|
|
|
dxUserInterface::dxUserInterface(GLFWwindow* windowHandle, Ref<dxSharedContext> sharedContext)
|
2021-06-02 17:20:15 +04:30
|
|
|
{
|
2021-06-19 15:12:42 +04:30
|
|
|
// create context
|
2021-06-02 17:20:15 +04:30
|
|
|
IMGUI_CHECKVERSION();
|
|
|
|
ImGui::CreateContext();
|
2021-06-19 15:12:42 +04:30
|
|
|
|
|
|
|
// configure io
|
2021-06-02 17:20:15 +04:30
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
|
|
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
|
|
|
|
|
2021-07-16 19:59:14 +04:30
|
|
|
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
|
|
|
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;
|
|
|
|
|
|
|
|
io.ConfigFlags |= ImGuiBackendFlags_PlatformHasViewports;
|
|
|
|
io.ConfigFlags |= ImGuiBackendFlags_RendererHasViewports;
|
|
|
|
|
2021-07-23 10:11:20 +04:30
|
|
|
// #todo: handle this in a better way
|
|
|
|
if(std::filesystem::exists("user_gui_layout.ini"))
|
|
|
|
io.IniFilename = "user_gui_layout.ini";
|
|
|
|
else
|
|
|
|
io.IniFilename = "default_gui_layout.ini";
|
|
|
|
|
2021-06-19 15:12:42 +04:30
|
|
|
// style
|
2021-06-02 17:20:15 +04:30
|
|
|
ImGui::StyleColorsDark();
|
|
|
|
|
2021-06-19 15:12:42 +04:30
|
|
|
// init
|
2021-06-02 17:20:15 +04:30
|
|
|
ImGui_ImplWin32_Init(glfwGetWin32Window(windowHandle));
|
2021-07-01 19:25:46 +04:30
|
|
|
ImGui_ImplDX11_Init(sharedContext->GetDevice().Get(), sharedContext->GetDeviceContext().Get());
|
2021-08-01 16:43:59 +04:30
|
|
|
|
|
|
|
// keyboard map
|
|
|
|
io.KeyMap[ImGuiKey_Tab] = Key::Tab;
|
|
|
|
io.KeyMap[ImGuiKey_LeftArrow] = Key::LeftArrow;
|
|
|
|
io.KeyMap[ImGuiKey_RightArrow] = Key::RightArrow;
|
|
|
|
io.KeyMap[ImGuiKey_UpArrow] = Key::UpArrow;
|
|
|
|
io.KeyMap[ImGuiKey_DownArrow] = Key::DownArrow;
|
|
|
|
io.KeyMap[ImGuiKey_PageUp] = Key::PageUp;
|
|
|
|
io.KeyMap[ImGuiKey_PageDown] = Key::PageDown;
|
|
|
|
io.KeyMap[ImGuiKey_Home] = Key::Home;
|
|
|
|
io.KeyMap[ImGuiKey_End] = Key::End;
|
|
|
|
io.KeyMap[ImGuiKey_Insert] = Key::Insert;
|
|
|
|
io.KeyMap[ImGuiKey_Delete] = Key::Delete;
|
|
|
|
io.KeyMap[ImGuiKey_Backspace] = Key::BackSpace;
|
|
|
|
io.KeyMap[ImGuiKey_Space] = Key::Space;
|
|
|
|
io.KeyMap[ImGuiKey_Enter] = Key::Enter;
|
|
|
|
io.KeyMap[ImGuiKey_Escape] = Key::Escape;
|
|
|
|
io.KeyMap[ImGuiKey_KeyPadEnter] = Key::Enter;
|
|
|
|
io.KeyMap[ImGuiKey_A] = Key::A;
|
|
|
|
io.KeyMap[ImGuiKey_C] = Key::C;
|
|
|
|
io.KeyMap[ImGuiKey_V] = Key::V;
|
|
|
|
io.KeyMap[ImGuiKey_X] = Key::X;
|
|
|
|
io.KeyMap[ImGuiKey_Y] = Key::Y;
|
|
|
|
io.KeyMap[ImGuiKey_Z] = Key::Z;
|
2021-08-10 11:46:13 +04:30
|
|
|
|
2021-08-10 17:10:16 +04:30
|
|
|
io.Fonts->AddFontFromFileTTF("res/Fonts/OpenSans/OpenSans-Bold.ttf", 18.0f);
|
2021-08-10 11:46:13 +04:30
|
|
|
io.FontDefault = io.Fonts->AddFontFromFileTTF("res/Fonts/OpenSans/OpenSans-Regular.ttf", 18.0f);
|
2021-08-10 17:10:16 +04:30
|
|
|
|
|
|
|
SetDarkThemeColors();
|
2021-06-02 17:20:15 +04:30
|
|
|
}
|
|
|
|
|
|
|
|
dxUserInterface::~dxUserInterface()
|
|
|
|
{
|
2021-07-23 10:11:20 +04:30
|
|
|
// #todo: handle this in a better way
|
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
|
|
|
|
|
|
if (io.IniFilename == "default_gui_layout.ini")
|
|
|
|
io.IniFilename = "user_gui_layout.ini";
|
|
|
|
|
2021-06-02 17:20:15 +04:30
|
|
|
ImGui_ImplDX11_Shutdown();
|
|
|
|
ImGui_ImplWin32_Shutdown();
|
|
|
|
ImGui::DestroyContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
void dxUserInterface::Begin()
|
|
|
|
{
|
|
|
|
ImGui_ImplDX11_NewFrame();
|
|
|
|
ImGui_ImplWin32_NewFrame();
|
|
|
|
ImGui::NewFrame();
|
|
|
|
}
|
|
|
|
|
|
|
|
void dxUserInterface::End()
|
|
|
|
{
|
|
|
|
ImGui::Render();
|
|
|
|
ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());
|
2021-07-16 19:59:14 +04:30
|
|
|
|
|
|
|
ImGui::UpdatePlatformWindows();
|
|
|
|
ImGui::RenderPlatformWindowsDefault();
|
2021-06-02 17:20:15 +04:30
|
|
|
}
|
|
|
|
|
|
|
|
void dxUserInterface::LogDebugData()
|
|
|
|
{
|
2021-06-19 15:12:42 +04:30
|
|
|
// #todo: improve
|
2021-06-02 17:20:15 +04:30
|
|
|
LT_ENGINE_INFO("________________________________________");
|
|
|
|
LT_ENGINE_INFO("UserInterface::");
|
|
|
|
LT_ENGINE_INFO(" API : ImGui");
|
|
|
|
LT_ENGINE_INFO(" Version: {}", ImGui::GetVersion());
|
2021-07-01 19:25:46 +04:30
|
|
|
LT_ENGINE_INFO(" GraphicsAPI : DirectX");
|
2021-06-02 17:20:15 +04:30
|
|
|
LT_ENGINE_INFO("________________________________________");
|
|
|
|
}
|
|
|
|
|
2021-08-10 17:10:16 +04:30
|
|
|
void dxUserInterface::SetDarkThemeColors()
|
|
|
|
{
|
|
|
|
auto& colors = ImGui::GetStyle().Colors;
|
|
|
|
colors[ImGuiCol_WindowBg] = ImVec4{ 0.1f, 0.105f, 0.11f, 1.0f };
|
|
|
|
|
|
|
|
// Headers
|
|
|
|
colors[ImGuiCol_Header] = ImVec4{ 0.2f, 0.205f, 0.21f, 1.0f };
|
|
|
|
colors[ImGuiCol_HeaderHovered] = ImVec4{ 0.3f, 0.305f, 0.31f, 1.0f };
|
|
|
|
colors[ImGuiCol_HeaderActive] = ImVec4{ 0.15f, 0.1505f, 0.151f, 1.0f };
|
|
|
|
|
|
|
|
// Buttons
|
|
|
|
colors[ImGuiCol_Button] = ImVec4{ 0.2f, 0.205f, 0.21f, 1.0f };
|
|
|
|
colors[ImGuiCol_ButtonHovered] = ImVec4{ 0.3f, 0.305f, 0.31f, 1.0f };
|
|
|
|
colors[ImGuiCol_ButtonActive] = ImVec4{ 0.15f, 0.1505f, 0.151f, 1.0f };
|
|
|
|
|
|
|
|
// Frame BG
|
|
|
|
colors[ImGuiCol_FrameBg] = ImVec4{ 0.2f, 0.205f, 0.21f, 1.0f };
|
|
|
|
colors[ImGuiCol_FrameBgHovered] = ImVec4{ 0.3f, 0.305f, 0.31f, 1.0f };
|
|
|
|
colors[ImGuiCol_FrameBgActive] = ImVec4{ 0.15f, 0.1505f, 0.151f, 1.0f };
|
|
|
|
|
|
|
|
// Tabs
|
|
|
|
colors[ImGuiCol_Tab] = ImVec4{ 0.15f, 0.1505f, 0.151f, 1.0f };
|
|
|
|
colors[ImGuiCol_TabHovered] = ImVec4{ 0.38f, 0.3805f, 0.381f, 1.0f };
|
|
|
|
colors[ImGuiCol_TabActive] = ImVec4{ 0.28f, 0.2805f, 0.281f, 1.0f };
|
|
|
|
colors[ImGuiCol_TabUnfocused] = ImVec4{ 0.15f, 0.1505f, 0.151f, 1.0f };
|
|
|
|
colors[ImGuiCol_TabUnfocusedActive] = ImVec4{ 0.2f, 0.205f, 0.21f, 1.0f };
|
|
|
|
|
|
|
|
// Title
|
|
|
|
colors[ImGuiCol_TitleBg] = ImVec4{ 0.15f, 0.1505f, 0.151f, 1.0f };
|
|
|
|
colors[ImGuiCol_TitleBgActive] = ImVec4{ 0.15f, 0.1505f, 0.151f, 1.0f };
|
|
|
|
colors[ImGuiCol_TitleBgCollapsed] = ImVec4{ 0.15f, 0.1505f, 0.151f, 1.0f };
|
|
|
|
}
|
|
|
|
|
2021-06-02 17:20:15 +04:30
|
|
|
}
|