Skip to content

Commit a6cd62c

Browse files
committed
Update ImGui to 1.91.6
1 parent 877e252 commit a6cd62c

15 files changed

+8214
-3435
lines changed

extensions/ImGui/src/ImGui/ImGuiPresenter.cpp

Lines changed: 35 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ THE SOFTWARE.
3131
#endif
3232
#include "imgui/imgui_internal.h"
3333

34+
#include "xxhash.h"
35+
3436
// TODO: mac metal
3537
#if defined(AX_USE_GL) && defined(AX_PLATFORM_PC)
3638
# define AX_IMGUI_ENABLE_MULTI_VIEWPORT 1
@@ -40,7 +42,6 @@ THE SOFTWARE.
4042

4143
NS_AX_EXT_BEGIN
4244

43-
4445
namespace
4546
{
4647
uint32_t fourccValue(std::string_view str)
@@ -139,12 +140,12 @@ std::tuple<ImVec2, ImVec2, ImVec2, ImVec2> getFourPointTextureUV(SpriteFrame* fr
139140

140141
ImVec2 operator+(const ImVec2& lhs, const ImVec2& rhs)
141142
{
142-
return { lhs.x + rhs.x, lhs.y + rhs.y };
143+
return {lhs.x + rhs.x, lhs.y + rhs.y};
143144
}
144145

145146
ImVec2 ImRotate(const ImVec2& v, float cos_a, float sin_a)
146147
{
147-
return { v.x * cos_a - v.y * sin_a, v.x * sin_a + v.y * cos_a };
148+
return {v.x * cos_a - v.y * sin_a, v.x * sin_a + v.y * cos_a};
148149
}
149150

150151
ImVec2& operator+=(ImVec2& lhs, const ImVec2& rhs)
@@ -153,8 +154,7 @@ ImVec2& operator+=(ImVec2& lhs, const ImVec2& rhs)
153154
lhs.y += rhs.y;
154155
return lhs;
155156
}
156-
}
157-
157+
} // namespace
158158

159159
class ImGuiEventTracker
160160
{
@@ -592,8 +592,8 @@ void ImGuiPresenter::endFrame()
592592
void ImGuiPresenter::update()
593593
{
594594
// clear things from last frame
595-
usedCCRefIdMap.clear();
596-
usedCCRef.clear();
595+
_objsRefIdMap.clear();
596+
_usedObjs.clear();
597597
// drawing commands
598598

599599
for (auto iter = _renderLoops.begin(); iter != _renderLoops.end();)
@@ -661,7 +661,7 @@ void ImGuiPresenter::image(Texture2D* tex,
661661
size_.x = tex->getPixelsWide();
662662
if (size_.y <= 0.f)
663663
size_.y = tex->getPixelsHigh();
664-
ImGui::PushID(getCCRefId(tex));
664+
ImGui::PushID(objectRef(tex));
665665
ImGui::Image((ImTextureID)tex, size_, uv0, uv1, tint_col, border_col);
666666
ImGui::PopID();
667667
}
@@ -705,7 +705,7 @@ void ImGuiPresenter::image(Sprite* sprite,
705705
const ImVec2 pos[4] = {ImVec2(bb.Min.x, bb.Min.y), ImVec2(bb.Max.x, bb.Min.y), ImVec2(bb.Max.x, bb.Max.y),
706706
ImVec2(bb.Min.x, bb.Max.y)};
707707

708-
ImGui::PushID(getCCRefId(sprite));
708+
ImGui::PushID(objectRef(sprite));
709709
if (border_col.w > 0.0f)
710710
{
711711
window->DrawList->AddRect(bb.Min, bb.Max, ImGui::GetColorU32(border_col), 0.0f);
@@ -759,7 +759,7 @@ void ImGuiPresenter::image(SpriteFrame* spriteFrame,
759759
const ImVec2 pos[4] = {ImVec2(bb.Min.x, bb.Min.y), ImVec2(bb.Max.x, bb.Min.y), ImVec2(bb.Max.x, bb.Max.y),
760760
ImVec2(bb.Min.x, bb.Max.y)};
761761

762-
ImGui::PushID(getCCRefId(spriteFrame));
762+
ImGui::PushID(objectRef(spriteFrame));
763763
if (border_col.w > 0.0f)
764764
{
765765
window->DrawList->AddRect(bb.Min, bb.Max, ImGui::GetColorU32(border_col), 0.0f);
@@ -780,7 +780,6 @@ bool ImGuiPresenter::imageButton(Texture2D* tex,
780780
const ImVec2& size,
781781
const ImVec2& uv0,
782782
const ImVec2& uv1,
783-
int frame_padding,
784783
const ImVec4& bg_col,
785784
const ImVec4& tint_col)
786785
{
@@ -791,15 +790,14 @@ bool ImGuiPresenter::imageButton(Texture2D* tex,
791790
size_.x = tex->getPixelsWide();
792791
if (size_.y <= 0.f)
793792
size_.y = tex->getPixelsHigh();
794-
ImGui::PushID(getCCRefId(tex));
795-
const auto ret = ImGui::ImageButton((ImTextureID)tex, size_, uv0, uv1, frame_padding, bg_col, tint_col);
793+
ImGui::PushID(objectRef(tex));
794+
const auto ret = ImGui::ImageButton("###", (ImTextureID)tex, size_, uv0, uv1, bg_col, tint_col);
796795
ImGui::PopID();
797796
return ret;
798797
}
799798

800799
bool ImGuiPresenter::imageButton(Sprite* sprite,
801800
const ImVec2& size,
802-
int frame_padding,
803801
const ImVec4& bg_col,
804802
const ImVec4& tint_col)
805803
{
@@ -812,9 +810,8 @@ bool ImGuiPresenter::imageButton(Sprite* sprite,
812810
if (size_.y <= 0.f)
813811
size_.y = rect.size.height;
814812
auto [uv0, uv1] = getTwoPointTextureUV(sprite);
815-
ImGui::PushID(getCCRefId(sprite));
816-
const auto ret =
817-
ImGui::ImageButton((ImTextureID)sprite->getTexture(), size_, uv0, uv1, frame_padding, bg_col, tint_col);
813+
ImGui::PushID(objectRef(sprite));
814+
const auto ret = ImGui::ImageButton("###", (ImTextureID)sprite->getTexture(), size_, uv0, uv1, bg_col, tint_col);
818815
ImGui::PopID();
819816
return ret;
820817
}
@@ -835,12 +832,12 @@ void ImGuiPresenter::node(Node* node, const ImVec4& tint_col, const ImVec4& bord
835832
tr.m[13] += 1;
836833
}
837834
node->setNodeToParentTransform(tr);
838-
ImGui::PushID(getCCRefId(node));
835+
ImGui::PushID(objectRef(node));
839836
ImGui::Image((ImTextureID)node, ImVec2(size.width, size.height), ImVec2(0, 0), ImVec2(1, 1), tint_col, border_col);
840837
ImGui::PopID();
841838
}
842839

843-
bool ImGuiPresenter::nodeButton(Node* node, int frame_padding, const ImVec4& bg_col, const ImVec4& tint_col)
840+
bool ImGuiPresenter::nodeButton(Node* node, const ImVec4& bg_col, const ImVec4& tint_col)
844841
{
845842
if (!node)
846843
return false;
@@ -850,50 +847,43 @@ bool ImGuiPresenter::nodeButton(Node* node, int frame_padding, const ImVec4& bg_
850847
tr.m[5] = -1;
851848
tr.m[12] = pos.x;
852849
tr.m[13] = pos.y + size.height;
853-
if (frame_padding >= 0)
854-
{
855-
tr.m[12] += (float)frame_padding;
856-
tr.m[13] += (float)frame_padding;
857-
}
858-
else
859-
{
860-
tr.m[12] += ImGui::GetStyle().FramePadding.x;
861-
tr.m[13] += ImGui::GetStyle().FramePadding.y;
862-
}
850+
tr.m[12] += ImGui::GetStyle().FramePadding.x;
851+
tr.m[13] += ImGui::GetStyle().FramePadding.y;
852+
863853
node->setNodeToParentTransform(tr);
864-
ImGui::PushID(getCCRefId(node));
865-
const auto ret = ImGui::ImageButton((ImTextureID)node, ImVec2(size.width, size.height), ImVec2(0, 0), ImVec2(1, 1),
866-
frame_padding, bg_col, tint_col);
854+
ImGui::PushID(objectRef(node));
855+
const auto ret = ImGui::ImageButton("###", (ImTextureID)node, ImVec2(size.width, size.height), ImVec2(0, 0),
856+
ImVec2(1, 1), bg_col, tint_col);
867857
ImGui::PopID();
868858
return ret;
869859
}
870860

871861
std::tuple<ImTextureID, int> ImGuiPresenter::useTexture(Texture2D* texture)
872862
{
873863
if (!texture)
874-
return std::tuple<ImTextureID, int>{nullptr, 0};
875-
return std::tuple{(ImTextureID)texture, getCCRefId(texture)};
864+
return std::tuple<ImTextureID, int>{0, 0};
865+
return std::tuple{(ImTextureID)texture, objectRef(texture)};
876866
}
877867

878868
std::tuple<ImTextureID, ImVec2, ImVec2, int> ImGuiPresenter::useSprite(Sprite* sprite)
879869
{
880870
if (!sprite || !sprite->getTexture())
881-
return std::tuple<ImTextureID, ImVec2, ImVec2, int>{nullptr, {}, {}, 0};
871+
return std::tuple<ImTextureID, ImVec2, ImVec2, int>{0, {}, {}, 0};
882872
auto [uv0, uv1] = getTwoPointTextureUV(sprite);
883-
return std::tuple{(ImTextureID)sprite->getTexture(), uv0, uv1, getCCRefId(sprite)};
873+
return std::tuple{(ImTextureID)sprite->getTexture(), uv0, uv1, objectRef(sprite)};
884874
}
885875

886876
std::tuple<ImTextureID, ImVec2, ImVec2, int> ImGuiPresenter::useNode(Node* node, const ImVec2& pos)
887877
{
888878
if (!node)
889-
return std::tuple<ImTextureID, ImVec2, ImVec2, int>{nullptr, {}, {}, 0};
879+
return std::tuple<ImTextureID, ImVec2, ImVec2, int>{0, {}, {}, 0};
890880
const auto size = node->getContentSize();
891881
Mat4 tr;
892882
tr.m[5] = -1;
893883
tr.m[12] = pos.x;
894884
tr.m[13] = pos.y + size.height;
895885
node->setNodeToParentTransform(tr);
896-
return std::tuple{(ImTextureID)node, pos, ImVec2(pos.x + size.width, pos.y + size.height), getCCRefId(node)};
886+
return std::tuple{(ImTextureID)node, pos, ImVec2(pos.x + size.width, pos.y + size.height), objectRef(node)};
897887
}
898888

899889
void ImGuiPresenter::setNodeColor(Node* node, const ImVec4& col)
@@ -1050,25 +1040,19 @@ void ImGuiPresenter::mergeFontGlyphs(ImFont* dst, ImFont* src, ImWchar start, Im
10501040
dst->BuildLookupTable();
10511041
}
10521042

1053-
int ImGuiPresenter::getCCRefId(Object* p)
1043+
int ImGuiPresenter::objectRef(Object* p)
10541044
{
10551045
int id = 0;
1056-
const auto it = usedCCRefIdMap.find(p);
1057-
if (it == usedCCRefIdMap.end())
1046+
const auto it = _objsRefIdMap.find(p);
1047+
if (it == _objsRefIdMap.end())
10581048
{
1059-
usedCCRefIdMap[p] = 0;
1060-
usedCCRef.pushBack(p);
1049+
_objsRefIdMap[p] = 0;
1050+
_usedObjs.pushBack(p);
10611051
}
10621052
else
10631053
id = ++it->second;
1064-
// BKDR hash
1065-
constexpr unsigned int seed = 131;
1066-
unsigned int hash = 0;
1067-
for (auto i = 0u; i < sizeof(void*); ++i)
1068-
hash = hash * seed + ((const char*)&p)[i];
1069-
for (auto i = 0u; i < sizeof(int); ++i)
1070-
hash = hash * seed + ((const char*)&id)[i];
1071-
return (int)hash;
1054+
1055+
return XXH32(&p, sizeof(p), id);
10721056
}
10731057

10741058
std::string_view ImGuiPresenter::getGlyphRangesId(GLYPH_RANGES glyphRanges)

extensions/ImGui/src/ImGui/ImGuiPresenter.h

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ class ImGuiPresenter
103103
/// <param name="glyphRange"></param>
104104
/// <param name="fontConfig"></param>
105105
void addFont(std::string_view fontFile,
106-
float fontSize = DEFAULT_FONT_SIZE,
107-
GLYPH_RANGES glyphRange = GLYPH_RANGES::NONE,
106+
float fontSize = DEFAULT_FONT_SIZE,
107+
GLYPH_RANGES glyphRange = GLYPH_RANGES::NONE,
108108
const ImFontConfig& fontConfig = ImFontConfig());
109109
/// <summary>
110110
/// Add ImGui font with contentZoomFactor and use pre-existing glyph range for the specified font
@@ -169,7 +169,7 @@ class ImGuiPresenter
169169
const ImVec4& border_col = ImVec4(0, 0, 0, 0));
170170
void image(Sprite* sprite,
171171
const ImVec2& size,
172-
bool keepAspectRatio = true,
172+
bool keepAspectRatio = true,
173173
const ImVec4& tint_col = ImVec4(1, 1, 1, 1),
174174
const ImVec4& border_col = ImVec4(0, 0, 0, 0));
175175
void image(SpriteFrame* spriteFrame,
@@ -181,18 +181,15 @@ class ImGuiPresenter
181181
const ImVec2& size,
182182
const ImVec2& uv0 = ImVec2(0, 0),
183183
const ImVec2& uv1 = ImVec2(1, 1),
184-
int frame_padding = -1,
185184
const ImVec4& bg_col = ImVec4(0, 0, 0, 0),
186185
const ImVec4& tint_col = ImVec4(1, 1, 1, 1));
187186
bool imageButton(Sprite* sprite,
188187
const ImVec2& size,
189-
int frame_padding = -1,
190188
const ImVec4& bg_col = ImVec4(0, 0, 0, 0),
191189
const ImVec4& tint_col = ImVec4(1, 1, 1, 1));
192190

193191
void node(Node* node, const ImVec4& tint_col = ImVec4(1, 1, 1, 1), const ImVec4& border_col = ImVec4(0, 0, 0, 0));
194192
bool nodeButton(Node* node,
195-
int frame_padding = -1,
196193
const ImVec4& bg_col = ImVec4(0, 0, 0, 0),
197194
const ImVec4& tint_col = ImVec4(1, 1, 1, 1));
198195

@@ -211,7 +208,7 @@ class ImGuiPresenter
211208
void removeGlyphRanges(std::string_view key);
212209
void clearGlyphRanges();
213210
static void mergeFontGlyphs(ImFont* dst, ImFont* src, ImWchar start, ImWchar end);
214-
int getCCRefId(Object* p);
211+
int objectRef(Object* p);
215212

216213
private:
217214
static void loadCustomFonts(void*);
@@ -233,12 +230,12 @@ class ImGuiPresenter
233230

234231
std::unordered_map<uint32_t, ImGuiLoop> _renderLoops;
235232

236-
std::unordered_map<Object*, int> usedCCRefIdMap;
233+
std::unordered_map<Object*, int> _objsRefIdMap;
237234
// cocos objects should be retained until next frame
238-
Vector<Object*> usedCCRef;
235+
Vector<Object*> _usedObjs;
239236

240237
hlookup::string_map<std::vector<ImWchar>> _glyphRanges;
241-
std::unordered_set<uintptr_t> _usedGlyphRanges; // there should be one intance of "each glyph ranges"
238+
std::unordered_set<uintptr_t> _usedGlyphRanges; // there should be one intance of "each glyph ranges"
242239
// temporarily stores the current erased/replaced ranges, gets cleared in the next `loadCustomFonts` interation
243240
std::vector<std::vector<ImWchar>> _eraseGlyphRanges;
244241

extensions/ImGui/src/ImGui/imgui/imconfig.h

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121

2222
//---- Define attributes of all API symbols declarations, e.g. for DLL under Windows
2323
// Using Dear ImGui via a shared library is not recommended, because of function call overhead and because we don't guarantee backward nor forward ABI compatibility.
24-
// DLL users: heaps and globals are not shared across DLL boundaries! You will need to call SetCurrentContext() + SetAllocatorFunctions()
25-
// for each static/DLL boundary you are calling from. Read "Context and Memory Allocators" section of imgui.cpp for more details.
26-
//#define IMGUI_API __declspec( dllexport )
27-
//#define IMGUI_API __declspec( dllimport )
24+
// - Windows DLL users: heaps and globals are not shared across DLL boundaries! You will need to call SetCurrentContext() + SetAllocatorFunctions()
25+
// for each static/DLL boundary you are calling from. Read "Context and Memory Allocators" section of imgui.cpp for more details.
26+
//#define IMGUI_API __declspec(dllexport) // MSVC Windows: DLL export
27+
//#define IMGUI_API __declspec(dllimport) // MSVC Windows: DLL import
28+
//#define IMGUI_API __attribute__((visibility("default"))) // GCC/Clang: override visibility when set is hidden
2829

2930
//---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to clean your code of obsolete function/names.
3031
//#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS
31-
//#define IMGUI_DISABLE_OBSOLETE_KEYIO // 1.87+ disable legacy io.KeyMap[]+io.KeysDown[] in favor io.AddKeyEvent(). This is automatically done by IMGUI_DISABLE_OBSOLETE_FUNCTIONS.
3232

3333
//---- Disable all of Dear ImGui or don't implement standard windows/tools.
3434
// It is very strongly recommended to NOT disable the demo windows and debug tool during development. They are extremely useful in day to day work. Please read comments in imgui_demo.cpp.
@@ -42,21 +42,29 @@
4242
//#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with non-Visual Studio compilers] Don't implement default IME handler (won't require imm32.lib/.a)
4343
//#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function (clipboard, IME).
4444
//#define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS // [OSX] Implement default OSX clipboard handler (need to link with '-framework ApplicationServices', this is why this is not the default).
45+
//#define IMGUI_DISABLE_DEFAULT_SHELL_FUNCTIONS // Don't implement default platform_io.Platform_OpenInShellFn() handler (Win32: ShellExecute(), require shell32.lib/.a, Mac/Linux: use system("")).
4546
//#define IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself (e.g. if you don't want to link with vsnprintf)
4647
//#define IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 so you can implement them yourself.
4748
//#define IMGUI_DISABLE_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle at all (replace them with dummies)
4849
//#define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle so you can implement them yourself if you don't want to link with fopen/fclose/fread/fwrite. This will also disable the LogToTTY() function.
4950
//#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions().
51+
//#define IMGUI_DISABLE_DEFAULT_FONT // Disable default embedded font (ProggyClean.ttf), remove ~9.5 KB from output binary. AddFontDefault() will assert.
5052
//#define IMGUI_DISABLE_SSE // Disable use of SSE intrinsics even if available
5153

54+
//---- Enable Test Engine / Automation features.
55+
//#define IMGUI_ENABLE_TEST_ENGINE // Enable imgui_test_engine hooks. Generally set automatically by include "imgui_te_config.h", see Test Engine for details.
56+
5257
//---- Include imgui_user.h at the end of imgui.h as a convenience
5358
// May be convenient for some users to only explicitly include vanilla imgui.h and have extra stuff included.
5459
//#define IMGUI_INCLUDE_IMGUI_USER_H
5560
//#define IMGUI_USER_H_FILENAME "my_folder/my_imgui_user.h"
5661

57-
//---- Pack colors to BGRA8 instead of RGBA8 (to avoid converting from one to another)
62+
//---- Pack vertex colors as BGRA8 instead of RGBA8 (to avoid converting from one to another). Need dedicated backend support.
5863
//#define IMGUI_USE_BGRA_PACKED_COLOR
5964

65+
//---- Use legacy CRC32-adler tables (used before 1.91.6), in order to preserve old .ini data that you cannot afford to invalidate.
66+
//#define IMGUI_USE_LEGACY_CRC32_ADLER
67+
6068
//---- Use 32-bit for ImWchar (default is 16-bit) to support Unicode planes 1-16. (e.g. point beyond 0xFFFF like emoticons, dingbats, symbols, shapes, ancient languages, etc...)
6169
//#define IMGUI_USE_WCHAR32
6270

@@ -78,10 +86,13 @@
7886
// On Windows you may use vcpkg with 'vcpkg install freetype --triplet=x64-windows' + 'vcpkg integrate install'.
7987
//#define IMGUI_ENABLE_FREETYPE
8088

81-
//---- Use FreeType+lunasvg library to render OpenType SVG fonts (SVGinOT)
82-
// Requires lunasvg headers to be available in the include path + program to be linked with the lunasvg library (not provided).
89+
//---- Use FreeType + plutosvg or lunasvg to render OpenType SVG fonts (SVGinOT)
8390
// Only works in combination with IMGUI_ENABLE_FREETYPE.
84-
// (implementation is based on Freetype's rsvg-port.c which is licensed under CeCILL-C Free Software License Agreement)
91+
// - lunasvg is currently easier to acquire/install, as e.g. it is part of vcpkg.
92+
// - plutosvg will support more fonts and may load them faster. It currently requires to be built manually but it is fairly easy. See misc/freetype/README for instructions.
93+
// - Both require headers to be available in the include path + program to be linked with the library code (not provided).
94+
// - (note: lunasvg implementation is based on Freetype's rsvg-port.c which is licensed under CeCILL-C Free Software License Agreement)
95+
//#define IMGUI_ENABLE_FREETYPE_PLUTOSVG
8596
//#define IMGUI_ENABLE_FREETYPE_LUNASVG
8697

8798
//---- Use stb_truetype to build and rasterize the font atlas (default)

0 commit comments

Comments
 (0)