1
0
Fork 0
mirror of https://github.com/gwm17/implot.git synced 2024-11-22 18:28:53 -05:00

attempt to make negative timestamps work

This commit is contained in:
epezent 2021-05-23 16:39:46 -07:00
parent 555ff688a8
commit f0ad989a4c
3 changed files with 34 additions and 18 deletions

View File

@ -827,8 +827,8 @@ ImPlotTime MkGmtTime(struct tm *ptm) {
#else
t.S = timegm(ptm);
#endif
if (t.S < 0)
t.S = 0;
// if (t.S < 0)
// t.S = 0;
return t;
}
@ -847,8 +847,8 @@ tm* GetGmtTime(const ImPlotTime& t, tm* ptm)
ImPlotTime MkLocTime(struct tm *ptm) {
ImPlotTime t;
t.S = mktime(ptm);
if (t.S < 0)
t.S = 0;
// if (t.S < 0)
// t.S = 0;
return t;
}
@ -881,8 +881,8 @@ ImPlotTime MakeTime(int year, int month, int day, int hour, int min, int sec, in
tm& Tm = GImPlot->Tm;
int yr = year - 1900;
if (yr < 0)
yr = 0;
// if (yr < 0)
// yr = 0;
sec = sec + us / 1000000;
us = us % 1000000;

View File

@ -53,10 +53,10 @@
#define IMPLOT_Y_AXES 3
// Zoom rate for scroll (e.g. 0.1f = 10% plot range every scroll click)
#define IMPLOT_ZOOM_RATE 0.1f
// Mimimum allowable timestamp value 01/01/1970 @ 12:00am (UTC) (DO NOT DECREASE THIS)
#define IMPLOT_MIN_TIME 0
// Maximum allowable timestamp value 01/01/3000 @ 12:00am (UTC) (DO NOT INCREASE THIS)
#define IMPLOT_MAX_TIME 32503680000
// Mimimum allowable timestamp value, default = 01/01/1900 @ 12:00am (UTC)
#define IMPLOT_MIN_TIME -2208988800.0
// Maximum allowable timestamp value, default = 01/01/3000 @ 12:00am (UTC)
#define IMPLOT_MAX_TIME 32503680000.0
// Default label format for axis labels
#define IMPLOT_LABEL_FMT "%g"
@ -92,6 +92,28 @@ extern IMPLOT_API ImPlotContext* GImPlot; // Current implicit context pointer
// [SECTION] Generic Helpers
//-----------------------------------------------------------------------------
// Numeric limits for integral types
template <typename T>
struct ImNumericLimits { static const T Min; static const T Max; };
template <> const short ImNumericLimits<short>::Min = SHRT_MIN;
template <> const short ImNumericLimits<short>::Max = SHRT_MAX;
template <> const int ImNumericLimits<int>::Min = INT_MIN;
template <> const int ImNumericLimits<int>::Max = INT_MAX;
template <> const long ImNumericLimits<long>::Min = LONG_MIN;
template <> const long ImNumericLimits<long>::Max = LONG_MAX;
template <> const long long ImNumericLimits<long long>::Min = LLONG_MIN;
template <> const long long ImNumericLimits<long long>::Max = LLONG_MAX;
template <> const unsigned short ImNumericLimits<unsigned short>::Min = 0;
template <> const unsigned short ImNumericLimits<unsigned short>::Max = USHRT_MAX;
template <> const unsigned int ImNumericLimits<unsigned int>::Min = 0;
template <> const unsigned int ImNumericLimits<unsigned int>::Max = UINT_MAX;
template <> const unsigned long ImNumericLimits<unsigned long>::Min = 0;
template <> const unsigned long ImNumericLimits<unsigned long>::Max = ULONG_MAX;
template <> const unsigned long long ImNumericLimits<unsigned long long>::Min = 0;
template <> const unsigned long long ImNumericLimits<unsigned long long>::Max = ULLONG_MAX;
// Computes the common (base-10) logarithm
static inline float ImLog10(float x) { return log10f(x); }
static inline double ImLog10(double x) { return log10(x); }

View File

@ -685,12 +685,6 @@ struct ShadedRenderer {
static const int VtxConsumed = 5;
};
// Stupid way of calculating maximum index size of ImDrawIdx without integer overflow issues
template <typename T>
struct MaxIdx { static const unsigned int Value; };
template <> const unsigned int MaxIdx<unsigned short>::Value = 65535;
template <> const unsigned int MaxIdx<unsigned int>::Value = 4294967295;
/// Renders primitive shapes in bulk as efficiently as possible.
template <typename Renderer>
inline void RenderPrimitives(const Renderer& renderer, ImDrawList& DrawList, const ImRect& cull_rect) {
@ -700,7 +694,7 @@ inline void RenderPrimitives(const Renderer& renderer, ImDrawList& DrawList, con
const ImVec2 uv = DrawList._Data->TexUvWhitePixel;
while (prims) {
// find how many can be reserved up to end of current draw command's limit
unsigned int cnt = ImMin(prims, (MaxIdx<ImDrawIdx>::Value - DrawList._VtxCurrentIdx) / Renderer::VtxConsumed);
unsigned int cnt = ImMin(prims, (ImNumericLimits<ImDrawIdx>::Max - DrawList._VtxCurrentIdx) / Renderer::VtxConsumed);
// make sure at least this many elements can be rendered to avoid situations where at the end of buffer this slow path is not taken all the time
if (cnt >= ImMin(64u, prims)) {
if (prims_culled >= cnt)
@ -716,7 +710,7 @@ inline void RenderPrimitives(const Renderer& renderer, ImDrawList& DrawList, con
DrawList.PrimUnreserve(prims_culled * Renderer::IdxConsumed, prims_culled * Renderer::VtxConsumed);
prims_culled = 0;
}
cnt = ImMin(prims, (MaxIdx<ImDrawIdx>::Value - 0/*DrawList._VtxCurrentIdx*/) / Renderer::VtxConsumed);
cnt = ImMin(prims, (ImNumericLimits<ImDrawIdx>::Max - 0/*DrawList._VtxCurrentIdx*/) / Renderer::VtxConsumed);
DrawList.PrimReserve(cnt * Renderer::IdxConsumed, cnt * Renderer::VtxConsumed); // reserve new draw command
}
prims -= cnt;