diff --git a/examples/ggwave-gui/common.h b/examples/ggwave-gui/common.h index cfca418..11a6b10 100644 --- a/examples/ggwave-gui/common.h +++ b/examples/ggwave-gui/common.h @@ -298,15 +298,65 @@ void renderMain() { // volume ImGui::Text("%s", ""); + { + auto posSave = ImGui::GetCursorScreenPos(); + ImGui::Text("%s", ""); + ImGui::SetCursorScreenPos({ posSave.x + kLabelWidth, posSave.y }); + if (settings.volume < 0.2f) { + ImGui::TextColored({ 0.0f, 1.0f, 0.0f, 0.5f }, "Normal volume"); + } else if (settings.volume < 0.5f) { + ImGui::TextColored({ 1.0f, 1.0f, 0.0f, 0.5f }, "Intermediate volume"); + } else { + ImGui::TextColored({ 1.0f, 0.0f, 0.0f, 0.5f }, "Warning: high volume!"); + } + } { auto posSave = ImGui::GetCursorScreenPos(); ImGui::Text("Volume: "); ImGui::SetCursorScreenPos({ posSave.x + kLabelWidth, posSave.y }); } - ImGui::SliderFloat("##volume", &settings.volume, 0.0f, 1.0f); + { + auto p0 = ImGui::GetCursorScreenPos(); + + { + auto & cols = ImGui::GetStyle().Colors; + ImGui::PushStyleColor(ImGuiCol_FrameBg, cols[ImGuiCol_WindowBg]); + ImGui::PushStyleColor(ImGuiCol_FrameBgActive, cols[ImGuiCol_WindowBg]); + ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, cols[ImGuiCol_WindowBg]); + ImGui::SliderFloat("##volume", &settings.volume, 0.0f, 1.0f); + ImGui::PopStyleColor(3); + } + + auto posSave = ImGui::GetCursorScreenPos(); + ImGui::SameLine(); + auto p1 = ImGui::GetCursorScreenPos(); + p1.x -= ImGui::CalcTextSize(" ").x; + p1.y += ImGui::GetTextLineHeightWithSpacing() + 0.5f*style.ItemInnerSpacing.y; + ImGui::GetWindowDrawList()->AddRectFilledMultiColor( + p0, { 0.35f*(p0.x + p1.x), p1.y }, + ImGui::ColorConvertFloat4ToU32({0.0f, 1.0f, 0.0f, 0.5f}), + ImGui::ColorConvertFloat4ToU32({1.0f, 1.0f, 0.0f, 0.3f}), + ImGui::ColorConvertFloat4ToU32({1.0f, 1.0f, 0.0f, 0.3f}), + ImGui::ColorConvertFloat4ToU32({0.0f, 1.0f, 0.0f, 0.5f}) + ); + ImGui::GetWindowDrawList()->AddRectFilledMultiColor( + { 0.35f*(p0.x + p1.x), p0.y }, p1, + ImGui::ColorConvertFloat4ToU32({1.0f, 1.0f, 0.0f, 0.3f}), + ImGui::ColorConvertFloat4ToU32({1.0f, 0.0f, 0.0f, 0.5f}), + ImGui::ColorConvertFloat4ToU32({1.0f, 0.0f, 0.0f, 0.5f}), + ImGui::ColorConvertFloat4ToU32({1.0f, 1.0f, 0.0f, 0.3f}) + ); + ImGui::SetCursorScreenPos(posSave); + } // protocol ImGui::Text("%s", ""); + { + auto posSave = ImGui::GetCursorScreenPos(); + ImGui::Text("%s", ""); + ImGui::SetCursorScreenPos({ posSave.x + kLabelWidth, posSave.y }); + ImGui::TextDisabled("[U] = ultrasound"); + } { auto posSave = ImGui::GetCursorScreenPos(); ImGui::Text("Tx Protocol: "); diff --git a/examples/ggwave-gui/main.cpp b/examples/ggwave-gui/main.cpp index 5d05203..ec75df0 100644 --- a/examples/ggwave-gui/main.cpp +++ b/examples/ggwave-gui/main.cpp @@ -8,10 +8,10 @@ // ImGui helpers -bool ImGui_beginFrame(SDL_Window * window); -bool ImGui_endFrame(SDL_Window * window); +bool ImGui_BeginFrame(SDL_Window * window); +bool ImGui_EndFrame(SDL_Window * window); -bool ImGui_beginFrame(SDL_Window * window) { +bool ImGui_BeginFrame(SDL_Window * window) { SDL_Event event; while (SDL_PollEvent(&event)) { @@ -25,7 +25,7 @@ bool ImGui_beginFrame(SDL_Window * window) { return true; } -bool ImGui_endFrame(SDL_Window * window) { +bool ImGui_EndFrame(SDL_Window * window) { // Rendering int display_w, display_h; SDL_GetWindowSize(window, &display_w, &display_h); @@ -41,6 +41,72 @@ bool ImGui_endFrame(SDL_Window * window) { return true; } +bool ImGui_SetStyle() { + ImGuiStyle & style = ImGui::GetStyle(); + + style.AntiAliasedFill = false; + style.AntiAliasedLines = false; + style.WindowRounding = 0.0f; + + style.WindowPadding = ImVec2(8, 8); + style.WindowRounding = 0.0f; + style.FramePadding = ImVec2(4, 3); + style.FrameRounding = 0.0f; + style.ItemSpacing = ImVec2(8, 4); + style.ItemInnerSpacing = ImVec2(4, 4); + style.IndentSpacing = 21.0f; + style.ScrollbarSize = 16.0f; + style.ScrollbarRounding = 9.0f; + style.GrabMinSize = 10.0f; + style.GrabRounding = 3.0f; + + style.Colors[ImGuiCol_Text] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); + style.Colors[ImGuiCol_TextDisabled] = ImVec4(0.24f, 0.41f, 0.41f, 1.00f); + style.Colors[ImGuiCol_WindowBg] = ImVec4(0.08f, 0.08f, 0.08f, 0.94f); + //style.Colors[ImGuiCol_ChildWindowBg] = ImVec4(0.07f, 0.07f, 0.09f, 1.00f); + style.Colors[ImGuiCol_PopupBg] = ImVec4(0.07f, 0.07f, 0.09f, 1.00f); + style.Colors[ImGuiCol_Border] = ImVec4(0.31f, 0.31f, 0.31f, 0.71f); + style.Colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); + style.Colors[ImGuiCol_FrameBg] = ImVec4(0.00f, 0.39f, 0.39f, 0.39f); + style.Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.26f, 1.00f, 1.00f, 0.39f); + style.Colors[ImGuiCol_FrameBgActive] = ImVec4(0.00f, 0.78f, 0.00f, 1.00f); + style.Colors[ImGuiCol_TitleBg] = ImVec4(0.00f, 0.50f, 0.50f, 0.70f); + style.Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.00f, 0.50f, 0.50f, 1.00f); + style.Colors[ImGuiCol_TitleBgActive] = ImVec4(0.00f, 0.70f, 0.70f, 1.00f); + style.Colors[ImGuiCol_MenuBarBg] = ImVec4(0.00f, 0.70f, 0.70f, 1.00f); + style.Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.10f, 0.27f, 0.27f, 1.00f); + style.Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.80f, 0.80f, 0.83f, 0.31f); + style.Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.26f, 1.00f, 1.00f, 0.39f); + style.Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.00f, 0.78f, 0.00f, 1.00f); + //style.Colors[ImGuiCol_ComboBg] = ImVec4(0.00f, 0.39f, 0.39f, 1.00f); + style.Colors[ImGuiCol_CheckMark] = ImVec4(0.80f, 0.80f, 0.83f, 0.39f); + style.Colors[ImGuiCol_SliderGrab] = ImVec4(0.80f, 0.80f, 0.83f, 0.39f); + style.Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.00f, 0.78f, 0.00f, 1.00f); + style.Colors[ImGuiCol_Button] = ImVec4(0.13f, 0.55f, 0.55f, 1.00f); + style.Colors[ImGuiCol_ButtonHovered] = ImVec4(0.61f, 1.00f, 0.00f, 0.51f); + style.Colors[ImGuiCol_ButtonActive] = ImVec4(0.00f, 0.78f, 0.00f, 1.00f); + style.Colors[ImGuiCol_Header] = ImVec4(0.79f, 0.51f, 0.00f, 0.51f); + style.Colors[ImGuiCol_HeaderHovered] = ImVec4(0.79f, 0.51f, 0.00f, 0.67f); + style.Colors[ImGuiCol_HeaderActive] = ImVec4(0.79f, 0.51f, 0.00f, 0.67f); + //style.Colors[ImGuiCol_Column] = ImVec4(0.79f, 0.51f, 0.00f, 0.67f); + //style.Colors[ImGuiCol_ColumnHovered] = ImVec4(0.25f, 1.00f, 0.00f, 1.00f); + //style.Colors[ImGuiCol_ColumnActive] = ImVec4(0.79f, 0.51f, 0.00f, 0.67f); + style.Colors[ImGuiCol_ResizeGrip] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); + style.Colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.26f, 1.00f, 1.00f, 0.39f); + style.Colors[ImGuiCol_ResizeGripActive] = ImVec4(0.00f, 0.78f, 0.00f, 1.00f); + //style.Colors[ImGuiCol_CloseButton] = ImVec4(0.40f, 0.39f, 0.38f, 0.16f); + //style.Colors[ImGuiCol_CloseButtonHovered] = ImVec4(0.26f, 1.00f, 1.00f, 0.39f); + //style.Colors[ImGuiCol_CloseButtonActive] = ImVec4(0.79f, 0.51f, 0.00f, 0.67f); + style.Colors[ImGuiCol_PlotLines] = ImVec4(1.00f, 0.65f, 0.38f, 0.67f); + style.Colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.25f, 1.00f, 0.00f, 1.00f); + style.Colors[ImGuiCol_PlotHistogram] = ImVec4(1.00f, 0.65f, 0.38f, 0.67f); + style.Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(0.25f, 1.00f, 0.00f, 1.00f); + style.Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.25f, 1.00f, 0.00f, 0.43f); + style.Colors[ImGuiCol_ModalWindowDarkening] = ImVec4(1.00f, 0.98f, 0.95f, 0.78f); + + return true; +} + static SDL_Window * g_window; static void * g_gl_context; @@ -71,84 +137,21 @@ int main(int argc, char** argv) { SDL_GL_SetSwapInterval(1); // Enable vsync ImGui_Init(g_window, g_gl_context); + ImGui_SetStyle(); ImGui_NewFrame(g_window); ImGui::Render(); - { - ImGuiStyle & style = ImGui::GetStyle(); - - style.AntiAliasedFill = false; - style.AntiAliasedLines = false; - style.WindowRounding = 0.0f; - - style.WindowPadding = ImVec2(8, 8); - style.WindowRounding = 0.0f; - style.FramePadding = ImVec2(4, 3); - style.FrameRounding = 0.0f; - style.ItemSpacing = ImVec2(8, 4); - style.ItemInnerSpacing = ImVec2(4, 4); - style.IndentSpacing = 21.0f; - style.ScrollbarSize = 16.0f; - style.ScrollbarRounding = 9.0f; - style.GrabMinSize = 10.0f; - style.GrabRounding = 3.0f; - - style.Colors[ImGuiCol_Text] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); - style.Colors[ImGuiCol_TextDisabled] = ImVec4(0.24f, 0.41f, 0.41f, 1.00f); - style.Colors[ImGuiCol_WindowBg] = ImVec4(0.08f, 0.08f, 0.08f, 0.94f); - //style.Colors[ImGuiCol_ChildWindowBg] = ImVec4(0.07f, 0.07f, 0.09f, 1.00f); - style.Colors[ImGuiCol_PopupBg] = ImVec4(0.07f, 0.07f, 0.09f, 1.00f); - style.Colors[ImGuiCol_Border] = ImVec4(0.31f, 0.31f, 0.31f, 0.71f); - style.Colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); - style.Colors[ImGuiCol_FrameBg] = ImVec4(0.00f, 0.39f, 0.39f, 0.39f); - style.Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.26f, 1.00f, 1.00f, 0.39f); - style.Colors[ImGuiCol_FrameBgActive] = ImVec4(0.00f, 0.78f, 0.00f, 1.00f); - style.Colors[ImGuiCol_TitleBg] = ImVec4(0.00f, 0.50f, 0.50f, 0.70f); - style.Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.00f, 0.50f, 0.50f, 1.00f); - style.Colors[ImGuiCol_TitleBgActive] = ImVec4(0.00f, 0.70f, 0.70f, 1.00f); - style.Colors[ImGuiCol_MenuBarBg] = ImVec4(0.00f, 0.70f, 0.70f, 1.00f); - style.Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.10f, 0.27f, 0.27f, 1.00f); - style.Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.80f, 0.80f, 0.83f, 0.31f); - style.Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.26f, 1.00f, 1.00f, 0.39f); - style.Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.00f, 0.78f, 0.00f, 1.00f); - //style.Colors[ImGuiCol_ComboBg] = ImVec4(0.00f, 0.39f, 0.39f, 1.00f); - style.Colors[ImGuiCol_CheckMark] = ImVec4(0.80f, 0.80f, 0.83f, 0.39f); - style.Colors[ImGuiCol_SliderGrab] = ImVec4(0.80f, 0.80f, 0.83f, 0.39f); - style.Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.00f, 0.78f, 0.00f, 1.00f); - style.Colors[ImGuiCol_Button] = ImVec4(0.13f, 0.55f, 0.55f, 1.00f); - style.Colors[ImGuiCol_ButtonHovered] = ImVec4(0.61f, 1.00f, 0.00f, 0.51f); - style.Colors[ImGuiCol_ButtonActive] = ImVec4(0.00f, 0.78f, 0.00f, 1.00f); - style.Colors[ImGuiCol_Header] = ImVec4(0.79f, 0.51f, 0.00f, 0.51f); - style.Colors[ImGuiCol_HeaderHovered] = ImVec4(0.79f, 0.51f, 0.00f, 0.67f); - style.Colors[ImGuiCol_HeaderActive] = ImVec4(0.79f, 0.51f, 0.00f, 0.67f); - //style.Colors[ImGuiCol_Column] = ImVec4(0.79f, 0.51f, 0.00f, 0.67f); - //style.Colors[ImGuiCol_ColumnHovered] = ImVec4(0.25f, 1.00f, 0.00f, 1.00f); - //style.Colors[ImGuiCol_ColumnActive] = ImVec4(0.79f, 0.51f, 0.00f, 0.67f); - style.Colors[ImGuiCol_ResizeGrip] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); - style.Colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.26f, 1.00f, 1.00f, 0.39f); - style.Colors[ImGuiCol_ResizeGripActive] = ImVec4(0.00f, 0.78f, 0.00f, 1.00f); - //style.Colors[ImGuiCol_CloseButton] = ImVec4(0.40f, 0.39f, 0.38f, 0.16f); - //style.Colors[ImGuiCol_CloseButtonHovered] = ImVec4(0.26f, 1.00f, 1.00f, 0.39f); - //style.Colors[ImGuiCol_CloseButtonActive] = ImVec4(0.79f, 0.51f, 0.00f, 0.67f); - style.Colors[ImGuiCol_PlotLines] = ImVec4(1.00f, 0.65f, 0.38f, 0.67f); - style.Colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.25f, 1.00f, 0.00f, 1.00f); - style.Colors[ImGuiCol_PlotHistogram] = ImVec4(1.00f, 0.65f, 0.38f, 0.67f); - style.Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(0.25f, 1.00f, 0.00f, 1.00f); - style.Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.25f, 1.00f, 0.00f, 0.43f); - style.Colors[ImGuiCol_ModalWindowDarkening] = ImVec4(1.00f, 0.98f, 0.95f, 0.78f); - } - auto worker = initMain(); while (true) { - if (ImGui_beginFrame(g_window) == false) { + if (ImGui_BeginFrame(g_window) == false) { break; } renderMain(); - ImGui_endFrame(g_window); + ImGui_EndFrame(g_window); } deinitMain(worker);