Added header for ImPlot utility and functions for drawing horizontal/vertical lines and boxes.
This commit is contained in:
parent
5ebd609507
commit
9bc56a2748
60
public/raid/imraid_plot.hpp
Normal file
60
public/raid/imraid_plot.hpp
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#if !defined(RAID_PUBLIC_RAID_IMRAID_PLOT_HPP_INCLUDED)
|
||||||
|
#define RAID_PUBLIC_RAID_IMRAID_PLOT_HPP_INCLUDED 1
|
||||||
|
|
||||||
|
#include <imgui.h>
|
||||||
|
#include <implot.h>
|
||||||
|
#include <implot_internal.h>
|
||||||
|
|
||||||
|
namespace ImRaid::Plot
|
||||||
|
{
|
||||||
|
inline void AddVerticalLine(double xValue, ImU32 color, float thickness = 1.f, ImAxis dataAxis = ImAxis_X1)
|
||||||
|
{
|
||||||
|
const ImVec2 plotPos = ImPlot::GetPlotPos();
|
||||||
|
const ImVec2 plotSize = ImPlot::GetPlotSize();
|
||||||
|
const float xScaled = ImPlot::GetCurrentPlot()->Axes[dataAxis].PlotToPixels(xValue);
|
||||||
|
const ImVec2 v0 = ImVec2(xScaled, plotPos.y);
|
||||||
|
const ImVec2 v1 = ImVec2(xScaled, plotPos.y + plotSize.y);
|
||||||
|
|
||||||
|
ImPlot::GetPlotDrawList()->AddLine(v0, v1, color, thickness);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void AddHorizontalLine(double yValue, ImU32 color, float thickness = 1.f, ImAxis dataAxis = ImAxis_Y1)
|
||||||
|
{
|
||||||
|
const ImVec2 plotPos = ImPlot::GetPlotPos();
|
||||||
|
const ImVec2 plotSize = ImPlot::GetPlotSize();
|
||||||
|
const float yScaled = ImPlot::GetCurrentPlot()->Axes[dataAxis].PlotToPixels(yValue);
|
||||||
|
const ImVec2 v0 = ImVec2(plotPos.y, yScaled);
|
||||||
|
const ImVec2 v1 = ImVec2(plotPos.y + plotSize.y, yScaled);
|
||||||
|
|
||||||
|
ImPlot::GetPlotDrawList()->AddLine(v0, v1, color, thickness);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void AddVerticalRect(double xStart, double xEnd, ImU32 color, ImAxis dataAxis = ImAxis_X1)
|
||||||
|
{
|
||||||
|
const ImVec2 plotPos = ImPlot::GetPlotPos();
|
||||||
|
const ImVec2 plotSize = ImPlot::GetPlotSize();
|
||||||
|
const float xStartScaled = ImPlot::GetCurrentPlot()->Axes[dataAxis].PlotToPixels(xStart);
|
||||||
|
const float xEndScaled = ImPlot::GetCurrentPlot()->Axes[dataAxis].PlotToPixels(xEnd);
|
||||||
|
const ImVec2 v0 = ImVec2(xStartScaled, plotPos.y);
|
||||||
|
const ImVec2 v1 = ImVec2(xEndScaled, plotPos.y + plotSize.y);
|
||||||
|
|
||||||
|
ImPlot::GetPlotDrawList()->AddRectFilled(v0, v1, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void AddHorizontalRect(double yStart, double yEnd, ImU32 color, ImAxis dataAxis = ImAxis_Y1)
|
||||||
|
{
|
||||||
|
const ImVec2 plotPos = ImPlot::GetPlotPos();
|
||||||
|
const ImVec2 plotSize = ImPlot::GetPlotSize();
|
||||||
|
const float yStartScaled = ImPlot::GetCurrentPlot()->Axes[dataAxis].PlotToPixels(yStart);
|
||||||
|
const float yEndScaled = ImPlot::GetCurrentPlot()->Axes[dataAxis].PlotToPixels(yEnd);
|
||||||
|
const ImVec2 v0 = ImVec2(plotPos.x, yStartScaled);
|
||||||
|
const ImVec2 v1 = ImVec2(plotPos.x + plotSize.x, yEndScaled);
|
||||||
|
|
||||||
|
ImPlot::GetPlotDrawList()->AddRectFilled(v0, v1, color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // !defined(RAID_PUBLIC_RAID_IMRAID_PLOT_HPP_INCLUDED)
|
Loading…
x
Reference in New Issue
Block a user