modifying multilines to fit what I want it to do

master
mitchellhansen 7 years ago
parent dd44955f33
commit 7679a5a938

@ -1,187 +1,203 @@
//
//#pragma once #pragma once
//#include "imgui.h" #include "imgui.h"
//#include "imgui_internal.h" #include "imgui_internal.h"
//
//
//
//namespace ImGui { namespace ImGui {
//
// static ImU32 InvertColorU32(ImU32 in) static ImU32 InvertColorU32(ImU32 in)
// { {
// ImVec4 in4 = ColorConvertU32ToFloat4(in); ImVec4 in4 = ColorConvertU32ToFloat4(in);
// in4.x = 1.f - in4.x; in4.x = 1.f - in4.x;
// in4.y = 1.f - in4.y; in4.y = 1.f - in4.y;
// in4.z = 1.f - in4.z; in4.z = 1.f - in4.z;
// return GetColorU32(in4); return GetColorU32(in4);
// } }
//
// static void PlotMultiEx( static ImVec2 add(const ImVec2& a, const ImVec2& b){
// ImGuiPlotType plot_type, return ImVec2(a.x+b.x, a.y+b.y);
// const char* label, }
// int num_datas, static ImVec2 subtract(const ImVec2& a, const ImVec2& b){
// const char** names, return ImVec2(a.x-b.x, a.y-b.y);
// const ImColor* colors, }
// float(*getter)(const void* data, int idx), static void PlotMultiEx(
// const void * const * datas, ImGuiPlotType plot_type,
// int values_count, const char* label,
// float scale_min, int num_datas,
// float scale_max, const char** names,
// ImVec2 graph_size) const ImColor* colors,
// { float(*getter)(const void* data, int idx),
// const int values_offset = 0; const void * const * datas,
// int values_count,
// ImGuiWindow* window = GetCurrentWindow(); float scale_min,
// if (window->SkipItems) float scale_max,
// return; ImVec2 graph_size){
//
// ImGuiContext& g = *GImGui; const int values_offset = 0;
// const ImGuiStyle& style = g.Style;
// ImGuiWindow* window = GetCurrentWindow();
// const ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true); if (window->SkipItems)
// if (graph_size.x == 0.0f) return;
// graph_size.x = CalcItemWidth();
// if (graph_size.y == 0.0f) ImGuiContext& g = *GImGui;
// graph_size.y = label_size.y + (style.FramePadding.y * 2); const ImGuiStyle& style = g.Style;
//
// const ImRect frame_bb();//window->DC.CursorPos, window->DC.CursorPos + ImVec2(graph_size.x, graph_size.y)); const ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true);
// const ImRect inner_bb();//frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding); if (graph_size.x == 0.0f)
// 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)); graph_size.x = CalcItemWidth();
// ItemSize(total_bb, style.FramePadding.y); if (graph_size.y == 0.0f)
// if (!ItemAdd(total_bb, NULL)) graph_size.y = label_size.y + (style.FramePadding.y * 2);
// return;
//
// // Determine scale from values if not specified
// if (scale_min == FLT_MAX || scale_max == FLT_MAX) 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));
// float v_min = FLT_MAX; ImVec2 thing = ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0);
// float v_max = -FLT_MAX; const ImRect total_bb(frame_bb.Min, add(frame_bb.Max , thing));
// for (int data_idx = 0; data_idx < num_datas; ++data_idx)
// {
// for (int i = 0; i < values_count; i++) // 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 float v = getter(datas[data_idx], i); // 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));
// v_min = ImMin(v_min, v);
// v_max = ImMax(v_max, v);
// } ItemSize(total_bb, style.FramePadding.y);
// } // if (!ItemAdd(total_bb, NULL))
// if (scale_min == FLT_MAX) // return;
// scale_min = v_min;
// if (scale_max == FLT_MAX) // Determine scale from values if not specified
// scale_max = v_max; if (scale_min == FLT_MAX || scale_max == FLT_MAX)
// } {
// float v_min = FLT_MAX;
// RenderFrame(frame_bb.Min, frame_bb.Max, GetColorU32(ImGuiCol_FrameBg), true, style.FrameRounding); float v_max = -FLT_MAX;
// for (int data_idx = 0; data_idx < num_datas; ++data_idx)
// int res_w = ImMin((int) graph_size.x, values_count) + ((plot_type == ImGuiPlotType_Lines) ? -1 : 0); {
// int item_count = values_count + ((plot_type == ImGuiPlotType_Lines) ? -1 : 0); for (int i = 0; i < values_count; i++)
// {
// // Tooltip on hover const float v = getter(datas[data_idx], i);
// int v_hovered = -1; v_min = ImMin(v_min, v);
// if (IsHovered(inner_bb, 0)) v_max = ImMax(v_max, v);
// { }
// const float t = ImClamp((g.IO.MousePos.x - inner_bb.Min.x) / (inner_bb.Max.x - inner_bb.Min.x), 0.0f, 0.9999f); }
// const int v_idx = (int) (t * item_count); if (scale_min == FLT_MAX)
// IM_ASSERT(v_idx >= 0 && v_idx < values_count); scale_min = v_min;
// if (scale_max == FLT_MAX)
// // std::string toolTip; scale_max = v_max;
// ImGui::BeginTooltip(); }
// const int idx0 = (v_idx + values_offset) % values_count;
// if (plot_type == ImGuiPlotType_Lines) RenderFrame(frame_bb.Min, frame_bb.Max, GetColorU32(ImGuiCol_FrameBg), true, style.FrameRounding);
// {
// const int idx1 = (v_idx + 1 + values_offset) % values_count; int res_w = ImMin((int) graph_size.x, values_count) + ((plot_type == ImGuiPlotType_Lines) ? -1 : 0);
// Text("%8d %8d | Name", v_idx, v_idx+1); int item_count = values_count + ((plot_type == ImGuiPlotType_Lines) ? -1 : 0);
// for (int dataIdx = 0; dataIdx < num_datas; ++dataIdx)
// { // Tooltip on hover
// const float v0 = getter(datas[dataIdx], idx0); // int v_hovered = -1;
// const float v1 = getter(datas[dataIdx], idx1); // if (IsHovered(inner_bb, 0))
// TextColored(colors[dataIdx], "%8.4g %8.4g | %s", v0, v1, names[dataIdx]); // {
// } // const float t = ImClamp((g.IO.MousePos.x - inner_bb.Min.x) / (inner_bb.Max.x - inner_bb.Min.x), 0.0f, 0.9999f);
// } // const int v_idx = (int) (t * item_count);
// else if (plot_type == ImGuiPlotType_Histogram) // IM_ASSERT(v_idx >= 0 && v_idx < values_count);
// { //
// for (int dataIdx = 0; dataIdx < num_datas; ++dataIdx) // // std::string toolTip;
// { // ImGui::BeginTooltip();
// const float v0 = getter(datas[dataIdx], idx0); // const int idx0 = (v_idx + values_offset) % values_count;
// TextColored(colors[dataIdx], "%d: %8.4g | %s", v_idx, v0, names[dataIdx]); // if (plot_type == ImGuiPlotType_Lines)
// } // {
// } // const int idx1 = (v_idx + 1 + values_offset) % values_count;
// ImGui::EndTooltip(); // Text("%8d %8d | Name", v_idx, v_idx+1);
// v_hovered = v_idx; // for (int dataIdx = 0; dataIdx < num_datas; ++dataIdx)
// } // {
// // const float v0 = getter(datas[dataIdx], idx0);
// for (int data_idx = 0; data_idx < num_datas; ++data_idx) // const float v1 = getter(datas[dataIdx], idx1);
// { // TextColored(colors[dataIdx], "%8.4g %8.4g | %s", v0, v1, names[dataIdx]);
// const float t_step = 1.0f / (float) res_w; // }
// // }
// float v0 = getter(datas[data_idx], (0 + values_offset) % values_count); // else if (plot_type == ImGuiPlotType_Histogram)
// float t0 = 0.0f; // {
// ImVec2 tp0 = ImVec2(t0, 1.0f - ImSaturate((v0 - scale_min) / (scale_max - scale_min))); // Point in the normalized space of our target rectangle // for (int dataIdx = 0; dataIdx < num_datas; ++dataIdx)
// // {
// const ImU32 col_base = colors[data_idx]; // const float v0 = getter(datas[dataIdx], idx0);
// const ImU32 col_hovered = InvertColorU32(colors[data_idx]); // TextColored(colors[dataIdx], "%d: %8.4g | %s", v_idx, v0, names[dataIdx]);
// // }
// //const ImU32 col_base = GetColorU32((plot_type == ImGuiPlotType_Lines) ? ImGuiCol_PlotLines : ImGuiCol_PlotHistogram); // }
// //const ImU32 col_hovered = GetColorU32((plot_type == ImGuiPlotType_Lines) ? ImGuiCol_PlotLinesHovered : ImGuiCol_PlotHistogramHovered); // ImGui::EndTooltip();
// // v_hovered = v_idx;
// for (int n = 0; n < res_w; n++) // }
// {
// const float t1 = t0 + t_step; for (int data_idx = 0; data_idx < num_datas; ++data_idx)
// const int v1_idx = (int) (t0 * item_count + 0.5f); {
// IM_ASSERT(v1_idx >= 0 && v1_idx < values_count); const float t_step = 1.0f / (float) res_w;
// const float v1 = getter(datas[data_idx], (v1_idx + values_offset + 1) % values_count);
// const ImVec2 tp1 = ImVec2(t1, 1.0f - ImSaturate((v1 - scale_min) / (scale_max - scale_min))); float v0 = getter(datas[data_idx], (0 + values_offset) % values_count);
// float t0 = 0.0f;
// // 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 tp0 = ImVec2(t0, 1.0f - ImSaturate((v0 - scale_min) / (scale_max - scale_min))); // Point in the normalized space of our target rectangle
// ImVec2 pos0 = ImLerp(inner_bb.Min, inner_bb.Max, tp0);
// ImVec2 pos1 = ImLerp(inner_bb.Min, inner_bb.Max, (plot_type == ImGuiPlotType_Lines) ? tp1 : ImVec2(tp1.x, 1.0f)); const ImU32 col_base = colors[data_idx];
// if (plot_type == ImGuiPlotType_Lines) const ImU32 col_hovered = InvertColorU32(colors[data_idx]);
// {
// window->DrawList->AddLine(pos0, pos1, v_hovered == v1_idx ? col_hovered : col_base); //const ImU32 col_base = GetColorU32((plot_type == ImGuiPlotType_Lines) ? ImGuiCol_PlotLines : ImGuiCol_PlotHistogram);
// } //const ImU32 col_hovered = GetColorU32((plot_type == ImGuiPlotType_Lines) ? ImGuiCol_PlotLinesHovered : ImGuiCol_PlotHistogramHovered);
// else if (plot_type == ImGuiPlotType_Histogram)
// { for (int n = 0; n < res_w; n++)
// if (pos1.x >= pos0.x + 2.0f) {
// pos1.x -= 1.0f; const float t1 = t0 + t_step;
// window->DrawList->AddRectFilled(pos0, pos1, v_hovered == v1_idx ? col_hovered : col_base); const int v1_idx = (int) (t0 * item_count + 0.5f);
// } IM_ASSERT(v1_idx >= 0 && v1_idx < values_count);
// const float v1 = getter(datas[data_idx], (v1_idx + values_offset + 1) % values_count);
// t0 = t1; const ImVec2 tp1 = ImVec2(t1, 1.0f - ImSaturate((v1 - scale_min) / (scale_max - scale_min)));
// tp0 = tp1;
// } // 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, (plot_type == ImGuiPlotType_Lines) ? tp1 : ImVec2(tp1.x, 1.0f));
// RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, inner_bb.Min.y), label); if (plot_type == ImGuiPlotType_Lines)
//} {
// window->DrawList->AddLine(pos0, pos1, col_base);
//void PlotMultiLines( }
// const char* label, else if (plot_type == ImGuiPlotType_Histogram)
// int num_datas, {
// const char** names, if (pos1.x >= pos0.x + 2.0f)
// const ImColor* colors, pos1.x -= 1.0f;
// float(*getter)(const void* data, int idx), window->DrawList->AddRectFilled(pos0, pos1, col_base);
// const void * const * datas, }
// int values_count,
// float scale_min, t0 = t1;
// float scale_max, tp0 = tp1;
// ImVec2 graph_size) }
//{ }
// PlotMultiEx(ImGuiPlotType_Lines, label, num_datas, names, colors, getter, datas, values_count, scale_min, scale_max, graph_size);
//} RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, inner_bb.Min.y), label);
// }
//void PlotMultiHistograms(
// const char* label, inline void PlotMultiLines(
// int num_hists, const char* label,
// const char** names, int num_datas,
// const ImColor* colors, const char** names,
// float(*getter)(const void* data, int idx), const ImColor* colors,
// const void * const * datas, float(*getter)(const void* data, int idx),
// int values_count, const void * const * datas,
// float scale_min, int values_count,
// float scale_max, float scale_min,
// ImVec2 graph_size) float scale_max,
//{ ImVec2 graph_size)
// PlotMultiEx(ImGuiPlotType_Histogram, label, num_hists, names, colors, getter, datas, values_count, scale_min, scale_max, graph_size); {
//} PlotMultiEx(ImGuiPlotType_Lines, label, num_datas, names, colors, getter, datas, values_count, scale_min, scale_max, graph_size);
// }
//} // namespace ImGui
inline void PlotMultiHistograms(
const char* label,
int num_hists,
const char** names,
const ImColor* colors,
float(*getter)(const void* data, int idx),
const void * const * datas,
int values_count,
float scale_min,
float scale_max,
ImVec2 graph_size)
{
PlotMultiEx(ImGuiPlotType_Histogram, label, num_hists, names, colors, getter, datas, values_count, scale_min, scale_max, graph_size);
}
} // namespace ImGui

@ -11,6 +11,7 @@
#include <SFML/System/Vector2.hpp> #include <SFML/System/Vector2.hpp>
#include <SFML/Graphics/Texture.hpp> #include <SFML/Graphics/Texture.hpp>
#include <imgui/imgui.h> #include <imgui/imgui.h>
#include <imgui/imgui-multilines.hpp>
#include "Vector4.hpp" #include "Vector4.hpp"
const double PI = 3.141592653589793238463; const double PI = 3.141592653589793238463;
@ -40,6 +41,10 @@ public:
instant_fps = delta_time; instant_fps = delta_time;
} }
static float edit(const void* data, int idx){
//*(int*)data = idx;
return *(int*)(data+sizeof(int)*idx);
};
void draw() { void draw() {
if (arr_pos == 1000) if (arr_pos == 1000)
@ -49,7 +54,21 @@ public:
arr_pos++; arr_pos++;
ImGui::Begin("Performance"); ImGui::Begin("Performance");
ImVec2 wh = ImGui::GetContentRegionAvail(); //ImVec2 wh = ImGui::GetContentRegionAvail();
ImVec2 wh(100, 200);
int a[3] = {1, 2, 7};
int b[3] = {5, 3, 1};
int c[3] = {8, 1, 4};
const void* to_data[3] = {&a, &b, &c};
const char* to_names[3] = {"a", "b", "z"};
ImGuiPlotType plottype = ImGuiPlotType_Lines;
ImColor color = ImColor(255, 255, 255);
ImGui::PlotMultiLines(
"label", 3, to_names, &color, &edit,
to_data, 3, 0.0f, 10.0f, ImVec2(300, 300));
ImGui::PlotLines("FPS", fps_array, 1000, 0, ImGui::PlotLines("FPS", fps_array, 1000, 0,
std::to_string(1.0 / fps_average).c_str(), std::to_string(1.0 / fps_average).c_str(),
0.0f, 150.0f, wh); 0.0f, 150.0f, wh);
@ -287,3 +306,4 @@ inline bool IsLeaf(const uint64_t descriptor) {
return false; return false;
} }

Loading…
Cancel
Save