1
0
Fork 0
mirror of https://github.com/gwm17/implot.git synced 2024-11-13 22:48:50 -05:00

add custom rendering utils

This commit is contained in:
Evan Pezent 2020-04-29 15:39:02 -05:00
parent dd5390f433
commit 3c1ef11525
3 changed files with 83 additions and 24 deletions

View File

@ -1295,6 +1295,35 @@ void SetNextPlotRangeY(float y_min, float y_max, ImGuiCond cond) {
gp.NextPlotData.YMax = y_max;
}
ImVec2 GetPlotPos() {
IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "GetPlotPos() Needs to be called between BeginPlot() and EndPlot()!");
return gp.BB_Grid.Min;
}
ImVec2 GetPlotSize() {
IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "GetPlotSize() Needs to be called between BeginPlot() and EndPlot()!");
return gp.BB_Grid.GetSize();
}
ImVec2 PixelsToPlot(const ImVec2& pix) {
IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "PixelsToPlot() Needs to be called between BeginPlot() and EndPlot()!");
return gp.FromPixels(pix);
}
ImVec2 PlotToPixels(const ImVec2& plt) {
IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "PlotToPixels() Needs to be called between BeginPlot() and EndPlot()!");
return gp.ToPixels(plt);
}
void PushPlotClipRect() {
IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "PushPlotClipRect() Needs to be called between BeginPlot() and EndPlot()!");
PushClipRect(gp.BB_Grid.Min, gp.BB_Grid.Max, true);
}
void PopPlotClipRect() {
PopClipRect();
}
bool IsPlotHovered() {
IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "IsPlotHovered() Needs to be called between BeginPlot() and EndPlot()!");
return gp.Hov_Grid;

View File

@ -147,28 +147,6 @@ bool BeginPlot(const char* title_id,
// of an if statement conditioned on BeginPlot().
void EndPlot();
/// Set the axes ranges of the next plot. Call right before BeginPlot(). If ImGuiCond_Always is used, the axes will be locked.
void SetNextPlotRange(float x_min, float x_max, float y_min, float y_max, ImGuiCond cond = ImGuiCond_Once);
/// Set the X axis range of the next plot. Call right before BeginPlot(). If ImGuiCond_Always is used, the axis will be locked.
void SetNextPlotRangeX(float x_min, float x_max, ImGuiCond cond = ImGuiCond_Once);
/// Set the X axis range of the next plot. Call right before BeginPlot(). If ImGuiCond_Always is used, the axis will be locked.
void SetNextPlotRangeY(float y_min, float y_max, ImGuiCond cond = ImGuiCond_Once);
//-----------------------------------------------------------------------------
// Plot Queries
//-----------------------------------------------------------------------------
/// Returns true if the plot area in the current or most recent plot is hovered.
bool IsPlotHovered();
/// Returns the mouse position in x,y coordinates of the current or most recent plot.
ImVec2 GetPlotMousePos();
/// Returns the current or most recent plot axis range.
ImPlotRange GetPlotRange();
/// Returns true if the current or most recent plot is being queried.
bool IsPlotQueried();
/// Returns the current or most recent plot querey range.
ImPlotRange GetPlotQuery();
//-----------------------------------------------------------------------------
// Plot Items
//-----------------------------------------------------------------------------
@ -192,6 +170,21 @@ void PlotErrorBars(const char* label_id, ImVec4 (*getter)(void* data, int idx),
// Plots a text label at point x,y.
void PlotLabel(const char* text, float x, float y, bool vertical = false, const ImVec2& pixel_offset = ImVec2(0,0));
//-----------------------------------------------------------------------------
// Plot Queries
//-----------------------------------------------------------------------------
/// Returns true if the plot area in the current or most recent plot is hovered.
bool IsPlotHovered();
/// Returns the mouse position in x,y coordinates of the current or most recent plot.
ImVec2 GetPlotMousePos();
/// Returns the current or most recent plot axis range.
ImPlotRange GetPlotRange();
/// Returns true if the current or most recent plot is being queried.
bool IsPlotQueried();
/// Returns the current or most recent plot querey range.
ImPlotRange GetPlotQuery();
//-----------------------------------------------------------------------------
// Plot Styling
//-----------------------------------------------------------------------------
@ -218,6 +211,32 @@ void PushPlotStyleVar(ImPlotStyleVar idx, int val);
// Undo temporary style modification.
void PopPlotStyleVar(int count = 1);
//-----------------------------------------------------------------------------
// Plot Utils
//-----------------------------------------------------------------------------
/// Set the axes ranges of the next plot. Call right before BeginPlot(). If ImGuiCond_Always is used, the axes will be locked.
void SetNextPlotRange(float x_min, float x_max, float y_min, float y_max, ImGuiCond cond = ImGuiCond_Once);
/// Set the X axis range of the next plot. Call right before BeginPlot(). If ImGuiCond_Always is used, the axis will be locked.
void SetNextPlotRangeX(float x_min, float x_max, ImGuiCond cond = ImGuiCond_Once);
/// Set the X axis range of the next plot. Call right before BeginPlot(). If ImGuiCond_Always is used, the axis will be locked.
void SetNextPlotRangeY(float y_min, float y_max, ImGuiCond cond = ImGuiCond_Once);
// Get the current Plot position (top-left) in pixels.
ImVec2 GetPlotPos();
// Get the curent Plot size in pixels.
ImVec2 GetPlotSize();
// Convert pixels to a position in the current plot's coordinate system.
ImVec2 PixelsToPlot(const ImVec2& pix);
// Convert a position in the current plot's coordinate system to pixels.
ImVec2 PlotToPixels(const ImVec2& plt);
// Push clip rect for rendering to current plot area
void PushPlotClipRect();
// Pop plot clip rect
void PopPlotClipRect();
//-----------------------------------------------------------------------------
// Demo
//-----------------------------------------------------------------------------

View File

@ -23,7 +23,6 @@
// ImPlot v0.1 WIP
#include <implot.h>
#include <imgui_internal.h>
#include <iostream>
namespace {
@ -48,7 +47,7 @@ struct RollingData {
ImVector<ImVec2> Data;
RollingData() { Data.reserve(1000); }
void AddPoint(float x, float y) {
float xmod = ImFmod(x, Span);
float xmod = fmodf(x, Span);
if (!Data.empty() && xmod < Data.back().x)
Data.shrink(0);
Data.push_back(ImVec2(xmod, y));
@ -493,6 +492,18 @@ void ShowImPlotDemoWindow(bool* p_open) {
ImGui::PopPlotStyleVar();
ImGui::RestorePlotPalette();
}
if (ImGui::CollapsingHeader("Custom Rendering")) {
if (ImGui::BeginPlot("##CustomRend",NULL,NULL,{-1,300})) {
ImVec2 cntr = ImGui::PlotToPixels({0.5f, 0.5f});
ImVec2 rmin = ImGui::PlotToPixels({0.25f, 0.75f});
ImVec2 rmax = ImGui::PlotToPixels({0.75f, 0.25f});
ImGui::PushPlotClipRect();
ImGui::GetWindowDrawList()->AddCircleFilled(cntr,20,IM_COL32(255,255,0,255),20);
ImGui::GetWindowDrawList()->AddRect(rmin, rmax, IM_COL32(128,0,255,255));
ImGui::PopPlotClipRect();
ImGui::EndPlot();
}
}
//-------------------------------------------------------------------------
// if (ImGui::CollapsingHeader("Benchmark")) {