Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using PolyLine and drawing less points. #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,16 +321,25 @@ 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++) {
// We only draw a fourth of the points plus the last one
int divisor = 4;
std::vector<ImVec2> points;
points.reserve(1 + WAVE_LEN/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));
if (i > 0)
window->DrawList->AddLine(lastPos, pos, ImGui::GetColorU32(ImGuiCol_PlotLines));
lastPos = pos;
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);


// Draw cell label
char label[64];
snprintf(label, sizeof(label), "%d", j);
Expand Down