diff --git a/include/td/display/ImGuiTheme.h b/include/td/display/ImGuiTheme.h new file mode 100644 index 0000000..3c450a7 --- /dev/null +++ b/include/td/display/ImGuiTheme.h @@ -0,0 +1,7 @@ +#pragma once + +namespace td { + +void LoadTheme(); + +} // namespace td diff --git a/src/td/display/Display.cpp b/src/td/display/Display.cpp index 19017ef..2ecda38 100644 --- a/src/td/display/Display.cpp +++ b/src/td/display/Display.cpp @@ -8,6 +8,7 @@ #include #include +#include namespace td { @@ -127,6 +128,7 @@ Display::Display(int a_Width, int a_Height, const std::string& a_Title) : // Setup Platform/Renderer backends ImGui_ImplSDL3_InitForOpenGL(m_Window, m_GLContext); ImGui_ImplOpenGL3_Init("#version 330"); + LoadTheme(); } void Display::Close() { diff --git a/src/td/display/ImGuiTheme.cpp b/src/td/display/ImGuiTheme.cpp new file mode 100644 index 0000000..34ac3c0 --- /dev/null +++ b/src/td/display/ImGuiTheme.cpp @@ -0,0 +1,88 @@ +#include + +#include + +namespace td { + +void LoadTheme() { + + static const bool bStyleDark_ = true; + static const float alpha_ = 0.8f; + + ImGuiStyle& style = ImGui::GetStyle(); + + // light style from PacĂ´me Danhiez (user itamago) https://github.com/ocornut/imgui/pull/511#issuecomment-175719267 + style.Alpha = 1.0f; + style.FrameRounding = 3.0f; + style.Colors[ImGuiCol_Text] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); + style.Colors[ImGuiCol_TextDisabled] = ImVec4(0.60f, 0.60f, 0.60f, 1.00f); + style.Colors[ImGuiCol_WindowBg] = ImVec4(0.94f, 0.94f, 0.94f, 0.94f); + // style.Colors[ImGuiCol_ChildWindowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); + style.Colors[ImGuiCol_PopupBg] = ImVec4(1.00f, 1.00f, 1.00f, 0.94f); + style.Colors[ImGuiCol_Border] = ImVec4(0.00f, 0.00f, 0.00f, 0.39f); + style.Colors[ImGuiCol_BorderShadow] = ImVec4(1.00f, 1.00f, 1.00f, 0.10f); + style.Colors[ImGuiCol_FrameBg] = ImVec4(1.00f, 1.00f, 1.00f, 0.94f); + style.Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.40f); + style.Colors[ImGuiCol_FrameBgActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.67f); + style.Colors[ImGuiCol_TitleBg] = ImVec4(0.96f, 0.96f, 0.96f, 1.00f); + style.Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(1.00f, 1.00f, 1.00f, 0.51f); + style.Colors[ImGuiCol_TitleBgActive] = ImVec4(0.82f, 0.82f, 0.82f, 1.00f); + style.Colors[ImGuiCol_MenuBarBg] = ImVec4(0.86f, 0.86f, 0.86f, 1.00f); + style.Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.98f, 0.98f, 0.98f, 0.53f); + style.Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.69f, 0.69f, 0.69f, 1.00f); + style.Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.59f, 0.59f, 0.59f, 1.00f); + style.Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.49f, 0.49f, 0.49f, 1.00f); + // style.Colors[ImGuiCol_ComboBg] = ImVec4(0.86f, 0.86f, 0.86f, 0.99f); + style.Colors[ImGuiCol_CheckMark] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); + style.Colors[ImGuiCol_SliderGrab] = ImVec4(0.24f, 0.52f, 0.88f, 1.00f); + style.Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); + style.Colors[ImGuiCol_Button] = ImVec4(0.26f, 0.59f, 0.98f, 0.40f); + style.Colors[ImGuiCol_ButtonHovered] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); + style.Colors[ImGuiCol_ButtonActive] = ImVec4(0.06f, 0.53f, 0.98f, 1.00f); + style.Colors[ImGuiCol_Header] = ImVec4(0.26f, 0.59f, 0.98f, 0.31f); + style.Colors[ImGuiCol_HeaderHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.80f); + style.Colors[ImGuiCol_HeaderActive] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); + // style.Colors[ImGuiCol_Column] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f); + // style.Colors[ImGuiCol_ColumnHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.78f); + // style.Colors[ImGuiCol_ColumnActive] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); + style.Colors[ImGuiCol_ResizeGrip] = ImVec4(1.00f, 1.00f, 1.00f, 0.50f); + style.Colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.67f); + style.Colors[ImGuiCol_ResizeGripActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.95f); + // style.Colors[ImGuiCol_CloseButton] = ImVec4(0.59f, 0.59f, 0.59f, 0.50f); + // style.Colors[ImGuiCol_CloseButtonHovered] = ImVec4(0.98f, 0.39f, 0.36f, 1.00f); + // style.Colors[ImGuiCol_CloseButtonActive] = ImVec4(0.98f, 0.39f, 0.36f, 1.00f); + style.Colors[ImGuiCol_PlotLines] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f); + style.Colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 1.00f); + style.Colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f); + style.Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f); + style.Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.26f, 0.59f, 0.98f, 0.35f); + // style.Colors[ImGuiCol_ModalWindowDarkening] = ImVec4(0.20f, 0.20f, 0.20f, 0.35f); + + if (bStyleDark_) { + for (int i = 0; i <= ImGuiCol_COUNT; i++) { + ImVec4& col = style.Colors[i]; + float H, S, V; + ImGui::ColorConvertRGBtoHSV(col.x, col.y, col.z, H, S, V); + + if (S < 0.1f) { + V = 1.0f - V; + } + ImGui::ColorConvertHSVtoRGB(H, S, V, col.x, col.y, col.z); + if (col.w < 1.00f) { + col.w *= alpha_; + } + } + } else { + for (int i = 0; i <= ImGuiCol_COUNT; i++) { + ImVec4& col = style.Colors[i]; + if (col.w < 1.00f) { + col.x *= alpha_; + col.y *= alpha_; + col.z *= alpha_; + col.w *= alpha_; + } + } + } +} + +} // namespace td