1
0
Fork 0
mirror of https://github.com/gwm17/implot.git synced 2024-11-26 12:18:52 -05:00

plot image demo

This commit is contained in:
epezent 2020-09-17 20:34:37 -05:00
parent ec8e87561f
commit fd746c3776
3 changed files with 23 additions and 4 deletions

View File

@ -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 <typename T> IMPLOT_API void PlotHeatmap(const char* label_id, const T*
template <typename T> 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
//-----------------------------------------------------------------------------

View File

@ -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.");

View File

@ -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();
}
}