From d4c34f8908f60209ec5bec1b96884e2572ac778b Mon Sep 17 00:00:00 2001 From: gs5579 Date: Fri, 27 Nov 2026 10:05:36 +0000 Subject: [PATCH] Clear filters on model load, show no-match hints, support system clipboard and non-ASCII text input Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- CMakeLists.txt | 3 ++- README.md | 4 +++- src/app/AppUi.cpp | 9 ++++++++ src/ui/ImGuiOsg.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 65 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e5ff9f0..b0467c7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,7 +57,8 @@ add_library(imgui STATIC target_include_directories(imgui PUBLIC ${imgui_SOURCE_DIR} ${imgui_SOURCE_DIR}/backends) target_link_libraries(imgui PUBLIC OpenGL::GL) if(APPLE) - target_compile_definitions(imgui PUBLIC GL_SILENCE_DEPRECATION) + target_compile_definitions(imgui PUBLIC GL_SILENCE_DEPRECATION IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS) + target_link_libraries(imgui PUBLIC "-framework ApplicationServices") endif() # --- Text encoding (Shift-JIS for PMD) ------------------------------------------- diff --git a/README.md b/README.md index c2a95ad..a22ef97 100644 --- a/README.md +++ b/README.md @@ -45,12 +45,14 @@ cmake --build build ```sh sudo apt install build-essential cmake ninja-build libopenscenegraph-dev libassimp-dev \ - libgl1-mesa-dev fonts-noto-cjk + libgl1-mesa-dev fonts-noto-cjk xclip cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release cmake --build build ./build/model_renderer path/to/model.pmx ``` +Copy/paste in text fields uses `xclip` or `xsel` on X11 and `wl-clipboard` on Wayland. + Fedora: `sudo dnf install cmake ninja-build gcc-c++ OpenSceneGraph-devel assimp-devel google-noto-sans-cjk-fonts`. ### Windows (Visual Studio 2022 + vcpkg) diff --git a/src/app/AppUi.cpp b/src/app/AppUi.cpp index 8e3bd03..9859e39 100644 --- a/src/app/AppUi.cpp +++ b/src/app/AppUi.cpp @@ -59,6 +59,8 @@ bool App::loadModel(const std::string& path) { modelNode_ = new ModelNode(model); root_->addChild(modelNode_); selectedBone_ = -1; + boneFilter_[0] = '\0'; + morphFilter_[0] = '\0'; lightingModel_ = model->format == SourceFormat::Assimp ? 1 : 0; applyViewSettings(); frameModel(); @@ -203,6 +205,7 @@ void App::drawBonesWindow() { ImGui::InputTextWithHint("##bonefilter", "Filter bones", boneFilter_, sizeof(boneFilter_)); ImGui::Checkbox("Only visible / skinning bones", &onlyVisibleBones_); ImGui::BeginChild("bonelist"); + int shown = 0; for (size_t i = 0; i < m.bones.size(); ++i) { const Bone& b = m.bones[i]; if (onlyVisibleBones_ && !b.visible && !b.isSkinBone) continue; @@ -210,6 +213,7 @@ void App::drawBonesWindow() { int depth = 0; for (int p = b.parent; p >= 0 && depth < 32; p = m.bones[p].parent) ++depth; if (*boneFilter_) depth = 0; + ++shown; const bool posed = poses[i] != BonePose(); std::string label = std::string(static_cast(std::min(depth, 12)) * 2, ' ') + (posed ? "* " : "") + b.name + "##" + std::to_string(i); @@ -218,6 +222,7 @@ void App::drawBonesWindow() { modelNode_->setSelectedBone(selectedBone_); } } + if (shown == 0) ImGui::TextDisabled(*boneFilter_ ? "No bones match the filter." : "No bones to show."); ImGui::EndChild(); ImGui::End(); } @@ -232,6 +237,10 @@ void App::drawMorphsWindow() { ImGui::SetNextItemWidth(-1); ImGui::InputTextWithHint("##morphfilter", "Filter morphs", morphFilter_, sizeof(morphFilter_)); if (m.morphs.empty()) ImGui::TextDisabled("This model has no morphs."); + int shown = 0; + for (const auto& morph : m.morphs) + shown += containsCaseInsensitive(morph.name, morphFilter_) || containsCaseInsensitive(morph.nameEn, morphFilter_); + if (!m.morphs.empty() && shown == 0) ImGui::TextDisabled("No morphs match the filter."); const MorphPanel order[] = {MorphPanel::Eye, MorphPanel::Mouth, MorphPanel::Eyebrow, MorphPanel::Other, MorphPanel::System}; for (MorphPanel panel : order) { diff --git a/src/ui/ImGuiOsg.cpp b/src/ui/ImGuiOsg.cpp index d558d7e..949ba51 100644 --- a/src/ui/ImGuiOsg.cpp +++ b/src/ui/ImGuiOsg.cpp @@ -8,6 +8,8 @@ #include #include +#include +#include #include #include @@ -42,6 +44,46 @@ ImGuiKey mapKey(int key) { return ImGuiKey_None; } +#if !defined(_WIN32) && !defined(__APPLE__) +// ImGui only has native clipboard support on Windows and macOS; on Linux use the standard CLI tools. +std::string g_clipboard; + +const char* const* clipboardCommands(bool paste) { + static const char* const waylandPaste[] = {"wl-paste -n 2>/dev/null", nullptr}; + static const char* const waylandCopy[] = {"wl-copy 2>/dev/null", nullptr}; + static const char* const x11Paste[] = {"xclip -selection clipboard -o 2>/dev/null", "xsel -bo 2>/dev/null", nullptr}; + static const char* const x11Copy[] = {"xclip -selection clipboard -i 2>/dev/null", "xsel -bi 2>/dev/null", nullptr}; + const bool wayland = std::getenv("WAYLAND_DISPLAY") != nullptr; + return paste ? (wayland ? waylandPaste : x11Paste) : (wayland ? waylandCopy : x11Copy); +} + +const char* getClipboardText(ImGuiContext*) { + for (const char* const* cmd = clipboardCommands(true); *cmd; ++cmd) { + FILE* pipe = popen(*cmd, "r"); + if (!pipe) continue; + std::string text; + char buf[4096]; + size_t n; + while ((n = fread(buf, 1, sizeof(buf), pipe)) > 0) text.append(buf, n); + if (pclose(pipe) == 0) { + g_clipboard = text; + break; + } + } + return g_clipboard.c_str(); +} + +void setClipboardText(ImGuiContext*, const char* text) { + g_clipboard = text ? text : ""; + for (const char* const* cmd = clipboardCommands(false); *cmd; ++cmd) { + FILE* pipe = popen(*cmd, "w"); + if (!pipe) continue; + fwrite(g_clipboard.data(), 1, g_clipboard.size(), pipe); + if (pclose(pipe) == 0) break; + } +} +#endif + class InitOperation : public osg::Operation { public: explicit InitOperation(ImGuiOsg* owner) : osg::Operation("ImGuiInit", false), owner_(owner) {} @@ -132,8 +174,11 @@ public: int key = ea.getUnmodifiedKey() ? ea.getUnmodifiedKey() : ea.getKey(); ImGuiKey imguiKey = mapKey(key); if (imguiKey != ImGuiKey_None) io.AddKeyEvent(imguiKey, down); + // OSG reports special keys as X11-style keysyms in 0xFF00-0xFFFF; everything else is a character. int ch = ea.getKey(); - if (down && ch >= 32 && ch < 127) io.AddInputCharacter(static_cast(ch)); + const bool ctrlOrSuper = (ea.getModKeyMask() & (E::MODKEY_CTRL | E::MODKEY_SUPER)) != 0; + if (down && !ctrlOrSuper && ch >= 32 && ch != 127 && !(ch >= 0xFF00 && ch <= 0xFFFF)) + io.AddInputCharacter(static_cast(ch)); return io.WantCaptureKeyboard; } default: return false; @@ -148,6 +193,11 @@ ImGuiOsg::ImGuiOsg(DrawFunction draw) : draw_(std::move(draw)) { ImGui::CreateContext(); ImGuiIO& io = ImGui::GetIO(); io.IniFilename = nullptr; +#if !defined(_WIN32) && !defined(__APPLE__) + ImGuiPlatformIO& platformIo = ImGui::GetPlatformIO(); + platformIo.Platform_GetClipboardTextFn = getClipboardText; + platformIo.Platform_SetClipboardTextFn = setClipboardText; +#endif ImGui::StyleColorsDark(); ImGui::GetStyle().WindowRounding = 4.f; loadFonts();