Skip to content

Commit

Permalink
wip: working on improved cursors
Browse files Browse the repository at this point in the history
  • Loading branch information
klonyyy committed Jul 12, 2023
1 parent b91f352 commit b38f092
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/Gui/Gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,12 +525,13 @@ void Gui::drawPlotCurveBar(Plot* plot, ScrollingBuffer<double>& time, std::map<s
double markerPos = plot->getMarkerValueX0();
if (markerPos == 0.0)
{
markerPos = plotLimits.X.Min * 1.1f;
markerPos = plotLimits.X.Min + ((std::abs(plotLimits.X.Max) - std::abs(plotLimits.X.Min)) / 3.0f);
plot->setMarkerValueX0(markerPos);
}
ImPlot::DragLineX(0, &markerPos, ImVec4(1, 0, 1, 1));
plot->setMarkerValueX0(markerPos);
ImPlot::Annotation(markerPos, 0, ImVec4(0, 0, 0, 0), ImVec2(-10, -100), true, "x0 %.5f", markerPos);

ImPlot::Annotation(markerPos, plotLimits.Y.Max, ImVec4(0, 0, 0, 0), ImVec2(-10, 0), true, "x0 %.5f", markerPos);
}
else
plot->setMarkerValueX0(0.0);
Expand All @@ -540,14 +541,14 @@ void Gui::drawPlotCurveBar(Plot* plot, ScrollingBuffer<double>& time, std::map<s
double markerPos = plot->getMarkerValueX1();
if (markerPos == 0.0)
{
markerPos = plotLimits.X.Max * 0.9f;
markerPos = plotLimits.X.Min + (2.0f * (std::abs(plotLimits.X.Max) - std::abs(plotLimits.X.Min)) / 3.0f);
plot->setMarkerValueX1(markerPos);
}
ImPlot::DragLineX(1, &markerPos, ImVec4(1, 1, 0, 1));
plot->setMarkerValueX1(markerPos);
ImPlot::Annotation(markerPos, 0, ImVec4(0, 0, 0, 0), ImVec2(10, -100), true, "x1 %.5f", markerPos);
ImPlot::Annotation(markerPos, plotLimits.Y.Max, ImVec4(0, 0, 0, 0), ImVec2(10, 0), true, "x1 %.5f", markerPos);
double dx = markerPos - plot->getMarkerValueX0();
ImPlot::Annotation(markerPos, 0, ImVec4(0, 0, 0, 0), ImVec2(10, 100), true, "x1-x0 %.5f", dx);
ImPlot::Annotation(markerPos, plotLimits.Y.Max, ImVec4(0, 0, 0, 0), ImVec2(10, 20), true, "x1-x0 %.5f", dx);
}
else
plot->setMarkerValueX1(0.0);
Expand All @@ -569,9 +570,11 @@ void Gui::drawPlotCurveBar(Plot* plot, ScrollingBuffer<double>& time, std::map<s
{
if (!serPtr->visible)
continue;
double value = *(serPtr->buffer->getFirstElementCopy() + time.getIndexFromvalue(plot->getMarkerValueX0()));
ImPlot::SetNextLineStyle(ImVec4(serPtr->var->getColor().r, serPtr->var->getColor().g, serPtr->var->getColor().b, 1.0f));
ImPlot::SetNextMarkerStyle(ImPlotMarker_Circle, 2.0f);
ImPlot::PlotLine(serPtr->var->getName().c_str(), time.getFirstElementCopy(), serPtr->buffer->getFirstElementCopy(), size, 0, offset, sizeof(double));
auto name = plot->getMarkerStateX0() ? (key + " = " + std::to_string(value)) : key;
ImPlot::PlotLine(name.c_str(), time.getFirstElementCopy(), serPtr->buffer->getFirstElementCopy(), size, 0, offset, sizeof(double));
}

ImPlot::EndPlot();
Expand Down
13 changes: 13 additions & 0 deletions src/ScrollingBuffer/ScrollingBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@ class ScrollingBuffer
maxSize = newMaxSize;
}

uint32_t getIndexFromvalue(double value)
{
for (uint32_t t = 0; t < getSize(); t++)
{
double first = dataCopy[t];
double second = dataCopy[t + 1];

if (value >= first && value <= second)
return t;
}
return 0;
}

private:
mutable std::mutex mtx;
uint32_t maxSize = 10000;
Expand Down

0 comments on commit b38f092

Please sign in to comment.