From 1df2e91812719e2976fda07c7a90333fcbe1de7d Mon Sep 17 00:00:00 2001 From: Nick Renieris Date: Sat, 27 Apr 2019 01:39:19 +0300 Subject: [PATCH] gui: Add Cherry imgui theme From here: https://github.com/ocornut/imgui/issues/707#issuecomment-430613104 --- src/gui/gui.cpp | 94 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 85 insertions(+), 9 deletions(-) diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 11cd0e7..dc1da29 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -50,13 +50,75 @@ __declspec(dllexport) uint32_t AmdPowerXpressRequestHighPerformance = 1; namespace gui { -static void gl_after_callback(const glbinding::FunctionCall& fn) { - for (GLenum error = glGetError(); error != GL_NO_ERROR; error = glGetError()) { - std::stringstream gl_error; - gl_error << error; - LOG_ERROR("OpenGL: {} set error {}.", fn.function->name(), gl_error.str()); - assert(0); - } +void init_theme() { + // cherry colors, 3 intensities +#define HI(v) ImVec4(0.502f, 0.075f, 0.256f, v) +#define MED(v) ImVec4(0.455f, 0.198f, 0.301f, v) +#define LOW(v) ImVec4(0.232f, 0.201f, 0.271f, v) +// backgrounds (@todo: complete with BG_MED, BG_LOW) +#define BG(v) ImVec4(0.200f, 0.220f, 0.270f, v) +// text +#define TEXT(v) ImVec4(0.860f, 0.930f, 0.890f, v) + + auto& style = ImGui::GetStyle(); + style.Colors[ImGuiCol_Text] = TEXT(0.78f); + style.Colors[ImGuiCol_TextDisabled] = TEXT(0.28f); + style.Colors[ImGuiCol_WindowBg] = ImVec4(0.13f, 0.14f, 0.17f, 1.00f); + style.Colors[ImGuiCol_ChildWindowBg] = BG(0.58f); + style.Colors[ImGuiCol_PopupBg] = BG(0.9f); + style.Colors[ImGuiCol_Border] = ImVec4(0.31f, 0.31f, 1.00f, 0.00f); + style.Colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); + style.Colors[ImGuiCol_FrameBg] = BG(1.00f); + style.Colors[ImGuiCol_FrameBgHovered] = MED(0.78f); + style.Colors[ImGuiCol_FrameBgActive] = MED(1.00f); + style.Colors[ImGuiCol_TitleBg] = LOW(1.00f); + style.Colors[ImGuiCol_TitleBgActive] = HI(1.00f); + style.Colors[ImGuiCol_TitleBgCollapsed] = BG(0.75f); + style.Colors[ImGuiCol_MenuBarBg] = BG(0.47f); + style.Colors[ImGuiCol_ScrollbarBg] = BG(1.00f); + style.Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.09f, 0.15f, 0.16f, 1.00f); + style.Colors[ImGuiCol_ScrollbarGrabHovered] = MED(0.78f); + style.Colors[ImGuiCol_ScrollbarGrabActive] = MED(1.00f); + style.Colors[ImGuiCol_CheckMark] = ImVec4(0.71f, 0.22f, 0.27f, 1.00f); + style.Colors[ImGuiCol_SliderGrab] = ImVec4(0.47f, 0.77f, 0.83f, 0.14f); + style.Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.71f, 0.22f, 0.27f, 1.00f); + style.Colors[ImGuiCol_Button] = ImVec4(0.47f, 0.77f, 0.83f, 0.14f); + style.Colors[ImGuiCol_ButtonHovered] = MED(0.86f); + style.Colors[ImGuiCol_ButtonActive] = MED(1.00f); + style.Colors[ImGuiCol_Header] = MED(0.76f); + style.Colors[ImGuiCol_HeaderHovered] = MED(0.86f); + style.Colors[ImGuiCol_HeaderActive] = HI(1.00f); + style.Colors[ImGuiCol_Column] = ImVec4(0.14f, 0.16f, 0.19f, 1.00f); + style.Colors[ImGuiCol_ColumnHovered] = MED(0.78f); + style.Colors[ImGuiCol_ColumnActive] = MED(1.00f); + style.Colors[ImGuiCol_ResizeGrip] = ImVec4(0.47f, 0.77f, 0.83f, 0.04f); + style.Colors[ImGuiCol_ResizeGripHovered] = MED(0.78f); + style.Colors[ImGuiCol_ResizeGripActive] = MED(1.00f); + style.Colors[ImGuiCol_PlotLines] = TEXT(0.63f); + style.Colors[ImGuiCol_PlotLinesHovered] = MED(1.00f); + style.Colors[ImGuiCol_PlotHistogram] = TEXT(0.63f); + style.Colors[ImGuiCol_PlotHistogramHovered] = MED(1.00f); + style.Colors[ImGuiCol_TextSelectedBg] = MED(0.43f); + style.Colors[ImGuiCol_ModalWindowDarkening] = BG(0.73f); + + style.WindowPadding = ImVec2(6, 4); + style.WindowRounding = 0.0f; + style.FramePadding = ImVec2(5, 2); + style.FrameRounding = 3.0f; + style.ItemSpacing = ImVec2(7, 1); + style.ItemInnerSpacing = ImVec2(1, 1); + style.TouchExtraPadding = ImVec2(0, 0); + style.IndentSpacing = 6.0f; + style.ScrollbarSize = 12.0f; + style.ScrollbarRounding = 16.0f; + style.GrabMinSize = 20.0f; + style.GrabRounding = 2.0f; + + style.WindowTitleAlign.x = 0.50f; + + style.Colors[ImGuiCol_Border] = ImVec4(0.539f, 0.479f, 0.255f, 0.162f); + style.FrameBorderSize = 0.0f; + style.WindowBorderSize = 1.0f; } void Gui::init() { @@ -91,14 +153,28 @@ void Gui::init() { return reinterpret_cast(SDL_GL_GetProcAddress(name)); }; glbinding::initialize(get_proc_address, false); - // glbinding::setCallbackMaskExcept(glbinding::CallbackMask::Before | glbinding::CallbackMask::After, - // { "glGetError" }); + + // On Debug builds, check every OpenGL call +#if !NDEBUG + auto gl_after_callback = [](const glbinding::FunctionCall& fn) { + for (GLenum error = glGetError(); error != GL_NO_ERROR; error = glGetError()) { + std::stringstream gl_error; + gl_error << error; + LOG_ERROR("OpenGL: {} error {}.", fn.function->name(), gl_error.str()); + assert(0); + } + }; + + glbinding::setCallbackMaskExcept(glbinding::CallbackMask::After, { "glGetError" }); glbinding::setAfterCallback(gl_after_callback); +#endif // Set-up imgui context IMGUI_CHECKVERSION(); ImGui::CreateContext(); + init_theme(); + // Setup platform/renderer bindings ImGui_ImplSDL2_InitForOpenGL(m_window, m_gl_context); ImGui_ImplOpenGL3_Init("#version 330 core");