PlotLines: fixed rendering issue added in previous commit (#342)

This commit is contained in:
ocornut 2015-09-20 11:37:46 +02:00
parent 994c286f61
commit e268303c02

View File

@ -6580,16 +6580,15 @@ void ImGui::PlotEx(ImGuiPlotType plot_type, const char* label, float (*values_ge
RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg), true, style.FrameRounding); RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg), true, style.FrameRounding);
int res_w = ImMin((int)graph_size.x, values_count); int res_w = ImMin((int)graph_size.x, values_count) + ((plot_type == ImGuiPlotType_Lines) ? -1 : 0);
if (plot_type == ImGuiPlotType_Lines) int item_count = values_count + ((plot_type == ImGuiPlotType_Lines) ? -1 : 0);
res_w -= 1;
// Tooltip on hover // Tooltip on hover
int v_hovered = -1; int v_hovered = -1;
if (IsHovered(inner_bb, 0)) if (IsHovered(inner_bb, 0))
{ {
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 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 * (values_count + ((plot_type == ImGuiPlotType_Lines) ? -1 : 0))); const int v_idx = (int)(t * item_count);
IM_ASSERT(v_idx >= 0 && v_idx < values_count); IM_ASSERT(v_idx >= 0 && v_idx < values_count);
const float v0 = values_getter(data, (v_idx + values_offset) % values_count); const float v0 = values_getter(data, (v_idx + values_offset) % values_count);
@ -6613,7 +6612,7 @@ void ImGui::PlotEx(ImGuiPlotType plot_type, const char* label, float (*values_ge
for (int n = 0; n < res_w; n++) for (int n = 0; n < res_w; n++)
{ {
const float t1 = t0 + t_step; const float t1 = t0 + t_step;
const int v_idx = (int)(t0 * values_count + 0.5f); const int v_idx = (int)(t0 * item_count + 0.5f);
IM_ASSERT(v_idx >= 0 && v_idx < values_count); IM_ASSERT(v_idx >= 0 && v_idx < values_count);
const float v1 = values_getter(data, (v_idx + values_offset + 1) % values_count); const float v1 = values_getter(data, (v_idx + values_offset + 1) % values_count);
const ImVec2 p1 = ImVec2( t1, 1.0f - ImSaturate((v1 - scale_min) / (scale_max - scale_min)) ); const ImVec2 p1 = ImVec2( t1, 1.0f - ImSaturate((v1 - scale_min) / (scale_max - scale_min)) );