From 47fd8431c10e94c2d7e6b34096f3b70a7333f464 Mon Sep 17 00:00:00 2001 From: Sepehr Taghdisian Date: Mon, 18 Aug 2014 13:19:35 +0430 Subject: [PATCH] minor fixes --- imgui.cpp | 20 ++++++++++---------- imgui.h | 5 +++++ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index a0f27d0cd..4806d853d 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -162,12 +162,12 @@ #include // intptr_t #include // vsnprintf #include // memset +#include // new (ptr) #ifdef _MSC_VER #pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen #endif -#include //------------------------------------------------------------------------- // Forward Declarations @@ -198,8 +198,8 @@ static ImGuiWindow* FindHoveredWindow(ImVec2 pos, bool excluding_childs); }; // namespace ImGui -static char* StrDup(const char *str); -static void StrDup_Free(char *str); +static char* ImStrDup(const char *str); +static void ImStrDup_Free(char *str); //----------------------------------------------------------------------------- // Platform dependant default implementations @@ -596,7 +596,7 @@ struct ImGuiIniData bool Collapsed; ImGuiIniData() { memset(this, 0, sizeof(*this)); } - ~ImGuiIniData() { if (Name) { StrDup_Free(Name); Name = NULL; } } + ~ImGuiIniData() { if (Name) { ImStrDup_Free(Name); Name = NULL; } } }; struct ImGuiState @@ -918,7 +918,7 @@ void ImGuiTextBuffer::append(const char* fmt, ...) ImGuiWindow::ImGuiWindow(const char* name, ImVec2 default_pos, ImVec2 default_size) { - Name = StrDup(name); + Name = ImStrDup(name); ID = GetID(name); IDStack.push_back(ID); @@ -953,7 +953,7 @@ ImGuiWindow::~ImGuiWindow() DrawList->~ImDrawList(); GImGui.IO.FreeFn(DrawList); DrawList = NULL; - StrDup_Free(Name); + ImStrDup_Free(Name); Name = NULL; } @@ -1036,7 +1036,7 @@ static ImGuiIniData* FindWindowSettings(const char* name) void *buff = GImGui.IO.MallocFn(sizeof(ImGuiIniData)); ImGuiIniData* ini = new(buff) ImGuiIniData(); - ini->Name = StrDup(name); + ini->Name = ImStrDup(name); ini->Collapsed = false; ini->Pos = ImVec2(FLT_MAX,FLT_MAX); ini->Size = ImVec2(0,0); @@ -5318,7 +5318,7 @@ static const char* GetClipboardTextFn_DefaultImpl() if (buf_handle == NULL) return NULL; if (char* buf_global = (char*)GlobalLock(buf_handle)) - buf_local = StrDup(buf_global); + buf_local = ImStrDup(buf_global); GlobalUnlock(buf_handle); CloseClipboard(); return buf_local; @@ -5855,7 +5855,7 @@ void ShowTestWindow(bool* open) }; // namespace ImGui -static char* StrDup(const char *str) +static char* ImStrDup(const char *str) { char *buff = (char*)GImGui.IO.MallocFn(strlen(str) + 1); IM_ASSERT(buff); @@ -5863,7 +5863,7 @@ static char* StrDup(const char *str) return buff; } -static void StrDup_Free(char *str) +static void ImStrDup_Free(char *str) { IM_ASSERT(str); GImGui.IO.FreeFn(str); diff --git a/imgui.h b/imgui.h index 892d822ed..7ed141494 100644 --- a/imgui.h +++ b/imgui.h @@ -25,6 +25,11 @@ struct ImGuiWindow; #define IM_ASSERT(_EXPR) assert(_EXPR) #endif +#ifndef IM_MALLOC +#define IM_MALLOC malloc +#endif + + typedef unsigned int ImU32; typedef ImU32 ImGuiID; typedef int ImGuiCol; // enum ImGuiCol_