diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b52092..908ecd9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ endif() project(DevTools VERSION 1.0.0) -file(GLOB_RECURSE SOURCES +file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS src/*.cpp ) diff --git a/mod.json b/mod.json index 9f3e326..e7f6f6f 100644 --- a/mod.json +++ b/mod.json @@ -26,5 +26,10 @@ "description": "Determines if the DevTools should use a custom GD window or not. Required to disable for some exotic configurations (MacOS Wine).", "default": true } + }, + "resources": { + "sprites": [ + "resources/*.png" + ] } } diff --git a/resources/devtools.png b/resources/devtools.png new file mode 100755 index 0000000..741f0fe Binary files /dev/null and b/resources/devtools.png differ diff --git a/src/DevTools.cpp b/src/DevTools.cpp index 6ab71b9..434d2f4 100644 --- a/src/DevTools.cpp +++ b/src/DevTools.cpp @@ -9,6 +9,7 @@ #include #include #include "ImGui.hpp" +#include "nodes/DragButton.hpp" template<> struct matjson::Serialize { @@ -26,7 +27,13 @@ struct matjson::Serialize { .showMemoryViewer = value["show_memory_viewer"].asBool().unwrapOr(std::move(defaults.showMemoryViewer)), .showModGraph = value["show_mod_graph"].asBool().unwrapOr(std::move(defaults.showModGraph)), .theme = value["theme"].asString().unwrapOr(std::move(defaults.theme)), - .themeColor = value["theme_color"].as().isOk() ? value["theme_color"].as().unwrap() : std::move(defaults.themeColor) + .themeColor = value["theme_color"].as().isOk() ? value["theme_color"].as().unwrap() : std::move(defaults.themeColor), + .buttonPos = CCPoint{ + value["button_x"].as().isOk() ? value["button_x"].as().unwrap() : std::move(defaults.buttonPos.x), + value["button_y"].as().isOk() ? value["button_y"].as().unwrap() : std::move(defaults.buttonPos.y) + }, + .buttonInEditor = value["button_editor"].asBool().isOk() ? value["button_editor"].asBool().unwrap() : std::move(defaults.buttonInEditor), + .buttonInGame = value["button_game"].asBool().isOk() ? value["button_game"].asBool().unwrap() : std::move(defaults.buttonInGame) }); } @@ -43,6 +50,10 @@ struct matjson::Serialize { { "show_mod_graph", settings.showModGraph }, { "theme", settings.theme }, { "theme_color", settings.themeColor }, + { "button_x", settings.buttonPos.x }, + { "button_y", settings.buttonPos.y }, + { "button_editor", settings.buttonInEditor }, + { "button_game", settings.buttonInGame }, }); } }; @@ -55,7 +66,10 @@ DevTools* DevTools::get() { } void DevTools::loadSettings() { m_settings = Mod::get()->getSavedValue("settings"); } -void DevTools::saveSettings() { Mod::get()->setSavedValue("settings", m_settings); } +void DevTools::saveSettings() { + m_settings.buttonPos = DragButton::get()->getPosition(); + Mod::get()->setSavedValue("settings", m_settings); +} Settings DevTools::getSettings() { return m_settings; } bool DevTools::shouldPopGame() const { diff --git a/src/DevTools.hpp b/src/DevTools.hpp index 614c303..57a2ecf 100644 --- a/src/DevTools.hpp +++ b/src/DevTools.hpp @@ -29,6 +29,9 @@ struct Settings { bool showModGraph = false; std::string theme = DARK_THEME; ccColor4B themeColor = {2, 119, 189, 255}; + CCPoint buttonPos = {50, 50}; + bool buttonInEditor = false; + bool buttonInGame = false; }; class DevTools { @@ -49,6 +52,9 @@ class DevTools { Ref m_selectedNode; std::vector> m_toHighlight; std::vector> m_customCallbacks; + std::string m_searchQuery; + std::string m_prevQuery; + std::unordered_map m_nodeOpen; void setupFonts(); void setupPlatform(); @@ -84,6 +90,8 @@ class DevTools { void renderDrawData(ImDrawData*); void renderDrawDataFallback(ImDrawData*); + bool searchBranch(CCNode* node); + bool hasExtension(const std::string& ext) const; DevTools() { loadSettings(); } diff --git a/src/backend.cpp b/src/backend.cpp index cf94671..38a1210 100644 --- a/src/backend.cpp +++ b/src/backend.cpp @@ -1,7 +1,10 @@ #include #include #include +#include #include +#include "Geode/cocos/text_input_node/CCIMEDelegate.h" +#include "Geode/platform/cplatform.h" #include "platform/platform.hpp" #include "DevTools.hpp" #include "ImGui.hpp" @@ -66,6 +69,65 @@ void DevTools::setupPlatform() { #endif } +#ifdef GEODE_IS_MOBILE + +class DevToolsIMEDelegate : public CCIMEDelegate { +protected: + bool m_attached = false; + std::string m_text; +public: + bool attachWithIME() override { + if (CCIMEDelegate::attachWithIME()) { + // being anywhere but end of line ends up messing up the text, so this sends it to the end of the line + #ifdef GEODE_IS_ANDROID + ImGui::GetIO().AddKeyEvent(ImGuiKey_End, true); + ImGui::GetIO().AddKeyEvent(ImGuiKey_End, false); + #endif + m_attached = true; + CCEGLView::get()->setIMEKeyboardState(true); + return true; + } + return false; + } + + bool detachWithIME() override { + if (CCIMEDelegate::detachWithIME()) { + m_attached = false; + CCEGLView::get()->setIMEKeyboardState(false); + ImGui::ClearActiveID(); + return true; + } + return false; + } + + bool canAttachWithIME() override { + return true; + } + + bool canDetachWithIME() override { + return true; + } + + char const* getContentText() override { + m_text = ""; + for (auto str : ImGui::GetInputTextState(ImGui::GetFocusID())->TextA) { + m_text += str; + } + return m_text.c_str(); + } + + bool isAttached() { + return m_attached; + } + + static DevToolsIMEDelegate* get() { + static DevToolsIMEDelegate* instance = new DevToolsIMEDelegate(); + return instance; + } +}; + +#endif + void DevTools::newFrame() { auto& io = ImGui::GetIO(); @@ -94,6 +156,15 @@ void DevTools::newFrame() { io.KeyAlt = kb->getAltKeyPressed() || kb->getCommandKeyPressed(); // look io.KeyCtrl = kb->getControlKeyPressed(); io.KeyShift = kb->getShiftKeyPressed(); + +#ifdef GEODE_IS_MOBILE + auto ime = DevToolsIMEDelegate::get(); + if (io.WantTextInput && !ime->isAttached()) { + ime->attachWithIME(); + } else if (!io.WantTextInput && ime->isAttached()) { + ime->detachWithIME(); + } +#endif } void DevTools::render(GLRenderCtx* ctx) { @@ -278,6 +349,18 @@ class $modify(CCMouseDispatcher) { #endif class $modify(CCTouchDispatcher) { + static void onModify(auto& self) { + /* + * some mods hook this instead of using normal touch delegates for some reason + * for example QOLMod, even in the rewrite + * so i added hook priority + */ + Result<> res = self.setHookPriorityPre("cocos2d::CCTouchDispatcher::touches", Priority::First); + if (!res) { + geode::log::warn("Failed to set hook priority for CCTouchDispatcher::touches: {}", res.unwrapErr()); + } + } + void touches(CCSet* touches, CCEvent* event, unsigned int type) { auto& io = ImGui::GetIO(); auto* touch = static_cast(touches->anyObject()); @@ -290,6 +373,7 @@ 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; @@ -306,7 +390,12 @@ class $modify(CCTouchDispatcher) { auto y = (1.f - relativePos.y / gdRect.GetHeight()) * win.y; auto pos = toCocos(ImVec2(x, y)); - touch->setTouchInfo(touch->getID(), pos.x, pos.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; + } CCTouchDispatcher::touches(touches, event, type); ImGui::SetWindowFocus("Geometry Dash"); @@ -318,6 +407,7 @@ class $modify(CCTouchDispatcher) { // TODO: dragging out of gd makes it click in imgui if (!didGDSwallow) { if (type == CCTOUCHBEGAN || type == CCTOUCHMOVED) { + GEODE_MOBILE(io.AddMouseSourceEvent(ImGuiMouseSource_TouchScreen);) io.AddMouseButtonEvent(0, true); } else { @@ -356,3 +446,103 @@ class $modify(CCIMEDispatcher) { io.AddKeyEvent(ImGuiKey_Backspace, false); } }; + +ImGuiKey cocosToImGuiKey(cocos2d::enumKeyCodes key) { + if (key >= KEY_A && key <= KEY_Z) { + return static_cast(ImGuiKey_A + (key - KEY_A)); + } + if (key >= KEY_Zero && key <= KEY_Nine) { + return static_cast(ImGuiKey_0 + (key - KEY_Zero)); + } + switch (key) { + case KEY_Up: return ImGuiKey_UpArrow; + case KEY_Down: return ImGuiKey_DownArrow; + case KEY_Left: return ImGuiKey_LeftArrow; + case KEY_Right: return ImGuiKey_RightArrow; + + case KEY_Control: return ImGuiKey_ModCtrl; + case KEY_LeftWindowsKey: return ImGuiKey_ModSuper; + case KEY_Shift: return ImGuiKey_ModShift; + case KEY_Alt: return ImGuiKey_ModAlt; + case KEY_Enter: return ImGuiKey_Enter; + + case KEY_Home: return ImGuiKey_Home; + case KEY_End: return ImGuiKey_End; + // macos uses delete instead of backspace for some reason + #ifndef GEODE_IS_MACOS + case KEY_Delete: return ImGuiKey_Delete; + #endif + case KEY_Escape: return ImGuiKey_Escape; + + // KEY_Control and KEY_Shift aren't called on android like windows or mac + #ifdef GEODE_IS_ANDROID + case KEY_LeftControl: return ImGuiKey_ModCtrl; + case KEY_RightContol: return ImGuiKey_ModCtrl; + case KEY_LeftShift: return ImGuiKey_ModShift; + case KEY_RightShift: return ImGuiKey_ModShift; + #endif + + default: return ImGuiKey_None; + } +} + +class $modify(CCKeyboardDispatcher) { + bool dispatchKeyboardMSG(enumKeyCodes key, bool down, bool repeat) { + auto& io = ImGui::GetIO(); + const auto imKey = cocosToImGuiKey(key); + if (imKey != ImGuiKey_None) { + io.AddKeyEvent(imKey, down); + } + + // CCIMEDispatcher stuff only gets called on mobile if the virtual keyboard would be up. + // Similarly, CCKeyboardDispatcher doesn't get called if the virtual keyboard would be up. + #ifdef GEODE_IS_MOBILE + if (down) { + char c = 0; + if (key >= KEY_A && key <= KEY_Z) { + c = static_cast(key); + if (!io.KeyShift) { + c = static_cast(tolower(c)); + } + } else if (key >= KEY_Zero && key <= KEY_Nine) { + c = static_cast('0' + (key - KEY_Zero)); + } else if (key == KEY_Space) { + c = ' '; + } + + if (c != 0) { + std::string str(1, c); + io.AddInputCharactersUTF8(str.c_str()); + } + } + if (key == KEY_Backspace) { + io.AddKeyEvent(ImGuiKey_Backspace, true); + io.AddKeyEvent(ImGuiKey_Backspace, false); + } + #endif + + if (io.WantCaptureKeyboard) { + return false; + } else { + return CCKeyboardDispatcher::dispatchKeyboardMSG(key, down, repeat); + } + } + + #if defined(GEODE_IS_MACOS) || defined(GEODE_IS_IOS) + static void onModify(auto& self) { + Result<> res = self.setHookPriorityBeforePre("CCKeyboardDispatcher::updateModifierKeys", "geode.custom-keybinds"); + if (!res) { + geode::log::warn("Failed to set hook priority for CCKeyboardDispatcher::updateModifierKeys: {}", res.unwrapErr()); + } + } + + void updateModifierKeys(bool shft, bool ctrl, bool alt, bool cmd) { + auto& io = ImGui::GetIO(); + io.AddKeyEvent(ImGuiKey_ModShift, shft); + io.AddKeyEvent(ImGuiKey_ModCtrl, ctrl); + io.AddKeyEvent(ImGuiKey_ModAlt, alt); + io.AddKeyEvent(ImGuiKey_ModSuper, cmd); + CCKeyboardDispatcher::updateModifierKeys(shft, ctrl, alt, cmd); + } + #endif +}; diff --git a/src/main.cpp b/src/main.cpp index 11f3df5..99c24ed 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,5 @@ +#include "Geode/ui/SceneManager.hpp" #include "platform/platform.hpp" #include #include @@ -9,6 +10,7 @@ #include "DevTools.hpp" #include #include "ImGui.hpp" +#include "nodes/DragButton.hpp" using namespace geode::prelude; @@ -32,11 +34,23 @@ class $modify(CCKeyboardDispatcher) { }; #ifdef GEODE_IS_MOBILE -// lol -#include -class $modify(MenuLayer) { - void onMoreGames(CCObject*) { - DevTools::get()->toggle(); + +#include +$execute { + new EventListener(+[](GameEvent*) { + DragButton::get(); + }, GameEventFilter(GameEventType::Loaded)); +} + +#include +class $modify(CCScene) { + int getHighestChildZ() { + auto btn = DragButton::get(); + int z = btn->getZOrder(); + btn->setZOrder(-1); + int ret = CCScene::getHighestChildZ(); + btn->setZOrder(z); + return ret; } }; @@ -68,6 +82,7 @@ class $modify(GameToolbox) { }; + class $modify(CCDirector) { void willSwitchToScene(CCScene* scene) { CCDirector::willSwitchToScene(scene); @@ -139,3 +154,15 @@ class $modify(CCEGLView) { CCEGLView::swapBuffers(); } }; + +// For the one eclipse shortcut +struct ToggleDevToolsEvent : geode::Event { + ToggleDevToolsEvent() {} +}; + +$on_mod(Loaded) { + new EventListener>(+[](ToggleDevToolsEvent* e) { + DevTools::get()->toggle(); + return ListenerResult::Stop; + }); +} diff --git a/src/nodes/DragButton.cpp b/src/nodes/DragButton.cpp new file mode 100644 index 0000000..5d77336 --- /dev/null +++ b/src/nodes/DragButton.cpp @@ -0,0 +1,103 @@ +#include "DragButton.hpp" +#include "../DevTools.hpp" + +using namespace geode::prelude; + +bool DragButton::init(CCNode* node, std::function onPress) { + if (!CCLayer::init()) return false; + this->setTouchEnabled(true); + this->setAnchorPoint({.5f, .5f}); + this->ignoreAnchorPointForPosition(false); + this->scheduleUpdate(); + if (node) { + this->setContentSize(node->getScaledContentSize()); + this->addChildAtPosition(node, Anchor::Center, CCPoint{0, 0}); + } + this->m_onPress = onPress; + return true; +} + +bool DragButton::ccTouchBegan(CCTouch* touch, CCEvent* event) { + if (!this->m_bVisible) return false; + CCPoint local = convertToNodeSpace(touch->getLocation()); + if (this->getContentWidth() > local.x && local.x > 0 && this->getContentHeight() > local.y && local.y > 0) { + this->stopActionByTag(123); + auto action = CCEaseSineOut::create(CCScaleTo::create(.3f, .8f)); + action->setTag(123); + this->runAction(action); + + m_diff = this->getParent()->convertToNodeSpace(touch->getLocation()) - this->getPosition(); + return true; + } + return false; +} + +void DragButton::ccTouchMoved(CCTouch* touch, CCEvent* event) { + auto pos = this->getParent()->convertToNodeSpace(touch->getLocation()) - m_diff; + this->setPosition(pos); +} + +void DragButton::ccTouchEnded(CCTouch* touch, CCEvent* event) { + this->stopActionByTag(123); + auto action = CCEaseSineOut::create(CCScaleTo::create(.3f, 1.f)); + action->setTag(123); + this->runAction(action); + + if ((touch->getLocation() - touch->getStartLocation()).getLength() > 3.f) return; + if (this->m_onPress) this->m_onPress(); +} + +void DragButton::ccTouchCancelled(CCTouch* touch, CCEvent* event) { + this->ccTouchEnded(touch, event); +} + +void DragButton::registerWithTouchDispatcher() { + CCTouchDispatcher::get()->addTargetedDelegate(this, -512, true); +} + +DragButton* DragButton::create(CCNode* node, std::function onPress) { + auto ret = new DragButton; + if (ret->init(node, onPress)) { + ret->autorelease(); + return ret; + } + delete ret; + return nullptr; +} + +void DragButton::update(float dt) { + const Settings& settings = DevTools::get()->getSettings(); + if (PlayLayer::get() && !CCScene::get()->getChildByType(0) && !settings.buttonInGame) { + setVisible(false); + } else if (auto lel = LevelEditorLayer::get(); lel && ((lel->m_playbackMode == PlaybackMode::Playing && !settings.buttonInGame) || !settings.buttonInEditor)) { + setVisible(false); + } else { + setVisible(true); + } +} + +void DragButton::setPosition(cocos2d::CCPoint const& pos_) { + auto winSize = CCDirector::get()->getWinSize(); + float pad = 5.f; + auto pos = pos_; + pos.x = std::clamp(pos.x, pad, winSize.width - pad); + pos.y = std::clamp(pos.y, pad, winSize.height - pad); + CCNode::setPosition(pos); +} + +DragButton* DragButton::get() { + static DragButton* instance = nullptr; + if (!instance) { + auto spr = CircleButtonSprite::createWithSprite("devtools.png"_spr, 1, CircleBaseColor::Green, CircleBaseSize::MediumAlt); + spr->setScale(.8f); + instance = DragButton::create(spr, [](){ + DevTools::get()->toggle(); + }); + instance->setPosition(DevTools::get()->getSettings().buttonPos); + instance->setZOrder(10000); + instance->setID("devtools-button"_spr); + CCScene::get()->addChild(instance); + SceneManager::get()->keepAcrossScenes(instance); + } + return instance; +} diff --git a/src/nodes/DragButton.hpp b/src/nodes/DragButton.hpp new file mode 100644 index 0000000..7efb737 --- /dev/null +++ b/src/nodes/DragButton.hpp @@ -0,0 +1,25 @@ +#pragma once + +#include "Geode/cocos/base_nodes/CCNode.h" +#include "Geode/cocos/touch_dispatcher/CCTouchDelegateProtocol.h" + +class DragButton : public cocos2d::CCLayer { +protected: + std::function m_onPress; + cocos2d::CCPoint m_diff = cocos2d::CCPoint{0, 0}; + + bool init(cocos2d::CCNode* node, std::function); + bool ccTouchBegan(cocos2d::CCTouch* touch, cocos2d::CCEvent* event) override; + void ccTouchMoved(cocos2d::CCTouch* touch, cocos2d::CCEvent* event) override; + void ccTouchEnded(cocos2d::CCTouch* touch, cocos2d::CCEvent* event) override; + void ccTouchCancelled(cocos2d::CCTouch* touch, cocos2d::CCEvent* event) override; + + void registerWithTouchDispatcher() override; + + void update(float dt) override; +public: + static DragButton* create(cocos2d::CCNode* node, std::function onPress); + static DragButton* get(); + + void setPosition(cocos2d::CCPoint const& position) override; +}; diff --git a/src/pages/Settings.cpp b/src/pages/Settings.cpp index 20e852f..041cbb0 100644 --- a/src/pages/Settings.cpp +++ b/src/pages/Settings.cpp @@ -155,6 +155,19 @@ void DevTools::drawSettings() { static_cast(frameSize.width / ratio), static_cast(frameSize.height / ratio) ); +#else + ImGui::Checkbox("Button In Editor", &m_settings.buttonInEditor); + if (ImGui::IsItemHovered()) { + ImGui::SetTooltip( + "Shows the mobile button in the editor." + ); + } + ImGui::Checkbox("Button In Game", &m_settings.buttonInGame); + if (ImGui::IsItemHovered()) { + ImGui::SetTooltip( + "Shows the mobile button in levels." + ); + } #endif #if 0 diff --git a/src/pages/Tree.cpp b/src/pages/Tree.cpp index e18669c..aa25de8 100644 --- a/src/pages/Tree.cpp +++ b/src/pages/Tree.cpp @@ -2,6 +2,7 @@ #include #include "../DevTools.hpp" #include "../platform/utils.hpp" +#include #ifndef GEODE_IS_WINDOWS #include #endif @@ -9,6 +10,10 @@ using namespace geode::prelude; void DevTools::drawTreeBranch(CCNode* node, size_t index) { + if (!searchBranch(node)) { + return; + } + auto selected = DevTools::get()->getSelectedNode() == node; ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_None; @@ -23,6 +28,14 @@ void DevTools::drawTreeBranch(CCNode* node, size_t index) { { flags |= ImGuiTreeNodeFlags_OpenOnArrow; } + + if (m_searchQuery.empty()) { + ImGui::SetNextItemOpen(m_nodeOpen.contains(node) && m_nodeOpen[node]); + } + else if (m_searchQuery != m_prevQuery) { + ImGui::SetNextItemOpen(true); + } + std::stringstream name; name << "[" << index << "] " << geode::cocos::getObjectName(node) << " "; if (node->getTag() != -1) { @@ -36,13 +49,31 @@ void DevTools::drawTreeBranch(CCNode* node, size_t index) { } // The order here is unusual due to imgui weirdness; see the second-to-last paragraph in https://kahwei.dev/2022/06/20/imgui-tree-node/ bool expanded = ImGui::TreeNodeEx(node, flags, "%s", name.str().c_str()); - if (ImGui::IsItemClicked()) { + if (ImGui::IsItemClicked()) { DevTools::get()->selectNode(node); selected = true; + + if (!m_searchQuery.empty()) { + CCNode* parent = node->getParent(); + while (parent) { + m_nodeOpen[parent] = true; + parent = parent->getParent(); + } + } } if (ImGui::IsItemHovered() && (m_settings.alwaysHighlight || ImGui::IsKeyDown(ImGuiMod_Shift))) { DevTools::get()->highlightNode(node, HighlightMode::Hovered); } + if (ImGui::IsItemToggledOpen() && (m_searchQuery.empty() || m_searchQuery == m_prevQuery)) { + if (!m_searchQuery.empty() && expanded) { + CCNode* parent = node->getParent(); + while (parent) { + m_nodeOpen[parent] = true; + parent = parent->getParent(); + } + } + m_nodeOpen[node] = expanded; + } if (expanded) { if (m_settings.attributesInTree) { this->drawNodeAttributes(node); @@ -59,6 +90,31 @@ void DevTools::drawTree() { #ifdef GEODE_IS_MOBILE ImGui::Dummy({0.f, 60.f}); #endif + m_prevQuery = m_searchQuery; + ImGui::SetNextItemWidth(-1.f); + ImGui::InputTextWithHint("##search", U8STR(FEATHER_SEARCH " Search for a node..."), &m_searchQuery, ImGuiInputTextFlags_EnterReturnsTrue); this->drawTreeBranch(CCDirector::get()->getRunningScene(), 0); } + +bool DevTools::searchBranch(CCNode* node) { + if (m_searchQuery.empty()) return true; + + std::string name(geode::cocos::getObjectName(node)); + std::string id = node->getID(); + std::string query = m_searchQuery; + + utils::string::toLowerIP(name); + utils::string::toLowerIP(id); + utils::string::toLowerIP(query); + + if (name.find(query) != std::string::npos || id.find(query) != std::string::npos) { + return true; + } + for (auto child : node->getChildrenExt()) { + if (searchBranch(child)) { + return true; + } + } + return false; +} \ No newline at end of file diff --git a/src/platform/Win32.cpp b/src/platform/Win32.cpp index 37725f0..b16cb2b 100644 --- a/src/platform/Win32.cpp +++ b/src/platform/Win32.cpp @@ -9,30 +9,6 @@ using namespace cocos2d; using namespace geode; -ImGuiKey keyFromGLFW(int key) { - if (key >= GLFW_KEY_0 && key <= GLFW_KEY_9) { - return static_cast(ImGuiKey_0 + (key - GLFW_KEY_0)); - } else if (key >= GLFW_KEY_A && key <= GLFW_KEY_Z) { - return static_cast(ImGuiKey_A + (key - GLFW_KEY_A)); - } - switch (key) { - case GLFW_KEY_SPACE: return ImGuiKey_Space; - case GLFW_KEY_BACKSPACE: return ImGuiKey_Backspace; - case GLFW_KEY_COMMA: return ImGuiKey_Comma; - case GLFW_KEY_LEFT: return ImGuiKey_LeftArrow; - case GLFW_KEY_RIGHT: return ImGuiKey_RightArrow; - case GLFW_KEY_UP: return ImGuiKey_UpArrow; - case GLFW_KEY_DOWN: return ImGuiKey_DownArrow; - case GLFW_KEY_ESCAPE: return ImGuiKey_Escape; - case GLFW_KEY_LEFT_SHIFT: return ImGuiKey_LeftShift; - case GLFW_KEY_RIGHT_SHIFT: return ImGuiKey_RightShift; - case GLFW_KEY_LEFT_CONTROL: return ImGuiKey_LeftCtrl; - case GLFW_KEY_LEFT_ALT: return ImGuiKey_LeftAlt; - // TODO: rest :-) - } - return ImGuiKey_None; -} - class $modify(CCEGLView) { void updateWindow(int width, int height) { shouldUpdateGDRenderBuffer() = true; @@ -47,14 +23,6 @@ class $modify(CCEGLView) { CCEGLView::toggleFullScreen(value, borderless, fix); DevTools::get()->setup(); } - - //todo: i dont care someone else can figure it out, it completely breaks keyboard support - /*void onGLFWKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods) { - //auto& io = ImGui::GetIO(); - CCEGLView::onGLFWKeyCallback(window, key, scancode, action, mods); - // in practice this is only used for arrow keys - //io.AddKeyEvent(keyFromGLFW(key), action != GLFW_RELEASE); - }*/ }; #include "utils.hpp"