diff --git a/implot.h b/implot.h index cf2274e..2783729 100644 --- a/implot.h +++ b/implot.h @@ -393,9 +393,14 @@ template IMPLOT_API void PlotHeatmap(const char* label_id, const T* template IMPLOT_API void PlotDigital(const char* label_id, const T* xs, const T* ys, int count, int offset=0, int stride=sizeof(T)); IMPLOT_API void PlotDigitalG(const char* label_id, ImPlotPoint (*getter)(void* data, int idx), void* data, int count, int offset=0); +// Plots an image. +IMPLOT_API void PlotImage(const char* label_id, ImTextureID user_texture_id, const ImPlotPoint& bounds_min, const ImPlotPoint& bounds_max, const ImVec2& uv0 = ImVec2(0, 0), const ImVec2& uv1 = ImVec2(1,1), const ImVec4& tint_col = ImVec4(1,1,1,1)); + // Plots a centered text label at point x,y with optional pixel offset. Text color can be changed with ImPlot::PushStyleColor(ImPlotCol_InlayText, ...). IMPLOT_API void PlotText(const char* text, double x, double y, bool vertical=false, const ImVec2& pixel_offset=ImVec2(0,0)); + + //----------------------------------------------------------------------------- // Plot Utils //----------------------------------------------------------------------------- diff --git a/implot_items.cpp b/implot_items.cpp index 5a35344..b3cedff 100644 --- a/implot_items.cpp +++ b/implot_items.cpp @@ -1705,6 +1705,27 @@ void PlotRects(const char* label_id, ImPlotPoint (*getter_func)(void* data, int return PlotRectsEx(label_id, getter); } +//----------------------------------------------------------------------------- +// PLOT IMAGE +//----------------------------------------------------------------------------- + +void PlotImage(const char* label_id, ImTextureID user_texture_id, const ImPlotPoint& bmin, const ImPlotPoint& bmax, const ImVec2& uv0, const ImVec2& uv1, const ImVec4& tint_col) { + if (BeginItem(label_id)) { + if (FitThisFrame()) { + FitPoint(bmin); + FitPoint(bmax); + } + GetCurrentItem()->Color = tint_col; + ImDrawList& DrawList = *GetPlotDrawList(); + ImVec2 p1 = PlotToPixels(bmin.x, bmax.y); + ImVec2 p2 = PlotToPixels(bmax.x, bmin.y); + PushPlotClipRect(); + DrawList.AddImage(user_texture_id, p1, p2, uv0, uv1, ImGui::ColorConvertFloat4ToU32(tint_col)); + PopPlotClipRect();; + EndItem(); + } +} + //----------------------------------------------------------------------------- // PLOT TEXT //-----------------------------------------------------------------------------