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 #else
t.S = timegm(ptm); t.S = timegm(ptm);
#endif #endif
if (t.S < 0) // if (t.S < 0)
t.S = 0; // t.S = 0;
return t; return t;
} }
@ -847,8 +847,8 @@ tm* GetGmtTime(const ImPlotTime& t, tm* ptm)
ImPlotTime MkLocTime(struct tm *ptm) { ImPlotTime MkLocTime(struct tm *ptm) {
ImPlotTime t; ImPlotTime t;
t.S = mktime(ptm); t.S = mktime(ptm);
if (t.S < 0) // if (t.S < 0)
t.S = 0; // t.S = 0;
return t; 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; tm& Tm = GImPlot->Tm;
int yr = year - 1900; int yr = year - 1900;
if (yr < 0) // if (yr < 0)
yr = 0; // yr = 0;
sec = sec + us / 1000000; sec = sec + us / 1000000;
us = us % 1000000; us = us % 1000000;

View File

@ -53,10 +53,10 @@
#define IMPLOT_Y_AXES 3 #define IMPLOT_Y_AXES 3
// Zoom rate for scroll (e.g. 0.1f = 10% plot range every scroll click) // Zoom rate for scroll (e.g. 0.1f = 10% plot range every scroll click)
#define IMPLOT_ZOOM_RATE 0.1f #define IMPLOT_ZOOM_RATE 0.1f
// Mimimum allowable timestamp value 01/01/1970 @ 12:00am (UTC) (DO NOT DECREASE THIS) // Mimimum allowable timestamp value, default = 01/01/1900 @ 12:00am (UTC)
#define IMPLOT_MIN_TIME 0 #define IMPLOT_MIN_TIME -2208988800.0
// Maximum allowable timestamp value 01/01/3000 @ 12:00am (UTC) (DO NOT INCREASE THIS) // Maximum allowable timestamp value, default = 01/01/3000 @ 12:00am (UTC)
#define IMPLOT_MAX_TIME 32503680000 #define IMPLOT_MAX_TIME 32503680000.0
// Default label format for axis labels // Default label format for axis labels
#define IMPLOT_LABEL_FMT "%g" #define IMPLOT_LABEL_FMT "%g"
@ -92,6 +92,28 @@ extern IMPLOT_API ImPlotContext* GImPlot; // Current implicit context pointer
// [SECTION] Generic Helpers // [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 // Computes the common (base-10) logarithm
static inline float ImLog10(float x) { return log10f(x); } static inline float ImLog10(float x) { return log10f(x); }
static inline double ImLog10(double x) { return log10(x); } static inline double ImLog10(double x) { return log10(x); }

View File

@ -685,12 +685,6 @@ struct ShadedRenderer {
static const int VtxConsumed = 5; 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. /// Renders primitive shapes in bulk as efficiently as possible.
template <typename Renderer> template <typename Renderer>
inline void RenderPrimitives(const Renderer& renderer, ImDrawList& DrawList, const ImRect& cull_rect) { 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; const ImVec2 uv = DrawList._Data->TexUvWhitePixel;
while (prims) { while (prims) {
// find how many can be reserved up to end of current draw command's limit // 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 // 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 (cnt >= ImMin(64u, prims)) {
if (prims_culled >= cnt) 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); DrawList.PrimUnreserve(prims_culled * Renderer::IdxConsumed, prims_culled * Renderer::VtxConsumed);
prims_culled = 0; 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 DrawList.PrimReserve(cnt * Renderer::IdxConsumed, cnt * Renderer::VtxConsumed); // reserve new draw command
} }
prims -= cnt; prims -= cnt;