diff --git a/README.md b/README.md index a8d4b45..b6900a5 100644 --- a/README.md +++ b/README.md @@ -32,14 +32,14 @@ ImPlot is an immediate mode plotting widget for [Dear ImGui](https://github.com/ ## Usage -The API is used just like any other ImGui `Begin`/`End` function. First, start a plotting context with `BeginPlot()`. Next, plot as many items as you want with the provided API functions (e.g. `Plot()`, `PlotBar()`, `PlotErrorBars()`, etc). Finally, wrap things up with a call to `EndPlot()`. That's it! +The API is used just like any other ImGui `BeginX`/`EndX` pair. First, start a plotting context with `ImPlot::BeginPlot()`. Next, plot as many items as you want with the provided API functions (e.g. `Plot()`, `Bar()`, `ErrorBars()`, etc). Finally, wrap things up with a call to `ImPlot::EndPlot()`. That's it! ```cpp -if (ImGui::BeginPlot("My Plot")) { - ImGui::Plot("My Line Plot", x_data, y_data, 1000); - ImGui::PlotBar("My Bar Plot", values, 10); +if (ImPlot::BeginPlot("My Plot")) { + ImPlot::Plot("My Line Plot", x_data, y_data, 1000); + ImPlot::Bar("My Bar Plot", values, 10); ... - ImGui::EndPlot(); + ImPlot::EndPlot(); } ``` diff --git a/implot.cpp b/implot.cpp index 77014d1..ba256b7 100644 --- a/implot.cpp +++ b/implot.cpp @@ -31,6 +31,12 @@ 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/05/11 (0.2) - ImPlotFlags_Selection was changed to ImPlotFlags_BoxSelect +- 2020/05/11 (0.2) - The namespace ImGui:: was replaced with ImPlot::. As a result, the following additional changes were made: + - Functions that were prefixed or decorated with the word "Plot" have been truncated. E.g., `ImGui::PlotBar` is now just `ImPlot::Bar`. + It should be fairly obvious what was what. + - Some functions have been given names that would have otherwise collided with the ImGui namespace. This has been done to maintain a consistent + style with ImGui. E.g., 'ImGui::PushPlotStyleVar` is now 'ImPlot::PushStyleVar'. - 2020/05/10 (0.2) - The following function/struct names were changes: - ImPlotRange -> ImPlotLimits - GetPlotRange() -> GetPlotLimits() @@ -113,7 +119,11 @@ bool ImPlotLimits::Contains(const ImVec2& p) const { return X.Contains(p.x) && Y.Contains(p.y); } -namespace ImGui { +ImVec2 ImPlotLimits::Size() const { + return ImVec2(X.Size(),Y.Size()); +} + +namespace ImPlot { namespace { @@ -210,7 +220,7 @@ inline void AddTextVertical(ImDrawList *DrawList, const char *text, ImVec2 pos, /// Calculates the size of vertical text inline ImVec2 CalcTextSizeVertical(const char *text) { - ImVec2 sz = CalcTextSize(text); + ImVec2 sz = ImGui::CalcTextSize(text); return ImVec2(sz.y, sz.x); } @@ -276,8 +286,8 @@ struct ImPlotAxis { }; /// Holds Plot state information that must persist between frames -struct ImPlot { - ImPlot() { +struct ImPlotState { + ImPlotState() { Selecting = Querying = Queried = DraggingQuery = false; SelectStart = QueryStart = ImVec2(0,0); Flags = PreviousFlags = ImPlotFlags_Default; @@ -318,13 +328,13 @@ struct ImPlotContext { ImPlotContext() : RenderX(), RenderY() { CurrentPlot = NULL; FitThisFrame = FitX = false; - RestorePlotPalette(); + RestorePalette(); } /// ALl Plots - ImPool Plots; + ImPool Plots; /// Current Plot - ImPlot* CurrentPlot; + ImPlotState* CurrentPlot; // Legend ImVector LegendIndices; ImGuiTextBuffer LegendLabels; @@ -610,7 +620,7 @@ inline void LabelTicks(ImVector &ticks, bool scientific, ImGuiTextBuffer else sprintf(temp, "%g", tk.PlotPos); buffer.append(temp, temp + strlen(temp) + 1); - tk.Size = CalcTextSize(buffer.Buf.Data + tk.TextOffset); + tk.Size = ImGui::CalcTextSize(buffer.Buf.Data + tk.TextOffset); } } } @@ -653,9 +663,9 @@ struct AxisState { void UpdateAxisColor(int axis_flag, ImPlotContext::AxisColor* col) { const ImVec4 col_Axis = gp.Style.Colors[axis_flag].w == -1 ? ImGui::GetStyle().Colors[ImGuiCol_Text] * ImVec4(1, 1, 1, 0.25f) : gp.Style.Colors[axis_flag]; - col->Major = GetColorU32(col_Axis); - col->Minor = GetColorU32(col_Axis * ImVec4(1, 1, 1, 0.25f)); - col->Txt = GetColorU32({col_Axis.x, col_Axis.y, col_Axis.z, 1}); + col->Major = ImGui::GetColorU32(col_Axis); + col->Minor = ImGui::GetColorU32(col_Axis * ImVec4(1, 1, 1, 0.25f)); + col->Txt = ImGui::GetColorU32({col_Axis.x, col_Axis.y, col_Axis.z, 1}); } ImRect GetAxisScale(int y_axis, float tx, float ty, float zoom_rate) { @@ -670,7 +680,7 @@ class YPadCalculator { : AxisStates(axis_states), MaxLabelWidths(max_label_widths), TxtOff(txt_off) {} float operator()(int y_axis) { - ImPlot& plot = *gp.CurrentPlot; + ImPlotState& plot = *gp.CurrentPlot; if (!AxisStates[y_axis].present) { return 0; } // If we have more than 1 axis present before us, then we need // extra space to account for our tick bar. @@ -711,11 +721,11 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons const ImGuiID ID = Window->GetID(title); const ImGuiStyle &Style = G.Style; - const ImGuiIO & IO = GetIO(); + const ImGuiIO & IO = ImGui::GetIO(); bool just_created = gp.Plots.GetByKey(ID) == NULL; gp.CurrentPlot = gp.Plots.GetOrAddByKey(ID); - ImPlot &plot = *gp.CurrentPlot; + ImPlotState &plot = *gp.CurrentPlot; plot.CurrentYAxis = 0; @@ -826,37 +836,37 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons // COLORS ----------------------------------------------------------------- - gp.Col_Frame = gp.Style.Colors[ImPlotCol_FrameBg].w == -1 ? GetColorU32(ImGuiCol_FrameBg) : GetColorU32(gp.Style.Colors[ImPlotCol_FrameBg]); - gp.Col_Bg = gp.Style.Colors[ImPlotCol_PlotBg].w == -1 ? GetColorU32(ImGuiCol_WindowBg) : GetColorU32(gp.Style.Colors[ImPlotCol_PlotBg]); - gp.Col_Border = gp.Style.Colors[ImPlotCol_PlotBorder].w == -1 ? GetColorU32(ImGuiCol_Text, 0.5f) : GetColorU32(gp.Style.Colors[ImPlotCol_PlotBorder]); + gp.Col_Frame = gp.Style.Colors[ImPlotCol_FrameBg].w == -1 ? ImGui::GetColorU32(ImGuiCol_FrameBg) : ImGui::GetColorU32(gp.Style.Colors[ImPlotCol_FrameBg]); + gp.Col_Bg = gp.Style.Colors[ImPlotCol_PlotBg].w == -1 ? ImGui::GetColorU32(ImGuiCol_WindowBg) : ImGui::GetColorU32(gp.Style.Colors[ImPlotCol_PlotBg]); + gp.Col_Border = gp.Style.Colors[ImPlotCol_PlotBorder].w == -1 ? ImGui::GetColorU32(ImGuiCol_Text, 0.5f) : ImGui::GetColorU32(gp.Style.Colors[ImPlotCol_PlotBorder]); UpdateAxisColor(ImPlotCol_XAxis, &gp.Col_X); UpdateAxisColor(ImPlotCol_YAxis, &gp.Col_Y[0]); UpdateAxisColor(ImPlotCol_YAxis2, &gp.Col_Y[1]); UpdateAxisColor(ImPlotCol_YAxis3, &gp.Col_Y[2]); - gp.Col_Txt = GetColorU32(ImGuiCol_Text); - gp.Col_TxtDis = GetColorU32(ImGuiCol_TextDisabled); - gp.Col_SlctBg = GetColorU32(gp.Style.Colors[ImPlotCol_Selection] * ImVec4(1,1,1,0.25f)); - gp.Col_SlctBd = GetColorU32(gp.Style.Colors[ImPlotCol_Selection]); - gp.Col_QryBg = GetColorU32(gp.Style.Colors[ImPlotCol_Query] * ImVec4(1,1,1,0.25f)); - gp.Col_QryBd = GetColorU32(gp.Style.Colors[ImPlotCol_Query]); + gp.Col_Txt = ImGui::GetColorU32(ImGuiCol_Text); + gp.Col_TxtDis = ImGui::GetColorU32(ImGuiCol_TextDisabled); + gp.Col_SlctBg = ImGui::GetColorU32(gp.Style.Colors[ImPlotCol_Selection] * ImVec4(1,1,1,0.25f)); + gp.Col_SlctBd = ImGui::GetColorU32(gp.Style.Colors[ImPlotCol_Selection]); + gp.Col_QryBg = ImGui::GetColorU32(gp.Style.Colors[ImPlotCol_Query] * ImVec4(1,1,1,0.25f)); + gp.Col_QryBd = ImGui::GetColorU32(gp.Style.Colors[ImPlotCol_Query]); // BB AND HOVER ----------------------------------------------------------- // frame - const ImVec2 frame_size = CalcItemSize(size, 100, 100); + const ImVec2 frame_size = ImGui::CalcItemSize(size, 100, 100); gp.BB_Frame = ImRect(Window->DC.CursorPos, Window->DC.CursorPos + frame_size); - ItemSize(gp.BB_Frame); - if (!ItemAdd(gp.BB_Frame, 0, &gp.BB_Frame)) { + ImGui::ItemSize(gp.BB_Frame); + if (!ImGui::ItemAdd(gp.BB_Frame, 0, &gp.BB_Frame)) { gp.NextPlotData = ImNextPlotData(); gp.CurrentPlot = NULL; if (!HasFlag(plot.Flags, ImPlotFlags_NoChild)) ImGui::EndChild(); return false; } - gp.Hov_Frame = ItemHoverable(gp.BB_Frame, ID); - RenderFrame(gp.BB_Frame.Min, gp.BB_Frame.Max, gp.Col_Frame, true, Style.FrameRounding); + gp.Hov_Frame = ImGui::ItemHoverable(gp.BB_Frame, ID); + ImGui::RenderFrame(gp.BB_Frame.Min, gp.BB_Frame.Max, gp.Col_Frame, true, Style.FrameRounding); // canvas bb gp.BB_Canvas = ImRect(gp.BB_Frame.Min + Style.WindowPadding, gp.BB_Frame.Max - Style.WindowPadding); @@ -896,9 +906,9 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons } // grid bb - const ImVec2 title_size = CalcTextSize(title, NULL, true); + const ImVec2 title_size = ImGui::CalcTextSize(title, NULL, true); const float txt_off = 5; - const float txt_height = GetTextLineHeight(); + const float txt_height = ImGui::GetTextLineHeight(); const float pad_top = title_size.x > 0.0f ? txt_height + txt_off : 0; const float pad_bot = (HasFlag(plot.XAxis.Flags, ImAxisFlags_TickLabels) ? txt_height + txt_off : 0) + (x_label ? txt_height + txt_off : 0); YPadCalculator y_axis_pad(y, max_label_width, txt_off); @@ -959,12 +969,12 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons plot.DraggingQuery = false; } if (plot.DraggingQuery) { - SetMouseCursor(ImGuiMouseCursor_ResizeAll); + ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeAll); plot.QueryRect.Min += IO.MouseDelta; plot.QueryRect.Max += IO.MouseDelta; } if (gp.Hov_Frame && gp.Hov_Grid && hov_query && !plot.DraggingQuery && !plot.Selecting && !hov_legend) { - SetMouseCursor(ImGuiMouseCursor_ResizeAll); + ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeAll); const bool any_y_dragging = plot.YAxis[0].Dragging || plot.YAxis[1].Dragging || plot.YAxis[2].Dragging; if (IO.MouseDown[0] && !plot.XAxis.Dragging && !any_y_dragging) { plot.DraggingQuery = true; @@ -1083,7 +1093,7 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons if (plot.Selecting && (IO.MouseReleased[1] || !IO.MouseDown[1])) { UpdateTransformCache(); ImVec2 select_size = plot.SelectStart - IO.MousePos; - if (HasFlag(plot.Flags, ImPlotFlags_Selection) && ImFabs(select_size.x) > 2 && ImFabs(select_size.y) > 2) { + if (HasFlag(plot.Flags, ImPlotFlags_BoxSelect) && ImFabs(select_size.x) > 2 && ImFabs(select_size.y) > 2) { ImVec2 p1 = PixelsToPlot(plot.SelectStart); ImVec2 p2 = PixelsToPlot(IO.MousePos); if (!x.lock_min && !IO.KeyAlt) @@ -1102,7 +1112,7 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons plot.Selecting = false; } // bad selection - if (plot.Selecting && (!HasFlag(plot.Flags, ImPlotFlags_Selection) || lock_plot) && ImLengthSqr(plot.SelectStart - IO.MousePos) > 4) { + if (plot.Selecting && (!HasFlag(plot.Flags, ImPlotFlags_BoxSelect) || lock_plot) && ImLengthSqr(plot.SelectStart - IO.MousePos) > 4) { ImGui::SetMouseCursor(ImGuiMouseCursor_NotAllowed); } // cancel selection @@ -1150,7 +1160,7 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons plot.Queried = true; plot.QueryStart = plot.SelectStart; } - if (HasFlag(plot.Flags, ImPlotFlags_Selection) && plot.Querying && !IO.KeyCtrl && !IO.MouseDown[2]) { + if (HasFlag(plot.Flags, ImPlotFlags_BoxSelect) && plot.Querying && !IO.KeyCtrl && !IO.MouseDown[2]) { plot.Selecting = true; plot.Querying = false; plot.Queried = false; @@ -1178,7 +1188,7 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons // focus window if ((IO.MouseClicked[0] || IO.MouseClicked[1]) && gp.Hov_Frame) - FocusWindow(GetCurrentWindow()); + ImGui::FocusWindow(ImGui::GetCurrentWindow()); UpdateTransformCache(); @@ -1224,25 +1234,25 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons // render title if (title_size.x > 0.0f) { - RenderText(ImVec2(gp.BB_Canvas.GetCenter().x - title_size.x * 0.5f, gp.BB_Canvas.Min.y), title, NULL, true); + ImGui::RenderText(ImVec2(gp.BB_Canvas.GetCenter().x - title_size.x * 0.5f, gp.BB_Canvas.Min.y), title, NULL, true); } // render labels if (HasFlag(plot.XAxis.Flags, ImAxisFlags_TickLabels)) { - PushClipRect(gp.BB_Frame.Min, gp.BB_Frame.Max, true); + ImGui::PushClipRect(gp.BB_Frame.Min, gp.BB_Frame.Max, true); for (ImTick &xt : gp.XTicks) { if (xt.RenderLabel && xt.PixelPos >= gp.BB_Grid.Min.x - 1 && xt.PixelPos <= gp.BB_Grid.Max.x + 1) DrawList.AddText({xt.PixelPos - xt.Size.x * 0.5f, gp.BB_Grid.Max.y + txt_off}, gp.Col_X.Txt, gp.XTickLabels.Buf.Data + xt.TextOffset); } - PopClipRect(); + ImGui::PopClipRect(); } if (x_label) { - const ImVec2 xLabel_size = CalcTextSize(x_label); + const ImVec2 xLabel_size = ImGui::CalcTextSize(x_label); const ImVec2 xLabel_pos(gp.BB_Grid.GetCenter().x - xLabel_size.x * 0.5f, gp.BB_Canvas.Max.y - txt_height); DrawList.AddText(xLabel_pos, gp.Col_X.Txt, x_label); } - PushClipRect(gp.BB_Frame.Min, gp.BB_Frame.Max, true); + ImGui::PushClipRect(gp.BB_Frame.Min, gp.BB_Frame.Max, true); for (int i = 0; i < MAX_Y_AXES; i++) { if (y[i].present && HasFlag(plot.YAxis[i].Flags, ImAxisFlags_TickLabels)) { const float x_start = @@ -1258,7 +1268,7 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons } } } - PopClipRect(); + ImGui::PopClipRect(); if (y_label) { const ImVec2 yLabel_size = CalcTextSizeVertical(y_label); const ImVec2 yLabel_pos(gp.BB_Canvas.Min.x, gp.BB_Grid.GetCenter().y + yLabel_size.y * 0.5f); @@ -1268,7 +1278,7 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons // PREP ------------------------------------------------------------------- // push plot ID into stack - PushID(ID); + ImGui::PushID(ID); // reset items count gp.VisibleItemCount = 0; // reset extents @@ -1335,11 +1345,11 @@ inline void AxisMenu(ImPlotAxis& Axis) { FlipFlag(Axis.Flags, ImAxisFlags_TickLabels); } -void PlotContextMenu(ImPlot& plot) { +void PlotContextMenu(ImPlotState& plot) { if (ImGui::BeginMenu("X-Axis")) { - PushID("X"); + ImGui::PushID("X"); AxisMenu(plot.XAxis); - PopID(); + ImGui::PopID(); ImGui::EndMenu(); } for (int i = 0; i < MAX_Y_AXES; i++) { @@ -1356,17 +1366,20 @@ void PlotContextMenu(ImPlot& plot) { snprintf(buf, sizeof(buf) - 1, "Y-Axis %d", i + 1); } if (ImGui::BeginMenu(buf)) { - PushID(i); + ImGui::PushID(i); AxisMenu(plot.YAxis[i]); - PopID(); + ImGui::PopID(); ImGui::EndMenu(); } } ImGui::Separator(); if ((ImGui::BeginMenu("Settings"))) { - if (ImGui::MenuItem("Box Select",NULL,HasFlag(plot.Flags, ImPlotFlags_Selection))) { - FlipFlag(plot.Flags, ImPlotFlags_Selection); + if (ImGui::MenuItem("Box Select",NULL,HasFlag(plot.Flags, ImPlotFlags_BoxSelect))) { + FlipFlag(plot.Flags, ImPlotFlags_BoxSelect); + } + if (ImGui::MenuItem("Query",NULL,HasFlag(plot.Flags, ImPlotFlags_Query))) { + FlipFlag(plot.Flags, ImPlotFlags_Query); } if (ImGui::MenuItem("Crosshairs",NULL,HasFlag(plot.Flags, ImPlotFlags_Crosshairs))) { FlipFlag(plot.Flags, ImPlotFlags_Crosshairs); @@ -1430,11 +1443,11 @@ void EndPlot() { IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "Mismatched BeginPlot()/EndPlot()!"); - ImPlot &plot = *gp.CurrentPlot; + ImPlotState &plot = *gp.CurrentPlot; ImGuiContext &G = *GImGui; ImGuiWindow * Window = G.CurrentWindow; ImDrawList & DrawList = *Window->DrawList; - const ImGuiIO & IO = GetIO(); + const ImGuiIO & IO = ImGui::GetIO(); // AXIS STATES ------------------------------------------------------------ @@ -1460,7 +1473,7 @@ void EndPlot() { } PopPlotClipRect(); - PushClipRect(gp.BB_Grid.Min, {gp.BB_Frame.Max.x, gp.BB_Grid.Max.y}, true); + ImGui::PushClipRect(gp.BB_Grid.Min, {gp.BB_Frame.Max.x, gp.BB_Grid.Max.y}, true); int axis_count = 0; for (int i = 0; i < MAX_Y_AXES; i++) { if (!y[i].present) { continue; } @@ -1490,13 +1503,13 @@ void EndPlot() { } } - PopClipRect(); + ImGui::PopClipRect(); PushPlotClipRect(); // render selection/query if (plot.Selecting) { ImRect select_bb(ImMin(IO.MousePos, plot.SelectStart), ImMax(IO.MousePos, plot.SelectStart)); - if (plot.Selecting && !lock_plot && HasFlag(plot.Flags, ImPlotFlags_Selection)) { + if (plot.Selecting && !lock_plot && HasFlag(plot.Flags, ImPlotFlags_BoxSelect)) { if (IO.KeyAlt && IO.KeyShift && select_bb.GetWidth() > 2 && select_bb.GetHeight() > 2) { DrawList.AddRectFilled(gp.BB_Grid.Min, gp.BB_Grid.Max, gp.Col_SlctBg); DrawList.AddRect( gp.BB_Grid.Min, gp.BB_Grid.Max, gp.Col_SlctBd); @@ -1533,7 +1546,7 @@ void EndPlot() { } // render legend - const float txt_ht = GetTextLineHeight(); + const float txt_ht = ImGui::GetTextLineHeight(); const ImVec2 legend_offset(10, 10); const ImVec2 legend_padding(5, 5); const float legend_icon_size = txt_ht; @@ -1545,14 +1558,14 @@ void EndPlot() { float max_label_width = 0; for (int i = 0; i < nItems; ++i) { const char* label = GetLegendLabel(i); - ImVec2 labelWidth = CalcTextSize(label, NULL, true); + ImVec2 labelWidth = ImGui::CalcTextSize(label, NULL, true); max_label_width = labelWidth.x > max_label_width ? labelWidth.x : max_label_width; } legend_content_bb = ImRect(gp.BB_Grid.Min + legend_offset, gp.BB_Grid.Min + legend_offset + ImVec2(max_label_width, nItems * txt_ht)); plot.BB_Legend = ImRect(legend_content_bb.Min, legend_content_bb.Max + legend_padding * 2 + ImVec2(legend_icon_size, 0)); hov_legend = HasFlag(plot.Flags, ImPlotFlags_Legend) ? gp.Hov_Frame && plot.BB_Legend.Contains(IO.MousePos) : false; // render legend box - DrawList.AddRectFilled(plot.BB_Legend.Min, plot.BB_Legend.Max, GetColorU32(ImGuiCol_PopupBg)); + DrawList.AddRectFilled(plot.BB_Legend.Min, plot.BB_Legend.Max, ImGui::GetColorU32(ImGuiCol_PopupBg)); DrawList.AddRect(plot.BB_Legend.Min, plot.BB_Legend.Max, gp.Col_Border); // render each legend item for (int i = 0; i < nItems; ++i) { @@ -1566,7 +1579,7 @@ void EndPlot() { ImU32 col_hl_txt; if (HasFlag(plot.Flags, ImPlotFlags_Highlight) && hov_legend && (icon_bb.Contains(IO.MousePos) || label_bb.Contains(IO.MousePos))) { item->Highlight = true; - col_hl_txt = GetColorU32(ImLerp(G.Style.Colors[ImGuiCol_Text], item->Color, 0.25f)); + col_hl_txt = ImGui::GetColorU32(ImLerp(G.Style.Colors[ImGuiCol_Text], item->Color, 0.25f)); } else item->Highlight = false; @@ -1574,16 +1587,16 @@ void EndPlot() { if (hov_legend && icon_bb.Contains(IO.MousePos)) { ImVec4 colAlpha = item->Color; colAlpha.w = 0.5f; - iconColor = item->Show ? GetColorU32(colAlpha) - : GetColorU32(ImGuiCol_TextDisabled, 0.5f); + iconColor = item->Show ? ImGui::GetColorU32(colAlpha) + : ImGui::GetColorU32(ImGuiCol_TextDisabled, 0.5f); if (IO.MouseClicked[0]) item->Show = !item->Show; } else { - iconColor = item->Show ? GetColorU32(item->Color) : gp.Col_TxtDis; + iconColor = item->Show ? ImGui::GetColorU32(item->Color) : gp.Col_TxtDis; } DrawList.AddRectFilled(icon_bb.Min, icon_bb.Max, iconColor, 1); const char* label = GetLegendLabel(i); - const char* text_display_end = FindRenderedTextEnd(label, NULL); + const char* text_display_end = ImGui::FindRenderedTextEnd(label, NULL); if (label != text_display_end) DrawList.AddText(legend_content_bb.Min + legend_padding + ImVec2(legend_icon_size, i * txt_ht), item->Show ? (item->Highlight ? col_hl_txt : gp.Col_Txt) : gp.Col_TxtDis, label, text_display_end); @@ -1621,7 +1634,7 @@ void EndPlot() { if (HasFlag(plot.Flags, ImPlotFlags_YAxis3)) { writer.Write(",(%.2f)", gp.LastMousePos[2].y); } - ImVec2 size = CalcTextSize(buffer); + ImVec2 size = ImGui::CalcTextSize(buffer); ImVec2 pos = gp.BB_Grid.Max - size - ImVec2(5, 5); DrawList.AddText(pos, gp.Col_Txt, buffer); } @@ -1666,8 +1679,8 @@ void EndPlot() { gp.CurrentPlot = NULL; // Reset next plot data gp.NextPlotData = ImNextPlotData(); - // Pop PushID at the end of BeginPlot - PopID(); + // Pop ImGui::PushID at the end of BeginPlot + ImGui::PopID(); // End child window if (!HasFlag(plot.Flags, ImPlotFlags_NoChild)) ImGui::EndChild(); @@ -1717,11 +1730,11 @@ ImVec2 GetPlotSize() { void PushPlotClipRect() { IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "PushPlotClipRect() Needs to be called between BeginPlot() and EndPlot()!"); - PushClipRect(gp.BB_Grid.Min, gp.BB_Grid.Max, true); + ImGui::PushClipRect(gp.BB_Grid.Min, gp.BB_Grid.Max, true); } void PopPlotClipRect() { - PopClipRect(); + ImGui::PopClipRect(); } bool IsPlotHovered() { @@ -1741,7 +1754,7 @@ ImPlotLimits GetPlotLimits(int y_axis_in) { IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "GetPlotLimits() Needs to be called between BeginPlot() and EndPlot()!"); const int y_axis = y_axis_in >= 0 ? y_axis_in : gp.CurrentPlot->CurrentYAxis; - ImPlot& plot = *gp.CurrentPlot; + ImPlotState& plot = *gp.CurrentPlot; ImPlotLimits limits; limits.X = plot.XAxis.Range; limits.Y = plot.YAxis[y_axis].Range; @@ -1756,7 +1769,7 @@ bool IsPlotQueried() { ImPlotLimits GetPlotQuery(int y_axis_in) { IM_ASSERT_USER_ERROR(y_axis_in >= -1 && y_axis_in < MAX_Y_AXES, "y_axis needs to between -1 and MAX_Y_AXES"); IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "GetPlotQuery() Needs to be called between BeginPlot() and EndPlot()!"); - ImPlot& plot = *gp.CurrentPlot; + ImPlotState& plot = *gp.CurrentPlot; const int y_axis = y_axis_in >= 0 ? y_axis_in : gp.CurrentPlot->CurrentYAxis; UpdateTransformCache(); @@ -1800,11 +1813,11 @@ static const ImPlotStyleVarInfo* GetPlotStyleVarInfo(ImPlotStyleVar idx) return &GPlotStyleVarInfo[idx]; } -ImPlotStyle& GetPlotStyle() { +ImPlotStyle& GetStyle() { return gp.Style; } -void SetPlotPalette(const ImVec4* colors, int num_colors) { +void SetPalette(const ImVec4* colors, int num_colors) { gp.ColorMap.shrink(0); gp.ColorMap.reserve(num_colors); for (int i = 0; i < num_colors; ++i) { @@ -1813,7 +1826,7 @@ void SetPlotPalette(const ImVec4* colors, int num_colors) { } /// Returns the next unused default plot color -void RestorePlotPalette() { +void RestorePalette() { static ImVec4 default_colors[10] = { {(0.0F), (0.7490196228F), (1.0F), (1.0F)}, // Blues::DeepSkyBlue, {(1.0F), (0.0F), (0.0F), (1.0F)}, // Reds::Red, @@ -1826,18 +1839,18 @@ void RestorePlotPalette() { {(0.5f), (0.5f), (0.5f), (1.0F)}, // Grays::Gray50, {(0.8235294223F), (0.7058823705F), (0.5490196347F), (1.0F)} // Browns::Tan }; - SetPlotPalette(default_colors, 10); + SetPalette(default_colors, 10); } -void PushPlotColor(ImPlotCol idx, ImU32 col) { +void PushStyleColor(ImPlotCol idx, ImU32 col) { ImGuiColorMod backup; backup.Col = idx; backup.BackupValue = gp.Style.Colors[idx]; gp.ColorModifiers.push_back(backup); - gp.Style.Colors[idx] = ColorConvertU32ToFloat4(col); + gp.Style.Colors[idx] = ImGui::ColorConvertU32ToFloat4(col); } -void PushPlotColor(ImPlotCol idx, const ImVec4& col) { +void PushStyleColor(ImPlotCol idx, const ImVec4& col) { ImGuiColorMod backup; backup.Col = idx; backup.BackupValue = gp.Style.Colors[idx]; @@ -1845,7 +1858,7 @@ void PushPlotColor(ImPlotCol idx, const ImVec4& col) { gp.Style.Colors[idx] = col; } -void PopPlotColor(int count) { +void PopStyleColor(int count) { while (count > 0) { ImGuiColorMod& backup = gp.ColorModifiers.back(); @@ -1855,7 +1868,7 @@ void PopPlotColor(int count) { } } -void PushPlotStyleVar(ImPlotStyleVar idx, float val) { +void PushStyleVar(ImPlotStyleVar idx, float val) { const ImPlotStyleVarInfo* var_info = GetPlotStyleVarInfo(idx); if (var_info->Type == ImGuiDataType_Float && var_info->Count == 1) { float* pvar = (float*)var_info->GetVarPtr(&gp.Style); @@ -1863,10 +1876,10 @@ void PushPlotStyleVar(ImPlotStyleVar idx, float val) { *pvar = val; return; } - IM_ASSERT(0 && "Called PushPlotStyleVar() float variant but variable is not a float!"); + IM_ASSERT(0 && "Called PushStyleVar() float variant but variable is not a float!"); } -void PushPlotStyleVar(ImPlotStyleVar idx, int val) { +void PushStyleVar(ImPlotStyleVar idx, int val) { const ImPlotStyleVarInfo* var_info = GetPlotStyleVarInfo(idx); if (var_info->Type == ImGuiDataType_S32 && var_info->Count == 1) { int* pvar = (int*)var_info->GetVarPtr(&gp.Style); @@ -1880,10 +1893,10 @@ void PushPlotStyleVar(ImPlotStyleVar idx, int val) { *pvar = (float)val; return; } - IM_ASSERT(0 && "Called PushPlotStyleVar() int variant but variable is not a int!"); + IM_ASSERT(0 && "Called PushStyleVar() int variant but variable is not a int!"); } -void PopPlotStyleVar(int count) { +void PopStyleVar(int count) { while (count > 0) { ImGuiStyleMod& backup = gp.StyleModifiers.back(); const ImPlotStyleVarInfo* info = GetPlotStyleVarInfo(backup.VarIdx); @@ -2155,7 +2168,7 @@ inline void PlotEx(const char* label_id, Getter getter, int count, int offset) { IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "Plot() Needs to be called between BeginPlot() and EndPlot()!"); - ImPlot* plot = gp.CurrentPlot; + ImPlotState* plot = gp.CurrentPlot; const int y_axis = plot->CurrentYAxis; ImPlotItem* item = RegisterItem(label_id); if (!item->Show) @@ -2167,9 +2180,9 @@ inline void PlotEx(const char* label_id, Getter getter, int count, int offset) const bool rend_mk_line = gp.Style.Colors[ImPlotCol_MarkerOutline].w != 0 && gp.Style.MarkerWeight > 0; const bool rend_mk_fill = gp.Style.Colors[ImPlotCol_MarkerFill].w != 0; - ImU32 col_line = gp.Style.Colors[ImPlotCol_Line].w == -1 ? GetColorU32(item->Color) : GetColorU32(gp.Style.Colors[ImPlotCol_Line]); - ImU32 col_mk_line = gp.Style.Colors[ImPlotCol_MarkerOutline].w == -1 ? col_line : GetColorU32(gp.Style.Colors[ImPlotCol_MarkerOutline]); - ImU32 col_mk_fill = gp.Style.Colors[ImPlotCol_MarkerFill].w == -1 ? col_line : GetColorU32(gp.Style.Colors[ImPlotCol_MarkerFill]); + ImU32 col_line = gp.Style.Colors[ImPlotCol_Line].w == -1 ? ImGui::GetColorU32(item->Color) : ImGui::GetColorU32(gp.Style.Colors[ImPlotCol_Line]); + ImU32 col_mk_line = gp.Style.Colors[ImPlotCol_MarkerOutline].w == -1 ? col_line : ImGui::GetColorU32(gp.Style.Colors[ImPlotCol_MarkerOutline]); + ImU32 col_mk_fill = gp.Style.Colors[ImPlotCol_MarkerFill].w == -1 ? col_line : ImGui::GetColorU32(gp.Style.Colors[ImPlotCol_MarkerFill]); const float line_weight = item->Highlight ? gp.Style.LineWeight * 2 : gp.Style.LineWeight; @@ -2250,19 +2263,19 @@ struct GetterBarH { template void PlotBarEx(const char* label_id, Getter getter, int count, float width, int offset) { - IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "PlotBar() Needs to be called between BeginPlot() and EndPlot()!"); + IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "Bar() Needs to be called between BeginPlot() and EndPlot()!"); ImPlotItem* item = RegisterItem(label_id); if (!item->Show) return; - ImDrawList & DrawList = *GetWindowDrawList(); + ImDrawList & DrawList = *ImGui::GetWindowDrawList(); bool rend_line = gp.Style.Colors[ImPlotCol_Line].w != 0 && gp.Style.LineWeight > 0; bool rend_fill = gp.Style.Colors[ImPlotCol_Fill].w != 0; - ImU32 col_line = gp.Style.Colors[ImPlotCol_Line].w == -1 ? GetColorU32(item->Color) : GetColorU32(gp.Style.Colors[ImPlotCol_Line]); - ImU32 col_fill = gp.Style.Colors[ImPlotCol_Fill].w == -1 ? col_line : GetColorU32(gp.Style.Colors[ImPlotCol_Fill]); + ImU32 col_line = gp.Style.Colors[ImPlotCol_Line].w == -1 ? ImGui::GetColorU32(item->Color) : ImGui::GetColorU32(gp.Style.Colors[ImPlotCol_Line]); + ImU32 col_fill = gp.Style.Colors[ImPlotCol_Fill].w == -1 ? col_line : ImGui::GetColorU32(gp.Style.Colors[ImPlotCol_Fill]); if (rend_fill && col_line == col_fill) rend_line = false; @@ -2300,17 +2313,17 @@ void PlotBarEx(const char* label_id, Getter getter, int count, float width, int PopPlotClipRect(); } -void PlotBar(const char* label_id, const float* values, int count, float width, float shift, int offset, int stride) { +void Bar(const char* label_id, const float* values, int count, float width, float shift, int offset, int stride) { GetterBarV getter(values,shift,stride); PlotBarEx(label_id, getter, count, width, offset); } -void PlotBar(const char* label_id, const float* xs, const float* ys, int count, float width, int offset, int stride) { +void Bar(const char* label_id, const float* xs, const float* ys, int count, float width, int offset, int stride) { Getter2D getter(xs,ys,stride); PlotBarEx(label_id, getter, count, width, offset); } -void PlotBar(const char* label_id, ImVec2 (*getter_func)(void* data, int idx), void* data, int count, float width, int offset) { +void Bar(const char* label_id, ImVec2 (*getter_func)(void* data, int idx), void* data, int count, float width, int offset) { GetterFuncPtrImVec2 getter(getter_func, data); PlotBarEx(label_id, getter, count, width, offset); } @@ -2320,19 +2333,19 @@ void PlotBar(const char* label_id, ImVec2 (*getter_func)(void* data, int idx), v template void PlotBarHEx(const char* label_id, Getter getter, int count, float height, int offset) { - IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "PlotBarH() Needs to be called between BeginPlot() and EndPlot()!"); + IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "BarH() Needs to be called between BeginPlot() and EndPlot()!"); ImPlotItem* item = RegisterItem(label_id); if (!item->Show) return; - ImDrawList & DrawList = *GetWindowDrawList(); + ImDrawList & DrawList = *ImGui::GetWindowDrawList(); bool rend_line = gp.Style.Colors[ImPlotCol_Line].w != 0 && gp.Style.LineWeight > 0; bool rend_fill = gp.Style.Colors[ImPlotCol_Fill].w != 0; - ImU32 col_line = gp.Style.Colors[ImPlotCol_Line].w == -1 ? GetColorU32(item->Color) : GetColorU32(gp.Style.Colors[ImPlotCol_Line]); - ImU32 col_fill = gp.Style.Colors[ImPlotCol_Fill].w == -1 ? col_line : GetColorU32(gp.Style.Colors[ImPlotCol_Fill]); + ImU32 col_line = gp.Style.Colors[ImPlotCol_Line].w == -1 ? ImGui::GetColorU32(item->Color) : ImGui::GetColorU32(gp.Style.Colors[ImPlotCol_Line]); + ImU32 col_fill = gp.Style.Colors[ImPlotCol_Fill].w == -1 ? col_line : ImGui::GetColorU32(gp.Style.Colors[ImPlotCol_Fill]); if (rend_fill && col_line == col_fill) rend_line = false; @@ -2370,17 +2383,17 @@ void PlotBarHEx(const char* label_id, Getter getter, int count, float height, i PopPlotClipRect(); } -void PlotBarH(const char* label_id, const float* values, int count, float height, float shift, int offset, int stride) { +void BarH(const char* label_id, const float* values, int count, float height, float shift, int offset, int stride) { GetterBarH getter(values,shift,stride); PlotBarHEx(label_id, getter, count, height, offset); } -void PlotBarH(const char* label_id, const float* xs, const float* ys, int count, float height, int offset, int stride) { +void BarH(const char* label_id, const float* xs, const float* ys, int count, float height, int offset, int stride) { Getter2D getter(xs,ys,stride); PlotBarHEx(label_id, getter, count, height, offset); } -void PlotBarH(const char* label_id, ImVec2 (*getter_func)(void* data, int idx), void* data, int count, float height, int offset) { +void BarH(const char* label_id, ImVec2 (*getter_func)(void* data, int idx), void* data, int count, float height, int offset) { GetterFuncPtrImVec2 getter(getter_func, data); PlotBarHEx(label_id, getter, count, height, offset); } @@ -2404,18 +2417,18 @@ struct GetterError { template void PlotErrorBarsEx(const char* label_id, Getter getter, int count, int offset) { - IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "PlotErrorBars() Needs to be called between BeginPlot() and EndPlot()!"); + IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "ErrorBars() Needs to be called between BeginPlot() and EndPlot()!"); - ImGuiID id = GetID(label_id); + ImGuiID id = ImGui::GetID(label_id); ImPlotItem* item = gp.CurrentPlot->Items.GetByKey(id); if (item != NULL && item->Show == false) return; - ImDrawList & DrawList = *GetWindowDrawList(); + ImDrawList & DrawList = *ImGui::GetWindowDrawList(); PushPlotClipRect(); - const ImU32 col = gp.Style.Colors[ImPlotCol_ErrorBar].w == -1 ? GetColorU32(ImGuiCol_Text) : GetColorU32(gp.Style.Colors[ImPlotCol_ErrorBar]); + const ImU32 col = gp.Style.Colors[ImPlotCol_ErrorBar].w == -1 ? ImGui::GetColorU32(ImGuiCol_Text) : ImGui::GetColorU32(gp.Style.Colors[ImPlotCol_ErrorBar]); const bool rend_whisker = gp.Style.ErrorBarSize > 0; const float half_whisker = gp.Style.ErrorBarSize * 0.5f; @@ -2445,17 +2458,17 @@ void PlotErrorBarsEx(const char* label_id, Getter getter, int count, int offset) PopPlotClipRect(); } -void PlotErrorBars(const char* label_id, const float* xs, const float* ys, const float* err, int count, int offset, int stride) { +void ErrorBars(const char* label_id, const float* xs, const float* ys, const float* err, int count, int offset, int stride) { GetterError getter(xs, ys, err, err, stride); PlotErrorBarsEx(label_id, getter, count, offset); } -void PlotErrorBars(const char* label_id, const float* xs, const float* ys, const float* neg, const float* pos, int count, int offset, int stride) { +void ErrorBars(const char* label_id, const float* xs, const float* ys, const float* neg, const float* pos, int count, int offset, int stride) { GetterError getter(xs, ys, neg, pos, stride); PlotErrorBarsEx(label_id, getter, count, offset); } -void PlotErrorBars(const char* label_id, ImVec4 (*getter_func)(void* data, int idx), void* data, int count, int offset) { +void ErrorBars(const char* label_id, ImVec4 (*getter_func)(void* data, int idx), void* data, int count, int offset) { GetterFuncPtrImVec4 getter(getter_func, data); PlotErrorBarsEx(label_id, getter, count, offset); } @@ -2478,9 +2491,9 @@ inline void DrawPieSlice(ImDrawList& DrawList, const ImVec2& center, float radiu } -void PlotPieChart(const char** label_ids, float* values, int count, const ImVec2& center, float radius, bool show_percents, float angle0) { - IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "PlotPieChart() Needs to be called between BeginPlot() and EndPlot()!"); - ImDrawList & DrawList = *GetWindowDrawList(); +void PieChart(const char** label_ids, float* values, int count, const ImVec2& center, float radius, bool show_percents, float angle0) { + IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "PieChart() Needs to be called between BeginPlot() and EndPlot()!"); + ImDrawList & DrawList = *ImGui::GetWindowDrawList(); float sum = 0; for (int i = 0; i < count; ++i) @@ -2493,7 +2506,7 @@ void PlotPieChart(const char** label_ids, float* values, int count, const ImVec2 float a1 = angle0 * 2 * IM_PI / 360.0f; for (int i = 0; i < count; ++i) { ImPlotItem* item = RegisterItem(label_ids[i]); - ImU32 col = GetColorU32(item->Color); + ImU32 col = ImGui::GetColorU32(item->Color); float percent = normalize ? values[i] / sum : values[i]; a1 = a0 + 2 * IM_PI * percent; if (item->Show) { @@ -2507,7 +2520,7 @@ void PlotPieChart(const char** label_ids, float* values, int count, const ImVec2 if (show_percents) { static char buffer[8]; sprintf(buffer, "%.0f%%", percent * 100); - ImVec2 size = CalcTextSize(buffer); + ImVec2 size = ImGui::CalcTextSize(buffer); float angle = a0 + (a1 - a0) * 0.5f; ImVec2 pos = PlotToPixels(center.x + 0.5f * radius * cos(angle), center.y + 0.5f * radius * sin(angle)); DrawList.AddText(pos - size * 0.5f + ImVec2(1,1), IM_COL32(0,0,0,255), buffer); @@ -2519,8 +2532,8 @@ void PlotPieChart(const char** label_ids, float* values, int count, const ImVec2 PopPlotClipRect(); } -void PlotLabel(const char* text, float x, float y, bool vertical, const ImVec2& pixel_offset) { - IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "PlotLabel() Needs to be called between BeginPlot() and EndPlot()!"); +void Text(const char* text, float x, float y, bool vertical, const ImVec2& pixel_offset) { + IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "Text() Needs to be called between BeginPlot() and EndPlot()!"); ImDrawList & DrawList = *ImGui::GetWindowDrawList(); PushPlotClipRect(); ImVec2 pos = PlotToPixels({x,y}) + pixel_offset; @@ -2601,7 +2614,7 @@ inline void PlotDigitalEx(const char* label_id, Getter getter, int count, int of if ((pMax.x > pMin.x) && (!cull || gp.BB_Grid.Contains(pMin) || gp.BB_Grid.Contains(pMax))) { ImVec4 colAlpha = item->Color; colAlpha.w = item->Highlight ? 1.0f : 0.9f; - DrawList.AddRectFilled(pMin, pMax, GetColorU32(colAlpha)); + DrawList.AddRectFilled(pMin, pMax, ImGui::GetColorU32(colAlpha)); } } gp.DigitalPlotItemCnt++; @@ -2610,14 +2623,14 @@ inline void PlotDigitalEx(const char* label_id, Getter getter, int count, int of ImGui::PopClipRect(); } -void PlotDigital(const char* label_id, const float* xs, const float* ys, int count, int offset, int stride) { +void Digital(const char* label_id, const float* xs, const float* ys, int count, int offset, int stride) { Getter2D getter(xs,ys,stride); return PlotDigitalEx(label_id, getter, count, offset); } -void PlotDigital(const char* label_id, ImVec2 (*getter_func)(void* data, int idx), void* data, int count, int offset) { +void Digital(const char* label_id, ImVec2 (*getter_func)(void* data, int idx), void* data, int count, int offset) { GetterFuncPtrImVec2 getter(getter_func,data); return PlotDigitalEx(label_id, getter, count, offset); } -} // namespace ImGui +} // namespace ImPlot diff --git a/implot.h b/implot.h index 4911094..e1ef4b8 100644 --- a/implot.h +++ b/implot.h @@ -40,7 +40,7 @@ enum ImPlotFlags_ { ImPlotFlags_MousePos = 1 << 0, // the mouse position, in plot coordinates, will be displayed in the bottom-right ImPlotFlags_Legend = 1 << 1, // a legend will be displayed in the top-left ImPlotFlags_Highlight = 1 << 2, // plot items will be highlighted when their legend entry is hovered - ImPlotFlags_Selection = 1 << 3, // the user will be able to box-select with right-mouse + ImPlotFlags_BoxSelect = 1 << 3, // the user will be able to box-select with right-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 a context menu with double-right click ImPlotFlags_Crosshairs = 1 << 6, // the default mouse cursor will be replaced with a crosshair when hovered @@ -49,7 +49,7 @@ enum ImPlotFlags_ { ImPlotFlags_NoChild = 1 << 9, // a child window region will not be used to capture mouse scroll (can boost performance for single ImGui window applications) ImPlotFlags_YAxis2 = 1 << 10, // enable a 2nd y axis ImPlotFlags_YAxis3 = 1 << 11, // enable a 3rd y axis - ImPlotFlags_Default = ImPlotFlags_MousePos | ImPlotFlags_Legend | ImPlotFlags_Highlight | ImPlotFlags_Selection | ImPlotFlags_ContextMenu | ImPlotFlags_CullData + ImPlotFlags_Default = ImPlotFlags_MousePos | ImPlotFlags_Legend | ImPlotFlags_Highlight | ImPlotFlags_BoxSelect | ImPlotFlags_ContextMenu | ImPlotFlags_CullData }; // Options for plot axes (X and Y) @@ -126,6 +126,7 @@ struct ImPlotLimits { ImPlotRange X, Y; ImPlotLimits(); bool Contains(const ImVec2& p) const; + ImVec2 Size() const; }; // Plot style structure @@ -145,7 +146,7 @@ struct ImPlotStyle { // Core API //----------------------------------------------------------------------------- -namespace ImGui { +namespace ImPlot { // Starts a 2D plotting context. If this function returns true, EndPlot() must // be called, e.g. "if (BeginPlot(...)) { ... EndPlot(); }"". #title_id must @@ -175,24 +176,24 @@ void Plot(const char* label_id, const float* xs, const float* ys, int count, int void Plot(const char* label_id, const ImVec2* data, int count, int offset = 0); void Plot(const char* label_id, ImVec2 (*getter)(void* data, int idx), void* data, int count, int offset = 0); // Plots vertical bars. -void PlotBar(const char* label_id, const float* values, int count, float width = 0.67f, float shift = 0, int offset = 0, int stride = sizeof(float)); -void PlotBar(const char* label_id, const float* xs, const float* ys, int count, float width, int offset = 0, int stride = sizeof(float)); -void PlotBar(const char* label_id, ImVec2 (*getter)(void* data, int idx), void* data, int count, float width, int offset = 0); +void Bar(const char* label_id, const float* values, int count, float width = 0.67f, float shift = 0, int offset = 0, int stride = sizeof(float)); +void Bar(const char* label_id, const float* xs, const float* ys, int count, float width, int offset = 0, int stride = sizeof(float)); +void Bar(const char* label_id, ImVec2 (*getter)(void* data, int idx), void* data, int count, float width, int offset = 0); // Plots horizontal bars. -void PlotBarH(const char* label_id, const float* values, int count, float height = 0.67f, float shift = 0, int offset = 0, int stride = sizeof(float)); -void PlotBarH(const char* label_id, const float* xs, const float* ys, int count, float height, int offset = 0, int stride = sizeof(float)); -void PlotBarH(const char* label_id, ImVec2 (*getter)(void* data, int idx), void* data, int count, float height, int offset = 0); +void BarH(const char* label_id, const float* values, int count, float height = 0.67f, float shift = 0, int offset = 0, int stride = sizeof(float)); +void BarH(const char* label_id, const float* xs, const float* ys, int count, float height, int offset = 0, int stride = sizeof(float)); +void BarH(const char* label_id, ImVec2 (*getter)(void* data, int idx), void* data, int count, float height, int offset = 0); // Plots vertical error bars. -void PlotErrorBars(const char* label_id, const float* xs, const float* ys, const float* err, int count, int offset = 0, int stride = sizeof(float)); -void PlotErrorBars(const char* label_id, const float* xs, const float* ys, const float* neg, const float* pos, int count, int offset = 0, int stride = sizeof(float)); -void PlotErrorBars(const char* label_id, ImVec4 (*getter)(void* data, int idx), void* data, int count, int offset = 0); +void ErrorBars(const char* label_id, const float* xs, const float* ys, const float* err, int count, int offset = 0, int stride = sizeof(float)); +void ErrorBars(const char* label_id, const float* xs, const float* ys, const float* neg, const float* pos, int count, int offset = 0, int stride = sizeof(float)); +void ErrorBars(const char* label_id, ImVec4 (*getter)(void* data, int idx), void* data, int count, int offset = 0); // Plots a pie chart. If the sum of values > 1, each value will be normalized. Center and radius are in plot coordinates. -void PlotPieChart(const char** label_ids, float* values, int count, const ImVec2& center, float radius, bool show_percents = true, float angle0 = 90); -// Plots a text label at point x,y. -void PlotLabel(const char* text, float x, float y, bool vertical = false, const ImVec2& pixel_offset = ImVec2(0,0)); +void PieChart(const char** label_ids, float* values, int count, const ImVec2& center, float radius, bool show_percents = true, float angle0 = 90); // Plots digital channels. -void PlotDigital(const char* label_id, const float* xs, const float* ys, int count, int offset = 0, int stride = sizeof(float)); -void PlotDigital(const char* label_id, ImVec2 (*getter)(void* data, int idx), void* data, int count, int offset = 0); +void Digital(const char* label_id, const float* xs, const float* ys, int count, int offset = 0, int stride = sizeof(float)); +void Digital(const char* label_id, ImVec2 (*getter)(void* data, int idx), void* data, int count, int offset = 0); +// Plots a text label at point x,y. +void Text(const char* text, float x, float y, bool vertical = false, const ImVec2& pixel_offset = ImVec2(0,0)); //----------------------------------------------------------------------------- // Plot Queries @@ -214,26 +215,26 @@ ImPlotLimits GetPlotQuery(int y_axis = -1); //----------------------------------------------------------------------------- // Provides access to plot style structure for permanant modifications to colors, sizes, etc. -ImPlotStyle& GetPlotStyle(); +ImPlotStyle& GetStyle(); // Sets the color palette to be used for plot items. -void SetPlotPalette(const ImVec4* colors, int num_colors); +void SetPalette(const ImVec4* colors, int num_colors); // Restores the default ImPlot color map. -void RestorePlotPalette(); +void RestorePalette(); // Temporarily modify a plot color. -void PushPlotColor(ImPlotCol idx, ImU32 col); +void PushStyleColor(ImPlotCol idx, ImU32 col); // Temporarily modify a plot color. -void PushPlotColor(ImPlotCol idx, const ImVec4& col); +void PushStyleColor(ImPlotCol idx, const ImVec4& col); // Undo temporary color modification. -void PopPlotColor(int count = 1); +void PopStyleColor(int count = 1); // Temporarily modify a style variable of float type. -void PushPlotStyleVar(ImPlotStyleVar idx, float val); +void PushStyleVar(ImPlotStyleVar idx, float val); // Temporarily modify a style variable of int type. -void PushPlotStyleVar(ImPlotStyleVar idx, int val); +void PushStyleVar(ImPlotStyleVar idx, int val); // Undo temporary style modification. -void PopPlotStyleVar(int count = 1); +void PopStyleVar(int count = 1); //----------------------------------------------------------------------------- // Plot Utils @@ -269,6 +270,6 @@ void PopPlotClipRect(); //----------------------------------------------------------------------------- // Shows the ImPlot demo. Add implot_demo.cpp to your sources! -void ShowImPlotDemoWindow(bool* p_open = NULL); +void ShowDemoWindow(bool* p_open = NULL); -} // namespace ImGui +} // namespace ImPlot diff --git a/implot_demo.cpp b/implot_demo.cpp index 192a4bb..85343d6 100644 --- a/implot_demo.cpp +++ b/implot_demo.cpp @@ -90,16 +90,27 @@ struct BenchmarkItem { ImVec4 Col; }; -} +} // private namespace -namespace ImGui { +namespace ImPlot { -void ShowImPlotDemoWindow(bool* p_open) { - - //ImVec2 main_viewport_pos = ImGui::GetMainViewport()->Pos; +void ShowDemoWindow(bool* p_open) { + static bool show_app_metrics = false; + static bool show_app_style_editor = false; + if (show_app_metrics) { ImGui::ShowMetricsWindow(&show_app_metrics); } + if (show_app_style_editor) { ImGui::Begin("Style Editor", &show_app_style_editor); ImGui::ShowStyleEditor(); ImGui::End(); } ImGui::SetNextWindowPos(ImVec2(50, 50), ImGuiCond_FirstUseEver); ImGui::SetNextWindowSize(ImVec2(520, 750), ImGuiCond_FirstUseEver); - ImGui::Begin("ImPlot Demo", p_open); + ImGui::Begin("ImPlot Demo", p_open, ImGuiWindowFlags_MenuBar); + if (ImGui::BeginMenuBar()) { + if (ImGui::BeginMenu("Tools")) { + ImGui::MenuItem("Metrics", NULL, &show_app_metrics); + ImGui::MenuItem("Style Editor (ImGui)", NULL, &show_app_style_editor); + ImGui::EndMenu(); + } + ImGui::EndMenuBar(); + } + //------------------------------------------------------------------------- ImGui::Text("ImPlot says hello. (0.2 WIP)"); if (ImGui::CollapsingHeader("Help")) { ImGui::Text("USER GUIDE:"); @@ -136,12 +147,12 @@ void ShowImPlotDemoWindow(bool* p_open) { xs2[i] = i * 0.1f; ys2[i] = xs2[i] * xs2[i]; } - if (ImGui::BeginPlot("Line Plot", "x", "f(x)", {-1,300})) { - ImGui::Plot("sin(50*x)", xs1, ys1, 1001); - ImGui::PushPlotStyleVar(ImPlotStyleVar_Marker, ImMarker_Circle); - ImGui::Plot("x^2", xs2, ys2, 11); - ImGui::PopPlotStyleVar(); - ImGui::EndPlot(); + if (ImPlot::BeginPlot("Line Plot", "x", "f(x)", {-1,300})) { + ImPlot::Plot("sin(50*x)", xs1, ys1, 1001); + ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Circle); + ImPlot::Plot("x^2", xs2, ys2, 11); + ImPlot::PopStyleVar(); + ImPlot::EndPlot(); } } //------------------------------------------------------------------------- @@ -157,18 +168,18 @@ void ShowImPlotDemoWindow(bool* p_open) { xs2[i] = 0.25f + 0.2f * ((float)rand() / (float)RAND_MAX); ys2[i] = 0.75f + 0.2f * ((float)rand() / (float)RAND_MAX); } - if (ImGui::BeginPlot("Scatter Plot", NULL, NULL, {-1,300})) { - ImGui::PushPlotStyleVar(ImPlotStyleVar_LineWeight, 0); - ImGui::PushPlotStyleVar(ImPlotStyleVar_Marker, ImMarker_Cross); - ImGui::PushPlotStyleVar(ImPlotStyleVar_MarkerSize, 3); - ImGui::Plot("Data 1", xs1, ys1, 100); - ImGui::PopPlotStyleVar(2); - ImGui::PushPlotStyleVar(ImPlotStyleVar_Marker, ImMarker_Circle); - ImGui::PushPlotColor(ImPlotCol_MarkerFill, ImVec4{1,0,0,0.25f}); - ImGui::Plot("Data 2", xs2, ys2, 50); - ImGui::PopPlotColor(); - ImGui::PopPlotStyleVar(2); - ImGui::EndPlot(); + if (ImPlot::BeginPlot("Scatter Plot", NULL, NULL, {-1,300})) { + ImPlot::PushStyleVar(ImPlotStyleVar_LineWeight, 0); + ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Cross); + ImPlot::PushStyleVar(ImPlotStyleVar_MarkerSize, 3); + ImPlot::Plot("Data 1", xs1, ys1, 100); + ImPlot::PopStyleVar(2); + ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Circle); + ImPlot::PushStyleColor(ImPlotCol_MarkerFill, ImVec4{1,0,0,0.25f}); + ImPlot::Plot("Data 2", xs2, ys2, 50); + ImPlot::PopStyleColor(); + ImPlot::PopStyleVar(2); + ImPlot::EndPlot(); } } //------------------------------------------------------------------------- @@ -176,24 +187,24 @@ void ShowImPlotDemoWindow(bool* p_open) { static bool horz = false; ImGui::Checkbox("Horizontal",&horz); if (horz) - ImGui::SetNextPlotLimits(0, 110, -0.5f, 9.5f, ImGuiCond_Always); + ImPlot::SetNextPlotLimits(0, 110, -0.5f, 9.5f, ImGuiCond_Always); else - ImGui::SetNextPlotLimits(-0.5f, 9.5f, 0, 110, ImGuiCond_Always); - if (ImGui::BeginPlot("Bar Plot", horz ? "Score": "Student", horz ? "Student" : "Score", {-1, 300})) { + ImPlot::SetNextPlotLimits(-0.5f, 9.5f, 0, 110, ImGuiCond_Always); + if (ImPlot::BeginPlot("Bar Plot", horz ? "Score": "Student", horz ? "Student" : "Score", {-1, 300})) { static float midtm[10] = {83, 67, 23, 89, 83, 78, 91, 82, 85, 90}; static float final[10] = {80, 62, 56, 99, 55, 78, 88, 78, 90, 100}; static float grade[10] = {80, 69, 52, 92, 72, 78, 75, 76, 89, 95}; if (horz) { - ImGui::PlotBarH("Midterm Exam", midtm, 10, 0.2f, -0.2f); - ImGui::PlotBarH("Final Exam", final, 10, 0.2f, 0); - ImGui::PlotBarH("Course Grade", grade, 10, 0.2f, 0.2f); + ImPlot::BarH("Midterm Exam", midtm, 10, 0.2f, -0.2f); + ImPlot::BarH("Final Exam", final, 10, 0.2f, 0); + ImPlot::BarH("Course Grade", grade, 10, 0.2f, 0.2f); } else { - ImGui::PlotBar("Midterm Exam", midtm, 10, 0.2f, -0.2f); - ImGui::PlotBar("Final Exam", final, 10, 0.2f, 0); - ImGui::PlotBar("Course Grade", grade, 10, 0.2f, 0.2f); + ImPlot::Bar("Midterm Exam", midtm, 10, 0.2f, -0.2f); + ImPlot::Bar("Final Exam", final, 10, 0.2f, 0); + ImPlot::Bar("Course Grade", grade, 10, 0.2f, 0.2f); } - ImGui::EndPlot(); + ImPlot::EndPlot(); } } //------------------------------------------------------------------------- @@ -203,21 +214,21 @@ void ShowImPlotDemoWindow(bool* p_open) { float bar[5] = {1,2,5,3,4}; float err1[5] = {0.2f, 0.4f, 0.2f, 0.6f, 0.4f}; float err2[5] = {0.4f, 0.2f, 0.4f, 0.8f, 0.6f}; - ImGui::SetNextPlotLimits(0, 6, 0, 10); - if (ImGui::BeginPlot("##ErrorBars",NULL,NULL,ImVec2(-1,300))) { + ImPlot::SetNextPlotLimits(0, 6, 0, 10); + if (ImPlot::BeginPlot("##ErrorBars",NULL,NULL,ImVec2(-1,300))) { - ImGui::PlotBar("Bar", xs, bar, 5, 0.5f); - ImGui::PlotErrorBars("Bar", xs, bar, err1, 5); + ImPlot::Bar("Bar", xs, bar, 5, 0.5f); + ImPlot::ErrorBars("Bar", xs, bar, err1, 5); - ImGui::PushPlotStyleVar(ImPlotStyleVar_Marker, ImMarker_Circle); - ImGui::PushPlotStyleVar(ImPlotStyleVar_MarkerSize, 3); - ImGui::PushPlotColor(ImPlotCol_ErrorBar, ImVec4(1,0,0,1)); - ImGui::PlotErrorBars("Line", xs, lin, err1, err2, 5); - ImGui::Plot("Line", xs, lin, 5); - ImGui::PopPlotStyleVar(2); - ImGui::PopPlotColor(); + ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Circle); + ImPlot::PushStyleVar(ImPlotStyleVar_MarkerSize, 3); + ImPlot::PushStyleColor(ImPlotCol_ErrorBar, ImVec4(1,0,0,1)); + ImPlot::ErrorBars("Line", xs, lin, err1, err2, 5); + ImPlot::Plot("Line", xs, lin, 5); + ImPlot::PopStyleVar(2); + ImPlot::PopStyleColor(); - ImGui::EndPlot(); + ImPlot::EndPlot(); } } //------------------------------------------------------------------------- @@ -228,9 +239,9 @@ void ShowImPlotDemoWindow(bool* p_open) { float radius = 0.4f; // in plot units, not pixels SetNextPlotLimits(0,1,0,1,ImGuiCond_Always); - if (ImGui::BeginPlot("##Pie1", NULL, NULL, ImVec2(250,250), ImPlotFlags_Legend, 0, 0)) { - ImGui::PlotPieChart(labels1, pre_normalized, 4, center, radius); - ImGui::EndPlot(); + if (ImPlot::BeginPlot("##Pie1", NULL, NULL, ImVec2(250,250), ImPlotFlags_Legend, 0, 0)) { + ImPlot::PieChart(labels1, pre_normalized, 4, center, radius); + ImPlot::EndPlot(); } ImGui::SameLine(); @@ -241,17 +252,16 @@ void ShowImPlotDemoWindow(bool* p_open) { {0.9882f, 0.3059f, 0.1647f, 1.0f}, {0.7412f, 0.0f, 0.1490f, 1.0f}, }; - ImGui::SetPlotPalette(YlOrRd, 5); + ImPlot::SetPalette(YlOrRd, 5); SetNextPlotLimits(0,1,0,1,ImGuiCond_Always); static const char* labels2[] = {"One","Two","Three","Four","Five"}; static float not_normalized[] = {1,2,3,4,5}; - if (ImGui::BeginPlot("##Pie2", NULL, NULL, ImVec2(250,250), ImPlotFlags_Legend, 0, 0)) { - ImGui::PlotPieChart(labels2, not_normalized, 5, center, radius); - ImGui::EndPlot(); + if (ImPlot::BeginPlot("##Pie2", NULL, NULL, ImVec2(250,250), ImPlotFlags_Legend, 0, 0)) { + ImPlot::PieChart(labels2, not_normalized, 5, center, radius); + ImPlot::EndPlot(); } - ImGui::RestorePlotPalette(); + ImPlot::RestorePalette(); } - //------------------------------------------------------------------------- if (ImGui::CollapsingHeader("Realtime Plots")) { ImGui::BulletText("Move your mouse to change the data!"); @@ -268,95 +278,94 @@ void ShowImPlotDemoWindow(bool* p_open) { sdata2.AddPoint(t, mouse.y * 0.0005f); rdata2.AddPoint(t, mouse.y * 0.0005f); } - ImGui::SetNextPlotLimitsX(t - 10, t, paused ? ImGuiCond_Once : ImGuiCond_Always); + ImPlot::SetNextPlotLimitsX(t - 10, t, paused ? ImGuiCond_Once : ImGuiCond_Always); static int rt_axis = ImAxisFlags_Default & ~ImAxisFlags_TickLabels; - if (ImGui::BeginPlot("##Scrolling", NULL, NULL, {-1,150}, ImPlotFlags_Default, rt_axis, rt_axis)) { - ImGui::Plot("Data 1", &sdata1.Data[0].x, &sdata1.Data[0].y, sdata1.Data.size(), sdata1.Offset, 2 * sizeof(float)); - ImGui::Plot("Data 2", &sdata2.Data[0].x, &sdata2.Data[0].y, sdata2.Data.size(), sdata2.Offset, 2 * sizeof(float)); - ImGui::EndPlot(); + if (ImPlot::BeginPlot("##Scrolling", NULL, NULL, {-1,150}, ImPlotFlags_Default, rt_axis, rt_axis)) { + ImPlot::Plot("Data 1", &sdata1.Data[0].x, &sdata1.Data[0].y, sdata1.Data.size(), sdata1.Offset, 2 * sizeof(float)); + ImPlot::Plot("Data 2", &sdata2.Data[0].x, &sdata2.Data[0].y, sdata2.Data.size(), sdata2.Offset, 2 * sizeof(float)); + ImPlot::EndPlot(); } - ImGui::SetNextPlotLimitsX(0, 10, ImGuiCond_Always); - if (ImGui::BeginPlot("##Rolling", NULL, NULL, {-1,150}, ImPlotFlags_Default, rt_axis, rt_axis)) { - ImGui::Plot("Data 1", &rdata1.Data[0].x, &rdata1.Data[0].y, rdata1.Data.size(), 0, 2 * sizeof(float)); - ImGui::Plot("Data 2", &rdata2.Data[0].x, &rdata2.Data[0].y, rdata2.Data.size(), 0, 2 * sizeof(float)); - ImGui::EndPlot(); + ImPlot::SetNextPlotLimitsX(0, 10, ImGuiCond_Always); + if (ImPlot::BeginPlot("##Rolling", NULL, NULL, {-1,150}, ImPlotFlags_Default, rt_axis, rt_axis)) { + ImPlot::Plot("Data 1", &rdata1.Data[0].x, &rdata1.Data[0].y, rdata1.Data.size(), 0, 2 * sizeof(float)); + ImPlot::Plot("Data 2", &rdata2.Data[0].x, &rdata2.Data[0].y, rdata2.Data.size(), 0, 2 * sizeof(float)); + ImPlot::EndPlot(); } } - //------------------------------------------------------------------------- - if (ImGui::CollapsingHeader("Markers and Labels")) { - ImGui::SetNextPlotLimits(0, 10, 0, 12); - if (ImGui::BeginPlot("##MarkerStyles", NULL, NULL, ImVec2(-1,300), 0, 0, 0)) { + if (ImGui::CollapsingHeader("Markers and Text")) { + ImPlot::SetNextPlotLimits(0, 10, 0, 12); + if (ImPlot::BeginPlot("##MarkerStyles", NULL, NULL, ImVec2(-1,300), 0, 0, 0)) { float xs[2] = {1,4}; float ys[2] = {10,11}; // filled - ImGui::PushPlotStyleVar(ImPlotStyleVar_Marker, ImMarker_Circle); - ImGui::Plot("Circle##Fill", xs, ys, 2); - ImGui::PushPlotStyleVar(ImPlotStyleVar_Marker, ImMarker_Square); ys[0]--; ys[1]--; - ImGui::Plot("Square##Fill", xs, ys, 2); - ImGui::PushPlotStyleVar(ImPlotStyleVar_Marker, ImMarker_Diamond); ys[0]--; ys[1]--; - ImGui::Plot("Diamond##Fill", xs, ys, 2); - ImGui::PushPlotStyleVar(ImPlotStyleVar_Marker, ImMarker_Up); ys[0]--; ys[1]--; - ImGui::Plot("Up##Fill", xs, ys, 2); - ImGui::PushPlotStyleVar(ImPlotStyleVar_Marker, ImMarker_Down); ys[0]--; ys[1]--; - ImGui::Plot("Down##Fill", xs, ys, 2); - ImGui::PushPlotStyleVar(ImPlotStyleVar_Marker, ImMarker_Left); ys[0]--; ys[1]--; - ImGui::Plot("Left##Fill", xs, ys, 2); - ImGui::PushPlotStyleVar(ImPlotStyleVar_Marker, ImMarker_Right); ys[0]--; ys[1]--; - ImGui::Plot("Right##Fill", xs, ys, 2); - ImGui::PushPlotStyleVar(ImPlotStyleVar_Marker, ImMarker_Cross); ys[0]--; ys[1]--; - ImGui::Plot("Cross##Fill", xs, ys, 2); - ImGui::PushPlotStyleVar(ImPlotStyleVar_Marker, ImMarker_Plus); ys[0]--; ys[1]--; - ImGui::Plot("Plus##Fill", xs, ys, 2); - ImGui::PushPlotStyleVar(ImPlotStyleVar_Marker, ImMarker_Asterisk); ys[0]--; ys[1]--; - ImGui::Plot("Asterisk##Fill", xs, ys, 2); - ImGui::PopPlotStyleVar(10); + ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Circle); + ImPlot::Plot("Circle##Fill", xs, ys, 2); + ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Square); ys[0]--; ys[1]--; + ImPlot::Plot("Square##Fill", xs, ys, 2); + ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Diamond); ys[0]--; ys[1]--; + ImPlot::Plot("Diamond##Fill", xs, ys, 2); + ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Up); ys[0]--; ys[1]--; + ImPlot::Plot("Up##Fill", xs, ys, 2); + ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Down); ys[0]--; ys[1]--; + ImPlot::Plot("Down##Fill", xs, ys, 2); + ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Left); ys[0]--; ys[1]--; + ImPlot::Plot("Left##Fill", xs, ys, 2); + ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Right); ys[0]--; ys[1]--; + ImPlot::Plot("Right##Fill", xs, ys, 2); + ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Cross); ys[0]--; ys[1]--; + ImPlot::Plot("Cross##Fill", xs, ys, 2); + ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Plus); ys[0]--; ys[1]--; + ImPlot::Plot("Plus##Fill", xs, ys, 2); + ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Asterisk); ys[0]--; ys[1]--; + ImPlot::Plot("Asterisk##Fill", xs, ys, 2); + ImPlot::PopStyleVar(10); xs[0] = 6; xs[1] = 9; ys[0] = 10; ys[1] = 11; - ImGui::PushPlotColor(ImPlotCol_MarkerFill, ImVec4(0,0,0,0)); - ImGui::PushPlotStyleVar(ImPlotStyleVar_Marker, ImMarker_Circle); - ImGui::Plot("Circle", xs, ys, 2); - ImGui::PushPlotStyleVar(ImPlotStyleVar_Marker, ImMarker_Square); ys[0]--; ys[1]--; - ImGui::Plot("Square", xs, ys, 2); - ImGui::PushPlotStyleVar(ImPlotStyleVar_Marker, ImMarker_Diamond); ys[0]--; ys[1]--; - ImGui::Plot("Diamond", xs, ys, 2); - ImGui::PushPlotStyleVar(ImPlotStyleVar_Marker, ImMarker_Up); ys[0]--; ys[1]--; - ImGui::Plot("Up", xs, ys, 2); - ImGui::PushPlotStyleVar(ImPlotStyleVar_Marker, ImMarker_Down); ys[0]--; ys[1]--; - ImGui::Plot("Down", xs, ys, 2); - ImGui::PushPlotStyleVar(ImPlotStyleVar_Marker, ImMarker_Left); ys[0]--; ys[1]--; - ImGui::Plot("Left", xs, ys, 2); - ImGui::PushPlotStyleVar(ImPlotStyleVar_Marker, ImMarker_Right); ys[0]--; ys[1]--; - ImGui::Plot("Right", xs, ys, 2); - ImGui::PushPlotStyleVar(ImPlotStyleVar_Marker, ImMarker_Cross); ys[0]--; ys[1]--; - ImGui::Plot("Cross", xs, ys, 2); - ImGui::PushPlotStyleVar(ImPlotStyleVar_Marker, ImMarker_Plus); ys[0]--; ys[1]--; - ImGui::Plot("Plus", xs, ys, 2); - ImGui::PushPlotStyleVar(ImPlotStyleVar_Marker, ImMarker_Asterisk); ys[0]--; ys[1]--; - ImGui::Plot("Asterisk", xs, ys, 2); - ImGui::PopPlotColor(); - ImGui::PopPlotStyleVar(10); + ImPlot::PushStyleColor(ImPlotCol_MarkerFill, ImVec4(0,0,0,0)); + ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Circle); + ImPlot::Plot("Circle", xs, ys, 2); + ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Square); ys[0]--; ys[1]--; + ImPlot::Plot("Square", xs, ys, 2); + ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Diamond); ys[0]--; ys[1]--; + ImPlot::Plot("Diamond", xs, ys, 2); + ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Up); ys[0]--; ys[1]--; + ImPlot::Plot("Up", xs, ys, 2); + ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Down); ys[0]--; ys[1]--; + ImPlot::Plot("Down", xs, ys, 2); + ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Left); ys[0]--; ys[1]--; + ImPlot::Plot("Left", xs, ys, 2); + ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Right); ys[0]--; ys[1]--; + ImPlot::Plot("Right", xs, ys, 2); + ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Cross); ys[0]--; ys[1]--; + ImPlot::Plot("Cross", xs, ys, 2); + ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Plus); ys[0]--; ys[1]--; + ImPlot::Plot("Plus", xs, ys, 2); + ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Asterisk); ys[0]--; ys[1]--; + ImPlot::Plot("Asterisk", xs, ys, 2); + ImPlot::PopStyleColor(); + ImPlot::PopStyleVar(10); xs[0] = 5; xs[1] = 5; ys[0] = 1; ys[1] = 11; - ImGui::PushPlotStyleVar(ImPlotStyleVar_LineWeight, 2); - ImGui::PushPlotStyleVar(ImPlotStyleVar_MarkerSize, 8); - ImGui::PushPlotStyleVar(ImPlotStyleVar_MarkerWeight, 2); - ImGui::PushPlotStyleVar(ImPlotStyleVar_Marker, ImMarker_Circle | ImMarker_Cross); - ImGui::PushPlotColor(ImPlotCol_MarkerOutline, ImVec4(0,0,0,1)); - ImGui::PushPlotColor(ImPlotCol_MarkerFill, ImVec4(1,1,1,1)); - ImGui::PushPlotColor(ImPlotCol_Line, ImVec4(0,0,0,1)); - ImGui::Plot("Circle|Cross", xs, ys, 2); - ImGui::PopPlotStyleVar(4); - ImGui::PopPlotColor(3); + ImPlot::PushStyleVar(ImPlotStyleVar_LineWeight, 2); + ImPlot::PushStyleVar(ImPlotStyleVar_MarkerSize, 8); + ImPlot::PushStyleVar(ImPlotStyleVar_MarkerWeight, 2); + ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Circle | ImMarker_Cross); + ImPlot::PushStyleColor(ImPlotCol_MarkerOutline, ImVec4(0,0,0,1)); + ImPlot::PushStyleColor(ImPlotCol_MarkerFill, ImVec4(1,1,1,1)); + ImPlot::PushStyleColor(ImPlotCol_Line, ImVec4(0,0,0,1)); + ImPlot::Plot("Circle|Cross", xs, ys, 2); + ImPlot::PopStyleVar(4); + ImPlot::PopStyleColor(3); - ImGui::PlotLabel("Filled Markers", 1.5, 11.75); - ImGui::PlotLabel("Open Markers", 6.75, 11.75); - ImGui::PlotLabel("Fancy Markers", 4.5, 4.25, true); + ImPlot::Text("Filled Markers", 1.5, 11.75); + ImPlot::Text("Open Markers", 6.75, 11.75); + ImPlot::Text("Fancy Markers", 4.5, 4.25, true); - ImGui::EndPlot(); + ImPlot::EndPlot(); } } //------------------------------------------------------------------------- @@ -369,13 +378,13 @@ void ShowImPlotDemoWindow(bool* p_open) { ys2[i] = log(xs[i]); ys3[i] = pow(10.0f, xs[i]); } - ImGui::SetNextPlotLimits(0.1f, 100, 0, 10); - if (ImGui::BeginPlot("Log Plot", NULL, NULL, ImVec2(-1,300), ImPlotFlags_Default, ImAxisFlags_Default | ImAxisFlags_LogScale )) { - ImGui::Plot("f(x) = x", xs, xs, 1001); - ImGui::Plot("f(x) = sin(x)+1", xs, ys1, 1001); - ImGui::Plot("f(x) = log(x)", xs, ys2, 1001); - ImGui::Plot("f(x) = 10^x", xs, ys3, 21); - ImGui::EndPlot(); + ImPlot::SetNextPlotLimits(0.1f, 100, 0, 10); + if (ImPlot::BeginPlot("Log Plot", NULL, NULL, ImVec2(-1,300), ImPlotFlags_Default, ImAxisFlags_Default | ImAxisFlags_LogScale )) { + ImPlot::Plot("f(x) = x", xs, xs, 1001); + ImPlot::Plot("f(x) = sin(x)+1", xs, ys1, 1001); + ImPlot::Plot("f(x) = log(x)", xs, ys2, 1001); + ImPlot::Plot("f(x) = 10^x", xs, ys3, 21); + ImPlot::EndPlot(); } } //------------------------------------------------------------------------- @@ -405,33 +414,33 @@ void ShowImPlotDemoWindow(bool* p_open) { ys3[i] = sin(xs[i]+0.5f) * 100 + 200; xs2[i] = xs[i] + 10.0f; } - ImGui::SetNextPlotLimits(0.1f, 100, 0, 10); - ImGui::SetNextPlotLimitsY(0, 1, ImGuiCond_Once, 1); - ImGui::SetNextPlotLimitsY(0, 300, ImGuiCond_Once, 2); - ImGui::PushPlotColor(ImPlotCol_YAxis, y1_col); - ImGui::PushPlotColor(ImPlotCol_YAxis2, y2_col); - ImGui::PushPlotColor(ImPlotCol_YAxis3, y3_col); + ImPlot::SetNextPlotLimits(0.1f, 100, 0, 10); + ImPlot::SetNextPlotLimitsY(0, 1, ImGuiCond_Once, 1); + ImPlot::SetNextPlotLimitsY(0, 300, ImGuiCond_Once, 2); + ImPlot::PushStyleColor(ImPlotCol_YAxis, y1_col); + ImPlot::PushStyleColor(ImPlotCol_YAxis2, y2_col); + ImPlot::PushStyleColor(ImPlotCol_YAxis3, y3_col); - if (ImGui::BeginPlot("Multi-Axis Plot", NULL, NULL, ImVec2(-1,300), + if (ImPlot::BeginPlot("Multi-Axis Plot", NULL, NULL, ImVec2(-1,300), ImPlotFlags_Default | (y2_axis ? ImPlotFlags_YAxis2 : 0) | (y3_axis ? ImPlotFlags_YAxis3 : 0))) { - ImGui::Plot("f(x) = x", xs, xs, 1001); - ImGui::Plot("f(x) = sin(x)*3+1", xs, ys1, 1001); + ImPlot::Plot("f(x) = x", xs, xs, 1001); + ImPlot::Plot("f(x) = sin(x)*3+1", xs, ys1, 1001); if (y2_axis) { - ImGui::SetPlotYAxis(1); - ImGui::Plot("f(x) = cos(x)*.2+.5 (Y2)", xs, ys2, 1001); + ImPlot::SetPlotYAxis(1); + ImPlot::Plot("f(x) = cos(x)*.2+.5 (Y2)", xs, ys2, 1001); } if (y3_axis) { - ImGui::SetPlotYAxis(2); - ImGui::Plot("f(x) = sin(x+.5)*100+200 (Y3)", xs2, ys3, 1001); + ImPlot::SetPlotYAxis(2); + ImPlot::Plot("f(x) = sin(x+.5)*100+200 (Y3)", xs2, ys3, 1001); } - ImGui::EndPlot(); + ImPlot::EndPlot(); } - ImGui::PopPlotColor(3); + ImPlot::PopStyleColor(3); } //------------------------------------------------------------------------- if (ImGui::CollapsingHeader("Querying")) { @@ -444,15 +453,15 @@ void ShowImPlotDemoWindow(bool* p_open) { ImGui::Unindent(); static ImVector data; ImPlotLimits range, query; - if (ImGui::BeginPlot("##Drawing", NULL, NULL, ImVec2(-1,300), ImPlotFlags_Default | ImPlotFlags_Query, ImAxisFlags_GridLines, ImAxisFlags_GridLines)) { - if (ImGui::IsPlotHovered() && ImGui::IsMouseClicked(0) && ImGui::GetIO().KeyCtrl) - data.push_back(ImGui::GetPlotMousePos()); - ImGui::PushPlotStyleVar(ImPlotStyleVar_LineWeight, 0); - ImGui::PushPlotStyleVar(ImPlotStyleVar_Marker, ImMarker_Diamond); + if (ImPlot::BeginPlot("##Drawing", NULL, NULL, ImVec2(-1,300), ImPlotFlags_Default | ImPlotFlags_Query, ImAxisFlags_GridLines, ImAxisFlags_GridLines)) { + if (ImPlot::IsPlotHovered() && ImGui::IsMouseClicked(0) && ImGui::GetIO().KeyCtrl) + data.push_back(ImPlot::GetPlotMousePos()); + ImPlot::PushStyleVar(ImPlotStyleVar_LineWeight, 0); + ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Diamond); if (data.size() > 0) - ImGui::Plot("Points", &data[0].x, &data[0].y, data.size(), 0, 2 * sizeof(float)); - if (ImGui::IsPlotQueried() && data.size() > 0) { - ImPlotLimits range = ImGui::GetPlotQuery(); + ImPlot::Plot("Points", &data[0].x, &data[0].y, data.size(), 0, 2 * sizeof(float)); + if (ImPlot::IsPlotQueried() && data.size() > 0) { + ImPlotLimits range = ImPlot::GetPlotQuery(); int cnt = 0; ImVec2 avg; for (int i = 0; i < data.size(); ++i) { @@ -465,13 +474,13 @@ void ShowImPlotDemoWindow(bool* p_open) { if (cnt > 0) { avg.x = avg.x / cnt; avg.y = avg.y / cnt; - ImGui::Plot("Average", &avg.x, &avg.y, 1); + ImPlot::Plot("Average", &avg.x, &avg.y, 1); } } - ImGui::PopPlotStyleVar(2); - range = ImGui::GetPlotLimits(); - query = ImGui::GetPlotQuery(); - ImGui::EndPlot(); + ImPlot::PopStyleVar(2); + range = ImPlot::GetPlotLimits(); + query = ImPlot::GetPlotQuery(); + ImPlot::EndPlot(); } ImGui::Text("The current plot limits are: [%g,%g,%g,%g]", range.X.Min, range.X.Max, range.Y.Min, range.Y.Max); ImGui::Text("The current query limits are: [%g,%g,%g,%g]", query.X.Min, query.X.Max, query.Y.Min, query.Y.Max); @@ -494,22 +503,22 @@ void ShowImPlotDemoWindow(bool* p_open) { y_data3[i] = y_data2[i] * -0.6f + sin(3 * arg) * 0.4f; } ImGui::BulletText("Query the first plot to render a subview in the second plot (see above for controls)."); - ImGui::SetNextPlotLimits(0,0.01f,-1,1); + ImPlot::SetNextPlotLimits(0,0.01f,-1,1); ImAxisFlags flgs = ImAxisFlags_Default & ~ImAxisFlags_TickLabels; ImPlotLimits query; - if (ImGui::BeginPlot("##View1",NULL,NULL,ImVec2(-1,150), ImPlotFlags_Default | ImPlotFlags_Query, flgs, flgs)) { - ImGui::Plot("Signal 1", x_data, y_data1, 512); - ImGui::Plot("Signal 2", x_data, y_data2, 512); - ImGui::Plot("Signal 3", x_data, y_data3, 512); - query = ImGui::GetPlotQuery(); - ImGui::EndPlot(); + if (ImPlot::BeginPlot("##View1",NULL,NULL,ImVec2(-1,150), ImPlotFlags_Default | ImPlotFlags_Query, flgs, flgs)) { + ImPlot::Plot("Signal 1", x_data, y_data1, 512); + ImPlot::Plot("Signal 2", x_data, y_data2, 512); + ImPlot::Plot("Signal 3", x_data, y_data3, 512); + query = ImPlot::GetPlotQuery(); + ImPlot::EndPlot(); } - ImGui::SetNextPlotLimits(query.X.Min, query.X.Max, query.Y.Min, query.Y.Max, ImGuiCond_Always); - if (ImGui::BeginPlot("##View2",NULL,NULL,ImVec2(-1,150), 0, 0, 0)) { - ImGui::Plot("Signal 1", x_data, y_data1, 512); - ImGui::Plot("Signal 2", x_data, y_data2, 512); - ImGui::Plot("Signal 3", x_data, y_data3, 512); - ImGui::EndPlot(); + ImPlot::SetNextPlotLimits(query.X.Min, query.X.Max, query.Y.Min, query.Y.Max, ImGuiCond_Always); + if (ImPlot::BeginPlot("##View2",NULL,NULL,ImVec2(-1,150), 0, 0, 0)) { + ImPlot::Plot("Signal 1", x_data, y_data1, 512); + ImPlot::Plot("Signal 2", x_data, y_data2, 512); + ImPlot::Plot("Signal 3", x_data, y_data3, 512); + ImPlot::EndPlot(); } } //------------------------------------------------------------------------- @@ -559,16 +568,16 @@ void ShowImPlotDemoWindow(bool* p_open) { data[i].Data.back().y + (0.005f + 0.0002f * (float)rand() / float(RAND_MAX)) * (-1 + 2 * (float)rand() / float(RAND_MAX))); } } - ImGui::SetNextPlotLimitsX(t - 10, t, paused ? ImGuiCond_Once : ImGuiCond_Always); - if (ImGui::BeginPlot("##DND", NULL, NULL, ImVec2(-1,300), ImPlotFlags_Default)) { + ImPlot::SetNextPlotLimitsX(t - 10, t, paused ? ImGuiCond_Once : ImGuiCond_Always); + if (ImPlot::BeginPlot("##DND", NULL, NULL, ImVec2(-1,300), ImPlotFlags_Default)) { for (int i = 0; i < 10; ++i) { if (show[i]) { char label[8]; sprintf(label, "data_%d", i); - ImGui::Plot(label, &data[i].Data[0].x, &data[i].Data[0].y, data[i].Data.size(), data[i].Offset, 2 * sizeof(float)); + ImPlot::Plot(label, &data[i].Data[0].x, &data[i].Data[0].y, data[i].Data.size(), data[i].Offset, 2 * sizeof(float)); } } - ImGui::EndPlot(); + ImPlot::EndPlot(); } if (ImGui::BeginDragDropTarget()) { if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("DND_PLOT")) { @@ -578,10 +587,8 @@ void ShowImPlotDemoWindow(bool* p_open) { ImGui::EndDragDropTarget(); } } - + //------------------------------------------------------------------------- if (ImGui::CollapsingHeader("Digital and Analog Signals")) { - - static bool paused = false; #define K_PLOT_DIGITAL_CH_COUNT 4 #define K_PLOT_ANALOG_CH_COUNT 4 @@ -660,16 +667,16 @@ void ShowImPlotDemoWindow(bool* p_open) { if (showAnalog[i]) dataAnalog[i].AddPoint(t, sin(2*t) - cos(2*t)); } - ImGui::SetNextPlotLimitsY(-1, 1); - ImGui::SetNextPlotLimitsX(t - 10.0f, t, paused ? ImGuiCond_Once : ImGuiCond_Always); - if (ImGui::BeginPlot("##Digital", NULL, NULL, ImVec2(-1,300), ImPlotFlags_Default)) { + ImPlot::SetNextPlotLimitsY(-1, 1); + ImPlot::SetNextPlotLimitsX(t - 10.0f, t, paused ? ImGuiCond_Once : ImGuiCond_Always); + if (ImPlot::BeginPlot("##Digital", NULL, NULL, ImVec2(-1,300), ImPlotFlags_Default)) { for (int i = 0; i < K_PLOT_DIGITAL_CH_COUNT; ++i) { if (showDigital[i]) { char label[32]; sprintf(label, "digital_%d", i); - ImGui::PushPlotStyleVar(ImPlotStyleVar_DigitalBitHeight, bitHeight); - ImGui::PlotDigital(label, &dataDigital[i].Data[0].x, &dataDigital[i].Data[0].y, dataDigital[i].Data.size(), dataDigital[i].Offset, 2 * sizeof(float)); - ImGui::PopPlotStyleVar(); + ImPlot::PushStyleVar(ImPlotStyleVar_DigitalBitHeight, bitHeight); + ImPlot::Digital(label, &dataDigital[i].Data[0].x, &dataDigital[i].Data[0].y, dataDigital[i].Data.size(), dataDigital[i].Offset, 2 * sizeof(float)); + ImPlot::PopStyleVar(); } } for (int i = 0; i < K_PLOT_ANALOG_CH_COUNT; ++i) { @@ -677,10 +684,10 @@ void ShowImPlotDemoWindow(bool* p_open) { char label[32]; sprintf(label, "analog_%d", i); if (dataAnalog[i].Data.size() > 0) - ImGui::Plot(label, &dataAnalog[i].Data[0].x, &dataAnalog[i].Data[0].y, dataAnalog[i].Data.size(), dataAnalog[i].Offset, 2 * sizeof(float)); + ImPlot::Plot(label, &dataAnalog[i].Data[0].x, &dataAnalog[i].Data[0].y, dataAnalog[i].Data.size(), dataAnalog[i].Offset, 2 * sizeof(float)); } } - ImGui::EndPlot(); + ImPlot::EndPlot(); } if (ImGui::BeginDragDropTarget()) { if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("DND_DIGITAL_PLOT")) { @@ -701,40 +708,41 @@ void ShowImPlotDemoWindow(bool* p_open) { {0.996f, 0.278f, 0.380f, 1.0f}, {(0.1176470593F), (0.5647059083F), (1.0F), (1.0F)}, }; - ImGui::SetPlotPalette(my_palette, 3); - ImGui::PushPlotColor(ImPlotCol_FrameBg, IM_COL32(32,51,77,255)); - ImGui::PushPlotColor(ImPlotCol_PlotBg, {0,0,0,0}); - ImGui::PushPlotColor(ImPlotCol_PlotBorder, {0,0,0,0}); - ImGui::PushPlotColor(ImPlotCol_XAxis, IM_COL32(192, 192, 192, 192)); - ImGui::PushPlotColor(ImPlotCol_YAxis, IM_COL32(192, 192, 192, 192)); - ImGui::PushPlotStyleVar(ImPlotStyleVar_LineWeight, 2); - ImGui::SetNextPlotLimits(-0.5f, 9.5f, -0.5f, 9.5f); - if (ImGui::BeginPlot("##Custom", NULL, NULL, {-1,300}, ImPlotFlags_Default & ~ImPlotFlags_Legend, 0)) { + ImPlot::SetPalette(my_palette, 3); + ImPlot::PushStyleColor(ImPlotCol_FrameBg, IM_COL32(32,51,77,255)); + ImPlot::PushStyleColor(ImPlotCol_PlotBg, {0,0,0,0}); + ImPlot::PushStyleColor(ImPlotCol_PlotBorder, {0,0,0,0}); + ImPlot::PushStyleColor(ImPlotCol_XAxis, IM_COL32(192, 192, 192, 192)); + ImPlot::PushStyleColor(ImPlotCol_YAxis, IM_COL32(192, 192, 192, 192)); + ImPlot::PushStyleVar(ImPlotStyleVar_LineWeight, 2); + ImPlot::SetNextPlotLimits(-0.5f, 9.5f, -0.5f, 9.5f); + if (ImPlot::BeginPlot("##Custom", NULL, NULL, {-1,300}, ImPlotFlags_Default & ~ImPlotFlags_Legend, 0)) { float lin[10] = {8,8,9,7,8,8,8,9,7,8}; float bar[10] = {1,2,5,3,4,1,2,5,3,4}; float dot[10] = {7,6,6,7,8,5,6,5,8,7}; - ImGui::PlotBar("Bar", bar, 10, 0.5f); - ImGui::Plot("Line", lin, 10); - ImGui::PushPlotStyleVar(ImPlotStyleVar_LineWeight, 0); - ImGui::PushPlotStyleVar(ImPlotStyleVar_Marker, ImMarker_Square); - ImGui::Plot("Dot", dot, 10); - ImGui::PopPlotStyleVar(2); - ImGui::EndPlot(); + ImPlot::Bar("Bar", bar, 10, 0.5f); + ImPlot::Plot("Line", lin, 10); + ImPlot::PushStyleVar(ImPlotStyleVar_LineWeight, 0); + ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Square); + ImPlot::Plot("Dot", dot, 10); + ImPlot::PopStyleVar(2); + ImPlot::EndPlot(); } - ImGui::PopPlotColor(5); - ImGui::PopPlotStyleVar(); - ImGui::RestorePlotPalette(); + ImPlot::PopStyleColor(5); + ImPlot::PopStyleVar(); + ImPlot::RestorePalette(); } + //------------------------------------------------------------------------- if (ImGui::CollapsingHeader("Custom Rendering")) { - if (ImGui::BeginPlot("##CustomRend",NULL,NULL,{-1,300})) { - ImVec2 cntr = ImGui::PlotToPixels({0.5f, 0.5f}); - ImVec2 rmin = ImGui::PlotToPixels({0.25f, 0.75f}); - ImVec2 rmax = ImGui::PlotToPixels({0.75f, 0.25f}); - ImGui::PushPlotClipRect(); + if (ImPlot::BeginPlot("##CustomRend",NULL,NULL,{-1,300})) { + ImVec2 cntr = ImPlot::PlotToPixels({0.5f, 0.5f}); + ImVec2 rmin = ImPlot::PlotToPixels({0.25f, 0.75f}); + ImVec2 rmax = ImPlot::PlotToPixels({0.75f, 0.25f}); + ImPlot::PushPlotClipRect(); ImGui::GetWindowDrawList()->AddCircleFilled(cntr,20,IM_COL32(255,255,0,255),20); ImGui::GetWindowDrawList()->AddRect(rmin, rmax, IM_COL32(128,0,255,255)); - ImGui::PopPlotClipRect(); - ImGui::EndPlot(); + ImPlot::PopPlotClipRect(); + ImPlot::EndPlot(); } } //------------------------------------------------------------------------- @@ -744,20 +752,19 @@ void ShowImPlotDemoWindow(bool* p_open) { ImGui::BulletText("Make sure VSync is disabled."); ImGui::BulletText("%d lines with %d points each @ %.3f FPS.",n_items,1000,ImGui::GetIO().Framerate); SetNextPlotLimits(0,1,0,1, ImGuiCond_Always); - if (ImGui::BeginPlot("##Bench",NULL,NULL,{-1,300},ImPlotFlags_Default | ImPlotFlags_NoChild)) { + if (ImPlot::BeginPlot("##Bench",NULL,NULL,{-1,300},ImPlotFlags_Default | ImPlotFlags_NoChild)) { char buff[16]; for (int i = 0; i < 100; ++i) { sprintf(buff, "item_%d",i); - ImGui::PushPlotColor(ImPlotCol_Line, items[i].Col); - ImGui::Plot(buff, items[i].Data, 1000); - ImGui::PopPlotColor(); + ImPlot::PushStyleColor(ImPlotCol_Line, items[i].Col); + ImPlot::Plot(buff, items[i].Data, 1000); + ImPlot::PopStyleColor(); } - ImGui::EndPlot(); + ImPlot::EndPlot(); } } //------------------------------------------------------------------------- - ImGui::End(); - + ImGui::End(); } } // namespace ImGui