1
0
Fork 0
mirror of https://github.com/gwm17/implot.git synced 2024-11-23 02:38:53 -05:00

Merge pull request #41 from sergeyn/pr_branch

Fixes issues when using 16-bit indices. Slight performance gains. Refactors how offsetting data works in the implementation. Improves Offset and Stride demo.
This commit is contained in:
Evan Pezent 2020-06-07 13:18:52 -05:00 committed by GitHub
commit c0bea59c58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 376 additions and 301 deletions

File diff suppressed because it is too large Load Diff

View File

@ -160,6 +160,12 @@ void ShowDemoWindow(bool* p_open) {
ImGui::Unindent(); ImGui::Unindent();
ImGui::BulletText("Double right click to open the plot context menu."); ImGui::BulletText("Double right click to open the plot context menu.");
ImGui::BulletText("Click legend label icons to show/hide plot items."); ImGui::BulletText("Click legend label icons to show/hide plot items.");
ImGui::BulletText("IMPORTANT: By default, anti-aliased lines are turned OFF.");
ImGui::Indent();
ImGui::BulletText("Software AA can be enabled per plot with ImPlotFlags_AntiAliased.");
ImGui::BulletText("AA for demo plots can be enabled from the plot's context menu.");
ImGui::BulletText("If allowable, you are better off using hardware AA (e.g. MSAA).");
ImGui::Unindent();
#ifdef IMPLOT_DEMO_USE_DOUBLE #ifdef IMPLOT_DEMO_USE_DOUBLE
ImGui::BulletText("The demo data precision is: double"); ImGui::BulletText("The demo data precision is: double");
#else #else
@ -831,18 +837,37 @@ void ShowDemoWindow(bool* p_open) {
} }
} }
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Offset Data")) { if (ImGui::CollapsingHeader("Offset and Stride")) {
t_float xs[50], ys[50]; static const int k_circles = 11;
for (int i = 0; i < 50; ++i) { static const int k_points_per = 50;
xs[i] = 0.5f + 0.4f * Cos(i/50.f * 6.28f); static const int k_size = 2 * k_points_per * k_circles;
ys[i] = 0.5f + 0.4f * Sin(i/50.f * 6.28f); static t_float interleaved_data[k_size];
for (int p = 0; p < k_points_per; ++p) {
for (int c = 0; c < k_circles; ++c) {
t_float r = (t_float)c / (k_circles - 1) * 0.2f + 0.2f;
interleaved_data[p*2*k_circles + 2*c + 0] = 0.5f + r * Cos((t_float)p/k_points_per * 6.28f);
interleaved_data[p*2*k_circles + 2*c + 1] = 0.5f + r * Sin((t_float)p/k_points_per * 6.28f);
}
} }
static int offset = 0; static int offset = 0;
ImGui::SliderInt("Offset", &offset, -100, 100); ImGui::BulletText("Offsetting is useful for realtime plots (see above) and circular buffers.");
if (ImPlot::BeginPlot("##offset")) { ImGui::BulletText("Striding is useful for interleaved data (e.g. audio) or plotting structs.");
ImPlot::PlotLine("circle", xs, ys, 50, offset); ImGui::BulletText("Here, all circle data is stored in a single interleaved buffer:");
ImGui::BulletText("[c0.x0 c0.y0 ... cn.x0 cn.y0 c0.x1 c0.y1 ... cn.x1 cn.y1 ... cn.xm cn.ym]");
ImGui::BulletText("The offset value indicates which circle point index is considered the first.");
ImGui::BulletText("Offsets can be negative and/or larger than the actual data count.");
ImGui::SliderInt("Offset", &offset, -2*k_points_per, 2*k_points_per);
if (ImPlot::BeginPlot("##strideoffset")) {
ImPlot::SetColormap(ImPlotColormap_Jet);
char buff[16];
for (int c = 0; c < k_circles; ++c) {
sprintf(buff, "Circle %d", c);
ImPlot::PlotLine(buff, &interleaved_data[c*2 + 0], &interleaved_data[c*2 + 1], k_points_per, offset, 2*k_circles*sizeof(t_float));
}
ImPlot::EndPlot(); ImPlot::EndPlot();
ImPlot::SetColormap(ImPlotColormap_Default);
} }
// offset++; uncomment for animation!
} }
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Custom Ticks")) { if (ImGui::CollapsingHeader("Custom Ticks")) {