From e5f54f22b21d5d3029527e7ecde5196329cda460 Mon Sep 17 00:00:00 2001 From: user666 Date: Sat, 25 Oct 2025 15:46:45 +0400 Subject: [PATCH 1/9] update imgui and add some basic fixes and features --- .gitignore | 4 ++- CMakeLists.txt | 2 +- src/DevTools.cpp | 70 ++++++++++++++++++++++++++++++++++++++++++++++++ src/backend.cpp | 31 ++++++++++++++++++--- src/themes.cpp | 4 +++ 5 files changed, 106 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 104fea3..7ab3d63 100644 --- a/.gitignore +++ b/.gitignore @@ -20,4 +20,6 @@ imgui/** imgui **/.DS_Store -.cache/ \ No newline at end of file +.cache/ +/CMakeSettings.json +/.vs diff --git a/CMakeLists.txt b/CMakeLists.txt index 908ecd9..913b40f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,7 +29,7 @@ endif() add_subdirectory($ENV{GEODE_SDK} ${CMAKE_CURRENT_BINARY_DIR}/geode) -CPMAddPackage("gh:ocornut/imgui@1.91.0-docking") +CPMAddPackage("gh:ocornut/imgui@1.92.4-docking") target_include_directories(${PROJECT_NAME} PRIVATE ${imgui_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/include) diff --git a/src/DevTools.cpp b/src/DevTools.cpp index d821618..6b5dc6a 100644 --- a/src/DevTools.cpp +++ b/src/DevTools.cpp @@ -108,7 +108,28 @@ void DevTools::addCustomCallback(std::function callback) { void DevTools::drawPage(const char* name, void(DevTools::*pageFun)()) { if (ImGui::Begin(name, nullptr, ImGuiWindowFlags_HorizontalScrollbar)) { + + // Fix wrapping after window resize + ImGui::PushTextWrapPos(ImGui::GetContentRegionAvail().x); + (this->*pageFun)(); + + // Scroll when dragging (useful for android users) + auto mouse_dt = ImGui::GetIO().MouseDelta; + ImVec2 delta = ImGui::GetIO().MouseDownDuration[0] > 0.1 ? ImVec2(mouse_dt.x * -1, mouse_dt.y * -1) : ImVec2(0, 0); + ImGuiContext& g = *ImGui::GetCurrentContext(); + ImGuiWindow* window = g.CurrentWindow; + if (!window) return; + bool hovered = false; + bool held = false; + ImGuiID id = window->GetID("##scrolldraggingoverlay"); + ImGui::KeepAliveID(id); + ImGuiButtonFlags button_flags = ImGuiButtonFlags_MouseButtonLeft; + if (g.HoveredId == 0) // If nothing hovered so far in the frame (not same as IsAnyItemHovered()!) + ImGui::ButtonBehavior(window->Rect(), id, &hovered, &held, button_flags); + if (held && fabs(delta.x) >= 0.1f) ImGui::SetScrollX(window, window->Scroll.x + delta.x); + if (held && fabs(delta.y) >= 0.1f) ImGui::SetScrollY(window, window->Scroll.y + delta.y); + } ImGui::End(); } @@ -208,6 +229,52 @@ void DevTools::draw(GLRenderCtx* ctx) { if (this->shouldUseGDWindow()) this->drawGD(ctx); ImGui::PopFont(); } + +#ifdef GEODE_IS_WINDOWS // Windows exclusive cursor updates from imgui-cocos + + // Shows imgui's cursor instead of hidden cursor if out of GD Window + auto isCursorVisible = false; + CURSORINFO ci = { sizeof(ci) }; //winapi + if (GetCursorInfo(&ci)) isCursorVisible = (ci.flags & CURSOR_SHOWING) != 0; + ImGui::GetIO().MouseDrawCursor = m_visible and !isCursorVisible and !shouldPassEventsToGDButTransformed(); + + struct GLFWCursorData { + void* next = nullptr; + HCURSOR cursor; + }; + auto& cursorField = *reinterpret_cast(reinterpret_cast( + CCEGLView::get()->getWindow()) + 0x50); + + auto cursor = ImGui::GetIO().MouseDrawCursor ? ImGuiMouseCursor_None : ImGui::GetMouseCursor(); + static ImGuiMouseCursor lastCursor = ImGuiMouseCursor_COUNT; + if (cursor != lastCursor) { + lastCursor = cursor; + auto winCursor = IDC_ARROW; + switch (cursor) + { + case ImGuiMouseCursor_Arrow: winCursor = IDC_ARROW; break; + case ImGuiMouseCursor_TextInput: winCursor = IDC_IBEAM; break; + case ImGuiMouseCursor_ResizeAll: winCursor = IDC_SIZEALL; break; + case ImGuiMouseCursor_ResizeEW: winCursor = IDC_SIZEWE; break; + case ImGuiMouseCursor_ResizeNS: winCursor = IDC_SIZENS; break; + case ImGuiMouseCursor_ResizeNESW: winCursor = IDC_SIZENESW; break; + case ImGuiMouseCursor_ResizeNWSE: winCursor = IDC_SIZENWSE; break; + case ImGuiMouseCursor_Hand: winCursor = IDC_HAND; break; + case ImGuiMouseCursor_NotAllowed: winCursor = IDC_NO; break; + } + if (cursorField) { + cursorField->cursor = LoadCursor(NULL, winCursor); + } + else { + // must be heap allocated + cursorField = new GLFWCursorData{ + .next = nullptr, + .cursor = LoadCursor(NULL, winCursor) + }; + } + } +#endif + } void DevTools::setupFonts() { @@ -256,6 +323,9 @@ void DevTools::setup() { // io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; io.ConfigWindowsResizeFromEdges = true; + // Allow user scaling text of individual window with CTRL+Wheel. + io.FontAllowUserScaling = true; + this->setupFonts(); this->setupPlatform(); diff --git a/src/backend.cpp b/src/backend.cpp index 38a1210..a4d33f2 100644 --- a/src/backend.cpp +++ b/src/backend.cpp @@ -14,6 +14,21 @@ using namespace cocos2d; // based off https://github.com/matcool/gd-imgui-cocos +// little helper function to convert ImTexture2D <=> GLuint, +// supporting both versions of imgui where this was a void* and is now a u64 +// (templated because c++ is stupid) +template +static auto textureID(auto value) { + if constexpr (std::is_same_v) { // GLuint -> ImTextureID + if constexpr (std::is_same_v) return reinterpret_cast(static_cast(value)); + else return static_cast(value); + } + else { // ImTextureID -> GLuint + if constexpr (std::is_same_v) return static_cast(reinterpret_cast(value)); + else return static_cast(value); + } +} + static bool g_useNormalPos = false; CCPoint getMousePos_H() { @@ -57,7 +72,7 @@ void DevTools::setupPlatform() { m_fontTexture->initWithData(pixels, kCCTexture2DPixelFormat_RGBA8888, width, height, CCSize(width, height)); m_fontTexture->retain(); - io.Fonts->SetTexID(reinterpret_cast(static_cast(m_fontTexture->getName()))); + io.Fonts->SetTexID(textureID(m_fontTexture->getName())); // fixes getMousePos to be relative to the GD view #ifndef GEODE_IS_MOBILE @@ -67,6 +82,16 @@ void DevTools::setupPlatform() { "geode::cocos::getMousePos" ); #endif + + // define geode's clipboard funcs for imgui + auto static read = geode::utils::clipboard::read(); + ImGui::GetPlatformIO().Platform_GetClipboardTextFn = [](ImGuiContext* ctx) { + read = geode::utils::clipboard::read(); + return read.c_str(); + }; + ImGui::GetPlatformIO().Platform_SetClipboardTextFn = [](ImGuiContext* ctx, const char* text) { + geode::utils::clipboard::write(text); + }; } #ifdef GEODE_IS_MOBILE @@ -219,7 +244,7 @@ void DevTools::renderDrawDataFallback(ImDrawData* draw_data) { auto* idxBuffer = list->IdxBuffer.Data; auto* vtxBuffer = list->VtxBuffer.Data; for (auto& cmd : list->CmdBuffer) { - ccGLBindTexture2D(static_cast(reinterpret_cast(cmd.GetTexID()))); + ccGLBindTexture2D(textureID(cmd.GetTexID())); const auto rect = cmd.ClipRect; const auto orig = toCocos(ImVec2(rect.x, rect.y)); @@ -306,7 +331,7 @@ void DevTools::renderDrawData(ImDrawData* draw_data) { glBufferData(GL_ELEMENT_ARRAY_BUFFER, list->IdxBuffer.Size * sizeof(ImDrawIdx), list->IdxBuffer.Data, GL_STREAM_DRAW); for (auto& cmd : list->CmdBuffer) { - ccGLBindTexture2D(static_cast(reinterpret_cast(cmd.GetTexID()))); + ccGLBindTexture2D(textureID(cmd.GetTexID())); const auto rect = cmd.ClipRect; const auto orig = toCocos(ImVec2(rect.x, rect.y)); diff --git a/src/themes.cpp b/src/themes.cpp index c194d6d..5943304 100644 --- a/src/themes.cpp +++ b/src/themes.cpp @@ -311,6 +311,10 @@ void applyCommon(ImGuiStyle& style) { // style.FrameRounding = 2.0f; // style.WindowPadding = { 3.f, 3.f }; // style.ColorButtonPosition = ImGuiDir_Left; + + //special sets for imgui 1.92.4 to keep old look of devtools + style.TabRounding = 0.f; + style.TabBarOverlineSize = 2.f; } ThemeDef getThemeDef(std::string const& name) { From 9e01079853125e8ca8d578ecbd0d77cf3c6fae06 Mon Sep 17 00:00:00 2001 From: user666 Date: Sat, 25 Oct 2025 16:05:04 +0400 Subject: [PATCH 2/9] oh i forgot a thing in platform.cpp --- src/ImGui.hpp | 15 +++++++++++++++ src/backend.cpp | 15 --------------- src/platform/platform.cpp | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/ImGui.hpp b/src/ImGui.hpp index 8aa10da..c168905 100644 --- a/src/ImGui.hpp +++ b/src/ImGui.hpp @@ -7,6 +7,21 @@ using namespace cocos2d; +// little helper function to convert ImTexture2D <=> GLuint, +// supporting both versions of imgui where this was a void* and is now a u64 +// (templated because c++ is stupid) +template +static auto textureID(auto value) { + if constexpr (std::is_same_v) { // GLuint -> ImTextureID + if constexpr (std::is_same_v) return reinterpret_cast(static_cast(value)); + else return static_cast(value); + } + else { // ImTextureID -> GLuint + if constexpr (std::is_same_v) return static_cast(reinterpret_cast(value)); + else return static_cast(value); + } +} + static std::ostream& operator<<(std::ostream& stream, ImVec2 const& vec) { return stream << vec.x << ", " << vec.y; } diff --git a/src/backend.cpp b/src/backend.cpp index a4d33f2..cd5aa40 100644 --- a/src/backend.cpp +++ b/src/backend.cpp @@ -14,21 +14,6 @@ using namespace cocos2d; // based off https://github.com/matcool/gd-imgui-cocos -// little helper function to convert ImTexture2D <=> GLuint, -// supporting both versions of imgui where this was a void* and is now a u64 -// (templated because c++ is stupid) -template -static auto textureID(auto value) { - if constexpr (std::is_same_v) { // GLuint -> ImTextureID - if constexpr (std::is_same_v) return reinterpret_cast(static_cast(value)); - else return static_cast(value); - } - else { // ImTextureID -> GLuint - if constexpr (std::is_same_v) return static_cast(reinterpret_cast(value)); - else return static_cast(value); - } -} - static bool g_useNormalPos = false; CCPoint getMousePos_H() { diff --git a/src/platform/platform.cpp b/src/platform/platform.cpp index 6088a7f..eceaee6 100644 --- a/src/platform/platform.cpp +++ b/src/platform/platform.cpp @@ -43,7 +43,7 @@ void GLRenderCtx::cleanup() { GLRenderCtx::GLRenderCtx(ImVec2 const& size) : m_size(size) {} ImTextureID GLRenderCtx::texture() const { - return reinterpret_cast(static_cast(m_texture)); + return textureID(m_texture); } ImVec2 GLRenderCtx::size() const { From 38cd0bf35e02c3b1b9e8fcc45e0a6246eb53f2b9 Mon Sep 17 00:00:00 2001 From: LatterRarity70 <90561697+LatterRarity70@users.noreply.github.com> Date: Sat, 25 Oct 2025 17:21:36 +0400 Subject: [PATCH 3/9] Update DevTools.cpp --- src/DevTools.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/DevTools.cpp b/src/DevTools.cpp index 6b5dc6a..7e765dc 100644 --- a/src/DevTools.cpp +++ b/src/DevTools.cpp @@ -250,17 +250,16 @@ void DevTools::draw(GLRenderCtx* ctx) { if (cursor != lastCursor) { lastCursor = cursor; auto winCursor = IDC_ARROW; - switch (cursor) - { - case ImGuiMouseCursor_Arrow: winCursor = IDC_ARROW; break; - case ImGuiMouseCursor_TextInput: winCursor = IDC_IBEAM; break; - case ImGuiMouseCursor_ResizeAll: winCursor = IDC_SIZEALL; break; - case ImGuiMouseCursor_ResizeEW: winCursor = IDC_SIZEWE; break; - case ImGuiMouseCursor_ResizeNS: winCursor = IDC_SIZENS; break; - case ImGuiMouseCursor_ResizeNESW: winCursor = IDC_SIZENESW; break; - case ImGuiMouseCursor_ResizeNWSE: winCursor = IDC_SIZENWSE; break; - case ImGuiMouseCursor_Hand: winCursor = IDC_HAND; break; - case ImGuiMouseCursor_NotAllowed: winCursor = IDC_NO; break; + switch (cursor) { + case ImGuiMouseCursor_Arrow: winCursor = IDC_ARROW; break; + case ImGuiMouseCursor_TextInput: winCursor = IDC_IBEAM; break; + case ImGuiMouseCursor_ResizeAll: winCursor = IDC_SIZEALL; break; + case ImGuiMouseCursor_ResizeEW: winCursor = IDC_SIZEWE; break; + case ImGuiMouseCursor_ResizeNS: winCursor = IDC_SIZENS; break; + case ImGuiMouseCursor_ResizeNESW: winCursor = IDC_SIZENESW; break; + case ImGuiMouseCursor_ResizeNWSE: winCursor = IDC_SIZENWSE; break; + case ImGuiMouseCursor_Hand: winCursor = IDC_HAND; break; + case ImGuiMouseCursor_NotAllowed: winCursor = IDC_NO; break; } if (cursorField) { cursorField->cursor = LoadCursor(NULL, winCursor); @@ -371,4 +370,5 @@ void DevTools::sceneChanged() { bool DevTools::shouldUseGDWindow() const { return Mod::get()->getSettingValue("should-use-gd-window"); -} \ No newline at end of file + +} From fd63a53c0e7d7b29831f724d48bf3b33c4751c74 Mon Sep 17 00:00:00 2001 From: LatterRarity70 <90561697+LatterRarity70@users.noreply.github.com> Date: Sat, 25 Oct 2025 17:23:35 +0400 Subject: [PATCH 4/9] Update backend.cpp --- src/backend.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/backend.cpp b/src/backend.cpp index cd5aa40..e03d23d 100644 --- a/src/backend.cpp +++ b/src/backend.cpp @@ -69,10 +69,8 @@ void DevTools::setupPlatform() { #endif // define geode's clipboard funcs for imgui - auto static read = geode::utils::clipboard::read(); ImGui::GetPlatformIO().Platform_GetClipboardTextFn = [](ImGuiContext* ctx) { - read = geode::utils::clipboard::read(); - return read.c_str(); + return geode::utils::clipboard::read().c_str(); }; ImGui::GetPlatformIO().Platform_SetClipboardTextFn = [](ImGuiContext* ctx, const char* text) { geode::utils::clipboard::write(text); From 80fa63e4f6cbb4c3a5f3f41e835a510fb3bcfeb8 Mon Sep 17 00:00:00 2001 From: LatterRarity70 <90561697+LatterRarity70@users.noreply.github.com> Date: Sat, 25 Oct 2025 17:29:36 +0400 Subject: [PATCH 5/9] Update backend.cpp --- src/backend.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/backend.cpp b/src/backend.cpp index e03d23d..2cabc0b 100644 --- a/src/backend.cpp +++ b/src/backend.cpp @@ -67,14 +67,6 @@ void DevTools::setupPlatform() { "geode::cocos::getMousePos" ); #endif - - // define geode's clipboard funcs for imgui - ImGui::GetPlatformIO().Platform_GetClipboardTextFn = [](ImGuiContext* ctx) { - return geode::utils::clipboard::read().c_str(); - }; - ImGui::GetPlatformIO().Platform_SetClipboardTextFn = [](ImGuiContext* ctx, const char* text) { - geode::utils::clipboard::write(text); - }; } #ifdef GEODE_IS_MOBILE From 45f314ac54361013c0c048dfea39ba220cb0fa70 Mon Sep 17 00:00:00 2001 From: user666 Date: Sat, 25 Oct 2025 17:40:09 +0400 Subject: [PATCH 6/9] no textureID --- src/ImGui.hpp | 15 --------------- src/backend.cpp | 6 +++--- src/platform/platform.cpp | 2 +- 3 files changed, 4 insertions(+), 19 deletions(-) diff --git a/src/ImGui.hpp b/src/ImGui.hpp index c168905..8aa10da 100644 --- a/src/ImGui.hpp +++ b/src/ImGui.hpp @@ -7,21 +7,6 @@ using namespace cocos2d; -// little helper function to convert ImTexture2D <=> GLuint, -// supporting both versions of imgui where this was a void* and is now a u64 -// (templated because c++ is stupid) -template -static auto textureID(auto value) { - if constexpr (std::is_same_v) { // GLuint -> ImTextureID - if constexpr (std::is_same_v) return reinterpret_cast(static_cast(value)); - else return static_cast(value); - } - else { // ImTextureID -> GLuint - if constexpr (std::is_same_v) return static_cast(reinterpret_cast(value)); - else return static_cast(value); - } -} - static std::ostream& operator<<(std::ostream& stream, ImVec2 const& vec) { return stream << vec.x << ", " << vec.y; } diff --git a/src/backend.cpp b/src/backend.cpp index 2cabc0b..0d2d538 100644 --- a/src/backend.cpp +++ b/src/backend.cpp @@ -57,7 +57,7 @@ void DevTools::setupPlatform() { m_fontTexture->initWithData(pixels, kCCTexture2DPixelFormat_RGBA8888, width, height, CCSize(width, height)); m_fontTexture->retain(); - io.Fonts->SetTexID(textureID(m_fontTexture->getName())); + io.Fonts->SetTexID(reinterpret_cast(static_cast(m_fontTexture->getName()))); // fixes getMousePos to be relative to the GD view #ifndef GEODE_IS_MOBILE @@ -219,7 +219,7 @@ void DevTools::renderDrawDataFallback(ImDrawData* draw_data) { auto* idxBuffer = list->IdxBuffer.Data; auto* vtxBuffer = list->VtxBuffer.Data; for (auto& cmd : list->CmdBuffer) { - ccGLBindTexture2D(textureID(cmd.GetTexID())); + ccGLBindTexture2D(static_cast(reinterpret_cast(cmd.GetTexID()))); const auto rect = cmd.ClipRect; const auto orig = toCocos(ImVec2(rect.x, rect.y)); @@ -306,7 +306,7 @@ void DevTools::renderDrawData(ImDrawData* draw_data) { glBufferData(GL_ELEMENT_ARRAY_BUFFER, list->IdxBuffer.Size * sizeof(ImDrawIdx), list->IdxBuffer.Data, GL_STREAM_DRAW); for (auto& cmd : list->CmdBuffer) { - ccGLBindTexture2D(textureID(cmd.GetTexID())); + ccGLBindTexture2D(static_cast(reinterpret_cast(cmd.GetTexID()))); const auto rect = cmd.ClipRect; const auto orig = toCocos(ImVec2(rect.x, rect.y)); diff --git a/src/platform/platform.cpp b/src/platform/platform.cpp index eceaee6..c3baf41 100644 --- a/src/platform/platform.cpp +++ b/src/platform/platform.cpp @@ -43,7 +43,7 @@ void GLRenderCtx::cleanup() { GLRenderCtx::GLRenderCtx(ImVec2 const& size) : m_size(size) {} ImTextureID GLRenderCtx::texture() const { - return textureID(m_texture); + return reinterpret_cast(static_cast(m_texture)); } ImVec2 GLRenderCtx::size() const { From 9e87552dd13d62ab903993a0b9cd920848d55d1a Mon Sep 17 00:00:00 2001 From: user666 Date: Sat, 25 Oct 2025 18:05:25 +0400 Subject: [PATCH 7/9] a? --- src/backend.cpp | 6 +++--- src/platform/platform.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/backend.cpp b/src/backend.cpp index 0d2d538..6cf7e56 100644 --- a/src/backend.cpp +++ b/src/backend.cpp @@ -57,7 +57,7 @@ void DevTools::setupPlatform() { m_fontTexture->initWithData(pixels, kCCTexture2DPixelFormat_RGBA8888, width, height, CCSize(width, height)); m_fontTexture->retain(); - io.Fonts->SetTexID(reinterpret_cast(static_cast(m_fontTexture->getName()))); + io.Fonts->SetTexID(reinterpret_cast(static_cast(m_fontTexture->getName()))); // fixes getMousePos to be relative to the GD view #ifndef GEODE_IS_MOBILE @@ -219,7 +219,7 @@ void DevTools::renderDrawDataFallback(ImDrawData* draw_data) { auto* idxBuffer = list->IdxBuffer.Data; auto* vtxBuffer = list->VtxBuffer.Data; for (auto& cmd : list->CmdBuffer) { - ccGLBindTexture2D(static_cast(reinterpret_cast(cmd.GetTexID()))); + ccGLBindTexture2D(static_cast(reinterpret_cast(cmd.GetTexID()))); const auto rect = cmd.ClipRect; const auto orig = toCocos(ImVec2(rect.x, rect.y)); @@ -306,7 +306,7 @@ void DevTools::renderDrawData(ImDrawData* draw_data) { glBufferData(GL_ELEMENT_ARRAY_BUFFER, list->IdxBuffer.Size * sizeof(ImDrawIdx), list->IdxBuffer.Data, GL_STREAM_DRAW); for (auto& cmd : list->CmdBuffer) { - ccGLBindTexture2D(static_cast(reinterpret_cast(cmd.GetTexID()))); + ccGLBindTexture2D(static_cast(reinterpret_cast(cmd.GetTexID()))); const auto rect = cmd.ClipRect; const auto orig = toCocos(ImVec2(rect.x, rect.y)); diff --git a/src/platform/platform.cpp b/src/platform/platform.cpp index c3baf41..b7dc1c9 100644 --- a/src/platform/platform.cpp +++ b/src/platform/platform.cpp @@ -43,7 +43,7 @@ void GLRenderCtx::cleanup() { GLRenderCtx::GLRenderCtx(ImVec2 const& size) : m_size(size) {} ImTextureID GLRenderCtx::texture() const { - return reinterpret_cast(static_cast(m_texture)); + return reinterpret_cast(static_cast(m_texture)); } ImVec2 GLRenderCtx::size() const { From c02dc83185e76000558bdc028b5dbee039d72777 Mon Sep 17 00:00:00 2001 From: user666 Date: Sat, 25 Oct 2025 18:18:47 +0400 Subject: [PATCH 8/9] k --- src/backend.cpp | 6 +++--- src/platform/platform.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/backend.cpp b/src/backend.cpp index 6cf7e56..d923be2 100644 --- a/src/backend.cpp +++ b/src/backend.cpp @@ -57,7 +57,7 @@ void DevTools::setupPlatform() { m_fontTexture->initWithData(pixels, kCCTexture2DPixelFormat_RGBA8888, width, height, CCSize(width, height)); m_fontTexture->retain(); - io.Fonts->SetTexID(reinterpret_cast(static_cast(m_fontTexture->getName()))); + io.Fonts->SetTexID(static_cast(m_fontTexture->getName())); // fixes getMousePos to be relative to the GD view #ifndef GEODE_IS_MOBILE @@ -219,7 +219,7 @@ void DevTools::renderDrawDataFallback(ImDrawData* draw_data) { auto* idxBuffer = list->IdxBuffer.Data; auto* vtxBuffer = list->VtxBuffer.Data; for (auto& cmd : list->CmdBuffer) { - ccGLBindTexture2D(static_cast(reinterpret_cast(cmd.GetTexID()))); + ccGLBindTexture2D(static_cast(cmd.GetTexID())); const auto rect = cmd.ClipRect; const auto orig = toCocos(ImVec2(rect.x, rect.y)); @@ -306,7 +306,7 @@ void DevTools::renderDrawData(ImDrawData* draw_data) { glBufferData(GL_ELEMENT_ARRAY_BUFFER, list->IdxBuffer.Size * sizeof(ImDrawIdx), list->IdxBuffer.Data, GL_STREAM_DRAW); for (auto& cmd : list->CmdBuffer) { - ccGLBindTexture2D(static_cast(reinterpret_cast(cmd.GetTexID()))); + ccGLBindTexture2D(static_cast(cmd.GetTexID())); const auto rect = cmd.ClipRect; const auto orig = toCocos(ImVec2(rect.x, rect.y)); diff --git a/src/platform/platform.cpp b/src/platform/platform.cpp index b7dc1c9..f045c38 100644 --- a/src/platform/platform.cpp +++ b/src/platform/platform.cpp @@ -43,7 +43,7 @@ void GLRenderCtx::cleanup() { GLRenderCtx::GLRenderCtx(ImVec2 const& size) : m_size(size) {} ImTextureID GLRenderCtx::texture() const { - return reinterpret_cast(static_cast(m_texture)); + return static_cast(m_texture); } ImVec2 GLRenderCtx::size() const { From 410edfec45bb52a129bd7286edade6cd48188a04 Mon Sep 17 00:00:00 2001 From: matcool <26722564+matcool@users.noreply.github.com> Date: Sun, 2 Nov 2025 11:19:17 -0300 Subject: [PATCH 9/9] reorganize --- src/DevTools.cpp | 94 ++++++++++++--------------------------- src/platform/Win32.cpp | 51 ++++++++++++++++++++- src/platform/platform.hpp | 5 +++ 3 files changed, 83 insertions(+), 67 deletions(-) diff --git a/src/DevTools.cpp b/src/DevTools.cpp index 7e765dc..bbc46a6 100644 --- a/src/DevTools.cpp +++ b/src/DevTools.cpp @@ -106,30 +106,36 @@ void DevTools::addCustomCallback(std::function callback) { m_customCallbacks.push_back(std::move(callback)); } +// Scroll when dragging empty space +void mobileScrollBehavior() { + auto* ctx = ImGui::GetCurrentContext(); + auto* window = ctx->CurrentWindow; + if (!window) return; + + bool hovered = false; + bool held = false; + ImGuiID id = window->GetID("##scroll_dragging_overlay"); + ImGui::KeepAliveID(id); + // If nothing hovered so far in the frame (not same as IsAnyItemHovered()!) + if (ctx->HoveredId == 0) { + ImGui::ButtonBehavior(window->Rect(), id, &hovered, &held, ImGuiButtonFlags_MouseButtonLeft); + } + if (held) { + ImVec2 delta = ImGui::GetIO().MouseDownDuration[0] > 0.1 ? -ImGui::GetIO().MouseDelta : ImVec2(0, 0); + if (std::abs(delta.x) >= 0.1f || std::abs(delta.y) >= 0.1f) { + ImGui::SetScrollX(window, window->Scroll.x + delta.x); + ImGui::SetScrollY(window, window->Scroll.y + delta.y); + } + } +} + void DevTools::drawPage(const char* name, void(DevTools::*pageFun)()) { if (ImGui::Begin(name, nullptr, ImGuiWindowFlags_HorizontalScrollbar)) { - - // Fix wrapping after window resize - ImGui::PushTextWrapPos(ImGui::GetContentRegionAvail().x); - (this->*pageFun)(); - // Scroll when dragging (useful for android users) - auto mouse_dt = ImGui::GetIO().MouseDelta; - ImVec2 delta = ImGui::GetIO().MouseDownDuration[0] > 0.1 ? ImVec2(mouse_dt.x * -1, mouse_dt.y * -1) : ImVec2(0, 0); - ImGuiContext& g = *ImGui::GetCurrentContext(); - ImGuiWindow* window = g.CurrentWindow; - if (!window) return; - bool hovered = false; - bool held = false; - ImGuiID id = window->GetID("##scrolldraggingoverlay"); - ImGui::KeepAliveID(id); - ImGuiButtonFlags button_flags = ImGuiButtonFlags_MouseButtonLeft; - if (g.HoveredId == 0) // If nothing hovered so far in the frame (not same as IsAnyItemHovered()!) - ImGui::ButtonBehavior(window->Rect(), id, &hovered, &held, button_flags); - if (held && fabs(delta.x) >= 0.1f) ImGui::SetScrollX(window, window->Scroll.x + delta.x); - if (held && fabs(delta.y) >= 0.1f) ImGui::SetScrollY(window, window->Scroll.y + delta.y); - +#ifdef GEODE_IS_MOBILE + mobileScrollBehavior(); +#endif } ImGui::End(); } @@ -230,50 +236,9 @@ void DevTools::draw(GLRenderCtx* ctx) { ImGui::PopFont(); } -#ifdef GEODE_IS_WINDOWS // Windows exclusive cursor updates from imgui-cocos - - // Shows imgui's cursor instead of hidden cursor if out of GD Window - auto isCursorVisible = false; - CURSORINFO ci = { sizeof(ci) }; //winapi - if (GetCursorInfo(&ci)) isCursorVisible = (ci.flags & CURSOR_SHOWING) != 0; - ImGui::GetIO().MouseDrawCursor = m_visible and !isCursorVisible and !shouldPassEventsToGDButTransformed(); - - struct GLFWCursorData { - void* next = nullptr; - HCURSOR cursor; - }; - auto& cursorField = *reinterpret_cast(reinterpret_cast( - CCEGLView::get()->getWindow()) + 0x50); - - auto cursor = ImGui::GetIO().MouseDrawCursor ? ImGuiMouseCursor_None : ImGui::GetMouseCursor(); - static ImGuiMouseCursor lastCursor = ImGuiMouseCursor_COUNT; - if (cursor != lastCursor) { - lastCursor = cursor; - auto winCursor = IDC_ARROW; - switch (cursor) { - case ImGuiMouseCursor_Arrow: winCursor = IDC_ARROW; break; - case ImGuiMouseCursor_TextInput: winCursor = IDC_IBEAM; break; - case ImGuiMouseCursor_ResizeAll: winCursor = IDC_SIZEALL; break; - case ImGuiMouseCursor_ResizeEW: winCursor = IDC_SIZEWE; break; - case ImGuiMouseCursor_ResizeNS: winCursor = IDC_SIZENS; break; - case ImGuiMouseCursor_ResizeNESW: winCursor = IDC_SIZENESW; break; - case ImGuiMouseCursor_ResizeNWSE: winCursor = IDC_SIZENWSE; break; - case ImGuiMouseCursor_Hand: winCursor = IDC_HAND; break; - case ImGuiMouseCursor_NotAllowed: winCursor = IDC_NO; break; - } - if (cursorField) { - cursorField->cursor = LoadCursor(NULL, winCursor); - } - else { - // must be heap allocated - cursorField = new GLFWCursorData{ - .next = nullptr, - .cursor = LoadCursor(NULL, winCursor) - }; - } - } +#ifdef GEODE_IS_WINDOWS + setMouseCursor(); #endif - } void DevTools::setupFonts() { @@ -322,9 +287,6 @@ void DevTools::setup() { // io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; io.ConfigWindowsResizeFromEdges = true; - // Allow user scaling text of individual window with CTRL+Wheel. - io.FontAllowUserScaling = true; - this->setupFonts(); this->setupPlatform(); diff --git a/src/platform/Win32.cpp b/src/platform/Win32.cpp index b16cb2b..94c337c 100644 --- a/src/platform/Win32.cpp +++ b/src/platform/Win32.cpp @@ -44,4 +44,53 @@ std::string formatAddressIntoOffsetImpl(uintptr_t addr, bool module) { return fmt::format("{:#x}", addr - reinterpret_cast(mod)); } -#endif \ No newline at end of file +// mostly copied from gd-imgui-cocos +void setMouseCursor() { + // Shows imgui's cursor instead of hidden cursor if out of GD Window + bool isCursorVisible = false; + CURSORINFO ci = { sizeof(ci) }; + if (GetCursorInfo(&ci)) { + isCursorVisible = (ci.flags & CURSOR_SHOWING) != 0; + } + // whether to draw a fake cursor + ImGui::GetIO().MouseDrawCursor = DevTools::get()->isVisible() && !isCursorVisible && !shouldPassEventsToGDButTransformed(); + + struct GLFWCursorData { + void* next = nullptr; + HCURSOR cursor; + }; + auto& cursorField = *reinterpret_cast(reinterpret_cast( + CCEGLView::get()->getWindow()) + 0x50); + + auto cursor = ImGui::GetIO().MouseDrawCursor ? ImGuiMouseCursor_None : ImGui::GetMouseCursor(); + static ImGuiMouseCursor lastCursor = ImGuiMouseCursor_COUNT; + if (cursor != lastCursor) { + lastCursor = cursor; + + auto winCursor = IDC_ARROW; + switch (cursor) { + case ImGuiMouseCursor_Arrow: winCursor = IDC_ARROW; break; + case ImGuiMouseCursor_TextInput: winCursor = IDC_IBEAM; break; + case ImGuiMouseCursor_ResizeAll: winCursor = IDC_SIZEALL; break; + case ImGuiMouseCursor_ResizeEW: winCursor = IDC_SIZEWE; break; + case ImGuiMouseCursor_ResizeNS: winCursor = IDC_SIZENS; break; + case ImGuiMouseCursor_ResizeNESW: winCursor = IDC_SIZENESW; break; + case ImGuiMouseCursor_ResizeNWSE: winCursor = IDC_SIZENWSE; break; + case ImGuiMouseCursor_Hand: winCursor = IDC_HAND; break; + case ImGuiMouseCursor_NotAllowed: winCursor = IDC_NO; break; + } + if (cursorField) { + cursorField->cursor = LoadCursor(NULL, winCursor); + } + else { + // must be heap allocated + cursorField = new GLFWCursorData { + .next = nullptr, + .cursor = LoadCursor(NULL, winCursor) + }; + } + } +} + +#endif + diff --git a/src/platform/platform.hpp b/src/platform/platform.hpp index 1e6e2f6..740cb78 100644 --- a/src/platform/platform.hpp +++ b/src/platform/platform.hpp @@ -8,6 +8,7 @@ #elif defined(GEODE_IS_IOS) #include #endif +#include ImRect& getGDWindowRect(); bool& shouldPassEventsToGDButTransformed(); @@ -35,3 +36,7 @@ class GLRenderCtx final { bool begin(); void end(); }; + +#ifdef GEODE_IS_WINDOWS +void setMouseCursor(); +#endif \ No newline at end of file