2025-07-10 13:29:03 +03:30
|
|
|
#include <ui/gl/ui.hpp>
|
|
|
|
#include <ui/ui.hpp>
|
2025-07-05 13:28:41 +03:30
|
|
|
|
|
|
|
#ifdef LIGHT_PLATFORM_WINDOWS
|
2025-07-10 13:29:03 +03:30
|
|
|
#include <renderer/dx/shared_context.hpp>
|
|
|
|
#include <renderer/dx/user_interface.hpp>
|
2025-07-05 13:28:41 +03:30
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <imgui.h>
|
2025-07-10 13:29:03 +03:30
|
|
|
#include <input/events/char.hpp>
|
|
|
|
#include <input/events/event.hpp>
|
|
|
|
#include <input/events/keyboard.hpp>
|
|
|
|
#include <input/events/mouse.hpp>
|
|
|
|
#include <input/key_codes.hpp>
|
|
|
|
#include <renderer/graphics_context.hpp>
|
2025-07-06 17:45:40 +03:30
|
|
|
#include <utility>
|
2025-07-05 13:28:41 +03:30
|
|
|
|
2025-07-07 15:13:05 +03:30
|
|
|
|
|
|
|
inline ImGuiDockNodeFlags_ operator|(ImGuiDockNodeFlags_ a, ImGuiDockNodeFlags_ b)
|
|
|
|
{
|
|
|
|
return static_cast<ImGuiDockNodeFlags_>(std::to_underlying(a) | std::to_underlying(b));
|
|
|
|
}
|
|
|
|
|
2025-07-11 00:05:48 +03:30
|
|
|
namespace lt {
|
2025-07-05 13:28:41 +03:30
|
|
|
|
2025-07-05 16:07:51 +03:30
|
|
|
UserInterface *UserInterface::s_context = nullptr;
|
2025-07-05 13:28:41 +03:30
|
|
|
|
2025-07-06 14:02:50 +03:30
|
|
|
auto UserInterface::create(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext)
|
|
|
|
-> Scope<UserInterface>
|
2025-07-05 13:28:41 +03:30
|
|
|
{
|
2025-07-06 14:02:50 +03:30
|
|
|
auto scopeUserInterface = Scope<UserInterface> { nullptr };
|
2025-07-05 13:28:41 +03:30
|
|
|
|
2025-07-05 15:36:53 +03:30
|
|
|
switch (GraphicsContext::get_graphics_api())
|
2025-07-05 13:28:41 +03:30
|
|
|
{
|
2025-07-05 15:36:53 +03:30
|
|
|
case GraphicsAPI::OpenGL: scopeUserInterface = create_scope<glUserInterface>(); break;
|
2025-07-05 13:28:41 +03:30
|
|
|
|
2025-07-05 15:36:53 +03:30
|
|
|
case GraphicsAPI::DirectX: lt_win(scopeUserInterface = create_scope<dxUserInterface>();) break;
|
2025-07-05 13:28:41 +03:30
|
|
|
|
|
|
|
default:
|
2025-07-11 02:12:55 +03:30
|
|
|
ensure(
|
2025-07-05 13:28:41 +03:30
|
|
|
false,
|
2025-07-05 15:36:53 +03:30
|
|
|
"UserInterface::create: invalid/unsupported 'GraphicsAPI' {}",
|
|
|
|
static_cast<uint32_t>(GraphicsContext::get_graphics_api())
|
2025-07-05 13:28:41 +03:30
|
|
|
);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2025-07-06 16:52:50 +03:30
|
|
|
scopeUserInterface->init(windowHandle, std::move(sharedContext));
|
2025-07-05 13:28:41 +03:30
|
|
|
return std::move(scopeUserInterface);
|
|
|
|
}
|
|
|
|
|
|
|
|
UserInterface::UserInterface()
|
2025-07-07 15:13:05 +03:30
|
|
|
// NOLINTBEGIN
|
2025-07-05 14:23:01 +03:30
|
|
|
: m_dockspace_flags(
|
2025-07-05 13:28:41 +03:30
|
|
|
ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoTitleBar
|
|
|
|
| ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove
|
|
|
|
| ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus
|
|
|
|
)
|
2025-07-07 15:13:05 +03:30
|
|
|
// NOLINTEND
|
2025-07-05 13:28:41 +03:30
|
|
|
{
|
2025-07-11 02:12:55 +03:30
|
|
|
ensure(
|
2025-07-05 16:07:51 +03:30
|
|
|
!s_context,
|
2025-07-05 13:28:41 +03:30
|
|
|
"UserInterface::UserInterface: an instance of 'UserInterface' already exists, do not "
|
|
|
|
"construct this class!"
|
|
|
|
);
|
2025-07-05 16:07:51 +03:30
|
|
|
s_context = this;
|
2025-07-05 13:28:41 +03:30
|
|
|
}
|
|
|
|
|
2025-07-05 15:36:53 +03:30
|
|
|
void UserInterface::init(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext)
|
2025-07-05 13:28:41 +03:30
|
|
|
{
|
|
|
|
// create context
|
|
|
|
IMGUI_CHECKVERSION();
|
|
|
|
ImGui::CreateContext();
|
|
|
|
|
|
|
|
// configure io
|
|
|
|
ImGuiIO &io = ImGui::GetIO();
|
2025-07-07 15:13:05 +03:30
|
|
|
// NOLINTBEGIN
|
2025-07-05 13:28:41 +03:30
|
|
|
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
|
|
|
|
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
|
|
|
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;
|
|
|
|
io.ConfigFlags |= ImGuiBackendFlags_PlatformHasViewports;
|
|
|
|
io.ConfigFlags |= ImGuiBackendFlags_RendererHasViewports;
|
2025-07-07 15:13:05 +03:30
|
|
|
// NOLINTEND
|
2025-07-05 13:28:41 +03:30
|
|
|
|
|
|
|
// #todo: handle this in a better way
|
2025-07-06 17:45:40 +03:30
|
|
|
if (std::filesystem::exists("user_gui_layout.ini"))
|
|
|
|
{
|
2025-07-05 13:28:41 +03:30
|
|
|
io.IniFilename = "user_gui_layout.ini";
|
2025-07-06 17:45:40 +03:30
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2025-07-05 13:28:41 +03:30
|
|
|
io.IniFilename = "default_gui_layout.ini";
|
2025-07-06 17:45:40 +03:30
|
|
|
}
|
2025-07-05 13:28:41 +03:30
|
|
|
|
|
|
|
// style
|
|
|
|
ImGui::StyleColorsDark();
|
|
|
|
|
2025-07-06 16:52:50 +03:30
|
|
|
platform_implementation(windowHandle, std::move(sharedContext));
|
2025-07-05 13:28:41 +03:30
|
|
|
|
2025-07-06 14:03:04 +03:30
|
|
|
io.Fonts->AddFontFromFileTTF("data/assets/fonts/open_sans/OpenSans-Bold.ttf", 18.0f);
|
2025-07-05 13:28:41 +03:30
|
|
|
io.FontDefault = io.Fonts->AddFontFromFileTTF(
|
2025-07-06 14:03:04 +03:30
|
|
|
"data/assets/fonts/open_sans/OpenSans-Regular.ttf",
|
2025-07-05 13:28:41 +03:30
|
|
|
18.0f
|
|
|
|
);
|
|
|
|
|
2025-07-05 15:36:53 +03:30
|
|
|
set_dark_theme_colors();
|
2025-07-05 13:28:41 +03:30
|
|
|
}
|
|
|
|
|
2025-07-05 15:36:53 +03:30
|
|
|
void UserInterface::dockspace_begin()
|
2025-07-05 13:28:41 +03:30
|
|
|
{
|
|
|
|
ImGuiViewport *viewport = ImGui::GetMainViewport();
|
|
|
|
ImGui::SetNextWindowPos(viewport->Pos);
|
|
|
|
ImGui::SetNextWindowSize(viewport->Size);
|
|
|
|
ImGui::SetNextWindowViewport(viewport->ID);
|
|
|
|
|
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
|
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
|
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
|
2025-07-06 16:52:50 +03:30
|
|
|
ImGui::Begin("Dockspace", (bool *)nullptr, s_context->m_dockspace_flags);
|
2025-07-05 13:28:41 +03:30
|
|
|
ImGui::PopStyleVar(3);
|
|
|
|
|
|
|
|
ImGuiStyle &style = ImGui::GetStyle();
|
2025-07-06 16:52:50 +03:30
|
|
|
float const minWinSizeX = style.WindowMinSize.x;
|
2025-07-05 13:28:41 +03:30
|
|
|
style.WindowMinSize.x = 370.0f;
|
|
|
|
ImGui::DockSpace(
|
|
|
|
ImGui::GetID("MyDockSpace"),
|
|
|
|
ImVec2(0.0f, 0.0f),
|
2025-07-07 15:13:05 +03:30
|
|
|
ImGuiDockNodeFlags_None | ImGuiWindowFlags_NoBackground // NOLINT
|
2025-07-05 13:28:41 +03:30
|
|
|
);
|
2025-07-07 15:13:05 +03:30
|
|
|
|
2025-07-05 13:28:41 +03:30
|
|
|
style.WindowMinSize.x = minWinSizeX;
|
|
|
|
}
|
|
|
|
|
2025-07-05 15:36:53 +03:30
|
|
|
void UserInterface::dockspace_end()
|
2025-07-05 13:28:41 +03:30
|
|
|
{
|
|
|
|
ImGui::End();
|
|
|
|
}
|
|
|
|
|
2025-07-05 15:36:53 +03:30
|
|
|
void UserInterface::set_dark_theme_colors()
|
2025-07-05 13:28:41 +03:30
|
|
|
{
|
|
|
|
ImGuiStyle &style = ImGui::GetStyle();
|
2025-07-20 05:20:43 +03:30
|
|
|
ImVec4(&colors)[60] = style.Colors;
|
2025-07-05 13:28:41 +03:30
|
|
|
|
|
|
|
style.WindowPadding = ImVec2(0.0f, 0.0f);
|
|
|
|
|
|
|
|
colors[ImGuiCol_Text] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
|
|
|
|
colors[ImGuiCol_TextDisabled] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f);
|
|
|
|
|
|
|
|
colors[ImGuiCol_WindowBg] = ImVec4(0.10f, 0.10f, 0.11f, 1.00f);
|
|
|
|
colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
|
|
|
|
colors[ImGuiCol_PopupBg] = ImVec4(0.08f, 0.08f, 0.08f, 0.94f);
|
|
|
|
|
|
|
|
colors[ImGuiCol_Border] = ImVec4(0.43f, 0.43f, 0.50f, 0.50f);
|
|
|
|
colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
|
|
|
|
|
|
|
|
colors[ImGuiCol_FrameBg] = ImVec4(0.20f, 0.20f, 0.21f, 1.00f);
|
|
|
|
colors[ImGuiCol_FrameBgHovered] = ImVec4(0.30f, 0.31f, 0.31f, 1.00f);
|
|
|
|
colors[ImGuiCol_FrameBgActive] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
|
|
|
|
|
|
|
|
colors[ImGuiCol_TitleBg] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
|
|
|
|
colors[ImGuiCol_TitleBgActive] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
|
|
|
|
colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
|
|
|
|
|
|
|
|
colors[ImGuiCol_MenuBarBg] = ImVec4(0.14f, 0.14f, 0.14f, 1.00f);
|
|
|
|
|
|
|
|
colors[ImGuiCol_ScrollbarBg] = ImVec4(0.02f, 0.02f, 0.02f, 0.53f);
|
|
|
|
colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.31f, 0.31f, 0.31f, 1.00f);
|
|
|
|
colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f);
|
|
|
|
colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.51f, 0.51f, 0.51f, 1.00f);
|
|
|
|
|
|
|
|
colors[ImGuiCol_CheckMark] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
|
|
|
|
|
|
|
|
colors[ImGuiCol_SliderGrab] = ImVec4(0.24f, 0.52f, 0.88f, 1.00f);
|
|
|
|
colors[ImGuiCol_SliderGrabActive] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
|
|
|
|
|
|
|
|
colors[ImGuiCol_Button] = ImVec4(0.20f, 0.20f, 0.21f, 1.00f);
|
|
|
|
colors[ImGuiCol_ButtonHovered] = ImVec4(0.30f, 0.31f, 0.31f, 1.00f);
|
|
|
|
colors[ImGuiCol_ButtonActive] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
|
|
|
|
|
|
|
|
colors[ImGuiCol_Header] = ImVec4(0.20f, 0.20f, 0.21f, 1.00f);
|
|
|
|
colors[ImGuiCol_HeaderHovered] = ImVec4(0.30f, 0.31f, 0.31f, 1.00f);
|
|
|
|
colors[ImGuiCol_HeaderActive] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
|
|
|
|
|
|
|
|
colors[ImGuiCol_Separator] = ImVec4(0.43f, 0.43f, 0.50f, 0.50f);
|
|
|
|
colors[ImGuiCol_SeparatorHovered] = ImVec4(0.10f, 0.40f, 0.75f, 0.78f);
|
|
|
|
colors[ImGuiCol_SeparatorActive] = ImVec4(0.10f, 0.40f, 0.75f, 1.00f);
|
|
|
|
|
|
|
|
colors[ImGuiCol_ResizeGrip] = ImVec4(0.26f, 0.59f, 0.98f, 0.20f);
|
|
|
|
colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.67f);
|
|
|
|
colors[ImGuiCol_ResizeGripActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.95f);
|
|
|
|
|
|
|
|
colors[ImGuiCol_Tab] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
|
|
|
|
colors[ImGuiCol_TabHovered] = ImVec4(0.38f, 0.38f, 0.38f, 1.00f);
|
|
|
|
colors[ImGuiCol_TabActive] = ImVec4(0.28f, 0.28f, 0.28f, 1.00f);
|
|
|
|
colors[ImGuiCol_TabUnfocused] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
|
|
|
|
colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.20f, 0.20f, 0.21f, 1.00f);
|
|
|
|
|
|
|
|
colors[ImGuiCol_DockingPreview] = ImVec4(0.26f, 0.59f, 0.98f, 0.70f);
|
|
|
|
colors[ImGuiCol_DockingEmptyBg] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f);
|
|
|
|
|
|
|
|
colors[ImGuiCol_PlotLines] = ImVec4(0.61f, 0.61f, 0.61f, 1.00f);
|
|
|
|
colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 1.00f);
|
|
|
|
colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
|
|
|
|
colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f);
|
|
|
|
|
|
|
|
colors[ImGuiCol_TableHeaderBg] = ImVec4(0.19f, 0.19f, 0.20f, 1.00f);
|
|
|
|
colors[ImGuiCol_TableBorderStrong] = ImVec4(0.31f, 0.31f, 0.35f, 1.00f);
|
|
|
|
colors[ImGuiCol_TableBorderLight] = ImVec4(0.23f, 0.23f, 0.25f, 1.00f);
|
|
|
|
colors[ImGuiCol_TableRowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
|
|
|
|
colors[ImGuiCol_TableRowBgAlt] = ImVec4(1.00f, 1.00f, 1.00f, 0.06f);
|
|
|
|
|
|
|
|
colors[ImGuiCol_TextSelectedBg] = ImVec4(0.26f, 0.59f, 0.98f, 0.35f);
|
|
|
|
|
|
|
|
colors[ImGuiCol_DragDropTarget] = ImVec4(1.00f, 1.00f, 0.00f, 0.90f);
|
|
|
|
|
|
|
|
colors[ImGuiCol_NavHighlight] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
|
|
|
|
colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f);
|
|
|
|
colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.20f);
|
|
|
|
|
|
|
|
colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.35f);
|
|
|
|
}
|
|
|
|
|
2025-07-11 00:05:48 +03:30
|
|
|
} // namespace lt
|