| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // This file is part of INSTINCT, the INS Toolkit for Integrated | ||
| 2 | // Navigation Concepts and Training by the Institute of Navigation of | ||
| 3 | // the University of Stuttgart, Germany. | ||
| 4 | // | ||
| 5 | // This Source Code Form is subject to the terms of the Mozilla Public | ||
| 6 | // License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| 7 | // file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
| 8 | |||
| 9 | #include "Spinner.hpp" | ||
| 10 | |||
| 11 | #include <imgui_internal.h> | ||
| 12 | |||
| 13 | #include <cmath> | ||
| 14 | |||
| 15 | ✗ | void NAV::gui::widgets::Spinner(const char* label, const ImU32& color, float radius, float thickness) | |
| 16 | { | ||
| 17 | ✗ | ImGuiWindow* window = ImGui::GetCurrentWindow(); | |
| 18 | ✗ | if (window->SkipItems) | |
| 19 | { | ||
| 20 | ✗ | return; | |
| 21 | } | ||
| 22 | |||
| 23 | ✗ | ImGuiContext& g = *GImGui; | |
| 24 | ✗ | const ImGuiStyle& style = g.Style; | |
| 25 | ✗ | const ImGuiID id = window->GetID(label); | |
| 26 | |||
| 27 | ✗ | ImVec2 pos = window->DC.CursorPos; | |
| 28 | ✗ | ImVec2 size((radius) * 2 + style.FramePadding.x, (radius + style.FramePadding.y) * 2); | |
| 29 | |||
| 30 | ✗ | const ImRect bb(pos, ImVec2(pos.x + size.x, pos.y + size.y)); | |
| 31 | ✗ | ImGui::ItemSize(bb, style.FramePadding.y); | |
| 32 | ✗ | if (!ImGui::ItemAdd(bb, id)) | |
| 33 | { | ||
| 34 | ✗ | return; | |
| 35 | } | ||
| 36 | |||
| 37 | // Render | ||
| 38 | ✗ | window->DrawList->PathClear(); | |
| 39 | |||
| 40 | ✗ | int num_segments = 30; | |
| 41 | ✗ | int start = static_cast<int>(std::abs(std::sin(g.Time * 1.8) * (num_segments - 5))); | |
| 42 | |||
| 43 | ✗ | const float a_min = IM_PI * 2.0F * static_cast<float>(start) / static_cast<float>(num_segments); | |
| 44 | ✗ | const float a_max = IM_PI * 2.0F * static_cast<float>(num_segments - 3) / static_cast<float>(num_segments); | |
| 45 | |||
| 46 | ✗ | const ImVec2 centre = ImVec2(pos.x + radius, pos.y + radius + style.FramePadding.y); | |
| 47 | |||
| 48 | ✗ | for (int i = 0; i < num_segments; i++) | |
| 49 | { | ||
| 50 | ✗ | const float a = a_min + (static_cast<float>(i) / static_cast<float>(num_segments)) * (a_max - a_min); | |
| 51 | ✗ | window->DrawList->PathLineTo(ImVec2(centre.x + ImCos(a + static_cast<float>(g.Time) * 8) * radius, | |
| 52 | ✗ | centre.y + ImSin(a + static_cast<float>(g.Time) * 8) * radius)); | |
| 53 | } | ||
| 54 | |||
| 55 | ✗ | window->DrawList->PathStroke(color, false, thickness); | |
| 56 | } | ||
| 57 |