mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-04 12:08:47 +02:00
Misc: Added IM_MALLOC/IM_FREE macros mimicking IM_NEW/IM_DELETE so user doesn't need to revert to using the ImGui::MemAlloc()/MemFree() calls directly.
This commit is contained in:
@ -130,8 +130,8 @@ namespace IMGUI_STB_NAMESPACE
|
||||
|
||||
#ifndef STB_TRUETYPE_IMPLEMENTATION // in case the user already have an implementation in the _same_ compilation unit (e.g. unity builds)
|
||||
#ifndef IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION
|
||||
#define STBTT_malloc(x,u) ((void)(u), ImGui::MemAlloc(x))
|
||||
#define STBTT_free(x,u) ((void)(u), ImGui::MemFree(x))
|
||||
#define STBTT_malloc(x,u) ((void)(u), IM_ALLOC(x))
|
||||
#define STBTT_free(x,u) ((void)(u), IM_FREE(x))
|
||||
#define STBTT_assert(x) IM_ASSERT(x)
|
||||
#define STBTT_fmod(x,y) ImFmod(x,y)
|
||||
#define STBTT_sqrt(x) ImSqrt(x)
|
||||
@ -1459,7 +1459,7 @@ void ImFontAtlas::ClearInputData()
|
||||
for (int i = 0; i < ConfigData.Size; i++)
|
||||
if (ConfigData[i].FontData && ConfigData[i].FontDataOwnedByAtlas)
|
||||
{
|
||||
ImGui::MemFree(ConfigData[i].FontData);
|
||||
IM_FREE(ConfigData[i].FontData);
|
||||
ConfigData[i].FontData = NULL;
|
||||
}
|
||||
|
||||
@ -1480,9 +1480,9 @@ void ImFontAtlas::ClearTexData()
|
||||
{
|
||||
IM_ASSERT(!Locked && "Cannot modify a locked ImFontAtlas between NewFrame() and EndFrame/Render()!");
|
||||
if (TexPixelsAlpha8)
|
||||
ImGui::MemFree(TexPixelsAlpha8);
|
||||
IM_FREE(TexPixelsAlpha8);
|
||||
if (TexPixelsRGBA32)
|
||||
ImGui::MemFree(TexPixelsRGBA32);
|
||||
IM_FREE(TexPixelsRGBA32);
|
||||
TexPixelsAlpha8 = NULL;
|
||||
TexPixelsRGBA32 = NULL;
|
||||
}
|
||||
@ -1528,7 +1528,7 @@ void ImFontAtlas::GetTexDataAsRGBA32(unsigned char** out_pixels, int* out_wid
|
||||
GetTexDataAsAlpha8(&pixels, NULL, NULL);
|
||||
if (pixels)
|
||||
{
|
||||
TexPixelsRGBA32 = (unsigned int*)ImGui::MemAlloc((size_t)TexWidth * (size_t)TexHeight * 4);
|
||||
TexPixelsRGBA32 = (unsigned int*)IM_ALLOC((size_t)TexWidth * (size_t)TexHeight * 4);
|
||||
const unsigned char* src = pixels;
|
||||
unsigned int* dst = TexPixelsRGBA32;
|
||||
for (int n = TexWidth * TexHeight; n > 0; n--)
|
||||
@ -1560,7 +1560,7 @@ ImFont* ImFontAtlas::AddFont(const ImFontConfig* font_cfg)
|
||||
new_font_cfg.DstFont = Fonts.back();
|
||||
if (!new_font_cfg.FontDataOwnedByAtlas)
|
||||
{
|
||||
new_font_cfg.FontData = ImGui::MemAlloc(new_font_cfg.FontDataSize);
|
||||
new_font_cfg.FontData = IM_ALLOC(new_font_cfg.FontDataSize);
|
||||
new_font_cfg.FontDataOwnedByAtlas = true;
|
||||
memcpy(new_font_cfg.FontData, font_cfg->FontData, (size_t)new_font_cfg.FontDataSize);
|
||||
}
|
||||
@ -1645,7 +1645,7 @@ ImFont* ImFontAtlas::AddFontFromMemoryTTF(void* ttf_data, int ttf_size, float si
|
||||
ImFont* ImFontAtlas::AddFontFromMemoryCompressedTTF(const void* compressed_ttf_data, int compressed_ttf_size, float size_pixels, const ImFontConfig* font_cfg_template, const ImWchar* glyph_ranges)
|
||||
{
|
||||
const unsigned int buf_decompressed_size = stb_decompress_length((const unsigned char*)compressed_ttf_data);
|
||||
unsigned char* buf_decompressed_data = (unsigned char *)ImGui::MemAlloc(buf_decompressed_size);
|
||||
unsigned char* buf_decompressed_data = (unsigned char *)IM_ALLOC(buf_decompressed_size);
|
||||
stb_decompress(buf_decompressed_data, (const unsigned char*)compressed_ttf_data, (unsigned int)compressed_ttf_size);
|
||||
|
||||
ImFontConfig font_cfg = font_cfg_template ? *font_cfg_template : ImFontConfig();
|
||||
@ -1657,10 +1657,10 @@ ImFont* ImFontAtlas::AddFontFromMemoryCompressedTTF(const void* compressed_ttf_d
|
||||
ImFont* ImFontAtlas::AddFontFromMemoryCompressedBase85TTF(const char* compressed_ttf_data_base85, float size_pixels, const ImFontConfig* font_cfg, const ImWchar* glyph_ranges)
|
||||
{
|
||||
int compressed_ttf_size = (((int)strlen(compressed_ttf_data_base85) + 4) / 5) * 4;
|
||||
void* compressed_ttf = ImGui::MemAlloc((size_t)compressed_ttf_size);
|
||||
void* compressed_ttf = IM_ALLOC((size_t)compressed_ttf_size);
|
||||
Decode85((const unsigned char*)compressed_ttf_data_base85, (unsigned char*)compressed_ttf);
|
||||
ImFont* font = AddFontFromMemoryCompressedTTF(compressed_ttf, compressed_ttf_size, size_pixels, font_cfg, glyph_ranges);
|
||||
ImGui::MemFree(compressed_ttf);
|
||||
IM_FREE(compressed_ttf);
|
||||
return font;
|
||||
}
|
||||
|
||||
@ -1960,7 +1960,7 @@ bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas)
|
||||
// 7. Allocate texture
|
||||
atlas->TexHeight = (atlas->Flags & ImFontAtlasFlags_NoPowerOfTwoHeight) ? (atlas->TexHeight + 1) : ImUpperPowerOfTwo(atlas->TexHeight);
|
||||
atlas->TexUvScale = ImVec2(1.0f / atlas->TexWidth, 1.0f / atlas->TexHeight);
|
||||
atlas->TexPixelsAlpha8 = (unsigned char*)ImGui::MemAlloc(atlas->TexWidth * atlas->TexHeight);
|
||||
atlas->TexPixelsAlpha8 = (unsigned char*)IM_ALLOC(atlas->TexWidth * atlas->TexHeight);
|
||||
memset(atlas->TexPixelsAlpha8, 0, atlas->TexWidth * atlas->TexHeight);
|
||||
spc.pixels = atlas->TexPixelsAlpha8;
|
||||
spc.height = atlas->TexHeight;
|
||||
|
Reference in New Issue
Block a user