From cf9b893841ba8e9e380332825605735423d3cab0 Mon Sep 17 00:00:00 2001 From: omar Date: Sat, 23 Dec 2017 13:40:01 +0100 Subject: [PATCH 01/11] Examples: Added null_example/ which is helpful for quick testing on multiple compilers/settings without relyong on graphics library. --- examples/null_example/build_win32.bat | 3 +++ examples/null_example/main.cpp | 33 +++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 examples/null_example/build_win32.bat create mode 100644 examples/null_example/main.cpp diff --git a/examples/null_example/build_win32.bat b/examples/null_example/build_win32.bat new file mode 100644 index 00000000..7bb78232 --- /dev/null +++ b/examples/null_example/build_win32.bat @@ -0,0 +1,3 @@ +@REM Build for Visual Studio compiler. Run your copy of vcvars32.bat or vcvarsall.bat to setup command-line compiler. +mkdir Debug +cl /nologo /Zi /MD /I ..\.. *.cpp ..\..\*.cpp /FeDebug/null_example.exe /FoDebug/ /link gdi32.lib shell32.lib diff --git a/examples/null_example/main.cpp b/examples/null_example/main.cpp new file mode 100644 index 00000000..b12f75c9 --- /dev/null +++ b/examples/null_example/main.cpp @@ -0,0 +1,33 @@ +// ImGui - null/dummy example application (compile and link imgui with no inputs, no outputs) +#include +#include + +int main(int, char**) +{ + ImGuiIO& io = ImGui::GetIO(); + + // Build atlas + unsigned char* tex_pixels = NULL; + int tex_w, tex_h; + io.Fonts->GetTexDataAsRGBA32(&tex_pixels, &tex_w, &tex_h); + + for (int n = 0; n < 50; n++) + { + printf("NewFrame() %d\n", n); + io.DisplaySize = ImVec2(1920, 1080); + io.DeltaTime = 1.0f / 60.0f; + ImGui::NewFrame(); + + static float f = 0.0f; + ImGui::Text("Hello, world!"); + ImGui::SliderFloat("float", &f, 0.0f, 1.0f); + ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate); + ImGui::ShowTestWindow(NULL); + + ImGui::Render(); + } + + printf("Shutdown()\n"); + ImGui::Shutdown(); + return 0; +} From 1f26652944d0a04dc9716578dcddef6ed3b67de1 Mon Sep 17 00:00:00 2001 From: omar Date: Sat, 23 Dec 2017 14:07:03 +0100 Subject: [PATCH 02/11] Various zealous warning fixes (thanks Clang). --- imgui.cpp | 9 ++++----- imgui.h | 2 +- imgui_draw.cpp | 5 ++--- imgui_internal.h | 2 +- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index dd580538..26c3b698 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -586,7 +586,6 @@ #include "imgui.h" #define IMGUI_DEFINE_MATH_OPERATORS -#define IMGUI_DEFINE_PLACEMENT_NEW #include "imgui_internal.h" #include // toupper, isprint @@ -3272,16 +3271,16 @@ void ImGui::RenderTriangle(ImVec2 p_min, ImGuiDir dir, float scale) switch (dir) { case ImGuiDir_Up: - r = -r; // ...fall through, no break! case ImGuiDir_Down: + if (dir == ImGuiDir_Up) r = -r; center.y -= r * 0.25f; a = ImVec2(0,1) * r; b = ImVec2(-0.866f,-0.5f) * r; c = ImVec2(+0.866f,-0.5f) * r; break; case ImGuiDir_Left: - r = -r; // ...fall through, no break! case ImGuiDir_Right: + if (dir == ImGuiDir_Left) r = -r; center.x -= r * 0.25f; a = ImVec2(1,0) * r; b = ImVec2(-0.500f,+0.866f) * r; @@ -10254,7 +10253,7 @@ static void RenderArrow(ImDrawList* draw_list, ImVec2 pos, ImVec2 half_sz, ImGui case ImGuiDir_Right: draw_list->AddTriangleFilled(ImVec2(pos.x - half_sz.x, pos.y + half_sz.y), ImVec2(pos.x - half_sz.x, pos.y - half_sz.y), pos, col); return; case ImGuiDir_Up: draw_list->AddTriangleFilled(ImVec2(pos.x + half_sz.x, pos.y + half_sz.y), ImVec2(pos.x - half_sz.x, pos.y + half_sz.y), pos, col); return; case ImGuiDir_Down: draw_list->AddTriangleFilled(ImVec2(pos.x - half_sz.x, pos.y - half_sz.y), ImVec2(pos.x + half_sz.x, pos.y - half_sz.y), pos, col); return; - default: return; // Fix warning for ImGuiDir_None + default: break; // Fix warning for ImGuiDir_None } } @@ -11491,7 +11490,7 @@ void ImGui::EndDragDropTarget() #if defined(_WIN32) && !defined(_WINDOWS_) && (!defined(IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS) || !defined(IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS)) #undef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN -#include +#include #endif // Win32 API clipboard implementation diff --git a/imgui.h b/imgui.h index c313080a..11213d69 100644 --- a/imgui.h +++ b/imgui.h @@ -622,7 +622,7 @@ enum ImGuiFocusedFlags_ { ImGuiFocusedFlags_ChildWindows = 1 << 0, // IsWindowFocused(): Return true if any children of the window is focused ImGuiFocusedFlags_RootWindow = 1 << 1, // IsWindowFocused(): Test from root window (top most parent of the current hierarchy) - ImGuiFocusedFlags_RootAndChildWindows = ImGuiFocusedFlags_RootWindow | ImGuiFocusedFlags_ChildWindows, + ImGuiFocusedFlags_RootAndChildWindows = ImGuiFocusedFlags_RootWindow | ImGuiFocusedFlags_ChildWindows }; // Flags for ImGui::IsItemHovered(), ImGui::IsWindowHovered() diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 2ce3c0bd..48500c7c 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -15,7 +15,6 @@ #include "imgui.h" #define IMGUI_DEFINE_MATH_OPERATORS -#define IMGUI_DEFINE_PLACEMENT_NEW #include "imgui_internal.h" #include // vsnprintf, sscanf, printf @@ -1254,8 +1253,8 @@ void ImGui::ShadeVertsLinearUV(ImDrawVert* vert_start, ImDrawVert* vert_end, con const ImVec2 size = b - a; const ImVec2 uv_size = uv_b - uv_a; const ImVec2 scale = ImVec2( - size.x ? (uv_size.x / size.x) : 0.0f, - size.y ? (uv_size.y / size.y) : 0.0f); + size.x != 0.0f ? (uv_size.x / size.x) : 0.0f, + size.y != 0.0f ? (uv_size.y / size.y) : 0.0f); if (clamp) { diff --git a/imgui_internal.h b/imgui_internal.h index 060b2004..1e0f8ae1 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -230,7 +230,7 @@ enum ImGuiAxis { ImGuiAxis_None = -1, ImGuiAxis_X = 0, - ImGuiAxis_Y = 1, + ImGuiAxis_Y = 1 }; enum ImGuiPlotType From b263bc568931b7065926a06e6a293fc05279c6e5 Mon Sep 17 00:00:00 2001 From: omar Date: Sat, 23 Dec 2017 14:07:27 +0100 Subject: [PATCH 03/11] Examples: DirectX: Using IM_ARRAYSIZE() --- examples/directx10_example/imgui_impl_dx10.cpp | 2 +- examples/directx11_example/imgui_impl_dx11.cpp | 2 +- examples/directx9_example/imgui_impl_dx9.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/directx10_example/imgui_impl_dx10.cpp b/examples/directx10_example/imgui_impl_dx10.cpp index 4670f053..59152673 100644 --- a/examples/directx10_example/imgui_impl_dx10.cpp +++ b/examples/directx10_example/imgui_impl_dx10.cpp @@ -228,7 +228,7 @@ void ImGui_ImplDX10_RenderDrawLists(ImDrawData* draw_data) static bool IsAnyMouseButtonDown() { ImGuiIO& io = ImGui::GetIO(); - for (int n = 0; n < ARRAYSIZE(io.MouseDown); n++) + for (int n = 0; n < IM_ARRAYSIZE(io.MouseDown); n++) if (io.MouseDown[n]) return true; return false; diff --git a/examples/directx11_example/imgui_impl_dx11.cpp b/examples/directx11_example/imgui_impl_dx11.cpp index df02577b..af6e54f4 100644 --- a/examples/directx11_example/imgui_impl_dx11.cpp +++ b/examples/directx11_example/imgui_impl_dx11.cpp @@ -235,7 +235,7 @@ void ImGui_ImplDX11_RenderDrawLists(ImDrawData* draw_data) static bool IsAnyMouseButtonDown() { ImGuiIO& io = ImGui::GetIO(); - for (int n = 0; n < ARRAYSIZE(io.MouseDown); n++) + for (int n = 0; n < IM_ARRAYSIZE(io.MouseDown); n++) if (io.MouseDown[n]) return true; return false; diff --git a/examples/directx9_example/imgui_impl_dx9.cpp b/examples/directx9_example/imgui_impl_dx9.cpp index 24f53ba3..484e84cd 100644 --- a/examples/directx9_example/imgui_impl_dx9.cpp +++ b/examples/directx9_example/imgui_impl_dx9.cpp @@ -174,7 +174,7 @@ void ImGui_ImplDX9_RenderDrawLists(ImDrawData* draw_data) static bool IsAnyMouseButtonDown() { ImGuiIO& io = ImGui::GetIO(); - for (int n = 0; n < ARRAYSIZE(io.MouseDown); n++) + for (int n = 0; n < IM_ARRAYSIZE(io.MouseDown); n++) if (io.MouseDown[n]) return true; return false; From 6172e932728a0fa629d910c1a1534d66a59e386a Mon Sep 17 00:00:00 2001 From: omar Date: Sat, 23 Dec 2017 14:49:23 +0100 Subject: [PATCH 04/11] ImVector: Added assignments and = operators + comments. --- imgui.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/imgui.h b/imgui.h index 11213d69..25c8721a 100644 --- a/imgui.h +++ b/imgui.h @@ -1005,7 +1005,7 @@ namespace ImGui //----------------------------------------------------------------------------- // Lightweight std::vector<> like class to avoid dragging dependencies (also: windows implementation of STL with debug enabled is absurdly slow, so let's bypass it so our code runs fast in debug). -// Our implementation does NOT call c++ constructors because we don't use them in ImGui. Don't use this class as a straight std::vector replacement in your code! +// Our implementation does NOT call C++ constructors/destructors. This is intentional and we do not require it. Do not use this class as a straight std::vector replacement in your code! template class ImVector { @@ -1020,6 +1020,8 @@ public: ImVector() { Size = Capacity = 0; Data = NULL; } ~ImVector() { if (Data) ImGui::MemFree(Data); } + ImVector(const ImVector& rhs) { Size = Capacity = 0; Data = NULL; if (rhs.Size) { resize(rhs.Size); memcpy(Data, rhs.Data, (size_t)rhs.Size * sizeof(T)); } } + ImVector& operator=(const ImVector& rhs) { resize(rhs.Size); if (rhs.Size) memcpy(Data, rhs.Data, (size_t)rhs.Size * sizeof(T)); return *this; } inline bool empty() const { return Size == 0; } inline int size() const { return Size; } From 8e8b5498f74715cf2caa2feaf28657c438ff7b36 Mon Sep 17 00:00:00 2001 From: omar Date: Sat, 23 Dec 2017 14:51:28 +0100 Subject: [PATCH 05/11] ImVector: insert() uses grow_capacity() - had inconsistent resize policy --- imgui.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui.h b/imgui.h index 25c8721a..35bfb60e 100644 --- a/imgui.h +++ b/imgui.h @@ -1061,7 +1061,7 @@ public: inline void push_front(const value_type& v) { if (Size == 0) push_back(v); else insert(Data, v); } inline iterator erase(const_iterator it) { IM_ASSERT(it >= Data && it < Data+Size); const ptrdiff_t off = it - Data; memmove(Data + off, Data + off + 1, ((size_t)Size - (size_t)off - 1) * sizeof(value_type)); Size--; return Data + off; } - inline iterator insert(const_iterator it, const value_type& v) { IM_ASSERT(it >= Data && it <= Data+Size); const ptrdiff_t off = it - Data; if (Size == Capacity) reserve(Capacity ? Capacity * 2 : 4); if (off < (int)Size) memmove(Data + off + 1, Data + off, ((size_t)Size - (size_t)off) * sizeof(value_type)); Data[off] = v; Size++; return Data + off; } + inline iterator insert(const_iterator it, const value_type& v) { IM_ASSERT(it >= Data && it <= Data+Size); const ptrdiff_t off = it - Data; if (Size == Capacity) reserve(_grow_capacity(Size + 1)); if (off < (int)Size) memmove(Data + off + 1, Data + off, ((size_t)Size - (size_t)off) * sizeof(value_type)); Data[off] = v; Size++; return Data + off; } inline bool contains(const value_type& v) const { const T* data = Data; const T* data_end = Data + Size; while (data < data_end) if (*data++ == v) return true; return false; } }; From 69879dd4f3e25c2d64dff233ef4bda32e6514237 Mon Sep 17 00:00:00 2001 From: omar Date: Sat, 23 Dec 2017 14:51:36 +0100 Subject: [PATCH 06/11] ImVector: Spacing. --- imgui.h | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/imgui.h b/imgui.h index 35bfb60e..a644337d 100644 --- a/imgui.h +++ b/imgui.h @@ -1018,10 +1018,10 @@ public: typedef value_type* iterator; typedef const value_type* const_iterator; - ImVector() { Size = Capacity = 0; Data = NULL; } - ~ImVector() { if (Data) ImGui::MemFree(Data); } - ImVector(const ImVector& rhs) { Size = Capacity = 0; Data = NULL; if (rhs.Size) { resize(rhs.Size); memcpy(Data, rhs.Data, (size_t)rhs.Size * sizeof(T)); } } - ImVector& operator=(const ImVector& rhs) { resize(rhs.Size); if (rhs.Size) memcpy(Data, rhs.Data, (size_t)rhs.Size * sizeof(T)); return *this; } + inline ImVector() { Size = Capacity = 0; Data = NULL; } + inline ~ImVector() { if (Data) ImGui::MemFree(Data); } + inline ImVector(const ImVector& rhs) { Size = Capacity = 0; Data = NULL; if (rhs.Size) { resize(rhs.Size); memcpy(Data, rhs.Data, (size_t)rhs.Size * sizeof(T)); } } + inline ImVector& operator=(const ImVector& rhs) { resize(rhs.Size); if (rhs.Size) memcpy(Data, rhs.Data, (size_t)rhs.Size * sizeof(T)); return *this; } inline bool empty() const { return Size == 0; } inline int size() const { return Size; } @@ -1037,8 +1037,8 @@ public: inline const_iterator end() const { return Data + Size; } inline value_type& front() { IM_ASSERT(Size > 0); return Data[0]; } inline const value_type& front() const { IM_ASSERT(Size > 0); return Data[0]; } - inline value_type& back() { IM_ASSERT(Size > 0); return Data[Size-1]; } - inline const value_type& back() const { IM_ASSERT(Size > 0); return Data[Size-1]; } + inline value_type& back() { IM_ASSERT(Size > 0); return Data[Size - 1]; } + inline const value_type& back() const { IM_ASSERT(Size > 0); return Data[Size - 1]; } inline void swap(ImVector& rhs) { int rhs_size = rhs.Size; rhs.Size = Size; Size = rhs_size; int rhs_cap = rhs.Capacity; rhs.Capacity = Capacity; Capacity = rhs_cap; value_type* rhs_data = rhs.Data; rhs.Data = Data; Data = rhs_data; } inline int _grow_capacity(int size) const { int new_capacity = Capacity ? (Capacity + Capacity/2) : 8; return new_capacity > size ? new_capacity : size; } @@ -1047,7 +1047,8 @@ public: inline void resize(int new_size, const T& v){ if (new_size > Capacity) reserve(_grow_capacity(new_size)); if (new_size > Size) for (int n = Size; n < new_size; n++) Data[n] = v; Size = new_size; } inline void reserve(int new_capacity) { - if (new_capacity <= Capacity) return; + if (new_capacity <= Capacity) + return; T* new_data = (value_type*)ImGui::MemAlloc((size_t)new_capacity * sizeof(T)); if (Data) memcpy(new_data, Data, (size_t)Size * sizeof(T)); @@ -1056,7 +1057,7 @@ public: Capacity = new_capacity; } - inline void push_back(const value_type& v) { if (Size == Capacity) reserve(_grow_capacity(Size+1)); Data[Size++] = v; } + inline void push_back(const value_type& v) { if (Size == Capacity) reserve(_grow_capacity(Size + 1)); Data[Size++] = v; } inline void pop_back() { IM_ASSERT(Size > 0); Size--; } inline void push_front(const value_type& v) { if (Size == 0) push_back(v); else insert(Data, v); } From 53b24ff79afd2b39d67580c77a68fb7a004def66 Mon Sep 17 00:00:00 2001 From: omar Date: Sat, 23 Dec 2017 15:02:36 +0100 Subject: [PATCH 07/11] Removed reliance on ImU64 type for the ImDrawList assert. (#1184) --- imgui.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 26c3b698..147db31d 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2846,15 +2846,17 @@ static void AddDrawListToRenderList(ImVector& out_render_list, ImDr IM_ASSERT(draw_list->IdxBuffer.Size == 0 || draw_list->_IdxWritePtr == draw_list->IdxBuffer.Data + draw_list->IdxBuffer.Size); IM_ASSERT((int)draw_list->_VtxCurrentIdx == draw_list->VtxBuffer.Size); - // Check that draw_list doesn't use more vertices than indexable in a single draw call (default ImDrawIdx = unsigned short = 2 bytes = 64K vertices per window) - // If this assert triggers because you are drawing lots of stuff manually, you can: - // A) Add '#define ImDrawIdx unsigned int' in imconfig.h to set the index size to 4 bytes. You'll need to handle the 4-bytes indices to your renderer. - // For example, the OpenGL example code detect index size at compile-time by doing: - // 'glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer_offset);' + // Check that draw_list doesn't use more vertices than indexable in a single draw call (default ImDrawIdx = unsigned short = 2 bytes = 64K vertices per ImDrawList = per window) + // If this assert triggers because you are drawing lots of stuff manually: + // A) Make sure you are coarse clipping, because ImDrawList let all your vertices pass. You can use thre Metrics window to inspect draw list contents. + // B) If you need/want meshes with more than 64K vertices, uncomment the '#define ImDrawIdx unsigned int' line in imconfig.h to set the index size to 4 bytes. + // You'll need to handle the 4-bytes indices to your renderer. For example, the OpenGL example code detect index size at compile-time by doing: + // glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer_offset); // Your own engine or render API may use different parameters or function calls to specify index sizes. 2 and 4 bytes indices are generally supported by most API. - // B) If for some reason you cannot use 4 bytes indices or don't want to, a workaround is to call BeginChild()/EndChild() before reaching the 64K limit to split your draw commands in multiple draw lists. - IM_ASSERT(((ImU64)draw_list->_VtxCurrentIdx >> (sizeof(ImDrawIdx)*8)) == 0); // Too many vertices in same ImDrawList. See comment above. - + // C) If for some reason you cannot use 4 bytes indices or don't want to, a workaround is to call BeginChild()/EndChild() before reaching the 64K limit to split your draw commands in multiple draw lists. + if (sizeof(ImDrawIdx) == 2) + IM_ASSERT(draw_list->_VtxCurrentIdx < (1 << 16) && "Too many vertices in ImDrawList using 16-bit indices. Read comment above"); + out_render_list.push_back(draw_list); GImGui->IO.MetricsRenderVertices += draw_list->VtxBuffer.Size; GImGui->IO.MetricsRenderIndices += draw_list->IdxBuffer.Size; From 983d8f5f8ea6c8deac1f8f60389d4b1c8549e9c7 Mon Sep 17 00:00:00 2001 From: omar Date: Sat, 23 Dec 2017 15:15:27 +0100 Subject: [PATCH 08/11] Various zealous warning fixes (Clang). --- imgui.cpp | 5 +++-- imgui_demo.cpp | 3 ++- imgui_draw.cpp | 2 ++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 147db31d..649d2e76 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3288,7 +3288,8 @@ void ImGui::RenderTriangle(ImVec2 p_min, ImGuiDir dir, float scale) b = ImVec2(-0.500f,+0.866f) * r; c = ImVec2(-0.500f,-0.866f) * r; break; - default: + case ImGuiDir_None: + case ImGuiDir_Count_: IM_ASSERT(0); break; } @@ -10255,7 +10256,7 @@ static void RenderArrow(ImDrawList* draw_list, ImVec2 pos, ImVec2 half_sz, ImGui case ImGuiDir_Right: draw_list->AddTriangleFilled(ImVec2(pos.x - half_sz.x, pos.y + half_sz.y), ImVec2(pos.x - half_sz.x, pos.y - half_sz.y), pos, col); return; case ImGuiDir_Up: draw_list->AddTriangleFilled(ImVec2(pos.x + half_sz.x, pos.y + half_sz.y), ImVec2(pos.x - half_sz.x, pos.y + half_sz.y), pos, col); return; case ImGuiDir_Down: draw_list->AddTriangleFilled(ImVec2(pos.x - half_sz.x, pos.y - half_sz.y), ImVec2(pos.x + half_sz.x, pos.y - half_sz.y), pos, col); return; - default: break; // Fix warning for ImGuiDir_None + case ImGuiDir_None: case ImGuiDir_Count_: break; // Fix warnings } } diff --git a/imgui_demo.cpp b/imgui_demo.cpp index fb0cff59..0624bdd3 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -1304,7 +1304,8 @@ void ImGui::ShowTestWindow(bool* p_open) if (n > 0) ImGui::SameLine(); ImGui::PushID(n + line * 1000); char num_buf[16]; - const char* label = (!(n%15)) ? "FizzBuzz" : (!(n%3)) ? "Fizz" : (!(n%5)) ? "Buzz" : (sprintf(num_buf, "%d", n), num_buf); + sprintf(num_buf, "%d", n); + const char* label = (!(n%15)) ? "FizzBuzz" : (!(n%3)) ? "Fizz" : (!(n%5)) ? "Buzz" : num_buf; float hue = n*0.05f; ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor::HSV(hue, 0.6f, 0.6f)); ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::HSV(hue, 0.7f, 0.7f)); diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 48500c7c..02cf42cc 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -42,6 +42,7 @@ #pragma clang diagnostic ignored "-Wfloat-equal" // warning : comparing floating point with == or != is unsafe // storing and comparing against same constants ok. #pragma clang diagnostic ignored "-Wglobal-constructors" // warning : declaration requires a global destructor // similar to above, not sure what the exact difference it. #pragma clang diagnostic ignored "-Wsign-conversion" // warning : implicit conversion changes signedness // +#pragma clang diagnostic ignored "-Wcomma" // warning : possible misuse of comma operator here // #if __has_warning("-Wreserved-id-macro") #pragma clang diagnostic ignored "-Wreserved-id-macro" // warning : macro name is a reserved identifier // #endif @@ -77,6 +78,7 @@ namespace IMGUI_STB_NAMESPACE #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunused-function" #pragma clang diagnostic ignored "-Wmissing-prototypes" +#pragma clang diagnostic ignored "-Wimplicit-fallthrough" #endif #ifdef __GNUC__ From a5739a0aa30f35271213157b994a0fcb0cd773b9 Mon Sep 17 00:00:00 2001 From: omar Date: Sat, 23 Dec 2017 15:19:48 +0100 Subject: [PATCH 09/11] Fixed warning with Clang+MSVC using __int64 to define the helper ImU64 type (#1184) --- imgui.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui.h b/imgui.h index a644337d..de9177c9 100644 --- a/imgui.h +++ b/imgui.h @@ -92,7 +92,7 @@ typedef int ImGuiTreeNodeFlags; // flags: for TreeNode*(),CollapsingHeader() typedef int ImGuiWindowFlags; // flags: for Begin*() // enum ImGuiWindowFlags_ typedef int (*ImGuiTextEditCallback)(ImGuiTextEditCallbackData *data); typedef void (*ImGuiSizeConstraintCallback)(ImGuiSizeConstraintCallbackData* data); -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(__clang__) typedef unsigned __int64 ImU64; // 64-bit unsigned integer #else typedef unsigned long long ImU64; // 64-bit unsigned integer From 9cda86d55a80c9f032af84f657b9fe8e6c7f3f52 Mon Sep 17 00:00:00 2001 From: omar Date: Sat, 23 Dec 2017 16:24:33 +0100 Subject: [PATCH 10/11] Internals: Added IM_NEW, IM_DELETE helper macros (#1517, #484, #504) --- imgui.cpp | 28 ++++++++-------------------- imgui_draw.cpp | 8 +------- imgui_internal.h | 12 ++++++++---- 3 files changed, 17 insertions(+), 31 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 649d2e76..6173f712 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1859,8 +1859,7 @@ ImGuiWindow::ImGuiWindow(ImGuiContext* context, const char* name) ItemWidthDefault = 0.0f; FontWindowScale = 1.0f; - DrawList = (ImDrawList*)ImGui::MemAlloc(sizeof(ImDrawList)); - IM_PLACEMENT_NEW(DrawList) ImDrawList(&context->DrawListSharedData); + DrawList = IM_NEW(ImDrawList)(&context->DrawListSharedData); DrawList->_OwnerName = Name; ParentWindow = NULL; RootWindow = NULL; @@ -1873,11 +1872,8 @@ ImGuiWindow::ImGuiWindow(ImGuiContext* context, const char* name) ImGuiWindow::~ImGuiWindow() { - DrawList->~ImDrawList(); - ImGui::MemFree(DrawList); - DrawList = NULL; - ImGui::MemFree(Name); - Name = NULL; + IM_DELETE(DrawList); + IM_DELETE(Name); } ImGuiID ImGuiWindow::GetID(const char* str, const char* str_end) @@ -2579,8 +2575,7 @@ static void SettingsHandlerWindow_WriteAll(ImGuiContext& g, ImGuiTextBuffer* buf void ImGui::Initialize() { ImGuiContext& g = *GImGui; - g.LogClipboard = (ImGuiTextBuffer*)ImGui::MemAlloc(sizeof(ImGuiTextBuffer)); - IM_PLACEMENT_NEW(g.LogClipboard) ImGuiTextBuffer(); + g.LogClipboard = IM_NEW(ImGuiTextBuffer)(); // Add .ini handle for ImGuiWindow type ImGuiSettingsHandler ini_handler; @@ -2613,10 +2608,7 @@ void ImGui::Shutdown() SaveIniSettingsToDisk(g.IO.IniFilename); for (int i = 0; i < g.Windows.Size; i++) - { - g.Windows[i]->~ImGuiWindow(); - ImGui::MemFree(g.Windows[i]); - } + IM_DELETE(g.Windows[i]); g.Windows.clear(); g.WindowsSortBuffer.clear(); g.CurrentWindow = NULL; @@ -2628,7 +2620,7 @@ void ImGui::Shutdown() g.ActiveIdWindow = NULL; g.MovingWindow = NULL; for (int i = 0; i < g.SettingsWindows.Size; i++) - ImGui::MemFree(g.SettingsWindows[i].Name); + IM_DELETE(g.SettingsWindows[i].Name); g.ColorModifiers.clear(); g.StyleModifiers.clear(); g.FontStack.clear(); @@ -2653,10 +2645,7 @@ void ImGui::Shutdown() g.LogFile = NULL; } if (g.LogClipboard) - { - g.LogClipboard->~ImGuiTextBuffer(); - ImGui::MemFree(g.LogClipboard); - } + IM_DELETE(g.LogClipboard); g.Initialized = false; } @@ -4157,8 +4146,7 @@ static ImGuiWindow* CreateNewWindow(const char* name, ImVec2 size, ImGuiWindowFl ImGuiContext& g = *GImGui; // Create window the first time - ImGuiWindow* window = (ImGuiWindow*)ImGui::MemAlloc(sizeof(ImGuiWindow)); - IM_PLACEMENT_NEW(window) ImGuiWindow(&g, name); + ImGuiWindow* window = IM_NEW(ImGuiWindow)(&g, name); window->Flags = flags; g.WindowsById.SetVoidPtr(window->ID, window); diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 02cf42cc..793aeffb 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1461,15 +1461,9 @@ ImFont* ImFontAtlas::AddFont(const ImFontConfig* font_cfg) // Create new font if (!font_cfg->MergeMode) - { - ImFont* font = (ImFont*)ImGui::MemAlloc(sizeof(ImFont)); - IM_PLACEMENT_NEW(font) ImFont(); - Fonts.push_back(font); - } + Fonts.push_back(IM_NEW(ImFont)); else - { IM_ASSERT(!Fonts.empty()); // When using MergeMode make sure that a font has already been added before. You can use ImGui::GetIO().Fonts->AddFontDefault() to add the default imgui font. - } ConfigData.push_back(*font_cfg); ImFontConfig& new_font_cfg = ConfigData.back(); diff --git a/imgui_internal.h b/imgui_internal.h index 1e0f8ae1..c08f5082 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -160,10 +160,14 @@ static inline ImVec2 ImMul(const ImVec2& lhs, const ImVec2& rhs) // We call C++ constructor on own allocated memory via the placement "new(ptr) Type()" syntax. // Defining a custom placement new() with a dummy parameter allows us to bypass including which on some platforms complains when user has disabled exceptions. -struct ImPlacementNewDummy {}; -inline void* operator new(size_t, ImPlacementNewDummy, void* ptr) { return ptr; } -inline void operator delete(void*, ImPlacementNewDummy, void*) {} -#define IM_PLACEMENT_NEW(_PTR) new(ImPlacementNewDummy(), _PTR) +struct ImNewAllocDummy {}; +struct ImNewPlacementDummy {}; +inline void* operator new(size_t, ImNewPlacementDummy, void* ptr) { return ptr; } +inline void operator delete(void*, ImNewPlacementDummy, void*) {} // This is only required so we can use the symetrical new() +inline void operator delete(void* p, ImNewAllocDummy) { ImGui::MemFree(p); } +#define IM_PLACEMENT_NEW(_PTR) new(ImNewPlacementDummy(), _PTR) +#define IM_NEW(_TYPE) new(ImNewPlacementDummy(), ImGui::MemAlloc(sizeof(_TYPE))) _TYPE +#define IM_DELETE(_PTR) delete(ImNewAllocDummy(), _PTR), _PTR = NULL //----------------------------------------------------------------------------- // Types From d976e4ea23d389a757800cef79261ad3296fb2c5 Mon Sep 17 00:00:00 2001 From: omar Date: Sat, 23 Dec 2017 16:27:16 +0100 Subject: [PATCH 11/11] Internals: Missing IM_DELETE usage (#1517) --- imgui_draw.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 793aeffb..2ffdf4be 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1403,10 +1403,7 @@ void ImFontAtlas::ClearTexData() void ImFontAtlas::ClearFonts() { for (int i = 0; i < Fonts.Size; i++) - { - Fonts[i]->~ImFont(); - ImGui::MemFree(Fonts[i]); - } + IM_DELETE(Fonts[i]); Fonts.clear(); }