From de269e7a48606e0c976395d15a606f1d05a8e30d Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sat, 2 Jul 2022 17:53:13 +0200 Subject: [PATCH] sys: Remove remaining references to hex.builtin from libimhex --- lib/libimhex/include/hex/api/event.hpp | 6 + lib/libimhex/include/hex/api/imhex_api.hpp | 7 + lib/libimhex/include/hex/ui/view.hpp | 17 +- lib/libimhex/source/api/imhex_api.cpp | 20 +++ lib/libimhex/source/helpers/fs.cpp | 3 +- lib/libimhex/source/providers/provider.cpp | 8 - lib/libimhex/source/ui/view.cpp | 132 +-------------- main/include/init/splash_window.hpp | 2 - main/source/init/splash_window.cpp | 2 +- main/source/main.cpp | 11 -- main/source/window/linux_window.cpp | 1 + main/source/window/macos_window.cpp | 1 + main/source/window/window.cpp | 2 - plugins/builtin/source/content/events.cpp | 6 + .../source/content/settings_entries.cpp | 36 ++++- .../builtin/source/content/tools_entries.cpp | 6 +- plugins/builtin/source/content/ui_items.cpp | 152 ++++++++++++++++++ .../source/content/views/view_information.cpp | 2 +- .../source/content/views/view_settings.cpp | 2 +- .../source/content/views/view_yara.cpp | 2 +- 20 files changed, 240 insertions(+), 178 deletions(-) diff --git a/lib/libimhex/include/hex/api/event.hpp b/lib/libimhex/include/hex/api/event.hpp index c451025e8..77503aefc 100644 --- a/lib/libimhex/include/hex/api/event.hpp +++ b/lib/libimhex/include/hex/api/event.hpp @@ -129,6 +129,12 @@ namespace hex { EVENT_DEF(RequestOpenPopup, std::string); EVENT_DEF(RequestCreateProvider, std::string, hex::prv::Provider **); + EVENT_DEF(RequestShowInfoPopup, std::string); + EVENT_DEF(RequestShowErrorPopup, std::string); + EVENT_DEF(RequestShowFatalErrorPopup, std::string); + EVENT_DEF(RequestShowYesNoQuestionPopup, std::string, std::function, std::function); + EVENT_DEF(RequestShowFileChooserPopup, std::vector, std::vector, std::function); + EVENT_DEF(QuerySelection, std::optional &); } \ No newline at end of file diff --git a/lib/libimhex/include/hex/api/imhex_api.hpp b/lib/libimhex/include/hex/api/imhex_api.hpp index fa9351fd0..d2fbdfeb9 100644 --- a/lib/libimhex/include/hex/api/imhex_api.hpp +++ b/lib/libimhex/include/hex/api/imhex_api.hpp @@ -162,6 +162,8 @@ namespace hex { void setCustomFontPath(const std::fs::path &path); void setFontSize(float size); + + void setGPUVendor(const std::string &vendor); } struct ProgramArguments { @@ -199,6 +201,11 @@ namespace hex { void enableSystemThemeDetection(bool enabled); bool usesSystemThemeDetection(); + + const std::vector &getAdditionalFolderPaths(); + void setAdditionalFolderPaths(const std::vector &paths); + + const std::string &getGPUVendor(); } } diff --git a/lib/libimhex/include/hex/ui/view.hpp b/lib/libimhex/include/hex/ui/view.hpp index 9d92a83cb..3d11a8c30 100644 --- a/lib/libimhex/include/hex/ui/view.hpp +++ b/lib/libimhex/include/hex/ui/view.hpp @@ -34,11 +34,9 @@ namespace hex { [[nodiscard]] virtual bool isAvailable() const; [[nodiscard]] virtual bool shouldProcess() const { return this->isAvailable() && this->getWindowOpenState(); } - static void drawCommonInterfaces(); - - static void showMessagePopup(const std::string &message); - static void showErrorPopup(const std::string &errorMessage); - static void showFatalPopup(const std::string &errorMessage); + static void showInfoPopup(const std::string &message); + static void showErrorPopup(const std::string &message); + static void showFatalPopup(const std::string &message); static void showYesNoQuestionPopup(const std::string &message, const std::function &yesCallback, const std::function &noCallback); static void showFileChooserPopup(const std::vector &paths, const std::vector &validExtensions, const std::function &callback); @@ -71,15 +69,6 @@ namespace hex { bool m_windowOpen = false; std::map> m_shortcuts; - static std::string s_popupMessage; - - static std::function s_yesCallback, s_noCallback; - - static u32 s_selectableFileIndex; - static std::vector s_selectableFiles; - static std::function s_selectableFileOpenCallback; - static std::vector s_selectableFilesValidExtensions; - static ImFontAtlas *s_fontAtlas; static ImFontConfig s_fontConfig; diff --git a/lib/libimhex/source/api/imhex_api.cpp b/lib/libimhex/source/api/imhex_api.cpp index 1ce08779e..706a76f28 100644 --- a/lib/libimhex/source/api/imhex_api.cpp +++ b/lib/libimhex/source/api/imhex_api.cpp @@ -328,6 +328,11 @@ namespace hex { s_fontSize = size; } + static std::string s_gpuVendor; + void setGPUVendor(const std::string &vendor) { + s_gpuVendor = vendor; + } + } @@ -406,6 +411,21 @@ namespace hex { bool usesSystemThemeDetection() { return s_systemThemeDetection; } + + + static std::vector s_additionalFolderPaths; + const std::vector &getAdditionalFolderPaths() { + return s_additionalFolderPaths; + } + + void setAdditionalFolderPaths(const std::vector &paths) { + s_additionalFolderPaths = paths; + } + + + const std::string &getGPUVendor() { + return impl::s_gpuVendor; + } } } diff --git a/lib/libimhex/source/helpers/fs.cpp b/lib/libimhex/source/helpers/fs.cpp index 81d6f8421..25ecf024f 100644 --- a/lib/libimhex/source/helpers/fs.cpp +++ b/lib/libimhex/source/helpers/fs.cpp @@ -100,8 +100,7 @@ namespace hex::fs { std::vector getDefaultPaths(ImHexPath path, bool listNonExisting) { std::vector result; const auto exePath = getExecutablePath(); - const std::string settingName { "hex.builtin.setting.folders" }; - auto userDirs = ContentRegistry::Settings::read(settingName, settingName, std::vector {}); + auto userDirs = ImHexApi::System::getAdditionalFolderPaths(); [[maybe_unused]] auto addUserDirs = [&userDirs](auto &paths) { diff --git a/lib/libimhex/source/providers/provider.cpp b/lib/libimhex/source/providers/provider.cpp index c761f93e7..e7f9179dc 100644 --- a/lib/libimhex/source/providers/provider.cpp +++ b/lib/libimhex/source/providers/provider.cpp @@ -2,25 +2,17 @@ #include #include -#include -#include #include #include #include #include -#include - -#include namespace hex::prv { Provider::Provider() { this->m_patches.emplace_back(); this->m_patternLanguageRuntime = ContentRegistry::PatternLanguage::createDefaultRuntime(this); - - if (this->hasLoadInterface()) - EventManager::post(View::toWindowName("hex.builtin.view.provider_settings.load_popup")); } Provider::~Provider() { diff --git a/lib/libimhex/source/ui/view.cpp b/lib/libimhex/source/ui/view.cpp index f95f04ed2..0bf24c5a4 100644 --- a/lib/libimhex/source/ui/view.cpp +++ b/lib/libimhex/source/ui/view.cpp @@ -8,15 +8,6 @@ namespace hex { - std::string View::s_popupMessage; - - std::function View::s_yesCallback, View::s_noCallback; - - u32 View::s_selectableFileIndex; - std::vector View::s_selectableFiles; - std::function View::s_selectableFileOpenCallback; - std::vector View::s_selectableFilesValidExtensions; - ImFontAtlas *View::s_fontAtlas; ImFontConfig View::s_fontConfig; @@ -26,123 +17,21 @@ namespace hex { return ImHexApi::Provider::isValid() && ImHexApi::Provider::get()->isAvailable(); } - void View::drawCommonInterfaces() { - auto windowSize = ImHexApi::System::getMainWindowSize(); - - ImGui::SetNextWindowSizeConstraints(scaled(ImVec2(400, 100)), scaled(ImVec2(600, 300))); - if (ImGui::BeginPopupModal("hex.builtin.common.info"_lang, nullptr, ImGuiWindowFlags_AlwaysAutoResize)) { - ImGui::TextFormattedWrapped("{}", s_popupMessage.c_str()); - ImGui::NewLine(); - ImGui::Separator(); - if (ImGui::Button("hex.builtin.common.okay"_lang) || ImGui::IsKeyDown(ImGuiKey_Escape)) - ImGui::CloseCurrentPopup(); - - ImGui::SetWindowPos((windowSize - ImGui::GetWindowSize()) / 2, ImGuiCond_Appearing); - ImGui::EndPopup(); - } - - ImGui::SetNextWindowSizeConstraints(scaled(ImVec2(400, 100)), scaled(ImVec2(600, 300))); - if (ImGui::BeginPopupModal("hex.builtin.common.error"_lang, nullptr, ImGuiWindowFlags_AlwaysAutoResize)) { - ImGui::TextFormattedWrapped("{}", s_popupMessage.c_str()); - ImGui::NewLine(); - ImGui::Separator(); - if (ImGui::Button("hex.builtin.common.okay"_lang) || ImGui::IsKeyDown(ImGuiKey_Escape)) - ImGui::CloseCurrentPopup(); - - ImGui::SetWindowPos((windowSize - ImGui::GetWindowSize()) / 2, ImGuiCond_Appearing); - ImGui::EndPopup(); - } - - ImGui::SetNextWindowSizeConstraints(scaled(ImVec2(400, 100)), scaled(ImVec2(600, 300))); - if (ImGui::BeginPopupModal("hex.builtin.common.fatal"_lang, nullptr, ImGuiWindowFlags_AlwaysAutoResize)) { - ImGui::TextFormattedWrapped("{}", s_popupMessage.c_str()); - ImGui::NewLine(); - ImGui::Separator(); - if (ImGui::Button("hex.builtin.common.okay"_lang) || ImGui::IsKeyDown(ImGuiKey_Escape)) { - ImHexApi::Common::closeImHex(); - ImGui::CloseCurrentPopup(); - } - - ImGui::SetWindowPos((windowSize - ImGui::GetWindowSize()) / 2, ImGuiCond_Appearing); - ImGui::EndPopup(); - } - - ImGui::SetNextWindowSizeConstraints(scaled(ImVec2(400, 100)), scaled(ImVec2(600, 300))); - if (ImGui::BeginPopupModal("hex.builtin.common.question"_lang, nullptr, ImGuiWindowFlags_AlwaysAutoResize)) { - ImGui::TextFormattedWrapped("{}", s_popupMessage.c_str()); - ImGui::NewLine(); - ImGui::Separator(); - - View::confirmButtons( - "hex.builtin.common.yes"_lang, "hex.builtin.common.no"_lang, [] { - s_yesCallback(); - ImGui::CloseCurrentPopup(); }, [] { - s_noCallback(); - ImGui::CloseCurrentPopup(); }); - - ImGui::SetWindowPos((windowSize - ImGui::GetWindowSize()) / 2, ImGuiCond_Appearing); - ImGui::EndPopup(); - } - - bool opened = true; - ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetCenter(), ImGuiCond_Appearing, ImVec2(0.5F, 0.5F)); - if (ImGui::BeginPopupModal("hex.builtin.common.choose_file"_lang, &opened, ImGuiWindowFlags_AlwaysAutoResize)) { - - if (ImGui::BeginListBox("##files", ImVec2(300_scaled, 0))) { - - u32 index = 0; - for (auto &path : View::s_selectableFiles) { - if (ImGui::Selectable(path.filename().string().c_str(), index == View::s_selectableFileIndex)) - View::s_selectableFileIndex = index; - index++; - } - - ImGui::EndListBox(); - } - - if (ImGui::Button("hex.builtin.common.open"_lang)) { - View::s_selectableFileOpenCallback(View::s_selectableFiles[View::s_selectableFileIndex]); - ImGui::CloseCurrentPopup(); - } - - ImGui::SameLine(); - - if (ImGui::Button("hex.builtin.common.browse"_lang)) { - fs::openFileBrowser(fs::DialogMode::Open, View::s_selectableFilesValidExtensions, [](const auto &path) { - View::s_selectableFileOpenCallback(path); - ImGui::CloseCurrentPopup(); - }); - } - - ImGui::EndPopup(); - } + void View::showInfoPopup(const std::string &message) { + EventManager::post(message); } - void View::showMessagePopup(const std::string &message) { - s_popupMessage = message; - - ImHexApi::Tasks::doLater([] { ImGui::OpenPopup("hex.builtin.common.info"_lang); }); + void View::showErrorPopup(const std::string &message) { + EventManager::post(message); } - void View::showErrorPopup(const std::string &errorMessage) { - s_popupMessage = errorMessage; - - ImHexApi::Tasks::doLater([] { ImGui::OpenPopup("hex.builtin.common.error"_lang); }); - } - - void View::showFatalPopup(const std::string &errorMessage) { - s_popupMessage = errorMessage; - - ImHexApi::Tasks::doLater([] { ImGui::OpenPopup("hex.builtin.common.fatal"_lang); }); + void View::showFatalPopup(const std::string &message) { + EventManager::post(message); } void View::showYesNoQuestionPopup(const std::string &message, const std::function &yesCallback, const std::function &noCallback) { - s_popupMessage = message; + EventManager::post(message, yesCallback, noCallback); - s_yesCallback = yesCallback; - s_noCallback = noCallback; - - ImHexApi::Tasks::doLater([] { ImGui::OpenPopup("hex.builtin.common.question"_lang); }); } void View::showFileChooserPopup(const std::vector &paths, const std::vector &validExtensions, const std::function &callback) { @@ -151,12 +40,7 @@ namespace hex { callback(path); }); } else { - View::s_selectableFileIndex = 0; - View::s_selectableFiles = paths; - View::s_selectableFilesValidExtensions = validExtensions; - View::s_selectableFileOpenCallback = callback; - - ImHexApi::Tasks::doLater([] { ImGui::OpenPopup("hex.builtin.common.choose_file"_lang); }); + EventManager::post(paths, validExtensions, callback); } } diff --git a/main/include/init/splash_window.hpp b/main/include/init/splash_window.hpp index fe7ff8ac8..416af1ffa 100644 --- a/main/include/init/splash_window.hpp +++ b/main/include/init/splash_window.hpp @@ -23,8 +23,6 @@ namespace hex::init { this->m_tasks.emplace_back(taskName, task); } - [[nodiscard]] const std::string &getGPUVendor() const { return this->m_gpuVendor; } - private: GLFWwindow *m_window; std::mutex m_progressMutex; diff --git a/main/source/init/splash_window.cpp b/main/source/init/splash_window.cpp index da5a6e339..e70754c84 100644 --- a/main/source/init/splash_window.cpp +++ b/main/source/init/splash_window.cpp @@ -30,7 +30,7 @@ namespace hex::init { this->initGLFW(); this->initImGui(); - this->m_gpuVendor = reinterpret_cast(glGetString(GL_VENDOR)); + ImHexApi::System::impl::setGPUVendor(reinterpret_cast(glGetString(GL_VENDOR))); } WindowSplash::~WindowSplash() { diff --git a/main/source/main.cpp b/main/source/main.cpp index 7e6dce816..60bb72b24 100644 --- a/main/source/main.cpp +++ b/main/source/main.cpp @@ -25,17 +25,6 @@ int main(int argc, char **argv, char **envp) { init::WindowSplash splashWindow; - // Intel's OpenGL driver has weird bugs that cause the drawn window to be offset to the bottom right. - // This can be fixed by either using Mesa3D's OpenGL Software renderer or by simply disabling it. - // If you want to try if it works anyways on your GPU, set the hex.builtin.setting.interface.force_borderless_window_mode setting to 1 - if (ImHexApi::System::isBorderlessWindowModeEnabled()) { - bool isIntelGPU = hex::containsIgnoreCase(splashWindow.getGPUVendor(), "Intel"); - ImHexApi::System::impl::setBorderlessWindowMode(!isIntelGPU); - - if (isIntelGPU) - log::warn("Intel GPU detected! Intel's OpenGL driver has bugs that can cause issues when using ImHex. If you experience any rendering bugs, please try the Mesa3D Software Renderer"); - } - for (const auto &[name, task] : init::getInitTasks()) splashWindow.addStartupTask(name, task); diff --git a/main/source/window/linux_window.cpp b/main/source/window/linux_window.cpp index 231c12791..51772b2b5 100644 --- a/main/source/window/linux_window.cpp +++ b/main/source/window/linux_window.cpp @@ -2,6 +2,7 @@ #if defined(OS_LINUX) + #include #include #include diff --git a/main/source/window/macos_window.cpp b/main/source/window/macos_window.cpp index c8678b1e5..80422d52a 100644 --- a/main/source/window/macos_window.cpp +++ b/main/source/window/macos_window.cpp @@ -2,6 +2,7 @@ #if defined(OS_MACOS) + #include #include #include diff --git a/main/source/window/window.cpp b/main/source/window/window.cpp index cacd9d70e..a48e7c454 100644 --- a/main/source/window/window.cpp +++ b/main/source/window/window.cpp @@ -421,8 +421,6 @@ namespace hex { calls.clear(); } - View::drawCommonInterfaces(); - for (auto &[name, view] : ContentRegistry::Views::getEntries()) { ImGui::GetCurrentContext()->NextWindowData.ClearFlags(); diff --git a/plugins/builtin/source/content/events.cpp b/plugins/builtin/source/content/events.cpp index 5246a150c..6c36d4eb4 100644 --- a/plugins/builtin/source/content/events.cpp +++ b/plugins/builtin/source/content/events.cpp @@ -1,6 +1,7 @@ #include #include +#include #include #include #include @@ -88,6 +89,11 @@ namespace hex::plugin::builtin { EventManager::subscribe([](auto, auto) { EventManager::post(); }); + + EventManager::subscribe([](hex::prv::Provider *provider) { + if (provider->hasLoadInterface()) + EventManager::post(View::toWindowName("hex.builtin.view.provider_settings.load_popup")); + }); } } \ No newline at end of file diff --git a/plugins/builtin/source/content/settings_entries.cpp b/plugins/builtin/source/content/settings_entries.cpp index c2b349033..48c343d0c 100644 --- a/plugins/builtin/source/content/settings_entries.cpp +++ b/plugins/builtin/source/content/settings_entries.cpp @@ -314,17 +314,34 @@ namespace hex::plugin::builtin { ContentRegistry::Settings::add(dirsSetting, dirsSetting, std::vector {}, [](auto name, nlohmann::json &setting) { hex::unused(name); - static std::vector folders = setting; - static size_t currentItemIndex = 0; + static size_t currentItemIndex = 0; + static std::vector folders = [&setting]{ + std::vector result; + + std::vector paths = setting; + for (const auto &path : paths) + result.emplace_back(path); + + return result; + }(); bool result = false; + auto writeSetting = [&setting]{ + std::vector folderStrings; + for (const auto &folder : folders) + folderStrings.push_back(folder.u8string()); + setting = folderStrings; + + ImHexApi::System::setAdditionalFolderPaths(folders); + }; + if (!ImGui::BeginListBox("", ImVec2(-38, -FLT_MIN))) { return false; } else { for (size_t n = 0; n < folders.size(); n++) { const bool isSelected = (currentItemIndex == n); - if (ImGui::Selectable(folders.at(n).c_str(), isSelected)) { currentItemIndex = n; } + if (ImGui::Selectable(folders.at(n).string().c_str(), isSelected)) { currentItemIndex = n; } if (isSelected) { ImGui::SetItemDefaultFocus(); } } ImGui::EndListBox(); @@ -334,11 +351,12 @@ namespace hex::plugin::builtin { if (ImGui::IconButton(ICON_VS_NEW_FOLDER, ImGui::GetCustomColorVec4(ImGuiCustomCol_DescButton), ImVec2(30, 30))) { fs::openFileBrowser(fs::DialogMode::Folder, {}, [&](const std::fs::path &path) { - auto pathStr = path.string(); - if (std::find(folders.begin(), folders.end(), pathStr) == folders.end()) { - folders.emplace_back(pathStr); - ContentRegistry::Settings::write(dirsSetting, dirsSetting, folders); + if (std::find(folders.begin(), folders.end(), path) == folders.end()) { + folders.emplace_back(path); + + writeSetting(); + result = true; } }); @@ -348,7 +366,9 @@ namespace hex::plugin::builtin { if (ImGui::IconButton(ICON_VS_REMOVE_CLOSE, ImGui::GetCustomColorVec4(ImGuiCustomCol_DescButton), ImVec2(30, 30))) { if (!folders.empty()) { folders.erase(std::next(folders.begin(), currentItemIndex)); - ContentRegistry::Settings::write(dirsSetting, dirsSetting, folders); + + writeSetting(); + result = true; } } diff --git a/plugins/builtin/source/content/tools_entries.cpp b/plugins/builtin/source/content/tools_entries.cpp index 3c74698fd..ee8b25bdb 100644 --- a/plugins/builtin/source/content/tools_entries.cpp +++ b/plugins/builtin/source/content/tools_entries.cpp @@ -853,7 +853,7 @@ namespace hex::plugin::builtin { file.remove(); - View::showMessagePopup("hex.builtin.tools.file_tools.shredder.success"_lang); + View::showInfoPopup("hex.builtin.tools.file_tools.shredder.success"_lang); }).detach(); } } @@ -976,7 +976,7 @@ namespace hex::plugin::builtin { index++; } - View::showMessagePopup("hex.builtin.tools.file_tools.splitter.success"_lang); + View::showInfoPopup("hex.builtin.tools.file_tools.splitter.success"_lang); }).detach(); } } @@ -1110,7 +1110,7 @@ namespace hex::plugin::builtin { selectedIndex = 0; outputPath.clear(); - View::showMessagePopup("hex.builtin.tools.file_tools.combiner.success"_lang); + View::showInfoPopup("hex.builtin.tools.file_tools.combiner.success"_lang); }).detach(); } } diff --git a/plugins/builtin/source/content/ui_items.cpp b/plugins/builtin/source/content/ui_items.cpp index e76660a1e..4e43857ad 100644 --- a/plugins/builtin/source/content/ui_items.cpp +++ b/plugins/builtin/source/content/ui_items.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -12,6 +13,13 @@ namespace hex::plugin::builtin { + static std::string s_popupMessage; + static std::function s_yesCallback, s_noCallback; + static u32 s_selectableFileIndex; + static std::vector s_selectableFiles; + static std::function s_selectableFileOpenCallback; + static std::vector s_selectableFilesValidExtensions; + static void drawGlobalPopups() { // "Are you sure you want to exit?" Popup @@ -28,10 +36,141 @@ namespace hex::plugin::builtin { ImGui::EndPopup(); } + + auto windowSize = ImHexApi::System::getMainWindowSize(); + + // Info popup + ImGui::SetNextWindowSizeConstraints(scaled(ImVec2(400, 100)), scaled(ImVec2(600, 300))); + if (ImGui::BeginPopupModal("hex.builtin.common.info"_lang, nullptr, ImGuiWindowFlags_AlwaysAutoResize)) { + ImGui::TextFormattedWrapped("{}", s_popupMessage.c_str()); + ImGui::NewLine(); + ImGui::Separator(); + if (ImGui::Button("hex.builtin.common.okay"_lang) || ImGui::IsKeyDown(ImGuiKey_Escape)) + ImGui::CloseCurrentPopup(); + + ImGui::SetWindowPos((windowSize - ImGui::GetWindowSize()) / 2, ImGuiCond_Appearing); + ImGui::EndPopup(); + } + + // Error popup + ImGui::SetNextWindowSizeConstraints(scaled(ImVec2(400, 100)), scaled(ImVec2(600, 300))); + if (ImGui::BeginPopupModal("hex.builtin.common.error"_lang, nullptr, ImGuiWindowFlags_AlwaysAutoResize)) { + ImGui::TextFormattedWrapped("{}", s_popupMessage.c_str()); + ImGui::NewLine(); + ImGui::Separator(); + if (ImGui::Button("hex.builtin.common.okay"_lang) || ImGui::IsKeyDown(ImGuiKey_Escape)) + ImGui::CloseCurrentPopup(); + + ImGui::SetWindowPos((windowSize - ImGui::GetWindowSize()) / 2, ImGuiCond_Appearing); + ImGui::EndPopup(); + } + + // Fatal error popup + ImGui::SetNextWindowSizeConstraints(scaled(ImVec2(400, 100)), scaled(ImVec2(600, 300))); + if (ImGui::BeginPopupModal("hex.builtin.common.fatal"_lang, nullptr, ImGuiWindowFlags_AlwaysAutoResize)) { + ImGui::TextFormattedWrapped("{}", s_popupMessage.c_str()); + ImGui::NewLine(); + ImGui::Separator(); + if (ImGui::Button("hex.builtin.common.okay"_lang) || ImGui::IsKeyDown(ImGuiKey_Escape)) { + ImHexApi::Common::closeImHex(); + ImGui::CloseCurrentPopup(); + } + + ImGui::SetWindowPos((windowSize - ImGui::GetWindowSize()) / 2, ImGuiCond_Appearing); + ImGui::EndPopup(); + } + + // Yes/No question popup + ImGui::SetNextWindowSizeConstraints(scaled(ImVec2(400, 100)), scaled(ImVec2(600, 300))); + if (ImGui::BeginPopupModal("hex.builtin.common.question"_lang, nullptr, ImGuiWindowFlags_AlwaysAutoResize)) { + ImGui::TextFormattedWrapped("{}", s_popupMessage.c_str()); + ImGui::NewLine(); + ImGui::Separator(); + + View::confirmButtons( + "hex.builtin.common.yes"_lang, "hex.builtin.common.no"_lang, [] { + s_yesCallback(); + ImGui::CloseCurrentPopup(); }, [] { + s_noCallback(); + ImGui::CloseCurrentPopup(); }); + + ImGui::SetWindowPos((windowSize - ImGui::GetWindowSize()) / 2, ImGuiCond_Appearing); + ImGui::EndPopup(); + } + + // File chooser popup + bool opened = true; + ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetCenter(), ImGuiCond_Appearing, ImVec2(0.5F, 0.5F)); + if (ImGui::BeginPopupModal("hex.builtin.common.choose_file"_lang, &opened, ImGuiWindowFlags_AlwaysAutoResize)) { + + if (ImGui::BeginListBox("##files", ImVec2(300_scaled, 0))) { + + u32 index = 0; + for (auto &path : s_selectableFiles) { + if (ImGui::Selectable(path.filename().string().c_str(), index == s_selectableFileIndex)) + s_selectableFileIndex = index; + index++; + } + + ImGui::EndListBox(); + } + + if (ImGui::Button("hex.builtin.common.open"_lang)) { + s_selectableFileOpenCallback(s_selectableFiles[s_selectableFileIndex]); + ImGui::CloseCurrentPopup(); + } + + ImGui::SameLine(); + + if (ImGui::Button("hex.builtin.common.browse"_lang)) { + fs::openFileBrowser(fs::DialogMode::Open, s_selectableFilesValidExtensions, [](const auto &path) { + s_selectableFileOpenCallback(path); + ImGui::CloseCurrentPopup(); + }); + } + + ImGui::EndPopup(); + } } void addGlobalUIItems() { EventManager::subscribe(drawGlobalPopups); + + EventManager::subscribe([](const std::string &message) { + s_popupMessage = message; + + ImHexApi::Tasks::doLater([] { ImGui::OpenPopup("hex.builtin.common.info"_lang); }); + }); + + EventManager::subscribe([](const std::string &message) { + s_popupMessage = message; + + ImHexApi::Tasks::doLater([] { ImGui::OpenPopup("hex.builtin.common.error"_lang); }); + }); + + EventManager::subscribe([](const std::string &message) { + s_popupMessage = message; + + ImHexApi::Tasks::doLater([] { ImGui::OpenPopup("hex.builtin.common.fatal"_lang); }); + }); + + EventManager::subscribe([](const std::string &message, const std::function &yesCallback, const std::function &noCallback) { + s_popupMessage = message; + + s_yesCallback = yesCallback; + s_noCallback = noCallback; + + ImHexApi::Tasks::doLater([] { ImGui::OpenPopup("hex.builtin.common.question"_lang); }); + }); + + EventManager::subscribe([](const std::vector &paths, const std::vector &validExtensions, const std::function &callback) { + s_selectableFileIndex = 0; + s_selectableFiles = paths; + s_selectableFilesValidExtensions = validExtensions; + s_selectableFileOpenCallback = callback; + + ImHexApi::Tasks::doLater([] { ImGui::OpenPopup("hex.builtin.common.choose_file"_lang); }); + }); } void addFooterItems() { @@ -178,4 +317,17 @@ namespace hex::plugin::builtin { } + void handleBorderlessWindowMode() { + // Intel's OpenGL driver has weird bugs that cause the drawn window to be offset to the bottom right. + // This can be fixed by either using Mesa3D's OpenGL Software renderer or by simply disabling it. + // If you want to try if it works anyways on your GPU, set the hex.builtin.setting.interface.force_borderless_window_mode setting to 1 + if (ImHexApi::System::isBorderlessWindowModeEnabled()) { + bool isIntelGPU = hex::containsIgnoreCase(ImHexApi::System::getGPUVendor(), "Intel"); + ImHexApi::System::impl::setBorderlessWindowMode(!isIntelGPU); + + if (isIntelGPU) + log::warn("Intel GPU detected! Intel's OpenGL driver has bugs that can cause issues when using ImHex. If you experience any rendering bugs, please try the Mesa3D Software Renderer"); + } + } + } \ No newline at end of file diff --git a/plugins/builtin/source/content/views/view_information.cpp b/plugins/builtin/source/content/views/view_information.cpp index ed82966c1..3f0b0c22f 100644 --- a/plugins/builtin/source/content/views/view_information.cpp +++ b/plugins/builtin/source/content/views/view_information.cpp @@ -49,7 +49,7 @@ namespace hex::plugin::builtin { ContentRegistry::FileHandler::add({ ".mgc" }, [](const auto &path) { for (const auto &destPath : fs::getDefaultPaths(fs::ImHexPath::Magic)) { if (fs::copyFile(path, destPath / path.filename(), std::fs::copy_options::overwrite_existing)) { - View::showMessagePopup("hex.builtin.view.information.magic_db_added"_lang); + View::showInfoPopup("hex.builtin.view.information.magic_db_added"_lang); return true; } } diff --git a/plugins/builtin/source/content/views/view_settings.cpp b/plugins/builtin/source/content/views/view_settings.cpp index decdc8ac2..842053cff 100644 --- a/plugins/builtin/source/content/views/view_settings.cpp +++ b/plugins/builtin/source/content/views/view_settings.cpp @@ -51,7 +51,7 @@ namespace hex::plugin::builtin { if (ImGui::BeginTabItem(LangEntry(category))) { const std::string &categoryDesc = descriptions.count(category) ? descriptions.at(category) : category.name; LangEntry descriptionEntry{categoryDesc}; - ImGui::TextUnformatted(descriptionEntry); + ImGui::TextWrapped("%s", static_cast(descriptionEntry)); ImGui::InfoTooltip(descriptionEntry); ImGui::Separator(); diff --git a/plugins/builtin/source/content/views/view_yara.cpp b/plugins/builtin/source/content/views/view_yara.cpp index 0f8bd1eeb..0fca028e5 100644 --- a/plugins/builtin/source/content/views/view_yara.cpp +++ b/plugins/builtin/source/content/views/view_yara.cpp @@ -20,7 +20,7 @@ namespace hex::plugin::builtin { ContentRegistry::FileHandler::add({ ".yar" }, [](const auto &path) { for (const auto &destPath : fs::getDefaultPaths(fs::ImHexPath::Yara)) { if (fs::copyFile(path, destPath / path.filename(), std::fs::copy_options::overwrite_existing)) { - View::showMessagePopup("hex.builtin.view.yara.rule_added"_lang); + View::showInfoPopup("hex.builtin.view.yara.rule_added"_lang); return true; } }