./
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
0 / 48
0.0%
Branches:
0 / 70
0.0%
Functions:
0 / 5
0.0%

libs/imgui/src/eu/imgui/scurve.cc
Line Branch Exec Source
1 #include "eu/imgui/scurve.h"
2
3 #include "eu/assert/assert.h"
4 #include "eu/base/cint.h"
5
6 #include "eu/imgui/ui.h"
7
8 #include "dear_imgui/imgui.h"
9
10 #include <cmath>
11
12 #include "eu/core/scurve.h"
13
14 namespace eu::imgui
15 {
16
17 ✗ SCurveGuiState::SCurveGuiState(float x, float y)
18 ✗ : drag(x, y)
19 {
20 ✗ }
21
22 ✗ SCurveGuiState SCurveGuiState::light_curve()
23 {
24 ✗ return {0.2f, 0.0f};
25 }
26
27 ✗ bool imgui_s_curve_editor(const char* title, core::SCurve* curve, SCurveGuiState* gui, FlipX flip_x, const SCurveImguiSettings& settings, bool force_init_curve)
28 {
29
0/4
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 70 not taken.
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 68 not taken.
✗ imgui_text(fmt::format("{} ({} {})", title, curve->slope, curve->threshold));
30
0/4
✗ Branch 5 → 6 not taken.
✗ Branch 5 → 7 not taken.
✗ Branch 8 → 9 not taken.
✗ Branch 8 → 77 not taken.
✗ if (ImGui::BeginChild(title, settings.widget_size, settings.widget_border ? ImGuiChildFlags_Borders : ImGuiChildFlags_None, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoMove)
31
0/2
✗ Branch 9 → 10 not taken.
✗ Branch 9 → 12 not taken.
✗ == false)
32 {
33
0/2
✗ Branch 10 → 11 not taken.
✗ Branch 10 → 77 not taken.
✗ ImGui::EndChild();
34 ✗ return false;
35 }
36
37 ✗ auto& points = gui->point_cache;
38
39 ✗ bool changed = false;
40
41
0/2
✗ Branch 12 → 13 not taken.
✗ Branch 12 → 77 not taken.
✗ const auto widget_position = ImGui::GetWindowPos();
42
0/2
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 77 not taken.
✗ const auto widget_size = ImGui::GetWindowSize();
43
44
0/2
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 77 not taken.
✗ auto* draw = ImGui::GetWindowDrawList();
45
0/2
✗ Branch 16 → 17 not taken.
✗ Branch 16 → 72 not taken.
✗ draw->AddRectFilled(widget_position, widget_position + widget_size, settings.background_color);
46
47
48
0/2
✗ Branch 18 → 19 not taken.
✗ Branch 18 → 20 not taken.
✗ if (points.max_size() != settings.num_points)
49 {
50
0/2
✗ Branch 19 → 20 not taken.
✗ Branch 19 → 77 not taken.
✗ points.resize(settings.num_points);
51 }
52
0/2
✗ Branch 29 → 21 not taken.
✗ Branch 29 → 30 not taken.
✗ for (std::size_t point_index = 0; point_index < settings.num_points; point_index += 1)
53 {
54 ✗ const float srcx = static_cast<float>(point_index) / static_cast<float>(settings.num_points - 1); // -1 here to include 1.0f when evaluating the curve
55
0/2
✗ Branch 21 → 22 not taken.
✗ Branch 21 → 23 not taken.
✗ const float x = flip_x == FlipX::yes? 1 - srcx : srcx;
56
0/2
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 77 not taken.
✗ const float y = core::calculate_s_curve(srcx, curve->slope, curve->threshold);
57 ✗ points[point_index] = ImVec2{x * widget_size.x, (1 - y) * widget_size.y} + widget_position;
58 }
59
0/2
✗ Branch 32 → 33 not taken.
✗ Branch 32 → 77 not taken.
✗ draw->AddPolyline(points.data(), int_from_sizet(settings.num_points), settings.line_color, ImDrawFlags_None, 1.0f);
60
61
0/2
✗ Branch 33 → 34 not taken.
✗ Branch 33 → 39 not taken.
✗ if (settings.draw_points)
62 {
63
0/2
✗ Branch 38 → 35 not taken.
✗ Branch 38 → 39 not taken.
✗ for (std::size_t point_index = 0; point_index < settings.num_points; point_index += 1)
64 {
65
0/2
✗ Branch 36 → 37 not taken.
✗ Branch 36 → 77 not taken.
✗ draw->AddCircleFilled(points[point_index], settings.point_radius, settings.point_color);
66 }
67 }
68
0/2
✗ Branch 41 → 42 not taken.
✗ Branch 41 → 73 not taken.
✗ draw->AddCircleFilled(ImVec2{gui->drag.x * widget_size.x, (1 - gui->drag.y) * widget_size.y} + widget_position, settings.drag_radius, settings.drag_color);
69
70 ✗ const auto t01 = [&widget_position, &widget_size](const ImVec2& mp)
71 {
72 ✗ const auto x = (mp.x - widget_position.x) / widget_size.x;
73 ✗ const auto y = 1 - ((mp.y - widget_position.y) / widget_size.y);
74 ✗ return ImVec2{x, y};
75 ✗ };
76
77 ✗ const auto within01 = [](const ImVec2& p)
78 {
79 #define T(s) \
80 do \
81 { \
82 if ((s) < 0.0f || (s) > 1.0f) \
83 return false; \
84 } while (false)
85
0/4
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 4 not taken.
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 5 not taken.
✗ T(p.x);
86
0/4
✗ Branch 5 → 6 not taken.
✗ Branch 5 → 7 not taken.
✗ Branch 6 → 7 not taken.
✗ Branch 6 → 8 not taken.
✗ T(p.y);
87 ✗ return true;
88 #undef T
89 };
90
91
0/10
✗ Branch 42 → 43 not taken.
✗ Branch 42 → 75 not taken.
✗ Branch 43 → 44 not taken.
✗ Branch 43 → 49 not taken.
✗ Branch 44 → 45 not taken.
✗ Branch 44 → 75 not taken.
✗ Branch 47 → 48 not taken.
✗ Branch 47 → 49 not taken.
✗ Branch 50 → 51 not taken.
✗ Branch 50 → 58 not taken.
✗ if (ImGui::IsMouseDown(settings.button) && within01(t01(ImGui::GetIO().MouseClickedPos[settings.button])))
92 {
93 // mouse is down and drag started inside the component
94
0/2
✗ Branch 51 → 52 not taken.
✗ Branch 51 → 76 not taken.
✗ const auto mp = ImGui::GetMousePos();
95 ✗ const auto n = t01(mp);
96 ✗ gui->drag.x = std::min(1.0f, std::max(n.x, 0.0f));
97 ✗ gui->drag.y = std::min(1.0f, std::max(n.y, 0.0f));
98 ✗ changed = true;
99 }
100
101
0/4
✗ Branch 58 → 59 not taken.
✗ Branch 58 → 60 not taken.
✗ Branch 59 → 60 not taken.
✗ Branch 59 → 64 not taken.
✗ if (changed || force_init_curve)
102 {
103
0/4
✗ Branch 60 → 61 not taken.
✗ Branch 60 → 62 not taken.
✗ Branch 63 → 64 not taken.
✗ Branch 63 → 77 not taken.
✗ *curve = core::s_curve_from_input(flip_x == FlipX::yes ? 1 - gui->drag.x : gui->drag.x, gui->drag.y);
104 }
105
106
0/2
✗ Branch 64 → 65 not taken.
✗ Branch 64 → 77 not taken.
✗ ImGui::EndChild();
107
108 ✗ return changed;
109 }
110
111 } // namespace eu::imgui_extra
112