Skip to content

Commit a07e707

Browse files
committed
aa
1 parent b79b7c3 commit a07e707

3 files changed

Lines changed: 77 additions & 42 deletions

File tree

src/DevTools.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,8 @@ void DevTools::draw(GLRenderCtx* ctx) {
253253
0, nullptr, ImGuiDockNodeFlags_PassthruCentralNode
254254
);
255255

256-
ImGui::GetIO().FontGlobalScale = m_settings.fontGlobalScale;
256+
ImGui::GetIO().FontGlobalScale = ImGui::GetMainViewport(
257+
)->Size.x / 1920.f * m_settings.fontGlobalScale;
257258

258259
ImGui::PushFont(m_defaultFont);
259260
this->drawPages();

src/backend.cpp

Lines changed: 69 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,14 @@ void DevTools::setupPlatform() {
4747
ImGui::GetPlatformIO().Platform_GetClipboardTextFn =
4848
[](ImGuiContext* ctx)
4949
{
50+
log::debug("{}()", __FUNCTION__);
5051
read = geode::utils::clipboard::read();
5152
return read.c_str();
5253
};
5354
ImGui::GetPlatformIO().Platform_SetClipboardTextFn =
5455
[](ImGuiContext* ctx, const char* text)
5556
{
57+
log::debug("{}()", __FUNCTION__);
5658
geode::utils::clipboard::write(text);
5759
};
5860

@@ -120,46 +122,68 @@ void DevTools::render(GLRenderCtx* ctx) {
120122

121123
DevTools::get()->draw(ctx);
122124

125+
ImGui::Render();
126+
127+
this->renderDrawData(ImGui::GetDrawData());
128+
123129
// ime fuckery for mobile
124130
if (GEODE_DESKTOP(false and) true) if (ImGui::IsMouseReleased(0)) {
125-
static Ref<CCTextInputNode> inpNodeRef;
131+
static Ref<TextInput> inpNodeRef;
126132
if (!inpNodeRef) {
127-
inpNodeRef = CCTextInputNode::create(100.f, 20.f, "xd", "geode.loader/mdFont.fnt");
128-
inpNodeRef->m_allowedChars = " !\"#$ % &'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
133+
inpNodeRef = TextInput::create(100.f, "xd", "geode.loader/mdFont.fnt");
134+
inpNodeRef->getInputNode()->m_allowedChars = " !\"#$ % &'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
135+
inpNodeRef->setCallback(
136+
[](const std::string& str) {
137+
ImGui::GetIO().AddKeyEvent(ImGuiMod_Ctrl, true);
138+
ImGui::GetIO().AddKeyEvent(ImGuiKey_A, true);
139+
ImGui::GetIO().AddKeyEvent(ImGuiKey_A, false);
140+
ImGui::GetIO().AddKeyEvent(ImGuiMod_Ctrl, false);
141+
ImGui::GetIO().AddKeyEvent(ImGuiKey_Backspace, true);
142+
ImGui::GetIO().AddKeyEvent(ImGuiKey_Backspace, false);
143+
ImGui::GetIO().AddInputCharactersUTF8(str.c_str());
144+
auto curPos = inpNodeRef->getInputNode()->m_textField->m_uCursorPos;
145+
if (curPos != -1) { //-1 is the cursor at the end
146+
for (auto a : str) {
147+
ImGui::GetIO().AddKeyEvent(ImGuiKey_LeftArrow, true);
148+
ImGui::GetIO().AddKeyEvent(ImGuiKey_LeftArrow, false);
149+
}
150+
for (auto c = 0; c < curPos; ++c) {
151+
ImGui::GetIO().AddKeyEvent(ImGuiKey_RightArrow, true);
152+
ImGui::GetIO().AddKeyEvent(ImGuiKey_RightArrow, false);
153+
}
154+
}
155+
}
156+
);
129157
log::info("Created text input node for ImGui: {}", inpNodeRef);
130-
//inpNodeRef->setPosition(CCScene::get()->getContentSize() / 2.f);
131158
}
132159
if (inpNodeRef) {
133160
if (ImGui::GetIO().WantTextInput) {
134-
CCScene::get()->runAction(CCSequence::create(
135-
CallFuncExt::create(
136-
[] {
137-
ImGui::GetIO().AddKeyEvent(ImGuiMod_Ctrl, true); // hold ctrl to do things
138-
ImGui::GetIO().AddKeyEvent(ImGuiKey_A, true); // select
139-
ImGui::GetIO().AddKeyEvent(ImGuiKey_A, false);
140-
ImGui::GetIO().AddKeyEvent(ImGuiKey_C, true); // copy
141-
}
142-
),
143-
CCDelayTime::create(0.01f), // wait wait wait ok
144-
CallFuncExt::create(
145-
[] {
146-
ImGui::GetIO().AddKeyEvent(ImGuiKey_C, false);
147-
ImGui::GetIO().AddKeyEvent(ImGuiMod_Ctrl, false); // release ctrl
148-
}
149-
),
150-
CCDelayTime::create(0.01f),
151-
CallFuncExt::create(
152-
[] {
153-
inpNodeRef->setString(ImGui::GetClipboardText());
154-
inpNodeRef->onClickTrackNode(true);
155-
//inpNodeRef->removeFromParent();
156-
//CCScene::get()->addChild(inpNodeRef);
157-
}
158-
),
159-
nullptr
160-
));
161+
ImGuiInputTextState& State = GImGui->InputTextState;
162+
static int imguicurpos_onclick;
163+
imguicurpos_onclick = State.GetCursorPos();
164+
165+
if (State.TextLen) {
166+
inpNodeRef->setString(std::string(State.TextA.Data, State.TextLen));
167+
168+
inpNodeRef->focus();
169+
inpNodeRef->getInputNode()->onClickTrackNode(true);
170+
171+
for (auto c : inpNodeRef->getString()) {
172+
CCIMEDispatcher::sharedDispatcher()->dispatchInsertText("a", 1, KEY_Left);
173+
}
174+
for (auto c = 0; c < imguicurpos_onclick; ++c) {
175+
CCIMEDispatcher::sharedDispatcher()->dispatchInsertText("a", 1, KEY_Right);
176+
}
177+
178+
//inpNodeRef->setPosition(CCScene::get()->getContentSize() / 2.f);
179+
//inpNodeRef->removeFromParentAndCleanup(false);
180+
//CCScene::get()->addChild(inpNodeRef);
181+
}
182+
}
183+
else {
184+
inpNodeRef->defocus();
185+
inpNodeRef->getInputNode()->onClickTrackNode(false);
161186
}
162-
else inpNodeRef->onClickTrackNode(false);
163187
};
164188
}
165189

@@ -201,10 +225,6 @@ void DevTools::render(GLRenderCtx* ctx) {
201225
}
202226
}
203227
#endif
204-
205-
ImGui::Render();
206-
207-
this->renderDrawData(ImGui::GetDrawData());
208228
}
209229

210230
bool DevTools::hasExtension(const std::string& ext) const {
@@ -440,10 +460,17 @@ class $modify(CCTouchDispatcher) {
440460

441461
class $modify(CCIMEDispatcher) {
442462
void dispatchInsertText(const char* text, int len, enumKeyCodes key) {
443-
log::debug("{}(\"{}\", {}, {})", __FUNCTION__, text, len, CCKeyboardDispatcher::get()->keyToString(((int)key > 1 ? key : KEY_ApplicationsKey)));
444-
auto& io = ImGui::GetIO();
463+
if (0) log::debug("{}(text = \"{}\", len = {}, KEY_{} = {})", __FUNCTION__,
464+
text, len, key > 1 ? CCKeyboardDispatcher::get()->keyToString(key) : "KEY_Unknown", (int)key
465+
);
445466
CCIMEDispatcher::dispatchInsertText(text, len, key);
446-
if (text and len) io.AddInputCharactersUTF8(std::string(text, len).c_str());
467+
if (key < 0) { // KEY_Unknown, -1
468+
ImGui::GetIO().AddInputCharactersUTF8(std::string(text, len).c_str());
469+
}
470+
else { // KEY_... (text "a")
471+
CCKeyboardDispatcher::get()->dispatchKeyboardMSG(key, true, false);
472+
CCKeyboardDispatcher::get()->dispatchKeyboardMSG(key, false, false);
473+
}
447474
}
448475
};
449476

@@ -454,7 +481,9 @@ class $modify(CCIMEDispatcher) {
454481
#include <Geode/modify/CCKeyboardDispatcher.hpp>
455482
class $modify(CCKeyboardDispatcher) {
456483
bool dispatchKeyboardMSG(enumKeyCodes key, bool down, bool arr) {
457-
log::debug("{}({},{},{})", __FUNCTION__, CCKeyboardDispatcher::get()->keyToString(((int)key > 1 ? key : KEY_ApplicationsKey)), down, arr);
484+
if (0) log::debug("{}(KEY_{} = {}, down = {}, arr = {})", __FUNCTION__,
485+
key > 1 ? CCKeyboardDispatcher::get()->keyToString(key) : "Unknown", (int)key, down, arr
486+
);
458487
auto& io = ImGui::GetIO();
459488
{
460489
if (key == KEY_Control) io.AddKeyAnalogEvent(ImGuiKey_ModCtrl, down, 1.f);

src/pages/Attributes.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,12 @@ void DevTools::drawLabelAttributes(CCNode* node) {
245245
std::string str = matjson::Value(label->getString()).dump();
246246
if (ImGui::InputText("Text", &str, 256)) {
247247
auto parse = matjson::parseAs<std::string>(str);
248-
label->setString(parse.err().value_or(parse.unwrapOrDefault()).c_str());
248+
if (parse.err()) {
249+
ImGui::BeginErrorTooltip();
250+
ImGui::Text("Parse error: %s", parse.err().value_or("unk").c_str());
251+
ImGui::EndTooltip();
252+
}
253+
else label->setString(parse.unwrapOrDefault().c_str());
249254
}
250255
}
251256
if (auto label = typeinfo_cast<CCLabelBMFont*>(node)) {

0 commit comments

Comments
 (0)