Changed ImGui::GetTime() return value from float to double to avoid accumulating floating point imprecisions over time.
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index c2044d3..bf01f8f 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -38,6 +38,7 @@
- Removed per-window ImGuiWindowFlags_ResizeFromAnySide beta flag in favor `io.OptResizeWindowsFromEdges=true` to enable the feature globally. (#1495)
The feature is not currently enabled by default because it is not satisfying enough.
- Style: Renamed ImGuiCol_ModalWindowDarkening to ImGuiCol_ModalWindowDimBg for consistency with other features. Kept redirection enum (will obsolete).
+ - Changed ImGui::GetTime() return value from float to double to avoid accumulating floating point imprecisions over time.
Other Changes:
diff --git a/imgui.cpp b/imgui.cpp
index a53a0ff..564708e 100644
--- a/imgui.cpp
+++ b/imgui.cpp
@@ -190,7 +190,7 @@
io.MouseDown[1] = my_mouse_buttons[1];
// Call NewFrame(), after this point you can use ImGui::* functions anytime
- // (So you want to try calling Newframe() as early as you can in your mainloop to be able to use imgui everywhere)
+ // (So you want to try calling NewFrame() as early as you can in your mainloop to be able to use imgui everywhere)
ImGui::NewFrame();
// Most of your application code here
@@ -305,6 +305,7 @@
When you are not sure about a old symbol or function name, try using the Search/Find function of your IDE to look for comments or references in all imgui files.
You can read releases logs https://github.com/ocornut/imgui/releases for more details.
+ - 2017/07/22 (1.63) - changed ImGui::GetTime() return value from float to double to avoid accumulating floating point imprecisions over time.
- 2018/07/08 (1.63) - style: renamed ImGuiCol_ModalWindowDarkening to ImGuiCol_ModalWindowDimBg for consistency with other features. Kept redirection enum (will obsolete).
- 2018/07/06 (1.63) - removed per-window ImGuiWindowFlags_ResizeFromAnySide beta flag in favor of a global io.OptResizeWindowsFromEdges to enable the feature.
- 2018/06/06 (1.62) - renamed GetGlyphRangesChinese() to GetGlyphRangesChineseFull() to distinguish other variants and discourage using the full set.
@@ -2907,7 +2908,7 @@
return g.DrawData.Valid ? &g.DrawData : NULL;
}
-float ImGui::GetTime()
+double ImGui::GetTime()
{
return GImGui->Time;
}
@@ -3667,7 +3668,7 @@
g.IO.MouseDoubleClicked[i] = false;
if (g.IO.MouseClicked[i])
{
- if (g.Time - g.IO.MouseClickedTime[i] < g.IO.MouseDoubleClickTime)
+ if ((float)(g.Time - g.IO.MouseClickedTime[i]) < g.IO.MouseDoubleClickTime)
{
ImVec2 delta_from_click_pos = IsMousePosValid(&g.IO.MousePos) ? (g.IO.MousePos - g.IO.MouseClickedPos[i]) : ImVec2(0.0f, 0.0f);
if (ImLengthSqr(delta_from_click_pos) < g.IO.MouseDoubleClickMaxDist * g.IO.MouseDoubleClickMaxDist)
@@ -3808,6 +3809,7 @@
g.TooltipOverrideCount = 0;
g.WindowsActiveCount = 0;
+ // Setup current font and draw list
SetCurrentFont(GetDefaultFont());
IM_ASSERT(g.Font->IsLoaded());
g.DrawListSharedData.ClipRectFullscreen = ImVec4(0.0f, 0.0f, g.IO.DisplaySize.x, g.IO.DisplaySize.y);
diff --git a/imgui.h b/imgui.h
index 6665025..f861fb3 100644
--- a/imgui.h
+++ b/imgui.h
@@ -525,7 +525,7 @@
IMGUI_API void SetItemAllowOverlap(); // allow last item to be overlapped by a subsequent item. sometimes useful with invisible buttons, selectables, etc. to catch unused area.
IMGUI_API bool IsRectVisible(const ImVec2& size); // test if rectangle (of given size, starting from cursor position) is visible / not clipped.
IMGUI_API bool IsRectVisible(const ImVec2& rect_min, const ImVec2& rect_max); // test if rectangle (in screen space) is visible / not clipped. to perform coarse clipping on user's side.
- IMGUI_API float GetTime();
+ IMGUI_API double GetTime();
IMGUI_API int GetFrameCount();
IMGUI_API ImDrawList* GetOverlayDrawList(); // this draw list will be the last rendered one, useful to quickly draw overlays shapes/text
IMGUI_API ImDrawListSharedData* GetDrawListSharedData(); // you may use this when creating your own ImDrawList instances
@@ -1162,7 +1162,7 @@
ImVec2 MousePosPrev; // Previous mouse position temporary storage (nb: not for public use, set to MousePos in NewFrame())
ImVec2 MouseClickedPos[5]; // Position at time of clicking
- float MouseClickedTime[5]; // Time of last click (used to figure out double-click)
+ double MouseClickedTime[5]; // Time of last click (used to figure out double-click)
bool MouseClicked[5]; // Mouse button went from !Down to Down
bool MouseDoubleClicked[5]; // Has mouse button been double-clicked?
bool MouseReleased[5]; // Mouse button went from Down to !Down
diff --git a/imgui_demo.cpp b/imgui_demo.cpp
index 5020e04..74b8843 100644
--- a/imgui_demo.cpp
+++ b/imgui_demo.cpp
@@ -819,7 +819,7 @@
// Tip: If your float aren't contiguous but part of a structure, you can pass a pointer to your first float and the sizeof() of your structure in the Stride parameter.
static float values[90] = { 0 };
static int values_offset = 0;
- static float refresh_time = 0.0f;
+ static double refresh_time = 0.0;
if (!animate || refresh_time == 0.0f)
refresh_time = ImGui::GetTime();
while (refresh_time < ImGui::GetTime()) // Create dummy data at fixed 60 hz rate for the demo
@@ -3020,8 +3020,8 @@
static ExampleAppLog log;
// Demo: add random items (unless Ctrl is held)
- static float last_time = -1.0f;
- float time = ImGui::GetTime();
+ static double last_time = -1.0;
+ double time = ImGui::GetTime();
if (time - last_time >= 0.20f && !ImGui::GetIO().KeyCtrl)
{
const char* random_words[] = { "system", "info", "warning", "error", "fatal", "notice", "log" };
diff --git a/imgui_internal.h b/imgui_internal.h
index 93ed9c9..b1e1302 100644
--- a/imgui_internal.h
+++ b/imgui_internal.h
@@ -616,7 +616,7 @@
float FontBaseSize; // (Shortcut) == IO.FontGlobalScale * Font->Scale * Font->FontSize. Base text height.
ImDrawListSharedData DrawListSharedData;
- float Time;
+ double Time;
int FrameCount;
int FrameCountEnded;
int FrameCountRendered;