|
|
|
@ -22,6 +22,95 @@ namespace ImGui {
|
|
|
|
|
static ImVec2 subtract(const ImVec2& a, const ImVec2& b){
|
|
|
|
|
return ImVec2(a.x-b.x, a.y-b.y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void PlotMultiLines(
|
|
|
|
|
const std::vector<std::vector<int>> &data,
|
|
|
|
|
std::string title,
|
|
|
|
|
const std::vector<std::string> &labels,
|
|
|
|
|
const std::vector<ImColor> &colors,
|
|
|
|
|
float maximum_scale,
|
|
|
|
|
float minimum_scale,
|
|
|
|
|
sf::Vector2f graph_size
|
|
|
|
|
){
|
|
|
|
|
|
|
|
|
|
int values_count = data.at(0).size();
|
|
|
|
|
|
|
|
|
|
ImGuiWindow* window = GetCurrentWindow();
|
|
|
|
|
if (window->SkipItems)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ImGuiContext& g = *GImGui;
|
|
|
|
|
const ImGuiStyle& style = g.Style;
|
|
|
|
|
|
|
|
|
|
const ImVec2 label_size = ImGui::CalcTextSize(title.c_str(), NULL, true);
|
|
|
|
|
|
|
|
|
|
if (graph_size.x == 0.0f)
|
|
|
|
|
graph_size.x = CalcItemWidth();
|
|
|
|
|
if (graph_size.y == 0.0f)
|
|
|
|
|
graph_size.y = label_size.y + (style.FramePadding.y * 2);
|
|
|
|
|
|
|
|
|
|
const ImRect frame_bb(window->DC.CursorPos,
|
|
|
|
|
add(window->DC.CursorPos, graph_size));
|
|
|
|
|
const ImRect inner_bb(add(frame_bb.Min,style.FramePadding),
|
|
|
|
|
subtract(frame_bb.Max , style.FramePadding));
|
|
|
|
|
ImVec2 thing = ImVec2(label_size.x > 0.0f ?
|
|
|
|
|
style.ItemInnerSpacing.x + label_size.x : 0.0f,
|
|
|
|
|
0);
|
|
|
|
|
const ImRect total_bb(frame_bb.Min, add(frame_bb.Max , thing));
|
|
|
|
|
|
|
|
|
|
ItemSize(total_bb, style.FramePadding.y);
|
|
|
|
|
if (!ItemAdd(total_bb, 0))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
RenderFrame(frame_bb.Min, frame_bb.Max, GetColorU32(ImGuiCol_FrameBg),
|
|
|
|
|
true, style.FrameRounding);
|
|
|
|
|
|
|
|
|
|
int res_w = ImMin((int) graph_size.x, values_count );
|
|
|
|
|
int item_count = values_count;
|
|
|
|
|
int text_margin = 10;
|
|
|
|
|
|
|
|
|
|
for (int data_idx = 0; data_idx < data.size(); ++data_idx)
|
|
|
|
|
{
|
|
|
|
|
const float t_step = 1.0f / (float) res_w;
|
|
|
|
|
|
|
|
|
|
float v0 = data.at(data_idx).at(0);
|
|
|
|
|
float t0 = 0.0f;
|
|
|
|
|
ImVec2 tp0 = ImVec2(t0,
|
|
|
|
|
1.0f - ImSaturate((v0 - minimum_scale) / (maximum_scale - minimum_scale))); // Point in the normalized space of our target rectangle
|
|
|
|
|
|
|
|
|
|
const ImU32 col_base = colors.at(data_idx);
|
|
|
|
|
const ImU32 col_hovered = InvertColorU32(colors.at(data_idx));
|
|
|
|
|
|
|
|
|
|
for (int n = 0; n < res_w; n++)
|
|
|
|
|
{
|
|
|
|
|
const float t1 = t0 + t_step;
|
|
|
|
|
const int v1_idx = (int) (t0 * item_count + 0.5f);
|
|
|
|
|
IM_ASSERT(v1_idx >= 0 && v1_idx < values_count);
|
|
|
|
|
const float v1 = data.at(data_idx).at(v1_idx);
|
|
|
|
|
const ImVec2 tp1 = ImVec2(t1,
|
|
|
|
|
1.0f - ImSaturate((v1 - minimum_scale) / (maximum_scale - minimum_scale)));
|
|
|
|
|
|
|
|
|
|
// NB: Draw calls are merged together by the DrawList system. Still, we should render our batch are lower level to save a bit of CPU.
|
|
|
|
|
ImVec2 pos0 = ImLerp(inner_bb.Min, inner_bb.Max, tp0);
|
|
|
|
|
ImVec2 pos1 = ImLerp(inner_bb.Min, inner_bb.Max, tp1);//ImVec2(tp1.x, 1.0f));
|
|
|
|
|
|
|
|
|
|
window->DrawList->AddLine(pos0, pos1, col_base);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t0 = t1;
|
|
|
|
|
tp0 = tp1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Render the text label
|
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_Text, (ImVec4)colors.at(data_idx));
|
|
|
|
|
RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, inner_bb.Min.y + text_margin * data_idx), labels.at(data_idx).c_str());
|
|
|
|
|
ImGui::PopStyleColor(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, inner_bb.Max.y), title.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void PlotMultiEx(
|
|
|
|
|
ImGuiPlotType plot_type,
|
|
|
|
|
const char* label,
|
|
|
|
@ -58,14 +147,9 @@ namespace ImGui {
|
|
|
|
|
const ImRect total_bb(frame_bb.Min, add(frame_bb.Max , thing));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(graph_size.x, graph_size.y));
|
|
|
|
|
// const ImRect inner_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding);
|
|
|
|
|
// const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ItemSize(total_bb, style.FramePadding.y);
|
|
|
|
|
// if (!ItemAdd(total_bb, NULL))
|
|
|
|
|
// return;
|
|
|
|
|
if (!ItemAdd(total_bb, 0))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Determine scale from values if not specified
|
|
|
|
|
if (scale_min == FLT_MAX || scale_max == FLT_MAX)
|
|
|
|
|