diff options
author | 2015-05-02 19:41:03 +0200 | |
---|---|---|
committer | 2015-05-02 19:41:03 +0200 | |
commit | cc3b682e52bf097d31db78032aad01d6a0b12e94 (patch) | |
tree | 860c97ca011b64c31a5ad277f5cea2b1d86eeaf0 /3rdparty/bgfx/examples/common/imgui/imgui.cpp | |
parent | 7df6a23ba2ae1c1df94ed8cc2398f2546f339997 (diff) | |
parent | a649a95488e1fc85813dda747dc74c596496bd1c (diff) |
Merge pull request #1 from mamedev/master
Sync to master
Diffstat (limited to '3rdparty/bgfx/examples/common/imgui/imgui.cpp')
-rw-r--r-- | 3rdparty/bgfx/examples/common/imgui/imgui.cpp | 61 |
1 files changed, 36 insertions, 25 deletions
diff --git a/3rdparty/bgfx/examples/common/imgui/imgui.cpp b/3rdparty/bgfx/examples/common/imgui/imgui.cpp index 6df549c1c2f..6d2d566dbec 100644 --- a/3rdparty/bgfx/examples/common/imgui/imgui.cpp +++ b/3rdparty/bgfx/examples/common/imgui/imgui.cpp @@ -50,6 +50,8 @@ // embedded font #include "droidsans.ttf.h" +BX_PRAGMA_DIAGNOSTIC_IGNORED_MSVC(4244); // warning C4244: '=' : conversion from '' to '', possible loss of data + #define USE_NANOVG_FONT 0 #define IMGUI_CONFIG_MAX_FONTS 20 @@ -67,34 +69,24 @@ static const int32_t SCROLL_AREA_PADDING = 6; static const int32_t AREA_HEADER = 20; static const float s_tabStops[4] = {150, 210, 270, 330}; -// For a custom allocator, define this and implement imguiMalloc and imguiFree somewhere in the project. -#ifndef IMGUI_CONFIG_CUSTOM_ALLOCATOR -# define IMGUI_CONFIG_CUSTOM_ALLOCATOR 0 -#endif // ENTRY_CONFIG_USE_TINYSTL - -#if IMGUI_CONFIG_CUSTOM_ALLOCATOR - void* imguiMalloc(size_t size, void* /*_userptr*/); - void imguiFree(void* _ptr, void* /*_userptr*/); -#else - static void* imguiMalloc(size_t _size, void* /*_userptr*/) - { - return malloc(_size); - } - - static void imguiFree(void* _ptr, void* /*_userptr*/) - { - free(_ptr); - } -#endif //IMGUI_CONFIG_CUSTOM_ALLOCATOR +void* imguiMalloc(size_t _size, void*); +void imguiFree(void* _ptr, void*); #define IMGUI_MIN(_a, _b) (_a)<(_b)?(_a):(_b) #define IMGUI_MAX(_a, _b) (_a)>(_b)?(_a):(_b) #define IMGUI_CLAMP(_a, _min, _max) IMGUI_MIN(IMGUI_MAX(_a, _min), _max) -#define STBTT_malloc(_x, _y) imguiMalloc(_x, _y) -#define STBTT_free(_x, _y) imguiFree(_x, _y) +BX_PRAGMA_DIAGNOSTIC_IGNORED_MSVC(4505); // error C4505: '' : unreferenced local function has been removed +BX_PRAGMA_DIAGNOSTIC_IGNORED_CLANG_GCC("-Wunused-function"); // warning: ‘int rect_width_compare(const void*, const void*)’ defined but not used +BX_PRAGMA_DIAGNOSTIC_PUSH(); +BX_PRAGMA_DIAGNOSTIC_IGNORED_CLANG_GCC("-Wtype-limits"); // warning: comparison is always true due to limited range of data type +#define STBTT_malloc(_size, _userData) imguiMalloc(_size, _userData) +#define STBTT_free(_ptr, _userData) imguiFree(_ptr, _userData) +#define STB_RECT_PACK_IMPLEMENTATION +#include <stb/stb_rect_pack.h> #define STB_TRUETYPE_IMPLEMENTATION #include <stb/stb_truetype.h> +BX_PRAGMA_DIAGNOSTIC_POP(); namespace { @@ -459,15 +451,23 @@ struct Imgui return bgfx::createTexture2D(uint16_t(_width), uint16_t(_height), 0, bgfx::TextureFormat::BGRA8, 0, mem); } - ImguiFontHandle create(const void* _data, uint32_t _size, float _fontSize) + ImguiFontHandle create(const void* _data, uint32_t _size, float _fontSize, bx::AllocatorI* _allocator) { + m_allocator = _allocator; + + if (NULL == m_allocator) + { + static bx::CrtAllocator allocator; + m_allocator = &allocator; + } + if (NULL == _data) { _data = s_droidSansTtf; _size = sizeof(s_droidSansTtf); } - IMGUI_create(_data, _size, _fontSize); + IMGUI_create(_data, _size, _fontSize, _allocator); m_nvg = nvgCreate(1, m_view); nvgCreateFontMem(m_nvg, "default", (unsigned char*)_data, INT32_MAX, 0); @@ -3148,6 +3148,7 @@ struct Imgui Ty m_ids[Max]; }; + bx::AllocatorI* m_allocator; int32_t m_mx; int32_t m_my; int32_t m_scroll; @@ -3220,9 +3221,19 @@ struct Imgui static Imgui s_imgui; -ImguiFontHandle imguiCreate(const void* _data, uint32_t _size, float _fontSize) +void* imguiMalloc(size_t _size, void*) +{ + return BX_ALLOC(s_imgui.m_allocator, _size); +} + +void imguiFree(void* _ptr, void*) +{ + BX_FREE(s_imgui.m_allocator, _ptr); +} + +ImguiFontHandle imguiCreate(const void* _data, uint32_t _size, float _fontSize, bx::AllocatorI* _allocator) { - return s_imgui.create(_data, _size, _fontSize); + return s_imgui.create(_data, _size, _fontSize, _allocator); } void imguiDestroy() |