From b84e74b885748cd50dbc2b657337c8bfe37d1028 Mon Sep 17 00:00:00 2001 From: epezent Date: Tue, 25 Aug 2020 22:47:03 -0500 Subject: [PATCH] add global AA variable to ImPlotStyle --- implot.cpp | 13 +++++++++++-- implot.h | 4 ++-- implot_demo.cpp | 7 ++++++- implot_items.cpp | 2 +- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/implot.cpp b/implot.cpp index 1a818e0..5d3b635 100644 --- a/implot.cpp +++ b/implot.cpp @@ -31,6 +31,7 @@ Below is a change-log of API breaking changes only. If you are using one of the When you are not sure about a old symbol or function name, try using the Search/Find function of your IDE to look for comments or references in all implot files. You can read releases logs https://github.com/epezent/implot/releases for more details. +- 2020/08/25 (0.5) - ImPlotAxisFlags_Scientific was removed. Logarithmic axes automatically uses scientific notation. - 2020/08/17 (0.5) - PlotText was changed so that text is centered horizontally and vertically about the desired point. - 2020/08/16 (0.5) - An ImPlotContext must be explicitly created and destroyed now with `CreateContext` and `DestroyContext`. Previously, the context was statically initialized in this source file. - 2020/06/13 (0.4) - The flags `ImPlotAxisFlag_Adaptive` and `ImPlotFlags_Cull` were removed. Both are now done internally by default. @@ -103,7 +104,8 @@ ImPlotStyle::ImPlotStyle() { ErrorBarWeight = 1.5f; DigitalBitHeight = 8; DigitalBitGap = 4; - + AntiAliasedLines = false; + PlotBorderSize = 1; MinorAlpha = 0.25f; MajorTickLen = ImVec2(10,10); @@ -609,11 +611,14 @@ void AddTicksLogarithmic(const ImPlotRange& range, int nMajor, ImPlotTickCollect void AddTicksCustom(const double* values, const char** labels, int n, ImPlotTickCollection& ticks) { for (int i = 0; i < n; ++i) { ImPlotTick tick(values[i], false, true); - tick.BufferOffset = ticks.Labels.size(); if (labels != NULL) { + tick.BufferOffset = ticks.Labels.size(); ticks.Labels.append(labels[i], labels[i] + strlen(labels[i]) + 1); tick.LabelSize = ImGui::CalcTextSize(labels[i]); } + else { + LabelTickDefault(tick, ticks.Labels); + } ticks.AddTick(tick); } } @@ -2315,6 +2320,10 @@ void ShowStyleEditor(ImPlotStyle* ref) { ImGui::SliderFloat("ErrorBarWeight", &style.ErrorBarWeight, 0.0f, 5.0f, "%.1f"); ImGui::SliderFloat("DigitalBitHeight", &style.DigitalBitHeight, 0.0f, 20.0f, "%.1f"); ImGui::SliderFloat("DigitalBitGap", &style.DigitalBitGap, 0.0f, 20.0f, "%.1f"); + float indent = ImGui::CalcItemWidth() - ImGui::GetFrameHeight(); + ImGui::Indent(ImGui::CalcItemWidth() - ImGui::GetFrameHeight()); + ImGui::Checkbox("AntiAliasedLines", &style.AntiAliasedLines); + ImGui::Unindent(indent); ImGui::Text("Plot Styling"); ImGui::SliderFloat("PlotBorderSize", &style.PlotBorderSize, 0.0f, 2.0f, "%.0f"); ImGui::SliderFloat("MinorAlpha", &style.MinorAlpha, 0.0f, 1.0f, "%.2f"); diff --git a/implot.h b/implot.h index 3216df5..2635a26 100644 --- a/implot.h +++ b/implot.h @@ -51,7 +51,7 @@ enum ImPlotFlags_ { ImPlotFlags_Query = 1 << 4, // the user will be able to draw query rects with middle-mouse ImPlotFlags_ContextMenu = 1 << 5, // the user will be able to open context menus with double-right click ImPlotFlags_Crosshairs = 1 << 6, // the default mouse cursor will be replaced with a crosshair when hovered - ImPlotFlags_AntiAliased = 1 << 7, // plot lines will be software anti-aliased (not recommended, prefer MSAA) + ImPlotFlags_AntiAliased = 1 << 7, // plot lines will be software anti-aliased (not recommended for density plots, prefer MSAA) ImPlotFlags_NoChild = 1 << 8, // a child window region will not be used to capture mouse scroll (can boost performance for single ImGui window applications) ImPlotFlags_YAxis2 = 1 << 9, // enable a 2nd y-axis ImPlotFlags_YAxis3 = 1 << 10, // enable a 3rd y-axis @@ -67,7 +67,6 @@ enum ImPlotAxisFlags_ { ImPlotAxisFlags_LockMin = 1 << 4, // the axis minimum value will be locked when panning/zooming ImPlotAxisFlags_LockMax = 1 << 5, // the axis maximum value will be locked when panning/zooming ImPlotAxisFlags_LogScale = 1 << 6, // a logartithmic (base 10) axis scale will be used - ImPlotAxisFlags_Scientific = 1 << 7, // scientific notation will be used for tick labels if displayed (WIP, not very good yet) ImPlotAxisFlags_Default = ImPlotAxisFlags_GridLines | ImPlotAxisFlags_TickMarks | ImPlotAxisFlags_TickLabels, ImPlotAxisFlags_Auxiliary = ImPlotAxisFlags_TickMarks | ImPlotAxisFlags_TickLabels, }; @@ -204,6 +203,7 @@ struct ImPlotStyle { float ErrorBarWeight; // = 1.5, error bar whisker weight in pixels float DigitalBitHeight; // = 8, digital channels bit height (at y = 1.0f) in pixels float DigitalBitGap; // = 4, digital channels bit padding gap in pixels + bool AntiAliasedLines; // = false, enable global anti-aliasing on plot lines (overrides ImPlotFlags_AntiAliased) // plot styling variables float PlotBorderSize; // = 1, line thickness of border around plot area float MinorAlpha; // = 0.25 alpha multiplier applied to minor axis grid lines diff --git a/implot_demo.cpp b/implot_demo.cpp index 097a47c..691911b 100644 --- a/implot_demo.cpp +++ b/implot_demo.cpp @@ -183,8 +183,9 @@ void ShowDemoWindow(bool* p_open) { ImGui::BulletText("See the ShowDemoWindow() code in implot_demo.cpp. <- you are here!"); ImGui::BulletText("By default, anti-aliased lines are turned OFF."); ImGui::Indent(); + ImGui::BulletText("Software AA can be enabled globally with ImPlotStyle.AntiAliasedLines."); 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("AA for plots can be toggled from the plot's context menu."); ImGui::BulletText("If permitable, you are better off using hardware AA (e.g. MSAA)."); ImGui::Unindent(); #ifdef IMPLOT_DEMO_USE_DOUBLE @@ -213,6 +214,10 @@ void ShowDemoWindow(bool* p_open) { } ImGui::EndCombo(); } + float indent = ImGui::CalcItemWidth() - ImGui::GetFrameHeight(); + ImGui::Indent(ImGui::CalcItemWidth() - ImGui::GetFrameHeight()); + ImGui::Checkbox("Anti-Aliased Lines", &ImPlot::GetStyle().AntiAliasedLines); + ImGui::Unindent(indent); } //------------------------------------------------------------------------- if (ImGui::CollapsingHeader("Line Plots")) { diff --git a/implot_items.cpp b/implot_items.cpp index 52ac0e0..17af817 100644 --- a/implot_items.cpp +++ b/implot_items.cpp @@ -481,7 +481,7 @@ inline void RenderPrimitives(Renderer renderer, ImDrawList& DrawList) { template inline void RenderLineStrip(Getter getter, Transformer transformer, ImDrawList& DrawList, float line_weight, ImU32 col) { ImPlotContext& gp = *GImPlot; - if (ImHasFlag(gp.CurrentPlot->Flags, ImPlotFlags_AntiAliased)) { + if (ImHasFlag(gp.CurrentPlot->Flags, ImPlotFlags_AntiAliased) || gp.Style.AntiAliasedLines) { ImVec2 p1 = transformer(getter(0)); for (int i = 0; i < getter.Count; ++i) { ImVec2 p2 = transformer(getter(i));