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: 4 additions & 0 deletions include/API.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ namespace devtools {
/// @return True if DevTools is open, false otherwise.
inline bool isOpen() GEODE_EVENT_EXPORT_NORES(&isOpen, ());

/// @brief Checks if the mouse is in the DevTools window.
/// @return True if the mouse is in the DevTools window, false otherwise.
inline bool isMouseInDevTools() GEODE_EVENT_EXPORT_NORES(&isMouseInDevTools, ());

/// @brief Waits for DevTools to be loaded and then calls the provided callback.
/// @param callback The function to call once DevTools is loaded.
template <typename F>
Expand Down
2 changes: 1 addition & 1 deletion mod.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"geode": "5.7.1",
"geode": "5.8.2",
"version": "v1.14.0",
"gd": {
"win": "2.2081",
Expand Down
3 changes: 3 additions & 0 deletions src/API.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ static void handleType() {
bool devtools::isOpen() {
return DevTools::get()->isVisible();
}
bool devtools::isMouseInDevTools() {
return !shouldPassEventsToGDButTransformed();
}
void devtools::newLine() {
ImGui::NewLine();
}
Expand Down
56 changes: 30 additions & 26 deletions src/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,37 +375,37 @@ class $modify(CCTouchDispatcher) {
const auto pos = toVec2(touch->getLocation());
GEODE_MOBILE(io.AddMouseSourceEvent(ImGuiMouseSource_TouchScreen);)
io.AddMousePosEvent(pos.x, pos.y);
if (io.WantCaptureMouse) {
bool didGDSwallow = false;

if (DevTools::get()->shouldUseGDWindow() && shouldPassEventsToGDButTransformed()) {
auto win = ImGui::GetMainViewport()->Size;
const auto gdRect = getGDWindowRect();
if (gdRect.Contains(pos) && !DevTools::get()->pausedGame()) {
auto relativePos = ImVec2(
pos.x - gdRect.Min.x,
pos.y - gdRect.Min.y
);
auto x = (relativePos.x / gdRect.GetWidth()) * win.x;
auto y = (1.f - relativePos.y / gdRect.GetHeight()) * win.y;

auto pos = toCocos(ImVec2(x, y));
// setTouchInfo messes up the previous location (causes issues like texturer loader's draggable nodes breaking)
touch->m_point = pos;
if (type == CCTOUCHBEGAN) {
// makes the start location in the touch correct
touch->m_startPoint = pos;
}

if (DevTools::get()->shouldUseGDWindow()) {
auto win = ImGui::GetMainViewport()->Size;
const auto gdRect = getGDWindowRect();
if ((gdRect.Contains(pos) || touchFromGD()) && !DevTools::get()->pausedGame()) {
auto relativePos = ImVec2(
pos.x - gdRect.Min.x,
pos.y - gdRect.Min.y
);
auto x = (relativePos.x / gdRect.GetWidth()) * win.x;
auto y = (1.f - relativePos.y / gdRect.GetHeight()) * win.y;

auto pos = toCocos(ImVec2(x, y));
// setTouchInfo messes up the previous location (causes issues like texturer loader's draggable nodes breaking)
touch->m_point = pos;
if (type == CCTOUCHBEGAN && shouldPassEventsToGDButTransformed()) {
touchFromGD() = true;
// makes the start location in the touch correct
touch->m_startPoint = pos;
}

if (touchFromGD()) {
CCTouchDispatcher::touches(touches, event, type);

ImGui::SetWindowFocus("Geometry Dash");
didGDSwallow = true;
ImGui::SetWindowFocus(getTitle().c_str());
io.AddMouseButtonEvent(0, false);
}
}

// TODO: dragging out of gd makes it click in imgui
if (!didGDSwallow) {
}
if (io.WantCaptureMouse) {
if (!touchFromGD()) {
if (type == CCTOUCHBEGAN || type == CCTOUCHMOVED) {
GEODE_MOBILE(io.AddMouseSourceEvent(ImGuiMouseSource_TouchScreen);)
io.AddMouseButtonEvent(0, true);
Expand All @@ -414,6 +414,10 @@ class $modify(CCTouchDispatcher) {
io.AddMouseButtonEvent(0, false);
}
}

if (type == CCTOUCHENDED || type == CCTOUCHCANCELLED) {
touchFromGD() = false;
}
}
else {
if (type != CCTOUCHMOVED) {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/GeometryDash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,11 @@ void DevTools::drawLayoutHighlights(CCNode* node) {
void DevTools::drawGD(GLRenderCtx* gdCtx) {
if (gdCtx) {
auto winSize = CCDirector::get()->getWinSize();
auto title = fmt::format(
getTitle() = fmt::format(
"Geometry Dash ({}x{})###devtools/geometry-dash",
winSize.width, winSize.height
);
if (ImGui::Begin(title.c_str())) {
if (ImGui::Begin(getTitle().c_str())) {
auto list = ImGui::GetWindowDrawList();
auto ratio = gdCtx->size().x / gdCtx->size().y;

Expand Down
10 changes: 10 additions & 0 deletions src/platform/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ using namespace geode::prelude;
static bool g_shouldPassEventsToGDButTransformed = false;
static bool g_updateBuffer = false;
static ImRect g_GDWindowRect;
static bool g_touchFromGD = false;
static std::string g_title;

ImRect& getGDWindowRect() {
return g_GDWindowRect;
Expand All @@ -21,6 +23,14 @@ bool& shouldUpdateGDRenderBuffer() {
return g_updateBuffer;
}

bool& touchFromGD() {
return g_touchFromGD;
}

std::string& getTitle() {
return g_title;
}

GLRenderCtx::~GLRenderCtx() {
this->cleanup();
}
Expand Down
2 changes: 2 additions & 0 deletions src/platform/platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
ImRect& getGDWindowRect();
bool& shouldPassEventsToGDButTransformed();
bool& shouldUpdateGDRenderBuffer();
bool& touchFromGD();
std::string& getTitle();

class GLRenderCtx final {
private:
Expand Down
Loading