From de3c881c46e3350fdd28d591f7a3433196284f66 Mon Sep 17 00:00:00 2001 From: clrnd Date: Fri, 17 Nov 2017 00:52:50 -0300 Subject: [PATCH 1/3] using PolyLine and drawing less points --- src/widgets.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/widgets.cpp b/src/widgets.cpp index 7bc40b6..10db0f0 100644 --- a/src/widgets.cpp +++ b/src/widgets.cpp @@ -321,15 +321,17 @@ void renderBankGrid(const char *name, float height, int gridWidth, float *gridX, // Draw lines ImGui::PushClipRect(cellBox.Min, cellBox.Max, true); - ImVec2 lastPos; - for (int i = 0; i < WAVE_LEN; i++) { + int divisor = 8; // only draw an eigth of the points plus the last one + std::vector points; + points.reserve(1 + WAVE_LEN/divisor); + for (int i = 0; i < 1 + WAVE_LEN; i += divisor) { float value = currentBank.waves[j].postSamples[i]; float margin = 3.0; ImVec2 pos = ImVec2(rescalef(i, 0, WAVE_LEN - 1, cellBox.Min.x, cellBox.Max.x), rescalef(value, 1.0, -1.0, cellBox.Min.y + margin, cellBox.Max.y - margin)); - if (i > 0) - window->DrawList->AddLine(lastPos, pos, ImGui::GetColorU32(ImGuiCol_PlotLines)); - lastPos = pos; + points.emplace_back(pos); } + window->DrawList->AddPolyline(points.data(), 1 + WAVE_LEN/divisor, ImGui::GetColorU32(ImGuiCol_PlotLines), false, 1.0, false); + // Draw cell label char label[64]; From 349046aae5680727f60cf6b7f919a2b5989c03e6 Mon Sep 17 00:00:00 2001 From: clrnd Date: Fri, 17 Nov 2017 01:05:32 -0300 Subject: [PATCH 2/3] nicer way to handle indices --- src/widgets.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/widgets.cpp b/src/widgets.cpp index 10db0f0..443cc36 100644 --- a/src/widgets.cpp +++ b/src/widgets.cpp @@ -321,15 +321,22 @@ void renderBankGrid(const char *name, float height, int gridWidth, float *gridX, // Draw lines ImGui::PushClipRect(cellBox.Min, cellBox.Max, true); - int divisor = 8; // only draw an eigth of the points plus the last one + // We only draw an eigth of the points plus the last one + int divisor = 4; std::vector points; points.reserve(1 + WAVE_LEN/divisor); - for (int i = 0; i < 1 + WAVE_LEN; i += divisor) { + for (int i = 0; i < WAVE_LEN; i += divisor) { float value = currentBank.waves[j].postSamples[i]; float margin = 3.0; ImVec2 pos = ImVec2(rescalef(i, 0, WAVE_LEN - 1, cellBox.Min.x, cellBox.Max.x), rescalef(value, 1.0, -1.0, cellBox.Min.y + margin, cellBox.Max.y - margin)); points.emplace_back(pos); } + + // last point + float value = currentBank.waves[j].postSamples[WAVE_LEN - 1]; + float margin = 3.0; + ImVec2 pos = ImVec2(rescalef(WAVE_LEN - 1, 0, WAVE_LEN - 1, cellBox.Min.x, cellBox.Max.x), rescalef(value, 1.0, -1.0, cellBox.Min.y + margin, cellBox.Max.y - margin)); + points.emplace_back(pos); window->DrawList->AddPolyline(points.data(), 1 + WAVE_LEN/divisor, ImGui::GetColorU32(ImGuiCol_PlotLines), false, 1.0, false); From 87a10d476b466f92adae4118643c4b34bc6786a0 Mon Sep 17 00:00:00 2001 From: clrnd Date: Fri, 17 Nov 2017 01:08:50 -0300 Subject: [PATCH 3/3] typo --- src/widgets.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widgets.cpp b/src/widgets.cpp index 443cc36..87aa9a0 100644 --- a/src/widgets.cpp +++ b/src/widgets.cpp @@ -321,7 +321,7 @@ void renderBankGrid(const char *name, float height, int gridWidth, float *gridX, // Draw lines ImGui::PushClipRect(cellBox.Min, cellBox.Max, true); - // We only draw an eigth of the points plus the last one + // We only draw a fourth of the points plus the last one int divisor = 4; std::vector points; points.reserve(1 + WAVE_LEN/divisor);