From fd746c377677c0f1e76d623794956f3fafdea2e8 Mon Sep 17 00:00:00 2001 From: epezent Date: Thu, 17 Sep 2020 20:34:37 -0500 Subject: [PATCH] plot image demo --- implot.h | 5 ++--- implot_demo.cpp | 20 ++++++++++++++++++++ implot_items.cpp | 2 +- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/implot.h b/implot.h index 2783729..5af49b6 100644 --- a/implot.h +++ b/implot.h @@ -188,6 +188,7 @@ struct ImPlotPoint { double x, y; ImPlotPoint() { x = y = 0.0; } ImPlotPoint(double _x, double _y) { x = _x; y = _y; } + ImPlotPoint(const ImVec2& p) { x = p.x; y = p.y; } double operator[] (size_t idx) const { return (&x)[idx]; } double& operator[] (size_t idx) { return (&x)[idx]; } #ifdef IMPLOT_POINT_CLASS_EXTRA @@ -393,14 +394,12 @@ 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. +// Plots an axis-aligned image. #bounds_min/bounds_max are in plot coordinatse (y-up) and #uv0/uv1 are in texture coordinates (y-down). 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_demo.cpp b/implot_demo.cpp index 6f67bed..2b7f5e5 100644 --- a/implot_demo.cpp +++ b/implot_demo.cpp @@ -508,6 +508,26 @@ void ShowDemoWindow(bool* p_open) { ImPlot::PopColormap(); } //------------------------------------------------------------------------- + if (ImGui::CollapsingHeader("Images")) { + ImGui::BulletText("Below we are displaying the font texture, which is the only texture we have\naccess to in this demo."); + ImGui::BulletText("Use the 'ImTextureID' type as storage to pass pointers or identifiers to your\nown texture data."); + ImGui::BulletText("See ImGui Wiki page 'Image Loading and Displaying Examples'."); + static ImVec2 bmin(0,0); + static ImVec2 bmax(1,1); + static ImVec2 uv0(0,0); + static ImVec2 uv1(1,1); + static ImVec4 tint(1,1,1,1); + ImGui::SliderFloat2("Min", &bmin.x, -2, 2, "%.1f"); + ImGui::SliderFloat2("Max", &bmax.x, -2, 2, "%.1f"); + ImGui::SliderFloat2("UV0", &uv0.x, -2, 2, "%.1f"); + ImGui::SliderFloat2("UV1", &uv1.x, -2, 2, "%.1f"); + ImGui::ColorEdit4("Tint",&tint.x); + if (ImPlot::BeginPlot("##image")) { + ImPlot::PlotImage("my image",ImGui::GetIO().Fonts->TexID, bmin, bmax, uv0, uv1, tint); + ImPlot::EndPlot(); + } + } + //------------------------------------------------------------------------- if (ImGui::CollapsingHeader("Realtime Plots")) { ImGui::BulletText("Move your mouse to change the data!"); ImGui::BulletText("This example assumes 60 FPS. Higher FPS requires larger buffer size."); diff --git a/implot_items.cpp b/implot_items.cpp index b3cedff..9b7c931 100644 --- a/implot_items.cpp +++ b/implot_items.cpp @@ -1721,7 +1721,7 @@ void PlotImage(const char* label_id, ImTextureID user_texture_id, const ImPlotPo ImVec2 p2 = PlotToPixels(bmax.x, bmin.y); PushPlotClipRect(); DrawList.AddImage(user_texture_id, p1, p2, uv0, uv1, ImGui::ColorConvertFloat4ToU32(tint_col)); - PopPlotClipRect();; + PopPlotClipRect(); EndItem(); } }