|
@@ -188,11 +188,13 @@
|
|
|
#include <stdint.h> // intptr_t
|
|
|
#include <stdio.h> // vsnprintf
|
|
|
#include <string.h> // memset
|
|
|
+#include <new> // new (ptr)
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
#pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen
|
|
|
#endif
|
|
|
|
|
|
+
|
|
|
//-------------------------------------------------------------------------
|
|
|
// Forward Declarations
|
|
|
//-------------------------------------------------------------------------
|
|
@@ -373,6 +375,14 @@ static int ImStricmp(const char* str1, const char* str2)
|
|
|
return d;
|
|
|
}
|
|
|
|
|
|
+static char* ImStrdup(const char *str)
|
|
|
+{
|
|
|
+ char *buff = (char*)IM_MALLOC(strlen(str) + 1);
|
|
|
+ IM_ASSERT(buff);
|
|
|
+ strcpy(buff, str);
|
|
|
+ return buff;
|
|
|
+}
|
|
|
+
|
|
|
static const char* ImStristr(const char* haystack, const char* needle, const char* needle_end)
|
|
|
{
|
|
|
if (!needle_end)
|
|
@@ -615,7 +625,7 @@ struct ImGuiIniData
|
|
|
bool Collapsed;
|
|
|
|
|
|
ImGuiIniData() { memset(this, 0, sizeof(*this)); }
|
|
|
- ~ImGuiIniData() { if (Name) { free(Name); Name = NULL; } }
|
|
|
+ ~ImGuiIniData() { if (Name) { IM_FREE(Name); Name = NULL; } }
|
|
|
};
|
|
|
|
|
|
struct ImGuiState
|
|
@@ -656,7 +666,7 @@ struct ImGuiState
|
|
|
// Logging
|
|
|
bool LogEnabled;
|
|
|
FILE* LogFile;
|
|
|
- ImGuiTextBuffer LogClipboard;
|
|
|
+ ImGuiTextBuffer* LogClipboard;
|
|
|
int LogAutoExpandMaxDepth;
|
|
|
|
|
|
ImGuiState()
|
|
@@ -679,6 +689,7 @@ struct ImGuiState
|
|
|
LogEnabled = false;
|
|
|
LogFile = NULL;
|
|
|
LogAutoExpandMaxDepth = 2;
|
|
|
+ LogClipboard = NULL;
|
|
|
}
|
|
|
};
|
|
|
|
|
@@ -944,7 +955,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);
|
|
|
|
|
@@ -971,14 +982,16 @@ ImGuiWindow::ImGuiWindow(const char* name, ImVec2 default_pos, ImVec2 default_si
|
|
|
FocusIdxRequestCurrent = IM_INT_MAX;
|
|
|
FocusIdxRequestNext = IM_INT_MAX;
|
|
|
|
|
|
- DrawList = new ImDrawList();
|
|
|
+ DrawList = (ImDrawList*)IM_MALLOC(sizeof(ImDrawList));
|
|
|
+ new(DrawList) ImDrawList();
|
|
|
}
|
|
|
|
|
|
ImGuiWindow::~ImGuiWindow()
|
|
|
{
|
|
|
- delete DrawList;
|
|
|
+ DrawList->~ImDrawList();
|
|
|
+ IM_FREE(DrawList);
|
|
|
DrawList = NULL;
|
|
|
- free(Name);
|
|
|
+ IM_FREE(Name);
|
|
|
Name = NULL;
|
|
|
}
|
|
|
|
|
@@ -1058,8 +1071,9 @@ static ImGuiIniData* FindWindowSettings(const char* name)
|
|
|
if (ImStricmp(ini->Name, name) == 0)
|
|
|
return ini;
|
|
|
}
|
|
|
- ImGuiIniData* ini = new ImGuiIniData();
|
|
|
- ini->Name = strdup(name);
|
|
|
+ ImGuiIniData* ini = (ImGuiIniData*)IM_MALLOC(sizeof(ImGuiIniData));
|
|
|
+ new(ini) ImGuiIniData();
|
|
|
+ ini->Name = ImStrdup(name);
|
|
|
ini->Collapsed = false;
|
|
|
ini->Pos = ImVec2(FLT_MAX,FLT_MAX);
|
|
|
ini->Size = ImVec2(0,0);
|
|
@@ -1097,12 +1111,12 @@ static void LoadSettings()
|
|
|
fclose(f);
|
|
|
return;
|
|
|
}
|
|
|
- char* f_data = new char[f_size+1];
|
|
|
+ char* f_data = (char*)IM_MALLOC(f_size+1);
|
|
|
f_size = fread(f_data, 1, f_size, f); // Text conversion alter read size so let's not be fussy about return value
|
|
|
fclose(f);
|
|
|
if (f_size == 0)
|
|
|
{
|
|
|
- delete[] f_data;
|
|
|
+ IM_FREE(f_data);
|
|
|
return;
|
|
|
}
|
|
|
f_data[f_size] = 0;
|
|
@@ -1136,7 +1150,7 @@ static void LoadSettings()
|
|
|
line_start = line_end+1;
|
|
|
}
|
|
|
|
|
|
- delete[] f_data;
|
|
|
+ IM_FREE(f_data);
|
|
|
}
|
|
|
|
|
|
static void SaveSettings()
|
|
@@ -1208,6 +1222,9 @@ void NewFrame()
|
|
|
if (!g.Initialized)
|
|
|
{
|
|
|
// Initialize on first frame
|
|
|
+ g.LogClipboard = (ImGuiTextBuffer*)IM_MALLOC(sizeof(ImGuiTextBuffer));
|
|
|
+ new(g.LogClipboard) ImGuiTextBuffer();
|
|
|
+
|
|
|
IM_ASSERT(g.Settings.empty());
|
|
|
LoadSettings();
|
|
|
if (!g.IO.Font)
|
|
@@ -1216,7 +1233,8 @@ void NewFrame()
|
|
|
const void* fnt_data;
|
|
|
unsigned int fnt_size;
|
|
|
ImGui::GetDefaultFontData(&fnt_data, &fnt_size, NULL, NULL);
|
|
|
- g.IO.Font = new ImBitmapFont();
|
|
|
+ g.IO.Font = (ImBitmapFont*)IM_MALLOC(sizeof(ImBitmapFont));
|
|
|
+ new(g.IO.Font) ImBitmapFont();
|
|
|
g.IO.Font->LoadFromMemory(fnt_data, fnt_size);
|
|
|
g.IO.FontYOffset = +1;
|
|
|
}
|
|
@@ -1343,14 +1361,21 @@ void Shutdown()
|
|
|
SaveSettings();
|
|
|
|
|
|
for (size_t i = 0; i < g.Windows.size(); i++)
|
|
|
- delete g.Windows[i];
|
|
|
+ {
|
|
|
+ g.Windows[i]->~ImGuiWindow();
|
|
|
+ IM_FREE(g.Windows[i]);
|
|
|
+ }
|
|
|
g.Windows.clear();
|
|
|
g.CurrentWindowStack.clear();
|
|
|
+ g.RenderDrawLists.clear();
|
|
|
g.FocusedWindow = NULL;
|
|
|
g.HoveredWindow = NULL;
|
|
|
g.HoveredWindowExcludingChilds = NULL;
|
|
|
for (size_t i = 0; i < g.Settings.size(); i++)
|
|
|
- delete g.Settings[i];
|
|
|
+ {
|
|
|
+ g.Settings[i]->~ImGuiIniData();
|
|
|
+ IM_FREE(g.Settings[i]);
|
|
|
+ }
|
|
|
g.Settings.clear();
|
|
|
g.ColorEditModeStorage.Clear();
|
|
|
if (g.LogFile && g.LogFile != stdout)
|
|
@@ -1360,16 +1385,23 @@ void Shutdown()
|
|
|
}
|
|
|
if (g.IO.Font)
|
|
|
{
|
|
|
- delete g.IO.Font;
|
|
|
+ g.IO.Font->~ImBitmapFont();
|
|
|
+ IM_FREE(g.IO.Font);
|
|
|
g.IO.Font = NULL;
|
|
|
}
|
|
|
|
|
|
if (g.PrivateClipboard)
|
|
|
{
|
|
|
- free(g.PrivateClipboard);
|
|
|
+ IM_FREE(g.PrivateClipboard);
|
|
|
g.PrivateClipboard = NULL;
|
|
|
}
|
|
|
|
|
|
+ if (g.LogClipboard)
|
|
|
+ {
|
|
|
+ g.LogClipboard->~ImGuiTextBuffer();
|
|
|
+ IM_FREE(g.LogClipboard);
|
|
|
+ }
|
|
|
+
|
|
|
g.Initialized = false;
|
|
|
}
|
|
|
|
|
@@ -1534,9 +1566,9 @@ static void LogText(const ImVec2& ref_pos, const char* text, const char* text_en
|
|
|
else
|
|
|
{
|
|
|
if (log_new_line || !is_first_line)
|
|
|
- g.LogClipboard.append("\n%*s%.*s", tree_depth*4, "", char_count, text_remaining);
|
|
|
+ g.LogClipboard->append("\n%*s%.*s", tree_depth*4, "", char_count, text_remaining);
|
|
|
else
|
|
|
- g.LogClipboard.append(" %.*s", char_count, text_remaining);
|
|
|
+ g.LogClipboard->append(" %.*s", char_count, text_remaining);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1859,7 +1891,8 @@ bool Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, ImGuiWin
|
|
|
// Create window the first time, and load settings
|
|
|
if (flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_Tooltip))
|
|
|
{
|
|
|
- window = new ImGuiWindow(name, ImVec2(0,0), size);
|
|
|
+ window = (ImGuiWindow*)IM_MALLOC(sizeof(ImGuiWindow));
|
|
|
+ new(window) ImGuiWindow(name, ImVec2(0,0), size);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -1867,7 +1900,8 @@ bool Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, ImGuiWin
|
|
|
if (settings && ImLength(settings->Size) > 0.0f && !(flags & ImGuiWindowFlags_NoResize))// && ImLengthsize) == 0.0f)
|
|
|
size = settings->Size;
|
|
|
|
|
|
- window = new ImGuiWindow(name, g.NewWindowDefaultPos, size);
|
|
|
+ window = (ImGuiWindow*)IM_MALLOC(sizeof(ImGuiWindow));
|
|
|
+ new(window) ImGuiWindow(name, g.NewWindowDefaultPos, size);
|
|
|
|
|
|
if (settings->Pos.x != FLT_MAX)
|
|
|
{
|
|
@@ -2267,12 +2301,12 @@ void End()
|
|
|
fclose(g.LogFile);
|
|
|
g.LogFile = NULL;
|
|
|
}
|
|
|
- if (g.LogClipboard.size() > 1)
|
|
|
+ if (g.LogClipboard->size() > 1)
|
|
|
{
|
|
|
- g.LogClipboard.append("\n");
|
|
|
+ g.LogClipboard->append("\n");
|
|
|
if (g.IO.SetClipboardTextFn)
|
|
|
- g.IO.SetClipboardTextFn(g.LogClipboard.begin(), g.LogClipboard.end());
|
|
|
- g.LogClipboard.clear();
|
|
|
+ g.IO.SetClipboardTextFn(g.LogClipboard->begin(), g.LogClipboard->end());
|
|
|
+ g.LogClipboard->clear();
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -3970,7 +4004,7 @@ bool InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlag
|
|
|
{
|
|
|
// Remove new-line from pasted buffer
|
|
|
size_t clipboard_len = strlen(clipboard);
|
|
|
- char* clipboard_filtered = (char*)malloc(clipboard_len+1);
|
|
|
+ char* clipboard_filtered = (char*)IM_MALLOC(clipboard_len+1);
|
|
|
int clipboard_filtered_len = 0;
|
|
|
for (int i = 0; clipboard[i]; i++)
|
|
|
{
|
|
@@ -3981,7 +4015,7 @@ bool InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlag
|
|
|
}
|
|
|
clipboard_filtered[clipboard_filtered_len] = 0;
|
|
|
stb_textedit_paste(&edit_state, &edit_state.StbState, clipboard_filtered, clipboard_filtered_len);
|
|
|
- free(clipboard_filtered);
|
|
|
+ IM_FREE(clipboard_filtered);
|
|
|
}
|
|
|
}
|
|
|
else if (g.IO.InputCharacters[0])
|
|
@@ -5100,7 +5134,7 @@ ImBitmapFont::ImBitmapFont()
|
|
|
void ImBitmapFont::Clear()
|
|
|
{
|
|
|
if (Data && DataOwned)
|
|
|
- free(Data);
|
|
|
+ IM_FREE(Data);
|
|
|
Data = NULL;
|
|
|
DataOwned = false;
|
|
|
Info = NULL;
|
|
@@ -5127,7 +5161,7 @@ bool ImBitmapFont::LoadFromFile(const char* filename)
|
|
|
DataSize = (size_t)f_size;
|
|
|
if (fseek(f, 0, SEEK_SET))
|
|
|
return false;
|
|
|
- if ((Data = (unsigned char*)malloc(DataSize)) == NULL)
|
|
|
+ if ((Data = (unsigned char*)IM_MALLOC(DataSize)) == NULL)
|
|
|
{
|
|
|
fclose(f);
|
|
|
return false;
|
|
@@ -5135,7 +5169,7 @@ bool ImBitmapFont::LoadFromFile(const char* filename)
|
|
|
if (fread(Data, 1, DataSize, f) != DataSize)
|
|
|
{
|
|
|
fclose(f);
|
|
|
- free(Data);
|
|
|
+ IM_FREE(Data);
|
|
|
return false;
|
|
|
}
|
|
|
fclose(f);
|
|
@@ -5378,7 +5412,7 @@ static const char* GetClipboardTextFn_DefaultImpl()
|
|
|
static char* buf_local = NULL;
|
|
|
if (buf_local)
|
|
|
{
|
|
|
- free(buf_local);
|
|
|
+ IM_FREE(buf_local);
|
|
|
buf_local = NULL;
|
|
|
}
|
|
|
if (!OpenClipboard(NULL))
|
|
@@ -5387,7 +5421,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;
|
|
@@ -5426,12 +5460,12 @@ static void SetClipboardTextFn_DefaultImpl(const char* text, const char* text_en
|
|
|
{
|
|
|
if (GImGui.PrivateClipboard)
|
|
|
{
|
|
|
- free(GImGui.PrivateClipboard);
|
|
|
+ IM_FREE(GImGui.PrivateClipboard);
|
|
|
GImGui.PrivateClipboard = NULL;
|
|
|
}
|
|
|
if (!text_end)
|
|
|
text_end = text + strlen(text);
|
|
|
- GImGui.PrivateClipboard = (char*)malloc((size_t)(text_end - text) + 1);
|
|
|
+ GImGui.PrivateClipboard = (char*)IM_MALLOC((size_t)(text_end - text) + 1);
|
|
|
memcpy(GImGui.PrivateClipboard, text, (size_t)(text_end - text));
|
|
|
GImGui.PrivateClipboard[(size_t)(text_end - text)] = 0;
|
|
|
}
|
|
@@ -5965,7 +5999,7 @@ void ShowTestWindow(bool* open)
|
|
|
/*
|
|
|
// Copyright (c) 2004, 2005 Tristan Grimmer
|
|
|
|
|
|
-// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
+// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
|
// in the Software without restriction, including without limitation the rights
|
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|