1
0
Fork 0
mirror of https://github.com/gwm17/implot.git synced 2024-10-09 15:47:26 -04:00

add global AA variable to ImPlotStyle

This commit is contained in:
epezent 2020-08-25 22:47:03 -05:00
parent 2880ae8414
commit b84e74b885
4 changed files with 20 additions and 6 deletions

View File

@ -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. 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. 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/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/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. - 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; ErrorBarWeight = 1.5f;
DigitalBitHeight = 8; DigitalBitHeight = 8;
DigitalBitGap = 4; DigitalBitGap = 4;
AntiAliasedLines = false;
PlotBorderSize = 1; PlotBorderSize = 1;
MinorAlpha = 0.25f; MinorAlpha = 0.25f;
MajorTickLen = ImVec2(10,10); 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) { void AddTicksCustom(const double* values, const char** labels, int n, ImPlotTickCollection& ticks) {
for (int i = 0; i < n; ++i) { for (int i = 0; i < n; ++i) {
ImPlotTick tick(values[i], false, true); ImPlotTick tick(values[i], false, true);
tick.BufferOffset = ticks.Labels.size();
if (labels != NULL) { if (labels != NULL) {
tick.BufferOffset = ticks.Labels.size();
ticks.Labels.append(labels[i], labels[i] + strlen(labels[i]) + 1); ticks.Labels.append(labels[i], labels[i] + strlen(labels[i]) + 1);
tick.LabelSize = ImGui::CalcTextSize(labels[i]); tick.LabelSize = ImGui::CalcTextSize(labels[i]);
} }
else {
LabelTickDefault(tick, ticks.Labels);
}
ticks.AddTick(tick); ticks.AddTick(tick);
} }
} }
@ -2315,6 +2320,10 @@ void ShowStyleEditor(ImPlotStyle* ref) {
ImGui::SliderFloat("ErrorBarWeight", &style.ErrorBarWeight, 0.0f, 5.0f, "%.1f"); ImGui::SliderFloat("ErrorBarWeight", &style.ErrorBarWeight, 0.0f, 5.0f, "%.1f");
ImGui::SliderFloat("DigitalBitHeight", &style.DigitalBitHeight, 0.0f, 20.0f, "%.1f"); ImGui::SliderFloat("DigitalBitHeight", &style.DigitalBitHeight, 0.0f, 20.0f, "%.1f");
ImGui::SliderFloat("DigitalBitGap", &style.DigitalBitGap, 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::Text("Plot Styling");
ImGui::SliderFloat("PlotBorderSize", &style.PlotBorderSize, 0.0f, 2.0f, "%.0f"); ImGui::SliderFloat("PlotBorderSize", &style.PlotBorderSize, 0.0f, 2.0f, "%.0f");
ImGui::SliderFloat("MinorAlpha", &style.MinorAlpha, 0.0f, 1.0f, "%.2f"); ImGui::SliderFloat("MinorAlpha", &style.MinorAlpha, 0.0f, 1.0f, "%.2f");

View File

@ -51,7 +51,7 @@ enum ImPlotFlags_ {
ImPlotFlags_Query = 1 << 4, // the user will be able to draw query rects with middle-mouse 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_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_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_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_YAxis2 = 1 << 9, // enable a 2nd y-axis
ImPlotFlags_YAxis3 = 1 << 10, // enable a 3rd 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_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_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_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_Default = ImPlotAxisFlags_GridLines | ImPlotAxisFlags_TickMarks | ImPlotAxisFlags_TickLabels,
ImPlotAxisFlags_Auxiliary = 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 ErrorBarWeight; // = 1.5, error bar whisker weight in pixels
float DigitalBitHeight; // = 8, digital channels bit height (at y = 1.0f) 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 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 // plot styling variables
float PlotBorderSize; // = 1, line thickness of border around plot area float PlotBorderSize; // = 1, line thickness of border around plot area
float MinorAlpha; // = 0.25 alpha multiplier applied to minor axis grid lines float MinorAlpha; // = 0.25 alpha multiplier applied to minor axis grid lines

View File

@ -183,8 +183,9 @@ void ShowDemoWindow(bool* p_open) {
ImGui::BulletText("See the ShowDemoWindow() code in implot_demo.cpp. <- you are here!"); ImGui::BulletText("See the ShowDemoWindow() code in implot_demo.cpp. <- you are here!");
ImGui::BulletText("By default, anti-aliased lines are turned OFF."); ImGui::BulletText("By default, anti-aliased lines are turned OFF.");
ImGui::Indent(); 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("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::BulletText("If permitable, you are better off using hardware AA (e.g. MSAA).");
ImGui::Unindent(); ImGui::Unindent();
#ifdef IMPLOT_DEMO_USE_DOUBLE #ifdef IMPLOT_DEMO_USE_DOUBLE
@ -213,6 +214,10 @@ void ShowDemoWindow(bool* p_open) {
} }
ImGui::EndCombo(); 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")) { if (ImGui::CollapsingHeader("Line Plots")) {

View File

@ -481,7 +481,7 @@ inline void RenderPrimitives(Renderer renderer, ImDrawList& DrawList) {
template <typename Getter, typename Transformer> template <typename Getter, typename Transformer>
inline void RenderLineStrip(Getter getter, Transformer transformer, ImDrawList& DrawList, float line_weight, ImU32 col) { inline void RenderLineStrip(Getter getter, Transformer transformer, ImDrawList& DrawList, float line_weight, ImU32 col) {
ImPlotContext& gp = *GImPlot; 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)); ImVec2 p1 = transformer(getter(0));
for (int i = 0; i < getter.Count; ++i) { for (int i = 0; i < getter.Count; ++i) {
ImVec2 p2 = transformer(getter(i)); ImVec2 p2 = transformer(getter(i));