Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ imgui/**
imgui

**/.DS_Store
.cache/
.cache/
/CMakeSettings.json
/.vs
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
70 changes: 70 additions & 0 deletions src/DevTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,28 @@ void DevTools::addCustomCallback(std::function<void(CCNode*)> 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();
}
Expand Down Expand Up @@ -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<GLFWCursorData**>(reinterpret_cast<uintptr_t>(
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)
{
Comment thread
matcool marked this conversation as resolved.
Outdated
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() {
Expand Down Expand Up @@ -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();

Expand Down
15 changes: 15 additions & 0 deletions src/ImGui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <class T = ImTextureID>
static auto textureID(auto value) {
if constexpr (std::is_same_v<decltype(value), GLuint>) { // GLuint -> ImTextureID
if constexpr (std::is_same_v<T, void*>) return reinterpret_cast<T>(static_cast<std::uintptr_t>(value));
else return static_cast<T>(value);
}
else { // ImTextureID -> GLuint
if constexpr (std::is_same_v<T, void*>) return static_cast<GLuint>(reinterpret_cast<std::uintptr_t>(value));
else return static_cast<GLuint>(value);
}
}

Comment thread
matcool marked this conversation as resolved.
Outdated
static std::ostream& operator<<(std::ostream& stream, ImVec2 const& vec) {
return stream << vec.x << ", " << vec.y;
}
Expand Down
16 changes: 13 additions & 3 deletions src/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ImTextureID>(static_cast<intptr_t>(m_fontTexture->getName())));
io.Fonts->SetTexID(textureID(m_fontTexture->getName()));

// fixes getMousePos to be relative to the GD view
#ifndef GEODE_IS_MOBILE
Expand All @@ -67,6 +67,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);
};
Comment thread
matcool marked this conversation as resolved.
Outdated
}

#ifdef GEODE_IS_MOBILE
Expand Down Expand Up @@ -219,7 +229,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<GLuint>(reinterpret_cast<intptr_t>(cmd.GetTexID())));
ccGLBindTexture2D(textureID(cmd.GetTexID()));

const auto rect = cmd.ClipRect;
const auto orig = toCocos(ImVec2(rect.x, rect.y));
Expand Down Expand Up @@ -306,7 +316,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<GLuint>(reinterpret_cast<intptr_t>(cmd.GetTexID())));
ccGLBindTexture2D(textureID(cmd.GetTexID()));

const auto rect = cmd.ClipRect;
const auto orig = toCocos(ImVec2(rect.x, rect.y));
Expand Down
2 changes: 1 addition & 1 deletion src/platform/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void GLRenderCtx::cleanup() {
GLRenderCtx::GLRenderCtx(ImVec2 const& size) : m_size(size) {}

ImTextureID GLRenderCtx::texture() const {
return reinterpret_cast<ImTextureID>(static_cast<uintptr_t>(m_texture));
return textureID(m_texture);
}

ImVec2 GLRenderCtx::size() const {
Expand Down
4 changes: 4 additions & 0 deletions src/themes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down