Skip to content

Commit d724b1a

Browse files
committed
Merge branch 'main' of https://github.com/geode-sdk/DevTools into drag-button
2 parents dea71bc + 618dfc5 commit d724b1a

File tree

8 files changed

+72
-23
lines changed

8 files changed

+72
-23
lines changed

.github/workflows/build.yml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ name: Build Geode Mod
22

33
on:
44
workflow_dispatch:
5+
pull_request:
56
push:
67
branches:
78
- '**'

CMakeLists.txt

+7
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ target_sources(${PROJECT_NAME} PRIVATE
3434
${imgui_SOURCE_DIR}/misc/cpp/imgui_stdlib.cpp
3535
)
3636

37+
# Love you imgui
38+
include(CheckCXXCompilerFlag)
39+
check_cxx_compiler_flag(-Wnontrivial-memcall HAVE_NONTRIVIAL_MEMCALL)
40+
if (HAVE_NONTRIVIAL_MEMCALL)
41+
target_compile_options(${PROJECT_NAME} PRIVATE -Wno-nontrivial-memcall)
42+
endif()
43+
3744
# i still dont like this (alk)
3845
target_compile_definitions(geode-sdk INTERFACE GEODE_EXPOSE_SECRET_INTERNALS_IN_HEADERS_DO_NOT_DEFINE_PLEASE)
3946

src/DevTools.cpp

+19-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#include <imgui_internal.h>
32
#include "DevTools.hpp"
43
#include "fonts/FeatherIcons.hpp"
@@ -203,11 +202,15 @@ void DevTools::setupFonts() {
203202
void* font, size_t realSize, float size, const ImWchar* range
204203
) {
205204
auto& io = ImGui::GetIO();
205+
// AddFontFromMemoryTTF assumes ownership of the passed data unless you configure it not to.
206+
// Our font data has static lifetime, so we're handling the ownership.
207+
206208
ImFontConfig config;
207-
config.MergeMode = true;
209+
config.FontDataOwnedByAtlas = false;
208210
auto* result = io.Fonts->AddFontFromMemoryTTF(
209-
font, realSize, size, nullptr, range
211+
font, realSize, size, &config, range
210212
);
213+
config.MergeMode = true;
211214
io.Fonts->AddFontFromMemoryTTF(
212215
Font_FeatherIcons, sizeof(Font_FeatherIcons), size - 4.f, &config, icon_ranges
213216
);
@@ -227,7 +230,7 @@ void DevTools::setup() {
227230

228231
IMGUI_CHECKVERSION();
229232

230-
auto ctx = ImGui::CreateContext();
233+
ImGui::CreateContext();
231234

232235
auto& io = ImGui::GetIO();
233236
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
@@ -248,23 +251,27 @@ void DevTools::setup() {
248251

249252
void DevTools::destroy() {
250253
if (!m_setup) return;
251-
m_setup = false;
252-
m_visible = false;
254+
this->show(false);
255+
auto& io = ImGui::GetIO();
256+
io.BackendPlatformUserData = nullptr;
257+
m_fontTexture->release();
258+
m_fontTexture = nullptr;
253259

254-
// crashes :(
255-
// ImGui::DestroyContext();
260+
ImGui::DestroyContext();
261+
m_setup = false;
262+
m_reloadTheme = true;
256263
}
257264

258265
void DevTools::show(bool visible) {
259266
m_visible = visible;
267+
268+
auto& io = ImGui::GetIO();
269+
io.WantCaptureMouse = visible;
270+
io.WantCaptureKeyboard = visible;
260271
}
261272

262273
void DevTools::toggle() {
263274
this->show(!m_visible);
264-
if (!m_visible) {
265-
ImGui::GetIO().WantCaptureMouse = false;
266-
ImGui::GetIO().WantCaptureKeyboard = false;
267-
}
268275
}
269276

270277
void DevTools::sceneChanged() {

src/DevTools.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <Geode/utils/addresser.hpp>
99
#include <Geode/loader/Loader.hpp>
1010
#include <Geode/loader/ModMetadata.hpp>
11-
#include <unordered_map>
1211

1312
using namespace geode::prelude;
1413

@@ -49,6 +48,7 @@ class DevTools {
4948
ImFont* m_smallFont = nullptr;
5049
ImFont* m_monoFont = nullptr;
5150
ImFont* m_boxFont = nullptr;
51+
CCTexture2D* m_fontTexture = nullptr;
5252
Ref<CCNode> m_selectedNode;
5353
std::vector<std::pair<CCNode*, HighlightMode>> m_toHighlight;
5454

src/backend.cpp

+37-7
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,30 @@ using namespace cocos2d;
1111

1212
// based off https://github.com/matcool/gd-imgui-cocos
1313

14-
void DevTools::setupPlatform() {
15-
ImGui::CreateContext();
14+
static bool g_useNormalPos = false;
15+
16+
CCPoint getMousePos_H() {
17+
CCPoint mouse = cocos::getMousePos();
18+
const auto pos = toVec2(mouse);
19+
20+
if (DevTools::get()->shouldUseGDWindow() && shouldPassEventsToGDButTransformed() && !g_useNormalPos) {
21+
auto win = ImGui::GetMainViewport()->Size;
22+
const auto gdRect = getGDWindowRect();
1623

24+
auto relativePos = ImVec2(
25+
pos.x - gdRect.Min.x,
26+
pos.y - gdRect.Min.y
27+
);
28+
auto x = (relativePos.x / gdRect.GetWidth()) * win.x;
29+
auto y = (relativePos.y / gdRect.GetHeight()) * win.y;
30+
31+
mouse = toCocos(ImVec2(x, y));
32+
}
33+
34+
return mouse;
35+
}
36+
37+
void DevTools::setupPlatform() {
1738
auto& io = ImGui::GetIO();
1839

1940
io.BackendPlatformUserData = this;
@@ -29,13 +50,20 @@ void DevTools::setupPlatform() {
2950
int width, height;
3051
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
3152

32-
auto* tex2d = new CCTexture2D;
33-
tex2d->initWithData(pixels, kCCTexture2DPixelFormat_RGBA8888, width, height, CCSize(width, height));
53+
m_fontTexture = new CCTexture2D;
54+
m_fontTexture->initWithData(pixels, kCCTexture2DPixelFormat_RGBA8888, width, height, CCSize(width, height));
55+
m_fontTexture->retain();
3456

35-
// TODO: not leak this :-)
36-
tex2d->retain();
57+
io.Fonts->SetTexID(reinterpret_cast<ImTextureID>(static_cast<intptr_t>(m_fontTexture->getName())));
3758

38-
io.Fonts->SetTexID(reinterpret_cast<ImTextureID>(static_cast<intptr_t>(tex2d->getName())));
59+
// fixes getMousePos to be relative to the GD view
60+
#ifndef GEODE_IS_MOBILE
61+
(void) Mod::get()->hook(
62+
reinterpret_cast<void*>(addresser::getNonVirtual(&geode::cocos::getMousePos)),
63+
&getMousePos_H,
64+
"geode::cocos::getMousePos"
65+
);
66+
#endif
3967
}
4068

4169
void DevTools::newFrame() {
@@ -54,7 +82,9 @@ void DevTools::newFrame() {
5482
io.DeltaTime = director->getDeltaTime();
5583

5684
#ifdef GEODE_IS_DESKTOP
85+
g_useNormalPos = true;
5786
const auto mousePos = toVec2(geode::cocos::getMousePos());
87+
g_useNormalPos = false;
5888
io.AddMousePosEvent(mousePos.x, mousePos.y);
5989
#endif
6090

src/pages/Attributes.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include <misc/cpp/imgui_stdlib.h>
55
#include <Geode/binding/CCMenuItemSpriteExtra.hpp>
66
#include "../platform/utils.hpp"
7+
#include <ccTypes.h>
8+
#include <Geode/ui/Layout.hpp>
79

810
using namespace geode::prelude;
911

@@ -132,7 +134,7 @@ void DevTools::drawNodeAttributes(CCNode* node) {
132134
auto color = rgbaNode->getColor();
133135
float _color[4] = { color.r / 255.f, color.g / 255.f, color.b / 255.f, rgbaNode->getOpacity() / 255.f };
134136
if (ImGui::ColorEdit4("Color", _color)) {
135-
rgbaNode->setColor(ccColor3B{
137+
rgbaNode->setColor(ccColor3B {
136138
static_cast<GLubyte>(_color[0] * 255),
137139
static_cast<GLubyte>(_color[1] * 255),
138140
static_cast<GLubyte>(_color[2] * 255)

src/pages/GeometryDash.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <Geode/utils/ranges.hpp>
55
#include <Geode/binding/FLAlertLayer.hpp>
66
#include <Geode/binding/GJDropDownLayer.hpp>
7+
#include <Geode/ui/Layout.hpp>
78

89
void drawRowAxisArrow(
910
ImDrawList& foreground,
@@ -285,8 +286,8 @@ void DevTools::drawGD(GLRenderCtx* gdCtx) {
285286

286287
auto pad = ImGui::GetStyle().FramePadding.x;
287288

288-
auto winPos = ImGui::GetCursorScreenPos();
289-
auto winSize = ImGui::GetContentRegionAvail();
289+
auto winPos = ImGui::GetCursorScreenPos();
290+
auto winSize = ImGui::GetContentRegionAvail();
290291

291292
ImVec2 imgSize = {
292293
(winSize.y - pad * 2) * ratio,

src/pages/Settings.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <Geode/modify/AppDelegate.hpp>
77
#include <fmod.hpp>
88
#include <numeric>
9+
#include <Geode/binding/GameManager.hpp>
910
#include "../nodes/DragButton.hpp"
1011

1112
using namespace geode::prelude;

0 commit comments

Comments
 (0)