diff --git a/lib/libimhex/include/hex/api/content_registry.hpp b/lib/libimhex/include/hex/api/content_registry.hpp index 816eca35f..99e52748e 100644 --- a/lib/libimhex/include/hex/api/content_registry.hpp +++ b/lib/libimhex/include/hex/api/content_registry.hpp @@ -113,13 +113,14 @@ namespace hex { } - template T, typename ... Args> void add(Args&& ... args) { return impl::add(new T(std::forward(args)...)); } - std::vector& getEntries(); + std::map& getEntries(); + + View* getViewByName(const std::string &unlocalizedName); } @@ -215,15 +216,39 @@ namespace hex { /* Interface Registry. Allows adding new items to various interfaces */ namespace Interface { - using DrawCallback = std::function; - void addWelcomeScreenEntry(const DrawCallback &function); - void addFooterItem(const DrawCallback &function); - void addToolbarItem(const DrawCallback &function); + namespace impl { - std::vector& getWelcomeScreenEntries(); - std::vector& getFooterItems(); - std::vector& getToolbarItems(); + using DrawCallback = std::function; + using LayoutFunction = std::function; + + struct Layout { + std::string unlocalizedName; + LayoutFunction callback; + }; + + struct MainMenuItem { + std::string unlocalizedName; + DrawCallback callback; + }; + + } + + u32 getDockSpaceId(); + + void registerMainMenuItem(const std::string &unlocalizedName, const impl::DrawCallback &function = []{}); + void addWelcomeScreenEntry(const impl::DrawCallback &function); + void addFooterItem(const impl::DrawCallback &function); + void addToolbarItem(const impl::DrawCallback &function); + + void addLayout(const std::string &unlocalizedName, const impl::LayoutFunction &function); + + std::vector& getMainMenuItems(); + std::vector& getWelcomeScreenEntries(); + std::vector& getFooterItems(); + std::vector& getToolbarItems(); + + std::vector& getLayouts(); } /* Provider Registry. Allows adding new data providers to be created from the UI */ diff --git a/lib/libimhex/include/hex/api/event.hpp b/lib/libimhex/include/hex/api/event.hpp index 0b401b26f..c565ce907 100644 --- a/lib/libimhex/include/hex/api/event.hpp +++ b/lib/libimhex/include/hex/api/event.hpp @@ -111,6 +111,8 @@ namespace hex { EVENT_DEF(EventAbnormalTermination, int); EVENT_DEF(EventOSThemeChanged); EVENT_DEF(EventProviderCreated, prv::Provider*); + EVENT_DEF(EventFrameBegin); + EVENT_DEF(EventFrameEnd); EVENT_DEF(RequestOpenWindow, std::string); EVENT_DEF(RequestSelectionChange, Region); diff --git a/lib/libimhex/include/hex/helpers/shared_data.hpp b/lib/libimhex/include/hex/helpers/shared_data.hpp index d69497087..46d969bd0 100644 --- a/lib/libimhex/include/hex/helpers/shared_data.hpp +++ b/lib/libimhex/include/hex/helpers/shared_data.hpp @@ -63,7 +63,7 @@ namespace hex { static nlohmann::json settingsJson; static std::vector commandPaletteCommands; static std::map patternLanguageFunctions; - static std::vector views; + static std::map views; static std::vector toolsEntries; static std::vector dataInspectorEntries; static u32 patternPaletteOffset; @@ -75,9 +75,13 @@ namespace hex { static std::map> languageDefinitions; static std::map loadedLanguageStrings; - static std::vector welcomeScreenEntries; - static std::vector footerItems; - static std::vector toolbarItems; + static ImGuiID dockSpaceId; + + static std::vector mainMenuItems; + static std::vector welcomeScreenEntries; + static std::vector footerItems; + static std::vector toolbarItems; + static std::vector layouts; static std::map> globalShortcuts; diff --git a/lib/libimhex/include/hex/views/view.hpp b/lib/libimhex/include/hex/views/view.hpp index cbd6f5d34..ebf7545cf 100644 --- a/lib/libimhex/include/hex/views/view.hpp +++ b/lib/libimhex/include/hex/views/view.hpp @@ -53,6 +53,7 @@ namespace hex { const bool& getWindowOpenState() const; [[nodiscard]] const std::string& getUnlocalizedName() const; + [[nodiscard]] std::string getName() const; static void confirmButtons(const std::string &textLeft, const std::string &textRight, const std::function &leftButtonFn, const std::function &rightButtonFn); static void discardNavigationRequests(); diff --git a/lib/libimhex/source/api/content_registry.cpp b/lib/libimhex/source/api/content_registry.cpp index 513e83f63..8d61a1444 100644 --- a/lib/libimhex/source/api/content_registry.cpp +++ b/lib/libimhex/source/api/content_registry.cpp @@ -206,13 +206,22 @@ namespace hex { void ContentRegistry::Views::impl::add(View *view) { log::info("Registered new view: {}", view->getUnlocalizedName()); - getEntries().emplace_back(view); + getEntries().insert({ view->getUnlocalizedName(), view }); } - std::vector& ContentRegistry::Views::getEntries() { + std::map& ContentRegistry::Views::getEntries() { return SharedData::views; } + View *ContentRegistry::Views::getViewByName(const std::string &unlocalizedName) { + auto &views = getEntries(); + + if (views.contains(unlocalizedName)) + return views[unlocalizedName]; + else + return nullptr; + } + /* Tools */ @@ -281,29 +290,53 @@ namespace hex { /* Interface */ - void ContentRegistry::Interface::addWelcomeScreenEntry(const ContentRegistry::Interface::DrawCallback &function) { + u32 ContentRegistry::Interface::getDockSpaceId() { + return SharedData::dockSpaceId; + } + + void ContentRegistry::Interface::registerMainMenuItem(const std::string &unlocalizedName, const impl::DrawCallback &function) { + log::info("Registered new main menu item: {}", unlocalizedName); + + getMainMenuItems().push_back({ unlocalizedName, function }); + } + + void ContentRegistry::Interface::addWelcomeScreenEntry(const ContentRegistry::Interface::impl::DrawCallback &function) { getWelcomeScreenEntries().push_back(function); } - void ContentRegistry::Interface::addFooterItem(const ContentRegistry::Interface::DrawCallback &function){ + void ContentRegistry::Interface::addFooterItem(const ContentRegistry::Interface::impl::DrawCallback &function){ getFooterItems().push_back(function); } - void ContentRegistry::Interface::addToolbarItem(const ContentRegistry::Interface::DrawCallback &function){ + void ContentRegistry::Interface::addToolbarItem(const ContentRegistry::Interface::impl::DrawCallback &function){ getToolbarItems().push_back(function); } + void ContentRegistry::Interface::addLayout(const std::string &unlocalizedName, const impl::LayoutFunction &function) { + log::info("Added new layout: {}", unlocalizedName); - std::vector& ContentRegistry::Interface::getWelcomeScreenEntries() { + getLayouts().push_back({ unlocalizedName, function }); + } + + + std::vector &ContentRegistry::Interface::getMainMenuItems() { + return SharedData::mainMenuItems; + } + + std::vector& ContentRegistry::Interface::getWelcomeScreenEntries() { return SharedData::welcomeScreenEntries; } - std::vector& ContentRegistry::Interface::getFooterItems() { + std::vector& ContentRegistry::Interface::getFooterItems() { return SharedData::footerItems; } - std::vector& ContentRegistry::Interface::getToolbarItems() { + std::vector& ContentRegistry::Interface::getToolbarItems() { return SharedData::toolbarItems; } + std::vector& ContentRegistry::Interface::getLayouts() { + return SharedData::layouts; + } + /* Providers */ diff --git a/lib/libimhex/source/helpers/shared_data.cpp b/lib/libimhex/source/helpers/shared_data.cpp index 1a7cee499..310a9ff1c 100644 --- a/lib/libimhex/source/helpers/shared_data.cpp +++ b/lib/libimhex/source/helpers/shared_data.cpp @@ -13,7 +13,7 @@ namespace hex { nlohmann::json SharedData::settingsJson; std::vector SharedData::commandPaletteCommands; std::map SharedData::patternLanguageFunctions; - std::vector SharedData::views; + std::map SharedData::views; std::vector SharedData::toolsEntries; std::vector SharedData::dataInspectorEntries; u32 SharedData::patternPaletteOffset; @@ -25,9 +25,13 @@ namespace hex { std::map> SharedData::languageDefinitions; std::map SharedData::loadedLanguageStrings; - std::vector SharedData::welcomeScreenEntries; - std::vector SharedData::footerItems; - std::vector SharedData::toolbarItems; + ImGuiID SharedData::dockSpaceId; + + std::vector SharedData::mainMenuItems; + std::vector SharedData::welcomeScreenEntries; + std::vector SharedData::footerItems; + std::vector SharedData::toolbarItems; + std::vector SharedData::layouts; std::map> SharedData::globalShortcuts; diff --git a/lib/libimhex/source/views/view.cpp b/lib/libimhex/source/views/view.cpp index f873dacfc..78bff3e2b 100644 --- a/lib/libimhex/source/views/view.cpp +++ b/lib/libimhex/source/views/view.cpp @@ -105,6 +105,10 @@ namespace hex { return this->m_unlocalizedViewName; } + std::string View::getName() const { + return View::toWindowName(this->m_unlocalizedViewName); + } + void View::discardNavigationRequests() { if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) ImGui::GetIO().ConfigFlags &= ~ImGuiConfigFlags_NavEnableKeyboard; diff --git a/main/include/helpers/plugin_manager.hpp b/main/include/helpers/plugin_manager.hpp index f55696b42..dc26f03d5 100644 --- a/main/include/helpers/plugin_manager.hpp +++ b/main/include/helpers/plugin_manager.hpp @@ -2,13 +2,10 @@ #include -#include -#include #include #include -#include -#include +#include struct ImGuiContext; @@ -39,17 +36,19 @@ namespace hex { void *m_handle = nullptr; fs::path m_path; - InitializePluginFunc m_initializePluginFunction = nullptr; - GetPluginNameFunc m_getPluginNameFunction = nullptr; - GetPluginAuthorFunc m_getPluginAuthorFunction = nullptr; - GetPluginDescriptionFunc m_getPluginDescriptionFunction = nullptr; - SetImGuiContextFunc m_setImGuiContextFunction = nullptr; + InitializePluginFunc m_initializePluginFunction = nullptr; + GetPluginNameFunc m_getPluginNameFunction = nullptr; + GetPluginAuthorFunc m_getPluginAuthorFunction = nullptr; + GetPluginDescriptionFunc m_getPluginDescriptionFunction = nullptr; + SetImGuiContextFunc m_setImGuiContextFunction = nullptr; template - auto getPluginFunction(const std::string &pluginName, const std::string &symbol) { - auto symbolName = hex::format(symbol.data(), pluginName.length(), pluginName.data()); - return reinterpret_cast(dlsym(this->m_handle, symbolName.c_str())); - }; + [[nodiscard]] auto getPluginFunction(const std::string &pluginName, const std::string &symbol) { + return reinterpret_cast(this->getPluginFunction(pluginName, symbol)); + } + + private: + [[nodiscard]] void* getPluginFunction(const std::string &pluginName, const std::string &symbol); }; class PluginManager { diff --git a/main/include/init/splash_window.hpp b/main/include/init/splash_window.hpp index 7d71c2b49..6faed2502 100644 --- a/main/include/init/splash_window.hpp +++ b/main/include/init/splash_window.hpp @@ -32,8 +32,8 @@ namespace hex::init { void initGLFW(); void initImGui(); - void deinitGLFW(); - void deinitImGui(); + void exitGLFW(); + void exitImGui(); std::future processTasksAsync(); diff --git a/main/include/window.hpp b/main/include/window.hpp index c8dde14e4..725929c09 100644 --- a/main/include/window.hpp +++ b/main/include/window.hpp @@ -34,12 +34,12 @@ namespace hex { void frameEnd(); void drawWelcomeScreen(); - void resetLayout(); + void resetLayout() const; void initGLFW(); void initImGui(); - void deinitGLFW(); - void deinitImGui(); + void exitGLFW(); + void exitImGui(); friend void *ImHexSettingsHandler_ReadOpenFn(ImGuiContext *ctx, ImGuiSettingsHandler *, const char *); friend void ImHexSettingsHandler_ReadLine(ImGuiContext*, ImGuiSettingsHandler *handler, void *, const char* line); @@ -48,15 +48,12 @@ namespace hex { GLFWwindow* m_window = nullptr; double m_targetFps = 60.0; - bool m_demoWindowOpen = false; bool m_layoutConfigured = false; std::string m_windowTitle; double m_lastFrameTime; - bool m_prevKeysDown[512]; - std::string m_availableUpdate; bool m_showTipOfTheDay; diff --git a/main/source/helpers/plugin_manager.cpp b/main/source/helpers/plugin_manager.cpp index baee65e87..dd500dee5 100644 --- a/main/source/helpers/plugin_manager.cpp +++ b/main/source/helpers/plugin_manager.cpp @@ -1,9 +1,9 @@ #include "helpers/plugin_manager.hpp" #include -#include #include +#include namespace hex { @@ -89,10 +89,15 @@ namespace hex { this->m_setImGuiContextFunction(ctx); } - const fs::path &Plugin::getPath() const { + const fs::path& Plugin::getPath() const { return this->m_path; } + void* Plugin::getPluginFunction(const std::string &pluginName, const std::string &symbol) { + auto symbolName = hex::format(symbol.data(), pluginName.length(), pluginName.data()); + return dlsym(this->m_handle, symbolName.c_str()); + } + bool PluginManager::load(const fs::path &pluginFolder) { diff --git a/main/source/init/splash_window.cpp b/main/source/init/splash_window.cpp index bd16ea99b..5ca8da70f 100644 --- a/main/source/init/splash_window.cpp +++ b/main/source/init/splash_window.cpp @@ -32,8 +32,8 @@ namespace hex::init { } WindowSplash::~WindowSplash() { - this->deinitImGui(); - this->deinitGLFW(); + this->exitImGui(); + this->exitGLFW(); } @@ -235,12 +235,12 @@ namespace hex::init { io.Fonts->SetTexID(reinterpret_cast(tex)); } - void WindowSplash::deinitGLFW() { + void WindowSplash::exitGLFW() { glfwDestroyWindow(this->m_window); glfwTerminate(); } - void WindowSplash::deinitImGui() { + void WindowSplash::exitImGui() { ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplGlfw_Shutdown(); ImGui::DestroyContext(); diff --git a/main/source/init/tasks.cpp b/main/source/init/tasks.cpp index f02b5c592..0f8aaf5e2 100644 --- a/main/source/init/tasks.cpp +++ b/main/source/init/tasks.cpp @@ -176,7 +176,7 @@ namespace hex::init { SharedData::commandPaletteCommands.clear(); SharedData::patternLanguageFunctions.clear(); - for (auto &view : SharedData::views) + for (auto &[name, view] : ContentRegistry::Views::getEntries()) delete view; SharedData::views.clear(); diff --git a/main/source/window/window.cpp b/main/source/window/window.cpp index 63b732be7..ebe536066 100644 --- a/main/source/window/window.cpp +++ b/main/source/window/window.cpp @@ -49,7 +49,7 @@ namespace hex { } void ImHexSettingsHandler_ReadLine(ImGuiContext*, ImGuiSettingsHandler *handler, void *, const char* line) { - for (auto &view : ContentRegistry::Views::getEntries()) { + for (auto &[name, view] : ContentRegistry::Views::getEntries()) { std::string format = std::string(view->getUnlocalizedName()) + "=%d"; sscanf(line, format.c_str(), &view->getWindowOpenState()); } @@ -60,8 +60,8 @@ namespace hex { buf->appendf("[%s][General]\n", handler->TypeName); - for (auto &view : ContentRegistry::Views::getEntries()) { - buf->appendf("%s=%d\n", view->getUnlocalizedName().data(), view->getWindowOpenState()); + for (auto &[name, view] : ContentRegistry::Views::getEntries()) { + buf->appendf("%s=%d\n", name.c_str(), view->getWindowOpenState()); } buf->append("\n"); @@ -291,8 +291,8 @@ namespace hex { } Window::~Window() { - this->deinitImGui(); - this->deinitGLFW(); + this->exitImGui(); + this->exitGLFW(); EventManager::unsubscribe(this); EventManager::unsubscribe(this); @@ -350,7 +350,7 @@ namespace hex { if (ImGui::Begin("DockSpace", nullptr, windowFlags)) { ImGui::PopStyleVar(); - ImGui::DockSpace(ImGui::GetID("MainDock"), ImVec2(0.0f, ImGui::GetContentRegionAvail().y - ImGui::GetTextLineHeightWithSpacing() - ImGui::GetStyle().FramePadding.y * 2 - 1)); + SharedData::dockSpaceId = ImGui::DockSpace(ImGui::GetID("MainDock"), ImVec2(0.0f, ImGui::GetContentRegionAvail().y - ImGui::GetTextLineHeightWithSpacing() - ImGui::GetStyle().FramePadding.y * 2 - 1)); ImGui::Separator(); ImGui::SetCursorPosX(8); @@ -374,32 +374,20 @@ namespace hex { ImGui::SetCursorPosX(5); ImGui::Image(this->m_logoTexture, ImVec2(menuBarHeight, menuBarHeight)); - for (const auto& menu : { "hex.menu.file"_lang, "hex.menu.edit"_lang, "hex.menu.view"_lang, "hex.menu.help"_lang }) - if (ImGui::BeginMenu(menu)) ImGui::EndMenu(); - - if (ImGui::BeginMenu("hex.menu.view"_lang)) { - for (auto &view : ContentRegistry::Views::getEntries()) { - if (view->hasViewMenuItemEntry()) - ImGui::MenuItem(LangEntry(view->getUnlocalizedName()), "", &view->getWindowOpenState()); - } + for (const auto &[name, function] : ContentRegistry::Interface::getMainMenuItems()) { + if (ImGui::BeginMenu(LangEntry(name))) { + function(); ImGui::EndMenu(); } + } - for (auto &view : ContentRegistry::Views::getEntries()) { - view->drawMenu(); - } + for (auto &[name, view] : ContentRegistry::Views::getEntries()) { + view->drawMenu(); + } - if (ImGui::BeginMenu("hex.menu.view"_lang)) { - #if defined(DEBUG) - ImGui::Separator(); - ImGui::MenuItem("hex.menu.view.demo"_lang, "", &this->m_demoWindowOpen); - #endif - ImGui::EndMenu(); - } + this->drawTitleBar(); - this->drawTitleBar(); - - ImGui::EndMainMenuBar(); + ImGui::EndMainMenuBar(); } ImGui::PopStyleVar(); @@ -502,6 +490,8 @@ namespace hex { return false; }); + + EventManager::post(); } void Window::frame() { @@ -511,7 +501,7 @@ namespace hex { View::drawCommonInterfaces(); - for (auto &view : ContentRegistry::Views::getEntries()) { + for (auto &[name, view] : ContentRegistry::Views::getEntries()) { ImGui::GetCurrentContext()->NextWindowData.ClearFlags(); view->drawAlwaysVisible(); @@ -525,13 +515,13 @@ namespace hex { } if (view->getWindowOpenState()) { - auto window = ImGui::FindWindowByName(View::toWindowName(view->getUnlocalizedName()).c_str()); + auto window = ImGui::FindWindowByName(view->getName().c_str()); bool hasWindow = window != nullptr; bool focused = false; if (hasWindow && !(window->Flags & ImGuiWindowFlags_Popup)) { - ImGui::Begin(View::toWindowName(view->getUnlocalizedName()).c_str()); + ImGui::Begin(View::toWindowName(name).c_str()); focused = ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows); ImGui::End(); @@ -543,17 +533,13 @@ namespace hex { } } } - this->m_pressedKeys.clear(); -#ifdef DEBUG - if (this->m_demoWindowOpen) { - ImGui::ShowDemoWindow(&this->m_demoWindowOpen); - ImPlot::ShowDemoWindow(&this->m_demoWindowOpen); - } - #endif + this->m_pressedKeys.clear(); } void Window::frameEnd() { + EventManager::post(); + this->endNativeWindowFrame(); ImGui::Render(); @@ -731,27 +717,14 @@ namespace hex { } } - void Window::resetLayout() { - auto dockId = ImGui::GetID("MainDock"); + void Window::resetLayout() const { - ImGui::DockBuilderRemoveNode(dockId); - ImGui::DockBuilderAddNode(dockId, ImGuiDockNodeFlags_DockSpace); - ImGui::DockBuilderSetNodeSize(dockId, ImGui::GetWindowSize()); + if (auto &layouts = ContentRegistry::Interface::getLayouts(); !layouts.empty()) { + auto &[name, function] = layouts[0]; - ImGuiID mainWindowId, splitWindowId, hexEditorId, utilitiesId, inspectorId, patternDataId; + function(ContentRegistry::Interface::getDockSpaceId()); + } - ImGui::DockBuilderSplitNode(dockId, ImGuiDir_Left, 0.8, &mainWindowId, &utilitiesId); - ImGui::DockBuilderSplitNode(mainWindowId, ImGuiDir_Down, 0.3, &patternDataId, &splitWindowId); - ImGui::DockBuilderSplitNode(splitWindowId, ImGuiDir_Right, 0.3, &inspectorId, &hexEditorId); - - for (auto &view : ContentRegistry::Views::getEntries()) - ImGui::DockBuilderDockWindow(view->getUnlocalizedName().data(), utilitiesId); - - ImGui::DockBuilderDockWindow("hex.builtin.view.hexeditor.name", hexEditorId); - ImGui::DockBuilderDockWindow("hex.builtin.view.data_inspector.name", inspectorId); - ImGui::DockBuilderDockWindow("hex.builtin.view.pattern_data.name", patternDataId); - - ImGui::DockBuilderFinish(dockId); } void Window::initGLFW() { @@ -1001,12 +974,12 @@ namespace hex { plugin.setImGuiContext(ImGui::GetCurrentContext()); } - void Window::deinitGLFW() { + void Window::exitGLFW() { glfwDestroyWindow(this->m_window); glfwTerminate(); } - void Window::deinitImGui() { + void Window::exitImGui() { delete static_cast(ImGui::GetIO().UserData); ImNodes::PopAttributeFlag(); diff --git a/plugins/builtin/CMakeLists.txt b/plugins/builtin/CMakeLists.txt index b0bad72ed..7b022f3d5 100644 --- a/plugins/builtin/CMakeLists.txt +++ b/plugins/builtin/CMakeLists.txt @@ -16,6 +16,8 @@ add_library(${PROJECT_NAME} SHARED source/content/providers.cpp source/content/views.cpp source/content/data_formatters.cpp + source/content/layouts.cpp + source/content/main_menu_items.cpp source/content/providers/file_provider.cpp source/content/providers/gdb_provider.cpp diff --git a/plugins/builtin/source/content/layouts.cpp b/plugins/builtin/source/content/layouts.cpp new file mode 100644 index 000000000..b4553d17b --- /dev/null +++ b/plugins/builtin/source/content/layouts.cpp @@ -0,0 +1,41 @@ +#include + +#include +#include +#include + +namespace hex::plugin::builtin { + + static void openViewAndDockTo(const std::string &unlocalizedName, ImGuiID dockId) { + auto view = ContentRegistry::Views::getViewByName(unlocalizedName); + + if (view != nullptr) { + view->getWindowOpenState() = true; + ImGui::DockBuilderDockWindow(view->getName().c_str(), dockId); + + } + } + + void registerLayouts() { + + ContentRegistry::Interface::addLayout("hex.builtin.layouts.default", [](ImGuiID dockMain) { + ImGuiID hexEditor = ImGui::DockBuilderSplitNode(dockMain, ImGuiDir_Left, 0.7F, nullptr, &dockMain); + ImGuiID utils = ImGui::DockBuilderSplitNode(dockMain, ImGuiDir_Right, 0.8F, nullptr, &dockMain); + ImGuiID patternData = ImGui::DockBuilderSplitNode(hexEditor, ImGuiDir_Down, 0.3F, nullptr, &hexEditor); + ImGuiID inspector = ImGui::DockBuilderSplitNode(hexEditor, ImGuiDir_Right, 0.3F, nullptr, &hexEditor); + + openViewAndDockTo("hex.builtin.view.hexeditor.name", hexEditor); + openViewAndDockTo("hex.builtin.view.data_inspector.name", inspector); + openViewAndDockTo("hex.builtin.view.pattern_data.name", patternData); + + openViewAndDockTo("hex.builtin.view.pattern_editor.name", utils); + openViewAndDockTo("hex.builtin.view.hashes.name", utils); + openViewAndDockTo("hex.builtin.view.data_information.name", utils); + openViewAndDockTo("hex.builtin.view.strings.name", utils); + openViewAndDockTo("hex.builtin.view.bookmarks.name", utils); + + }); + + } + +} \ No newline at end of file diff --git a/plugins/builtin/source/content/main_menu_items.cpp b/plugins/builtin/source/content/main_menu_items.cpp new file mode 100644 index 000000000..439dc04ec --- /dev/null +++ b/plugins/builtin/source/content/main_menu_items.cpp @@ -0,0 +1,57 @@ +#include + +#include +#include + +#include + +namespace hex::plugin::builtin { + + static bool g_demoWindowOpen = false; + + void registerMainMenuEntries() { + + ContentRegistry::Interface::registerMainMenuItem("hex.builtin.menu.file"); + ContentRegistry::Interface::registerMainMenuItem("hex.builtin.menu.edit"); + + ContentRegistry::Interface::registerMainMenuItem("hex.builtin.menu.view", [] { + for (auto &[name, view] : ContentRegistry::Views::getEntries()) { + if (view->hasViewMenuItemEntry()) + ImGui::MenuItem(LangEntry(view->getUnlocalizedName()), "", &view->getWindowOpenState()); + } + + #if defined(DEBUG) + ImGui::Separator(); + ImGui::MenuItem("hex.builtin.menu.view.demo"_lang, "", &g_demoWindowOpen); + #endif + }); + + ContentRegistry::Interface::registerMainMenuItem("hex.builtin.menu.layout", [] { + for (auto &[layoutName, func] : ContentRegistry::Interface::getLayouts()) { + if (ImGui::MenuItem(LangEntry(layoutName), "", false, ImHexApi::Provider::isValid())) { + auto dock = ContentRegistry::Interface::getDockSpaceId(); + + for (auto &[viewName, view] : ContentRegistry::Views::getEntries()) { + view->getWindowOpenState() = false; + } + + ImGui::DockBuilderRemoveNode(dock); + ImGui::DockBuilderAddNode(dock); + func(dock); + ImGui::DockBuilderFinish(dock); + } + } + }); + + (void) EventManager::subscribe([]{ + if (g_demoWindowOpen) { + ImGui::ShowDemoWindow(&g_demoWindowOpen); + ImPlot::ShowDemoWindow(&g_demoWindowOpen); + } + }); + + ContentRegistry::Interface::registerMainMenuItem("hex.builtin.menu.help"); + + } + +} \ No newline at end of file diff --git a/plugins/builtin/source/content/views/view_help.cpp b/plugins/builtin/source/content/views/view_help.cpp index 63da05274..e752c4bda 100644 --- a/plugins/builtin/source/content/views/view_help.cpp +++ b/plugins/builtin/source/content/views/view_help.cpp @@ -160,7 +160,7 @@ namespace hex::plugin::builtin { } void ViewHelp::drawMenu() { - if (ImGui::BeginMenu("hex.menu.help"_lang)) { + if (ImGui::BeginMenu("hex.builtin.menu.help"_lang)) { if (ImGui::MenuItem("hex.builtin.view.help.about.name"_lang, "")) { View::doLater([] { ImGui::OpenPopup(View::toWindowName("hex.builtin.view.help.about.name").c_str()); }); this->m_aboutWindowOpen = true; diff --git a/plugins/builtin/source/content/views/view_hexeditor.cpp b/plugins/builtin/source/content/views/view_hexeditor.cpp index 8c096fe5d..a16a3f6a1 100644 --- a/plugins/builtin/source/content/views/view_hexeditor.cpp +++ b/plugins/builtin/source/content/views/view_hexeditor.cpp @@ -180,9 +180,9 @@ namespace hex::plugin::builtin { if (ImGui::Begin(View::toWindowName("hex.builtin.view.hexeditor.name").c_str())) { if (ImGui::IsMouseReleased(ImGuiMouseButton_Right) && ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows)) - ImGui::OpenPopup("hex.menu.edit"_lang); + ImGui::OpenPopup("hex.builtin.menu.edit"_lang); - if (ImGui::BeginPopup("hex.menu.edit"_lang)) { + if (ImGui::BeginPopup("hex.builtin.menu.edit"_lang)) { this->drawEditPopup(); ImGui::EndPopup(); } @@ -339,7 +339,7 @@ namespace hex::plugin::builtin { auto provider = ImHexApi::Provider::get(); bool providerValid = ImHexApi::Provider::isValid(); - if (ImGui::BeginMenu("hex.menu.file"_lang)) { + if (ImGui::BeginMenu("hex.builtin.menu.file"_lang)) { if (ImGui::MenuItem("hex.builtin.view.hexeditor.menu.file.open_file"_lang, "CTRL + O")) { hex::openFileBrowser("hex.builtin.view.hexeditor.open_file"_lang, DialogMode::Open, { }, [](const auto &path) { @@ -598,7 +598,7 @@ namespace hex::plugin::builtin { ImGui::EndMenu(); } - if (ImGui::BeginMenu("hex.menu.edit"_lang)) { + if (ImGui::BeginMenu("hex.builtin.menu.edit"_lang)) { this->drawEditPopup(); ImGui::EndMenu(); } diff --git a/plugins/builtin/source/content/views/view_pattern_editor.cpp b/plugins/builtin/source/content/views/view_pattern_editor.cpp index 03af39bb4..b5de09080 100644 --- a/plugins/builtin/source/content/views/view_pattern_editor.cpp +++ b/plugins/builtin/source/content/views/view_pattern_editor.cpp @@ -209,7 +209,7 @@ namespace hex::plugin::builtin { } void ViewPatternEditor::drawMenu() { - if (ImGui::BeginMenu("hex.menu.file"_lang)) { + if (ImGui::BeginMenu("hex.builtin.menu.file"_lang)) { ImGui::Separator(); diff --git a/plugins/builtin/source/content/views/view_provider_settings.cpp b/plugins/builtin/source/content/views/view_provider_settings.cpp index 3aaea4eaf..0b051209e 100644 --- a/plugins/builtin/source/content/views/view_provider_settings.cpp +++ b/plugins/builtin/source/content/views/view_provider_settings.cpp @@ -14,7 +14,7 @@ namespace hex::plugin::builtin { } void ViewProviderSettings::drawContent() { - if (ImGui::Begin(View::toWindowName("hex.builtin.view.provider_settings.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) { + if (ImGui::Begin(this->getName().c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) { auto provider = hex::ImHexApi::Provider::get(); if (provider != nullptr) diff --git a/plugins/builtin/source/content/views/view_settings.cpp b/plugins/builtin/source/content/views/view_settings.cpp index 555b1245a..a279c5522 100644 --- a/plugins/builtin/source/content/views/view_settings.cpp +++ b/plugins/builtin/source/content/views/view_settings.cpp @@ -46,7 +46,7 @@ namespace hex::plugin::builtin { } void ViewSettings::drawMenu() { - if (ImGui::BeginMenu("hex.menu.help"_lang)) { + if (ImGui::BeginMenu("hex.builtin.menu.help"_lang)) { ImGui::Separator(); diff --git a/plugins/builtin/source/content/views/view_store.cpp b/plugins/builtin/source/content/views/view_store.cpp index b701b418b..279413423 100644 --- a/plugins/builtin/source/content/views/view_store.cpp +++ b/plugins/builtin/source/content/views/view_store.cpp @@ -235,7 +235,7 @@ namespace hex::plugin::builtin { } void ViewStore::drawMenu() { - if (ImGui::BeginMenu("hex.menu.help"_lang)) { + if (ImGui::BeginMenu("hex.builtin.menu.help"_lang)) { if (ImGui::MenuItem("hex.builtin.view.store.name"_lang)) { View::doLater([]{ ImGui::OpenPopup(View::toWindowName("hex.builtin.view.store.name").c_str()); }); this->getWindowOpenState() = true; diff --git a/plugins/builtin/source/lang/de_DE.cpp b/plugins/builtin/source/lang/de_DE.cpp index 5b6ec9e54..a81270389 100644 --- a/plugins/builtin/source/lang/de_DE.cpp +++ b/plugins/builtin/source/lang/de_DE.cpp @@ -8,12 +8,6 @@ namespace hex::plugin::builtin { ContentRegistry::Language::addLocalizations("de-DE", { /* ImHex default functionality */ - { "hex.menu.file", "Datei" }, - { "hex.menu.edit", "Bearbeiten" }, - { "hex.menu.view", "Ansicht" }, - { "hex.menu.view.fps", "FPS anzeigen" }, - { "hex.menu.view.demo", "ImGui Demo anzeigen" }, - { "hex.menu.help", "Hilfe" }, { "hex.menu.feedback", "Feedback hinterlassen" }, { "hex.menu.debug_build", "Debug build"}, @@ -91,6 +85,14 @@ namespace hex::plugin::builtin { /* Builtin plugin features */ + { "hex.builtin.menu.file", "Datei" }, + { "hex.builtin.menu.edit", "Bearbeiten" }, + { "hex.builtin.menu.view", "Ansicht" }, + { "hex.builtin.menu.layout", "Layout" }, + { "hex.builtin.menu.view.fps", "FPS anzeigen" }, + { "hex.builtin.menu.view.demo", "ImGui Demo anzeigen" }, + { "hex.builtin.menu.help", "Hilfe" }, + { "hex.builtin.view.bookmarks.name", "Lesezeichen" }, { "hex.builtin.view.bookmarks.default_title", "Lesezeichen [0x{0:X} - 0x{1:X}]" }, { "hex.builtin.view.bookmarks.no_bookmarks", "Noch kein Lesezeichen erstellt. Füge eines hinzu mit Bearbeiten -> Lesezeichen erstellen" }, @@ -695,6 +697,8 @@ namespace hex::plugin::builtin { { "hex.builtin.provider.disk.disk_size", "Datenträgergrösse" }, { "hex.builtin.provider.disk.sector_size", "Sektorgrösse" }, { "hex.builtin.provider.disk.reload", "Neu laden" }, + + { "hex.builtin.layouts.default", "Standard" } }); } diff --git a/plugins/builtin/source/lang/en_US.cpp b/plugins/builtin/source/lang/en_US.cpp index 909b7c6fe..f61413974 100644 --- a/plugins/builtin/source/lang/en_US.cpp +++ b/plugins/builtin/source/lang/en_US.cpp @@ -8,12 +8,6 @@ namespace hex::plugin::builtin { ContentRegistry::Language::addLocalizations("en-US", { /* ImHex default functionality */ - { "hex.menu.file", "File" }, - { "hex.menu.edit", "Edit" }, - { "hex.menu.view", "View" }, - { "hex.menu.view.fps", "Display FPS" }, - { "hex.menu.view.demo", "Show ImGui Demo" }, - { "hex.menu.help", "Help" }, { "hex.menu.feedback", "Leave Feedback" }, { "hex.menu.debug_build", "Debug build"}, @@ -90,6 +84,14 @@ namespace hex::plugin::builtin { /* Builtin plugin features */ + { "hex.builtin.menu.file", "File" }, + { "hex.builtin.menu.edit", "Edit" }, + { "hex.builtin.menu.view", "View" }, + { "hex.builtin.menu.layout", "Layout" }, + { "hex.builtin.menu.view.fps", "Display FPS" }, + { "hex.builtin.menu.view.demo", "Show ImGui Demo" }, + { "hex.builtin.menu.help", "Help" }, + { "hex.builtin.view.bookmarks.name", "Bookmarks" }, { "hex.builtin.view.bookmarks.default_title", "Bookmark [0x{0:X} - 0x{1:X}]" }, { "hex.builtin.view.bookmarks.no_bookmarks", "No bookmarks created yet. Add one with Edit -> Create Bookmark" }, @@ -698,6 +700,8 @@ namespace hex::plugin::builtin { { "hex.builtin.provider.disk.disk_size", "Disk Size" }, { "hex.builtin.provider.disk.sector_size", "Sector Size" }, { "hex.builtin.provider.disk.reload", "Reload" }, + + { "hex.builtin.layouts.default", "Default" } }); } diff --git a/plugins/builtin/source/lang/it_IT.cpp b/plugins/builtin/source/lang/it_IT.cpp index 15cce93de..9daafaa90 100644 --- a/plugins/builtin/source/lang/it_IT.cpp +++ b/plugins/builtin/source/lang/it_IT.cpp @@ -8,12 +8,6 @@ namespace hex::plugin::builtin { ContentRegistry::Language::addLocalizations("it-IT", { /* ImHex default functionality */ - { "hex.menu.file", "File" }, - { "hex.menu.edit", "Modifica" }, - { "hex.menu.view", "Vista" }, - { "hex.menu.view.fps", "Mostra FPS" }, - { "hex.menu.view.demo", "Mostra la demo di ImGui" }, - { "hex.menu.help", "Aiuto" }, { "hex.menu.feedback", "Lascia una Recensione" }, { "hex.menu.debug_build", "Build di Debug"}, @@ -89,6 +83,14 @@ namespace hex::plugin::builtin { /* Builtin plugin features */ + { "hex.builtin.menu.file", "File" }, + { "hex.builtin.menu.edit", "Modifica" }, + { "hex.builtin.menu.view", "Vista" }, + //{ "hex.builtin.menu.layout", "Layout" }, + { "hex.builtin.menu.view.fps", "Mostra FPS" }, + { "hex.builtin.menu.view.demo", "Mostra la demo di ImGui" }, + { "hex.builtin.menu.help", "Aiuto" }, + { "hex.builtin.view.bookmarks.name", "Segnalibri" }, { "hex.builtin.view.bookmarks.default_title", "Segnalibro [0x{0:X} - 0x{1:X}]" }, { "hex.builtin.view.bookmarks.no_bookmarks", "Non è stato creato alcun segnalibro. Aggiungine uno andando su Modifica -> Crea Segnalibro" }, @@ -692,6 +694,8 @@ namespace hex::plugin::builtin { //{ "hex.builtin.provider.disk.disk_size", "Disk Size" }, //{ "hex.builtin.provider.disk.sector_size", "Sector Size" }, //{ "hex.builtin.provider.disk.reload", "Reload" }, + + //{ "hex.builtin.layouts.default", "Default" } }); } diff --git a/plugins/builtin/source/lang/zh_CN.cpp b/plugins/builtin/source/lang/zh_CN.cpp index 30f6cad57..8a7d79a87 100644 --- a/plugins/builtin/source/lang/zh_CN.cpp +++ b/plugins/builtin/source/lang/zh_CN.cpp @@ -8,12 +8,6 @@ namespace hex::plugin::builtin { ContentRegistry::Language::addLocalizations("zh-CN", { /* ImHex default functionality */ - { "hex.menu.file", "文件" }, - { "hex.menu.edit", "编辑" }, - { "hex.menu.view", "视图" }, - { "hex.menu.view.fps", "显示FPS" }, - { "hex.menu.view.demo", "显示ImGui演示" }, - { "hex.menu.help", "帮助" }, { "hex.menu.feedback", "反馈" }, { "hex.menu.debug_build", "调试构建"}, @@ -90,6 +84,14 @@ namespace hex::plugin::builtin { /* Builtin plugin features */ + { "hex.builtin.menu.file", "文件" }, + { "hex.builtin.menu.edit", "编辑" }, + { "hex.builtin.menu.view", "视图" }, + //{ "hex.builtin.menu.layout", "Layout" }, + { "hex.builtin.menu.view.fps", "显示FPS" }, + { "hex.builtin.menu.view.demo", "显示ImGui演示" }, + { "hex.builtin.menu.help", "帮助" }, + { "hex.builtin.view.bookmarks.name", "书签" }, { "hex.builtin.view.bookmarks.default_title", "书签 [0x{0:X} - 0x{1:X}]" }, { "hex.builtin.view.bookmarks.no_bookmarks", "空空如也。通过 编辑->添加书签" }, @@ -693,6 +695,8 @@ namespace hex::plugin::builtin { //{ "hex.builtin.provider.disk.disk_size", "Disk Size" }, //{ "hex.builtin.provider.disk.sector_size", "Sector Size" }, //{ "hex.builtin.provider.disk.reload", "Reload" }, + + //{ "hex.builtin.layouts.default", "Default" } }); } diff --git a/plugins/builtin/source/plugin_builtin.cpp b/plugins/builtin/source/plugin_builtin.cpp index 05ba086e2..b5227a9eb 100644 --- a/plugins/builtin/source/plugin_builtin.cpp +++ b/plugins/builtin/source/plugin_builtin.cpp @@ -13,6 +13,8 @@ namespace hex::plugin::builtin { void registerDataProcessorNodes(); void registerProviders(); void registerDataFormatters(); + void registerLayouts(); + void registerMainMenuEntries(); void addFooterItems(); void addToolbarItems(); @@ -40,6 +42,8 @@ IMHEX_PLUGIN_SETUP("Built-in", "WerWolv", "Default ImHex functionality") { addFooterItems(); addToolbarItems(); + registerLayouts(); + registerMainMenuEntries(); registerLanguageEnUS(); registerLanguageDeDE();