Elevate Engine 1
Loading...
Searching...
No Matches
ImGuiLoadingIndicator.h
Go to the documentation of this file.
1#pragma once
2
3#include <imgui.h>
4#include <imgui_internal.h>
5
6namespace ImGui {
7 bool BufferingBar(const char* label, float value, const ImVec2& size_arg, const ImU32& bg_col, const ImU32& fg_col) {
8 ImGuiWindow* window = GetCurrentWindow();
9 if (window->SkipItems)
10 return false;
11
12 ImGuiContext& g = *GImGui;
13 const ImGuiStyle& style = g.Style;
14 const ImGuiID id = window->GetID(label);
15
16 ImVec2 pos = window->DC.CursorPos;
17 ImVec2 size = size_arg;
18 size.x -= style.FramePadding.x * 2.0f;
19
20 const ImRect bb(pos, ImVec2(pos.x + size.x, pos.y + size.y));
21 ItemSize(bb, style.FramePadding.y);
22 if (!ItemAdd(bb, id))
23 return false;
24
25 // Render
26 const float circleStart = size.x * 0.7f;
27 const float circleEnd = size.x;
28 const float circleWidth = circleEnd - circleStart;
29
30 window->DrawList->AddRectFilled(bb.Min, ImVec2(pos.x + circleStart, bb.Max.y), bg_col);
31 window->DrawList->AddRectFilled(bb.Min, ImVec2(pos.x + circleStart*value, bb.Max.y), fg_col);
32
33 const float t = (float) g.Time;
34 const float r = size.y / 2.0f;
35 const float speed = 1.5f;
36
37 const float a = speed*0;
38 const float b = speed*0.333f;
39 const float c = speed*0.666f;
40
41 const float o1 = (circleWidth+r) * (t+a - speed * (int)((t+a) / speed)) / speed;
42 const float o2 = (circleWidth+r) * (t+b - speed * (int)((t+b) / speed)) / speed;
43 const float o3 = (circleWidth+r) * (t+c - speed * (int)((t+c) / speed)) / speed;
44
45 window->DrawList->AddCircleFilled(ImVec2(pos.x + circleEnd - o1, bb.Min.y + r), r, bg_col);
46 window->DrawList->AddCircleFilled(ImVec2(pos.x + circleEnd - o2, bb.Min.y + r), r, bg_col);
47 window->DrawList->AddCircleFilled(ImVec2(pos.x + circleEnd - o3, bb.Min.y + r), r, bg_col);
48 return true;
49 }
50
51 bool Spinner(const char* label, float radius, int thickness, const ImU32& color) {
52 ImGuiWindow* window = GetCurrentWindow();
53 if (window->SkipItems)
54 return false;
55
56 ImGuiContext& g = *GImGui;
57 const ImGuiStyle& style = g.Style;
58 const ImGuiID id = window->GetID(label);
59
60 ImVec2 pos = window->DC.CursorPos;
61 ImVec2 size((radius )*2, (radius + style.FramePadding.y)*2);
62
63 const ImRect bb(pos, ImVec2(pos.x + size.x, pos.y + size.y));
64 ItemSize(bb, style.FramePadding.y);
65 if (!ItemAdd(bb, id))
66 return false;
67
68 // Render
69 window->DrawList->PathClear();
70
71 int num_segments = 30;
72 int start = (int) abs(ImSin((float)g.Time*1.8f)*(num_segments-5));
73
74 const float a_min = IM_PI*2.0f * ((float)start) / (float)num_segments;
75 const float a_max = IM_PI*2.0f * ((float)num_segments-3) / (float)num_segments;
76
77 const ImVec2 centre = ImVec2(pos.x+radius, pos.y+radius+style.FramePadding.y);
78
79 for (int i = 0; i < num_segments; i++) {
80 const float a = a_min + ((float)i / (float)num_segments) * (a_max - a_min);
81 window->DrawList->PathLineTo(ImVec2(centre.x + ImCos(a+(float)g.Time*8.0f) * radius,
82 centre.y + ImSin(a+(float)g.Time*8.0f) * radius));
83 }
84
85 window->DrawList->PathStroke(color, false, (float)thickness);
86 return true;
87 }
88}
bool Spinner(const char *label, float radius, int thickness, const ImU32 &color)
bool BufferingBar(const char *label, float value, const ImVec2 &size_arg, const ImU32 &bg_col, const ImU32 &fg_col)