Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
34 changes: 33 additions & 1 deletion src/DevTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,36 @@ void DevTools::addCustomCallback(std::function<void(CCNode*)> 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)) {
(this->*pageFun)();

#ifdef GEODE_IS_MOBILE
mobileScrollBehavior();
#endif
}
ImGui::End();
}
Expand Down Expand Up @@ -208,6 +235,10 @@ void DevTools::draw(GLRenderCtx* ctx) {
if (this->shouldUseGDWindow()) this->drawGD(ctx);
ImGui::PopFont();
}

#ifdef GEODE_IS_WINDOWS
setMouseCursor();
#endif
}

void DevTools::setupFonts() {
Expand Down Expand Up @@ -301,4 +332,5 @@ void DevTools::sceneChanged() {

bool DevTools::shouldUseGDWindow() const {
return Mod::get()->getSettingValue<bool>("should-use-gd-window");
}

}
6 changes: 3 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(static_cast<ImTextureID>(m_fontTexture->getName()));

// fixes getMousePos to be relative to the GD view
#ifndef GEODE_IS_MOBILE
Expand Down Expand Up @@ -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<GLuint>(reinterpret_cast<intptr_t>(cmd.GetTexID())));
ccGLBindTexture2D(static_cast<GLuint>(cmd.GetTexID()));

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

const auto rect = cmd.ClipRect;
const auto orig = toCocos(ImVec2(rect.x, rect.y));
Expand Down
51 changes: 50 additions & 1 deletion src/platform/Win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,53 @@ std::string formatAddressIntoOffsetImpl(uintptr_t addr, bool module) {
return fmt::format("{:#x}", addr - reinterpret_cast<uintptr_t>(mod));
}

#endif
// 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<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) {
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

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 static_cast<ImTextureID>(m_texture);
}

ImVec2 GLRenderCtx::size() const {
Expand Down
5 changes: 5 additions & 0 deletions src/platform/platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#elif defined(GEODE_IS_IOS)
#include <OpenGLES/ES2/gl.h>
#endif
#include <Geode/platform/cplatform.h>

ImRect& getGDWindowRect();
bool& shouldPassEventsToGDButTransformed();
Expand Down Expand Up @@ -35,3 +36,7 @@ class GLRenderCtx final {
bool begin();
void end();
};

#ifdef GEODE_IS_WINDOWS
void setMouseCursor();
#endif
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