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

C++11 extension fixes

warning: range-based for loop is a C++11 extension [-Wc++11-extensions]
for (ImTick &xt : gp.XTicks) {
for (ImTick &yt : gp.YTicks[i]) {
This commit is contained in:
ozlb 2020-05-13 06:45:34 +02:00 committed by GitHub
parent f766614db0
commit 1ea1a2664e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 133 additions and 110 deletions

View File

@ -314,7 +314,7 @@ struct ImPlotState {
};
struct ImNextPlotData {
ImNextPlotData() : HasXRange{}, HasYRange{} {}
//ImNextPlotData() : HasXRange{}, HasYRange{} {}
ImGuiCond XRangeCond;
ImGuiCond YRangeCond[MAX_Y_AXES];
bool HasXRange;
@ -349,7 +349,8 @@ struct ImPlotContext {
ImU32 Col_Frame, Col_Bg, Col_Border,
Col_Txt, Col_TxtDis,
Col_SlctBg, Col_SlctBd,
Col_QryBg, Col_QryBd;
Col_QryBg, Col_QryBd,
Col_QryX;
struct AxisColor {
AxisColor() : Major(), Minor(), Txt() {}
ImU32 Major, Minor, Txt;
@ -374,7 +375,7 @@ struct ImPlotContext {
ImPlotRange ExtentsY[MAX_Y_AXES];
bool FitThisFrame; bool FitX;
bool FitY[MAX_Y_AXES] = {};
bool FitY[MAX_Y_AXES];
int VisibleItemCount;
// Render flags
bool RenderX, RenderY[MAX_Y_AXES];
@ -487,8 +488,8 @@ struct Plt2PixLinLin {
ImVec2 operator()(const ImVec2& plt) { return (*this)(plt.x, plt.y); }
ImVec2 operator()(float x, float y) {
return { gp.PixelRange[y_axis].Min.x + gp.Mx * (x - gp.CurrentPlot->XAxis.Range.Min),
gp.PixelRange[y_axis].Min.y + gp.My[y_axis] * (y - gp.CurrentPlot->YAxis[y_axis].Range.Min) };
return ImVec2( gp.PixelRange[y_axis].Min.x + gp.Mx * (x - gp.CurrentPlot->XAxis.Range.Min),
gp.PixelRange[y_axis].Min.y + gp.My[y_axis] * (y - gp.CurrentPlot->YAxis[y_axis].Range.Min) );
}
int y_axis;
@ -501,8 +502,8 @@ struct Plt2PixLogLin {
ImVec2 operator()(float x, float y) {
float t = log10(x / gp.CurrentPlot->XAxis.Range.Min) / gp.LogDenX;
x = ImLerp(gp.CurrentPlot->XAxis.Range.Min, gp.CurrentPlot->XAxis.Range.Max, t);
return { gp.PixelRange[y_axis].Min.x + gp.Mx * (x - gp.CurrentPlot->XAxis.Range.Min),
gp.PixelRange[y_axis].Min.y + gp.My[y_axis] * (y - gp.CurrentPlot->YAxis[y_axis].Range.Min) };
return ImVec2( gp.PixelRange[y_axis].Min.x + gp.Mx * (x - gp.CurrentPlot->XAxis.Range.Min),
gp.PixelRange[y_axis].Min.y + gp.My[y_axis] * (y - gp.CurrentPlot->YAxis[y_axis].Range.Min) );
}
int y_axis;
@ -515,8 +516,8 @@ struct Plt2PixLinLog {
ImVec2 operator()(float x, float y) {
float t = log10(y / gp.CurrentPlot->YAxis[y_axis].Range.Min) / gp.LogDenY[y_axis];
y = ImLerp(gp.CurrentPlot->YAxis[y_axis].Range.Min, gp.CurrentPlot->YAxis[y_axis].Range.Max, t);
return { gp.PixelRange[y_axis].Min.x + gp.Mx * (x - gp.CurrentPlot->XAxis.Range.Min),
gp.PixelRange[y_axis].Min.y + gp.My[y_axis] * (y - gp.CurrentPlot->YAxis[y_axis].Range.Min) };
return ImVec2( gp.PixelRange[y_axis].Min.x + gp.Mx * (x - gp.CurrentPlot->XAxis.Range.Min),
gp.PixelRange[y_axis].Min.y + gp.My[y_axis] * (y - gp.CurrentPlot->YAxis[y_axis].Range.Min) );
}
int y_axis;
@ -531,8 +532,8 @@ struct Plt2PixLogLog {
x = ImLerp(gp.CurrentPlot->XAxis.Range.Min, gp.CurrentPlot->XAxis.Range.Max, t);
t = log10(y / gp.CurrentPlot->YAxis[y_axis].Range.Min) / gp.LogDenY[y_axis];
y = ImLerp(gp.CurrentPlot->YAxis[y_axis].Range.Min, gp.CurrentPlot->YAxis[y_axis].Range.Max, t);
return { gp.PixelRange[y_axis].Min.x + gp.Mx * (x - gp.CurrentPlot->XAxis.Range.Min),
gp.PixelRange[y_axis].Min.y + gp.My[y_axis] * (y - gp.CurrentPlot->YAxis[y_axis].Range.Min) };
return ImVec2( gp.PixelRange[y_axis].Min.x + gp.Mx * (x - gp.CurrentPlot->XAxis.Range.Min),
gp.PixelRange[y_axis].Min.y + gp.My[y_axis] * (y - gp.CurrentPlot->YAxis[y_axis].Range.Min) );
}
int y_axis;
@ -613,15 +614,16 @@ inline void GetTicks(const ImPlotRange& scale, int nMajor, int nMinor, bool logs
inline void LabelTicks(ImVector<ImTick> &ticks, bool scientific, ImGuiTextBuffer& buffer) {
buffer.Buf.resize(0);
char temp[32];
for (ImTick &tk : ticks) {
if (tk.RenderLabel) {
tk.TextOffset = buffer.size();
for (int t = 0; t < ticks.Size; t++) {
ImTick *tk = &ticks[t];
if (tk->RenderLabel) {
tk->TextOffset = buffer.size();
if (scientific)
sprintf(temp, "%.0e", tk.PlotPos);
sprintf(temp, "%.0e", tk->PlotPos);
else
sprintf(temp, "%g", tk.PlotPos);
sprintf(temp, "%g", tk->PlotPos);
buffer.append(temp, temp + strlen(temp) + 1);
tk.Size = ImGui::CalcTextSize(buffer.Buf.Data + tk.TextOffset);
tk->Size = ImGui::CalcTextSize(buffer.Buf.Data + tk->TextOffset);
}
}
}
@ -666,7 +668,7 @@ 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 = 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});
col->Txt = ImGui::GetColorU32(ImVec4(col_Axis.x, col_Axis.y, col_Axis.z, 1));
}
ImRect GetAxisScale(int y_axis, float tx, float ty, float zoom_rate) {
@ -900,8 +902,9 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons
for (int i = 0; i < MAX_Y_AXES; i++) {
if (y[i].present && HasFlag(plot.YAxis[i].Flags, ImAxisFlags_TickLabels)) {
LabelTicks(gp.YTicks[i], HasFlag(plot.YAxis[i].Flags, ImAxisFlags_Scientific), gp.YTickLabels[i]);
for (ImTick &yt : gp.YTicks[i]) {
max_label_width[i] = yt.Size.x > max_label_width[i] ? yt.Size.x : max_label_width[i];
for (int t = 0; t < gp.YTicks[i].Size; t++) {
ImTick *yt = &gp.YTicks[i][t];
max_label_width[i] = yt->Size.x > max_label_width[i] ? yt->Size.x : max_label_width[i];
}
}
}
@ -935,15 +938,15 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons
(gp.AxisLabelReference[1] + y_axis_pad(1) + 6);
ImRect yAxisRegion_bb[MAX_Y_AXES];
yAxisRegion_bb[0] = ImRect({gp.BB_Frame.Min.x, gp.BB_Grid.Min.y}, {gp.BB_Grid.Min.x + 6, gp.BB_Grid.Max.y - 10});
yAxisRegion_bb[0] = ImRect(ImVec2(gp.BB_Frame.Min.x, gp.BB_Grid.Min.y), ImVec2(gp.BB_Grid.Min.x + 6, gp.BB_Grid.Max.y - 10));
// The auxiliary y axes are off to the right of the BB grid.
yAxisRegion_bb[1] = ImRect({gp.BB_Grid.Max.x - 6, gp.BB_Grid.Min.y},
yAxisRegion_bb[1] = ImRect(ImVec2(gp.BB_Grid.Max.x - 6, gp.BB_Grid.Min.y),
gp.BB_Grid.Max + ImVec2(y_axis_pad(1), 0));
yAxisRegion_bb[2] = ImRect({gp.AxisLabelReference[2] - 6, gp.BB_Grid.Min.y},
yAxisRegion_bb[2] = ImRect(ImVec2(gp.AxisLabelReference[2] - 6, gp.BB_Grid.Min.y),
yAxisRegion_bb[1].Max + ImVec2(y_axis_pad(2), 0));
ImRect centralRegion({gp.BB_Grid.Min.x + 6, gp.BB_Grid.Min.y},
{gp.BB_Grid.Max.x - 6, gp.BB_Grid.Max.y});
ImRect centralRegion(ImVec2(gp.BB_Grid.Min.x + 6, gp.BB_Grid.Min.y),
ImVec2(gp.BB_Grid.Max.x - 6, gp.BB_Grid.Max.y));
const bool hov_y_axis_region[MAX_Y_AXES] = {
y[0].present && (yAxisRegion_bb[0].Contains(IO.MousePos) || centralRegion.Contains(IO.MousePos)),
@ -1208,26 +1211,34 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons
// transform ticks
if (gp.RenderX) {
for (ImTick& xt : gp.XTicks)
xt.PixelPos = PlotToPixels((float)xt.PlotPos, 0, 0).x;
for (int t = 0; t < gp.XTicks.Size; t++) {
ImTick *xt = &gp.XTicks[t];
xt->PixelPos = PlotToPixels((float)xt->PlotPos, 0, 0).x;
}
}
for (int i = 0; i < MAX_Y_AXES; i++) {
if (gp.RenderY[i]) {
for (ImTick& yt : gp.YTicks[i])
yt.PixelPos = PlotToPixels(0, (float)yt.PlotPos, i).y;
for (int t = 0; t < gp.YTicks[i].Size; t++) {
ImTick *yt = &gp.YTicks[i][t];
yt->PixelPos = PlotToPixels(0, (float)yt->PlotPos, i).y;
}
}
}
// render grid
if (HasFlag(plot.XAxis.Flags, ImAxisFlags_GridLines)) {
for (ImTick &xt : gp.XTicks)
DrawList.AddLine({xt.PixelPos, gp.BB_Grid.Min.y}, {xt.PixelPos, gp.BB_Grid.Max.y}, xt.Major ? gp.Col_X.Major : gp.Col_X.Minor, 1);
for (int t = 0; t < gp.XTicks.Size; t++) {
ImTick *xt = &gp.XTicks[t];
DrawList.AddLine(ImVec2(xt->PixelPos, gp.BB_Grid.Min.y), ImVec2(xt->PixelPos, gp.BB_Grid.Max.y), xt->Major ? gp.Col_X.Major : gp.Col_X.Minor, 1);
}
}
for (int i = 0; i < MAX_Y_AXES; i++) {
if (y[i].present && HasFlag(plot.YAxis[i].Flags, ImAxisFlags_GridLines)) {
for (ImTick &yt : gp.YTicks[i])
DrawList.AddLine({gp.BB_Grid.Min.x, yt.PixelPos}, {gp.BB_Grid.Max.x, yt.PixelPos}, yt.Major ? gp.Col_Y[i].Major : gp.Col_Y[i].Minor, 1);
for (int t = 0; t < gp.YTicks[i].Size; t++) {
ImTick *yt = &gp.YTicks[i][t];
DrawList.AddLine(ImVec2(gp.BB_Grid.Min.x, yt->PixelPos), ImVec2(gp.BB_Grid.Max.x, yt->PixelPos), yt->Major ? gp.Col_Y[i].Major : gp.Col_Y[i].Minor, 1);
}
}
}
@ -1241,9 +1252,10 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons
// render labels
if (HasFlag(plot.XAxis.Flags, ImAxisFlags_TickLabels)) {
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);
for (int t = 0; t < gp.XTicks.Size; t++) {
ImTick *xt = &gp.XTicks[t];
if (xt->RenderLabel && xt->PixelPos >= gp.BB_Grid.Min.x - 1 && xt->PixelPos <= gp.BB_Grid.Max.x + 1)
DrawList.AddText(ImVec2(xt->PixelPos - xt->Size.x * 0.5f, gp.BB_Grid.Max.y + txt_off), gp.Col_X.Txt, gp.XTickLabels.Buf.Data + xt->TextOffset);
}
ImGui::PopClipRect();
}
@ -1261,10 +1273,11 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons
((i == 0) ?
(-txt_off - max_label_width[0]) :
txt_off);
for (ImTick &yt : gp.YTicks[i]) {
if (yt.RenderLabel && yt.PixelPos >= gp.BB_Grid.Min.y - 1 && yt.PixelPos <= gp.BB_Grid.Max.y + 1) {
ImVec2 start(x_start, yt.PixelPos - 0.5f * yt.Size.y);
DrawList.AddText(start, gp.Col_Y[i].Txt, gp.YTickLabels[i].Buf.Data + yt.TextOffset);
for (int t = 0; t < gp.YTicks[i].Size; t++) {
ImTick *yt = &gp.YTicks[i][t];
if (yt->RenderLabel && yt->PixelPos >= gp.BB_Grid.Min.y - 1 && yt->PixelPos <= gp.BB_Grid.Max.y + 1) {
ImVec2 start(x_start, yt->PixelPos - 0.5f * yt->Size.y);
DrawList.AddText(start, gp.Col_Y[i].Txt, gp.YTickLabels[i].Buf.Data + yt->TextOffset);
}
}
}
@ -1470,12 +1483,14 @@ void EndPlot() {
// render ticks
PushPlotClipRect();
if (HasFlag(plot.XAxis.Flags, ImAxisFlags_TickMarks)) {
for (ImTick &xt : gp.XTicks)
DrawList.AddLine({xt.PixelPos, gp.BB_Grid.Max.y},{xt.PixelPos, gp.BB_Grid.Max.y - (xt.Major ? 10.0f : 5.0f)}, gp.Col_Border, 1);
for (int t = 0; t < gp.XTicks.Size; t++) {
ImTick *xt = &gp.XTicks[t];
DrawList.AddLine(ImVec2(xt->PixelPos, gp.BB_Grid.Max.y),ImVec2(xt->PixelPos, gp.BB_Grid.Max.y - (xt->Major ? 10.0f : 5.0f)), gp.Col_Border, 1);
}
}
PopPlotClipRect();
ImGui::PushClipRect(gp.BB_Grid.Min, {gp.BB_Frame.Max.x, gp.BB_Grid.Max.y}, true);
ImGui::PushClipRect(gp.BB_Grid.Min, ImVec2(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; }
@ -1487,12 +1502,13 @@ void EndPlot() {
float direction = (i == 0) ? 1.0f : -1.0f;
bool no_major = axis_count >= 3;
for (ImTick &yt : gp.YTicks[i]) {
ImVec2 start = ImVec2(x_start, yt.PixelPos);
for (int t = 0; t < gp.YTicks[i].Size; t++) {
ImTick *yt = &gp.YTicks[i][t];
ImVec2 start = ImVec2(x_start, yt->PixelPos);
DrawList.AddLine(
start,
start + ImVec2(direction * ((!no_major && yt.Major) ? 10.0f : 5.0f), 0),
start + ImVec2(direction * ((!no_major && yt->Major) ? 10.0f : 5.0f), 0),
gp.Col_Border, 1);
}
@ -1831,16 +1847,16 @@ void SetPalette(const ImVec4* colors, int num_colors) {
/// Returns the next unused default plot color
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,
{(0.4980392158F), (1.0F), (0.0F), (1.0F)}, // Greens::Chartreuse,
{(1.0F), (1.0F), (0.0F), (1.0F)}, // Yellows::Yellow,
{(0.0F), (1.0F), (1.0F), (1.0F)}, // Cyans::Cyan,
{(1.0F), (0.6470588446F), (0.0F), (1.0F)}, // Oranges::Orange,
{(1.0F), (0.0F), (1.0F), (1.0F)}, // Purples::Magenta,
{(0.5411764979F), (0.1686274558F), (0.8862745166F), (1.0F)}, // Purples::BlueViolet,
{(0.5f), (0.5f), (0.5f), (1.0F)}, // Grays::Gray50,
{(0.8235294223F), (0.7058823705F), (0.5490196347F), (1.0F)} // Browns::Tan
ImVec4((0.0F), (0.7490196228F), (1.0F), (1.0F)), // Blues::DeepSkyBlue,
ImVec4((1.0F), (0.0F), (0.0F), (1.0F)), // Reds::Red,
ImVec4((0.4980392158F), (1.0F), (0.0F), (1.0F)), // Greens::Chartreuse,
ImVec4((1.0F), (1.0F), (0.0F), (1.0F)), // Yellows::Yellow,
ImVec4((0.0F), (1.0F), (1.0F), (1.0F)), // Cyans::Cyan,
ImVec4((1.0F), (0.6470588446F), (0.0F), (1.0F)), // Oranges::Orange,
ImVec4((1.0F), (0.0F), (1.0F), (1.0F)), // Purples::Magenta,
ImVec4((0.5411764979F), (0.1686274558F), (0.8862745166F), (1.0F)), // Purples::BlueViolet,
ImVec4((0.5f), (0.5f), (0.5f), (1.0F)), // Grays::Gray50,
ImVec4((0.8235294223F), (0.7058823705F), (0.5490196347F), (1.0F)) // Browns::Tan
};
SetPalette(default_colors, 10);
}
@ -1944,51 +1960,51 @@ inline void MarkerGeneral(ImDrawList& DrawList, ImVec2* points, int n, const ImV
}
inline void MarkerCircle(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) {
ImVec2 marker[10] = {{1.0f, 0.0f},
{0.809017f, 0.58778524f},
{0.30901697f, 0.95105654f},
{-0.30901703f, 0.9510565f},
{-0.80901706f, 0.5877852f},
{-1.0f, 0.0f},
{-0.80901694f, -0.58778536f},
{-0.3090171f, -0.9510565f},
{0.30901712f, -0.9510565f},
{0.80901694f, -0.5877853f}};
ImVec2 marker[10] = {ImVec2(1.0f, 0.0f),
ImVec2(0.809017f, 0.58778524f),
ImVec2(0.30901697f, 0.95105654f),
ImVec2(-0.30901703f, 0.9510565f),
ImVec2(-0.80901706f, 0.5877852f),
ImVec2(-1.0f, 0.0f),
ImVec2(-0.80901694f, -0.58778536f),
ImVec2(-0.3090171f, -0.9510565f),
ImVec2(0.30901712f, -0.9510565f),
ImVec2(0.80901694f, -0.5877853f)};
MarkerGeneral(DrawList, marker, 10, c, s, outline, col_outline, fill, col_fill, weight);
}
inline void MarkerDiamond(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) {
ImVec2 marker[4] = {{1, 0}, {0, -1}, {-1, 0}, {0, 1}};
ImVec2 marker[4] = {ImVec2(1, 0), ImVec2(0, -1), ImVec2(-1, 0), ImVec2(0, 1)};
MarkerGeneral(DrawList, marker, 4, c, s, outline, col_outline, fill, col_fill, weight);
}
inline void MarkerSquare(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) {
ImVec2 marker[4] = {{SQRT_1_2,SQRT_1_2},{SQRT_1_2,-SQRT_1_2},{-SQRT_1_2,-SQRT_1_2},{-SQRT_1_2,SQRT_1_2}};
ImVec2 marker[4] = {ImVec2(SQRT_1_2,SQRT_1_2),ImVec2(SQRT_1_2,-SQRT_1_2),ImVec2(-SQRT_1_2,-SQRT_1_2),ImVec2(-SQRT_1_2,SQRT_1_2)};
MarkerGeneral(DrawList, marker, 4, c, s, outline, col_outline, fill, col_fill, weight);
}
inline void MarkerUp(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) {
ImVec2 marker[3] = {{SQRT_3_2,0.5f},{0,-1},{-SQRT_3_2,0.5f}};
ImVec2 marker[3] = {ImVec2(SQRT_3_2,0.5f),ImVec2(0,-1),ImVec2(-SQRT_3_2,0.5f)};
MarkerGeneral(DrawList, marker, 3, c, s, outline, col_outline, fill, col_fill, weight);
}
inline void MarkerDown(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) {
ImVec2 marker[3] = {{SQRT_3_2,-0.5f},{0,1},{-SQRT_3_2,-0.5f}};
ImVec2 marker[3] = {ImVec2(SQRT_3_2,-0.5f),ImVec2(0,1),ImVec2(-SQRT_3_2,-0.5f)};
MarkerGeneral(DrawList, marker, 3, c, s, outline, col_outline, fill, col_fill, weight);
}
inline void MarkerLeft(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) {
ImVec2 marker[3] = {{-1,0}, {0.5, SQRT_3_2}, {0.5, -SQRT_3_2}};
ImVec2 marker[3] = {ImVec2(-1,0), ImVec2(0.5, SQRT_3_2), ImVec2(0.5, -SQRT_3_2)};
MarkerGeneral(DrawList, marker, 3, c, s, outline, col_outline, fill, col_fill, weight);
}
inline void MarkerRight(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) {
ImVec2 marker[3] = {{1,0}, {-0.5, SQRT_3_2}, {-0.5, -SQRT_3_2}};
ImVec2 marker[3] = {ImVec2(1,0), ImVec2(-0.5, SQRT_3_2), ImVec2(-0.5, -SQRT_3_2)};
MarkerGeneral(DrawList, marker, 3, c, s, outline, col_outline, fill, col_fill, weight);
}
inline void MarkerAsterisk(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) {
ImVec2 marker[6] = {{SQRT_3_2, 0.5f}, {0, -1}, {-SQRT_3_2, 0.5f}, {SQRT_3_2, -0.5f}, {0, 1}, {-SQRT_3_2, -0.5f}};
ImVec2 marker[6] = {ImVec2(SQRT_3_2, 0.5f), ImVec2(0, -1), ImVec2(-SQRT_3_2, 0.5f), ImVec2(SQRT_3_2, -0.5f), ImVec2(0, 1), ImVec2(-SQRT_3_2, -0.5f)};
TransformMarker(marker, 6, c, s);
DrawList.AddLine(marker[0], marker[5], col_outline, weight);
DrawList.AddLine(marker[1], marker[4], col_outline, weight);
@ -1996,14 +2012,14 @@ inline void MarkerAsterisk(ImDrawList& DrawList, const ImVec2& c, float s, bool
}
inline void MarkerPlus(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) {
ImVec2 marker[4] = {{1, 0}, {0, -1}, {-1, 0}, {0, 1}};
ImVec2 marker[4] = {ImVec2(1, 0), ImVec2(0, -1), ImVec2(-1, 0), ImVec2(0, 1)};
TransformMarker(marker, 4, c, s);
DrawList.AddLine(marker[0], marker[2], col_outline, weight);
DrawList.AddLine(marker[1], marker[3], col_outline, weight);
}
inline void MarkerCross(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) {
ImVec2 marker[4] = {{SQRT_1_2,SQRT_1_2},{SQRT_1_2,-SQRT_1_2},{-SQRT_1_2,-SQRT_1_2},{-SQRT_1_2,SQRT_1_2}};
ImVec2 marker[4] = {ImVec2(SQRT_1_2,SQRT_1_2),ImVec2(SQRT_1_2,-SQRT_1_2),ImVec2(-SQRT_1_2,-SQRT_1_2),ImVec2(-SQRT_1_2,SQRT_1_2)};
TransformMarker(marker, 4, c, s);
DrawList.AddLine(marker[0], marker[2], col_outline, weight);
DrawList.AddLine(marker[1], marker[3], col_outline, weight);
@ -2539,7 +2555,7 @@ void Text(const char* text, float x, float y, bool vertical, const ImVec2& pixel
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;
ImVec2 pos = PlotToPixels(ImVec2(x,y)) + pixel_offset;
if (vertical)
AddTextVertical(&DrawList, text, pos, gp.Col_Txt);
else

View File

@ -30,7 +30,7 @@
#pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen
#endif
#include <implot.h>
#include "implot.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
@ -43,10 +43,14 @@ float RandomRange( float min, float max ) {
}
struct ScrollingData {
int MaxSize = 1000;
int Offset = 0;
int MaxSize;
int Offset;
ImVector<ImVec2> Data;
ScrollingData() { Data.reserve(MaxSize); }
ScrollingData() {
MaxSize = 1000;
Offset = 0;
Data.reserve(MaxSize);
}
void AddPoint(float x, float y) {
if (Data.size() < MaxSize)
Data.push_back(ImVec2(x,y));
@ -64,9 +68,12 @@ struct ScrollingData {
};
struct RollingData {
float Span = 10.0f;
float Span;
ImVector<ImVec2> Data;
RollingData() { Data.reserve(1000); }
RollingData() {
Span = 10.0f;
Data.reserve(1000);
}
void AddPoint(float x, float y) {
float xmod = fmodf(x, Span);
if (!Data.empty() && xmod < Data.back().x)
@ -147,7 +154,7 @@ void ShowDemoWindow(bool* p_open) {
xs2[i] = i * 0.1f;
ys2[i] = xs2[i] * xs2[i];
}
if (ImPlot::BeginPlot("Line Plot", "x", "f(x)", {-1,300})) {
if (ImPlot::BeginPlot("Line Plot", "x", "f(x)", ImVec2(-1,300))) {
ImPlot::Plot("sin(50*x)", xs1, ys1, 1001);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImMarker_Circle);
ImPlot::Plot("x^2", xs2, ys2, 11);
@ -168,14 +175,14 @@ void ShowDemoWindow(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 (ImPlot::BeginPlot("Scatter Plot", NULL, NULL, {-1,300})) {
if (ImPlot::BeginPlot("Scatter Plot", NULL, NULL, ImVec2(-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::PushStyleColor(ImPlotCol_MarkerFill, ImVec4(1,0,0,0.25f));
ImPlot::Plot("Data 2", xs2, ys2, 50);
ImPlot::PopStyleColor();
ImPlot::PopStyleVar(2);
@ -190,7 +197,7 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::SetNextPlotLimits(0, 110, -0.5f, 9.5f, ImGuiCond_Always);
else
ImPlot::SetNextPlotLimits(-0.5f, 9.5f, 0, 110, ImGuiCond_Always);
if (ImPlot::BeginPlot("Bar Plot", horz ? "Score": "Student", horz ? "Student" : "Score", {-1, 300})) {
if (ImPlot::BeginPlot("Bar Plot", horz ? "Score": "Student", horz ? "Student" : "Score", ImVec2(-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};
@ -246,11 +253,11 @@ void ShowDemoWindow(bool* p_open) {
ImGui::SameLine();
static ImVec4 YlOrRd[5] = {
{1.0000f, 1.0000f, 0.8000f, 1.0f},
{0.9961f, 0.8510f, 0.4627f, 1.0f},
{0.9961f, 0.6314f, 0.2627f, 1.0f},
{0.9882f, 0.3059f, 0.1647f, 1.0f},
{0.7412f, 0.0f, 0.1490f, 1.0f},
ImVec4(1.0000f, 1.0000f, 0.8000f, 1.0f),
ImVec4(0.9961f, 0.8510f, 0.4627f, 1.0f),
ImVec4(0.9961f, 0.6314f, 0.2627f, 1.0f),
ImVec4(0.9882f, 0.3059f, 0.1647f, 1.0f),
ImVec4(0.7412f, 0.0f, 0.1490f, 1.0f),
};
ImPlot::SetPalette(YlOrRd, 5);
SetNextPlotLimits(0,1,0,1,ImGuiCond_Always);
@ -280,13 +287,13 @@ void ShowDemoWindow(bool* p_open) {
}
ImPlot::SetNextPlotLimitsX(t - 10, t, paused ? ImGuiCond_Once : ImGuiCond_Always);
static int rt_axis = ImAxisFlags_Default & ~ImAxisFlags_TickLabels;
if (ImPlot::BeginPlot("##Scrolling", NULL, NULL, {-1,150}, ImPlotFlags_Default, rt_axis, rt_axis)) {
if (ImPlot::BeginPlot("##Scrolling", NULL, NULL, ImVec2(-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();
}
ImPlot::SetNextPlotLimitsX(0, 10, ImGuiCond_Always);
if (ImPlot::BeginPlot("##Rolling", NULL, NULL, {-1,150}, ImPlotFlags_Default, rt_axis, rt_axis)) {
if (ImPlot::BeginPlot("##Rolling", NULL, NULL, ImVec2(-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();
@ -536,20 +543,20 @@ void ShowDemoWindow(bool* p_open) {
}
ImGui::BulletText("Drag data items from the left column onto the plot.");
ImGui::BeginGroup();
if (ImGui::Button("Clear", {100, 0})) {
if (ImGui::Button("Clear", ImVec2(100, 0))) {
for (int i = 0; i < 10; ++i) {
show[i] = false;
data[i].Data.shrink(0);
data[i].Offset = 0;
}
}
if (ImGui::Button(paused ? "Resume" : "Pause", {100,0}))
if (ImGui::Button(paused ? "Resume" : "Pause", ImVec2(100,0)))
paused = !paused;
ImGui::Separator();
for (int i = 0; i < 10; ++i) {
char label[8];
sprintf(label, "data_%d", i);
ImGui::Selectable(label, false, 0, {100, 0});
ImGui::Selectable(label, false, 0, ImVec2(100, 0));
if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_None)) {
ImGui::SetDragDropPayload("DND_PLOT", &i, sizeof(int));
ImGui::TextUnformatted(label);
@ -603,13 +610,13 @@ void ShowDemoWindow(bool* p_open) {
ImGui::Text("you can drag analog signals over the rising/falling digital edge.");
ImGui::Unindent();
ImGui::BeginGroup();
if (ImGui::Button("Clear", {100, 0})) {
if (ImGui::Button("Clear", ImVec2(100, 0))) {
for (int i = 0; i < K_PLOT_DIGITAL_CH_COUNT; ++i)
showDigital[i] = false;
for (int i = 0; i < K_PLOT_ANALOG_CH_COUNT; ++i)
showAnalog[i] = false;
}
if (ImGui::Button(paused ? "Resume" : "Pause", {100,0}))
if (ImGui::Button(paused ? "Resume" : "Pause", ImVec2(100,0)))
paused = !paused;
ImGui::SetNextItemWidth(100);
static float bitHeight = 8;
@ -708,19 +715,19 @@ void ShowDemoWindow(bool* p_open) {
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Custom Styles")) {
static ImVec4 my_palette[3] = {
{0.000f, 0.980f, 0.604f, 1.0f},
{0.996f, 0.278f, 0.380f, 1.0f},
{(0.1176470593F), (0.5647059083F), (1.0F), (1.0F)},
ImVec4(0.000f, 0.980f, 0.604f, 1.0f),
ImVec4(0.996f, 0.278f, 0.380f, 1.0f),
ImVec4(0.1176470593f, 0.5647059083f, 1.0f, 1.0f),
};
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_PlotBg, ImVec4(0,0,0,0));
ImPlot::PushStyleColor(ImPlotCol_PlotBorder, ImVec4(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)) {
if (ImPlot::BeginPlot("##Custom", NULL, NULL, ImVec2(-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};
@ -738,10 +745,10 @@ void ShowDemoWindow(bool* p_open) {
}
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Custom Rendering")) {
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});
if (ImPlot::BeginPlot("##CustomRend",NULL,NULL,ImVec2(-1,300))) {
ImVec2 cntr = ImPlot::PlotToPixels(ImVec2(0.5f, 0.5f));
ImVec2 rmin = ImPlot::PlotToPixels(ImVec2(0.25f, 0.75f));
ImVec2 rmax = ImPlot::PlotToPixels(ImVec2(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));
@ -756,7 +763,7 @@ void ShowDemoWindow(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 (ImPlot::BeginPlot("##Bench",NULL,NULL,{-1,300},ImPlotFlags_Default | ImPlotFlags_NoChild)) {
if (ImPlot::BeginPlot("##Bench",NULL,NULL,ImVec2(-1,300),ImPlotFlags_Default | ImPlotFlags_NoChild)) {
char buff[16];
for (int i = 0; i < 100; ++i) {
sprintf(buff, "item_%d",i);
@ -771,4 +778,4 @@ void ShowDemoWindow(bool* p_open) {
ImGui::End();
}
} // namespace ImPlot
} // namespace ImGui