ui: Added API to add custom layouts, imhex application and api cleanup
This commit is contained in:
parent
c4cbcc7232
commit
ee8b665472
@ -113,13 +113,14 @@ namespace hex {
|
||||
|
||||
}
|
||||
|
||||
|
||||
template<hex::derived_from<View> T, typename ... Args>
|
||||
void add(Args&& ... args) {
|
||||
return impl::add(new T(std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
std::vector<View*>& getEntries();
|
||||
std::map<std::string, View*>& 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()>;
|
||||
|
||||
void addWelcomeScreenEntry(const DrawCallback &function);
|
||||
void addFooterItem(const DrawCallback &function);
|
||||
void addToolbarItem(const DrawCallback &function);
|
||||
namespace impl {
|
||||
|
||||
std::vector<DrawCallback>& getWelcomeScreenEntries();
|
||||
std::vector<DrawCallback>& getFooterItems();
|
||||
std::vector<DrawCallback>& getToolbarItems();
|
||||
using DrawCallback = std::function<void()>;
|
||||
using LayoutFunction = std::function<void(u32)>;
|
||||
|
||||
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<impl::MainMenuItem>& getMainMenuItems();
|
||||
std::vector<impl::DrawCallback>& getWelcomeScreenEntries();
|
||||
std::vector<impl::DrawCallback>& getFooterItems();
|
||||
std::vector<impl::DrawCallback>& getToolbarItems();
|
||||
|
||||
std::vector<impl::Layout>& getLayouts();
|
||||
}
|
||||
|
||||
/* Provider Registry. Allows adding new data providers to be created from the UI */
|
||||
|
@ -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);
|
||||
|
@ -63,7 +63,7 @@ namespace hex {
|
||||
static nlohmann::json settingsJson;
|
||||
static std::vector<ContentRegistry::CommandPaletteCommands::Entry> commandPaletteCommands;
|
||||
static std::map<std::string, ContentRegistry::PatternLanguage::Function> patternLanguageFunctions;
|
||||
static std::vector<View*> views;
|
||||
static std::map<std::string, View*> views;
|
||||
static std::vector<ContentRegistry::Tools::impl::Entry> toolsEntries;
|
||||
static std::vector<ContentRegistry::DataInspector::impl::Entry> dataInspectorEntries;
|
||||
static u32 patternPaletteOffset;
|
||||
@ -75,9 +75,13 @@ namespace hex {
|
||||
static std::map<std::string, std::vector<LanguageDefinition>> languageDefinitions;
|
||||
static std::map<std::string, std::string> loadedLanguageStrings;
|
||||
|
||||
static std::vector<ContentRegistry::Interface::DrawCallback> welcomeScreenEntries;
|
||||
static std::vector<ContentRegistry::Interface::DrawCallback> footerItems;
|
||||
static std::vector<ContentRegistry::Interface::DrawCallback> toolbarItems;
|
||||
static ImGuiID dockSpaceId;
|
||||
|
||||
static std::vector<ContentRegistry::Interface::impl::MainMenuItem> mainMenuItems;
|
||||
static std::vector<ContentRegistry::Interface::impl::DrawCallback> welcomeScreenEntries;
|
||||
static std::vector<ContentRegistry::Interface::impl::DrawCallback> footerItems;
|
||||
static std::vector<ContentRegistry::Interface::impl::DrawCallback> toolbarItems;
|
||||
static std::vector<ContentRegistry::Interface::impl::Layout> layouts;
|
||||
|
||||
static std::map<Shortcut, std::function<void()>> globalShortcuts;
|
||||
|
||||
|
@ -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<void()> &leftButtonFn, const std::function<void()> &rightButtonFn);
|
||||
static void discardNavigationRequests();
|
||||
|
@ -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<View*>& ContentRegistry::Views::getEntries() {
|
||||
std::map<std::string, View*>& 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::DrawCallback>& ContentRegistry::Interface::getWelcomeScreenEntries() {
|
||||
getLayouts().push_back({ unlocalizedName, function });
|
||||
}
|
||||
|
||||
|
||||
std::vector<ContentRegistry::Interface::impl::MainMenuItem> &ContentRegistry::Interface::getMainMenuItems() {
|
||||
return SharedData::mainMenuItems;
|
||||
}
|
||||
|
||||
std::vector<ContentRegistry::Interface::impl::DrawCallback>& ContentRegistry::Interface::getWelcomeScreenEntries() {
|
||||
return SharedData::welcomeScreenEntries;
|
||||
}
|
||||
std::vector<ContentRegistry::Interface::DrawCallback>& ContentRegistry::Interface::getFooterItems() {
|
||||
std::vector<ContentRegistry::Interface::impl::DrawCallback>& ContentRegistry::Interface::getFooterItems() {
|
||||
return SharedData::footerItems;
|
||||
}
|
||||
std::vector<ContentRegistry::Interface::DrawCallback>& ContentRegistry::Interface::getToolbarItems() {
|
||||
std::vector<ContentRegistry::Interface::impl::DrawCallback>& ContentRegistry::Interface::getToolbarItems() {
|
||||
return SharedData::toolbarItems;
|
||||
}
|
||||
|
||||
std::vector<ContentRegistry::Interface::impl::Layout>& ContentRegistry::Interface::getLayouts() {
|
||||
return SharedData::layouts;
|
||||
}
|
||||
|
||||
|
||||
/* Providers */
|
||||
|
||||
|
@ -13,7 +13,7 @@ namespace hex {
|
||||
nlohmann::json SharedData::settingsJson;
|
||||
std::vector<ContentRegistry::CommandPaletteCommands::Entry> SharedData::commandPaletteCommands;
|
||||
std::map<std::string, ContentRegistry::PatternLanguage::Function> SharedData::patternLanguageFunctions;
|
||||
std::vector<View*> SharedData::views;
|
||||
std::map<std::string, View*> SharedData::views;
|
||||
std::vector<ContentRegistry::Tools::impl::Entry> SharedData::toolsEntries;
|
||||
std::vector<ContentRegistry::DataInspector::impl::Entry> SharedData::dataInspectorEntries;
|
||||
u32 SharedData::patternPaletteOffset;
|
||||
@ -25,9 +25,13 @@ namespace hex {
|
||||
std::map<std::string, std::vector<LanguageDefinition>> SharedData::languageDefinitions;
|
||||
std::map<std::string, std::string> SharedData::loadedLanguageStrings;
|
||||
|
||||
std::vector<ContentRegistry::Interface::DrawCallback> SharedData::welcomeScreenEntries;
|
||||
std::vector<ContentRegistry::Interface::DrawCallback> SharedData::footerItems;
|
||||
std::vector<ContentRegistry::Interface::DrawCallback> SharedData::toolbarItems;
|
||||
ImGuiID SharedData::dockSpaceId;
|
||||
|
||||
std::vector<ContentRegistry::Interface::impl::MainMenuItem> SharedData::mainMenuItems;
|
||||
std::vector<ContentRegistry::Interface::impl::DrawCallback> SharedData::welcomeScreenEntries;
|
||||
std::vector<ContentRegistry::Interface::impl::DrawCallback> SharedData::footerItems;
|
||||
std::vector<ContentRegistry::Interface::impl::DrawCallback> SharedData::toolbarItems;
|
||||
std::vector<ContentRegistry::Interface::impl::Layout> SharedData::layouts;
|
||||
|
||||
std::map<Shortcut, std::function<void()>> SharedData::globalShortcuts;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -2,13 +2,10 @@
|
||||
|
||||
#include <hex.hpp>
|
||||
|
||||
#include <hex/views/view.hpp>
|
||||
#include <hex/providers/provider.hpp>
|
||||
#include <hex/helpers/fmt.hpp>
|
||||
#include <hex/helpers/paths.hpp>
|
||||
|
||||
#include <string_view>
|
||||
#include <dlfcn.h>
|
||||
#include <string>
|
||||
|
||||
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<typename T>
|
||||
auto getPluginFunction(const std::string &pluginName, const std::string &symbol) {
|
||||
auto symbolName = hex::format(symbol.data(), pluginName.length(), pluginName.data());
|
||||
return reinterpret_cast<T>(dlsym(this->m_handle, symbolName.c_str()));
|
||||
};
|
||||
[[nodiscard]] auto getPluginFunction(const std::string &pluginName, const std::string &symbol) {
|
||||
return reinterpret_cast<T>(this->getPluginFunction(pluginName, symbol));
|
||||
}
|
||||
|
||||
private:
|
||||
[[nodiscard]] void* getPluginFunction(const std::string &pluginName, const std::string &symbol);
|
||||
};
|
||||
|
||||
class PluginManager {
|
||||
|
@ -32,8 +32,8 @@ namespace hex::init {
|
||||
void initGLFW();
|
||||
void initImGui();
|
||||
|
||||
void deinitGLFW();
|
||||
void deinitImGui();
|
||||
void exitGLFW();
|
||||
void exitImGui();
|
||||
|
||||
std::future<bool> processTasksAsync();
|
||||
|
||||
|
@ -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;
|
||||
|
@ -1,9 +1,9 @@
|
||||
#include "helpers/plugin_manager.hpp"
|
||||
|
||||
#include <hex/helpers/logger.hpp>
|
||||
#include <hex/helpers/paths.hpp>
|
||||
|
||||
#include <filesystem>
|
||||
#include <dlfcn.h>
|
||||
|
||||
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) {
|
||||
|
@ -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<ImTextureID>(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();
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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<EventSettingsChanged>(this);
|
||||
EventManager::unsubscribe<EventFileLoaded>(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<EventFrameBegin>();
|
||||
}
|
||||
|
||||
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<EventFrameEnd>();
|
||||
|
||||
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::ImHexCustomData*>(ImGui::GetIO().UserData);
|
||||
|
||||
ImNodes::PopAttributeFlag();
|
||||
|
@ -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
|
||||
|
41
plugins/builtin/source/content/layouts.cpp
Normal file
41
plugins/builtin/source/content/layouts.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
#include <hex/api/content_registry.hpp>
|
||||
|
||||
#include <imgui.h>
|
||||
#include <imgui_internal.h>
|
||||
#include <hex/views/view.hpp>
|
||||
|
||||
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);
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
57
plugins/builtin/source/content/main_menu_items.cpp
Normal file
57
plugins/builtin/source/content/main_menu_items.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
#include <hex/api/content_registry.hpp>
|
||||
|
||||
#include <imgui.h>
|
||||
#include <implot.h>
|
||||
|
||||
#include <hex/views/view.hpp>
|
||||
|
||||
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<EventFrameEnd>([]{
|
||||
if (g_demoWindowOpen) {
|
||||
ImGui::ShowDemoWindow(&g_demoWindowOpen);
|
||||
ImPlot::ShowDemoWindow(&g_demoWindowOpen);
|
||||
}
|
||||
});
|
||||
|
||||
ContentRegistry::Interface::registerMainMenuItem("hex.builtin.menu.help");
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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" }
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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" }
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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" }
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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" }
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user