diff --git a/lib/libimhex/include/hex/api/theme_manager.hpp b/lib/libimhex/include/hex/api/theme_manager.hpp index 4e996f616..1f674d34f 100644 --- a/lib/libimhex/include/hex/api/theme_manager.hpp +++ b/lib/libimhex/include/hex/api/theme_manager.hpp @@ -9,7 +9,7 @@ #include #include -namespace hex::api { +namespace hex { /** * @brief The Theme Manager takes care of loading and applying themes diff --git a/lib/libimhex/source/api/theme_manager.cpp b/lib/libimhex/source/api/theme_manager.cpp index 4d0b82d35..d5e55a6fc 100644 --- a/lib/libimhex/source/api/theme_manager.cpp +++ b/lib/libimhex/source/api/theme_manager.cpp @@ -6,7 +6,7 @@ #include -namespace hex::api { +namespace hex { std::map ThemeManager::s_themes; std::map ThemeManager::s_themeHandlers; diff --git a/main/source/init/tasks.cpp b/main/source/init/tasks.cpp index 892cb0da5..059168133 100644 --- a/main/source/init/tasks.cpp +++ b/main/source/init/tasks.cpp @@ -290,7 +290,7 @@ namespace hex::init { ContentRegistry::FileHandler::impl::getEntries().clear(); ContentRegistry::Hashes::impl::getHashes().clear(); - api::ThemeManager::reset(); + ThemeManager::reset(); { auto &visualizers = ContentRegistry::HexEditor::impl::getVisualizers(); diff --git a/plugins/builtin/source/content/settings_entries.cpp b/plugins/builtin/source/content/settings_entries.cpp index 5b3654a0a..9687aa545 100644 --- a/plugins/builtin/source/content/settings_entries.cpp +++ b/plugins/builtin/source/content/settings_entries.cpp @@ -116,12 +116,12 @@ namespace hex::plugin::builtin { ContentRegistry::Settings::add("hex.builtin.setting.interface", "hex.builtin.setting.interface.color", "Dark", [](auto name, nlohmann::json &setting) { static auto selection = static_cast(setting); - const auto themeNames = hex::api::ThemeManager::getThemeNames(); + const auto themeNames = ThemeManager::getThemeNames(); bool changed = false; if (ImGui::BeginCombo(name.data(), selection.c_str())) { - if (ImGui::Selectable(api::ThemeManager::NativeTheme, selection == api::ThemeManager::NativeTheme)) { - selection = api::ThemeManager::NativeTheme; + if (ImGui::Selectable(ThemeManager::NativeTheme, selection == ThemeManager::NativeTheme)) { + selection = ThemeManager::NativeTheme; setting = selection; ImHexApi::System::enableSystemThemeDetection(true); changed = true; @@ -132,7 +132,7 @@ namespace hex::plugin::builtin { selection = themeName; setting = selection; ImHexApi::System::enableSystemThemeDetection(false); - api::ThemeManager::changeTheme(selection); + ThemeManager::changeTheme(selection); changed = true; } } @@ -613,13 +613,13 @@ namespace hex::plugin::builtin { } static void loadThemeSettings() { - auto theme = ContentRegistry::Settings::read("hex.builtin.setting.interface", "hex.builtin.setting.interface.color", api::ThemeManager::NativeTheme); + auto theme = ContentRegistry::Settings::read("hex.builtin.setting.interface", "hex.builtin.setting.interface.color", ThemeManager::NativeTheme); - if (theme == api::ThemeManager::NativeTheme) + if (theme == ThemeManager::NativeTheme) ImHexApi::System::enableSystemThemeDetection(true); else { ImHexApi::System::enableSystemThemeDetection(false); - api::ThemeManager::changeTheme(theme); + ThemeManager::changeTheme(theme); } } diff --git a/plugins/builtin/source/content/themes.cpp b/plugins/builtin/source/content/themes.cpp index f65113cb1..1c5389324 100644 --- a/plugins/builtin/source/content/themes.cpp +++ b/plugins/builtin/source/content/themes.cpp @@ -20,7 +20,7 @@ namespace hex::plugin::builtin { void registerThemeHandlers() { EventManager::subscribe([]() { { - const static api::ThemeManager::ColorMap ImGuiColorMap = { + const static ThemeManager::ColorMap ImGuiColorMap = { { "text", ImGuiCol_Text }, { "text-disabled", ImGuiCol_TextDisabled }, { "window-background", ImGuiCol_WindowBg }, @@ -78,7 +78,7 @@ namespace hex::plugin::builtin { { "modal-window-dim-background", ImGuiCol_ModalWindowDimBg } }; - api::ThemeManager::addThemeHandler("imgui", ImGuiColorMap, + ThemeManager::addThemeHandler("imgui", ImGuiColorMap, [](u32 colorId) -> ImColor { return ImGui::GetStyle().Colors[colorId]; }, @@ -89,7 +89,7 @@ namespace hex::plugin::builtin { } { - const static api::ThemeManager::ColorMap ImPlotColorMap = { + const static ThemeManager::ColorMap ImPlotColorMap = { { "line", ImPlotCol_Line }, { "fill", ImPlotCol_Fill }, { "marker-outline", ImPlotCol_MarkerOutline }, @@ -113,7 +113,7 @@ namespace hex::plugin::builtin { { "crosshairs", ImPlotCol_Crosshairs } }; - api::ThemeManager::addThemeHandler("implot", ImPlotColorMap, + ThemeManager::addThemeHandler("implot", ImPlotColorMap, [](u32 colorId) -> ImColor { return ImPlot::GetStyle().Colors[colorId]; }, @@ -124,7 +124,7 @@ namespace hex::plugin::builtin { } { - const static api::ThemeManager::ColorMap ImNodesColorMap = { + const static ThemeManager::ColorMap ImNodesColorMap = { { "node-background", ImNodesCol_NodeBackground }, { "node-background-hovered", ImNodesCol_NodeBackgroundHovered }, { "node-background-selected", ImNodesCol_NodeBackgroundSelected }, @@ -156,7 +156,7 @@ namespace hex::plugin::builtin { { "mini-map-canvas-outline", ImNodesCol_MiniMapCanvasOutline }, }; - api::ThemeManager::addThemeHandler("imnodes", ImNodesColorMap, + ThemeManager::addThemeHandler("imnodes", ImNodesColorMap, [](u32 colorId) -> ImColor { return ImNodes::GetStyle().Colors[colorId]; }, @@ -167,7 +167,7 @@ namespace hex::plugin::builtin { } { - const static api::ThemeManager::ColorMap ImHexColorMap = { + const static ThemeManager::ColorMap ImHexColorMap = { { "desc-button", ImGuiCustomCol_DescButton }, { "desc-button-hovered", ImGuiCustomCol_DescButtonHovered }, { "desc-button-active", ImGuiCustomCol_DescButtonActive }, @@ -181,7 +181,7 @@ namespace hex::plugin::builtin { { "highlight", ImGuiCustomCol_Highlight } }; - api::ThemeManager::addThemeHandler("imhex", ImHexColorMap, + ThemeManager::addThemeHandler("imhex", ImHexColorMap, [](u32 colorId) -> ImColor { return static_cast(GImGui->IO.UserData)->Colors[colorId]; @@ -193,7 +193,7 @@ namespace hex::plugin::builtin { } { - const static api::ThemeManager::ColorMap TextEditorColorMap = { + const static ThemeManager::ColorMap TextEditorColorMap = { { "default", u32(TextEditor::PaletteIndex::Default) }, { "keyword", u32(TextEditor::PaletteIndex::Keyword) }, { "number", u32(TextEditor::PaletteIndex::Number) }, @@ -217,7 +217,7 @@ namespace hex::plugin::builtin { { "current-line-edge", u32(TextEditor::PaletteIndex::CurrentLineEdge) } }; - api::ThemeManager::addThemeHandler("text-editor", TextEditorColorMap, + ThemeManager::addThemeHandler("text-editor", TextEditorColorMap, [](u32 colorId) -> ImColor { return TextEditor::GetPalette()[colorId]; }, @@ -235,7 +235,7 @@ namespace hex::plugin::builtin { EventManager::subscribe([]() { { auto &style = ImGui::GetStyle(); - const static api::ThemeManager::StyleMap ImGuiStyleMap = { + const static ThemeManager::StyleMap ImGuiStyleMap = { { "alpha", { &style.Alpha, 0.001F, 1.0F, false } }, { "disabled-alpha", { &style.DisabledAlpha, 0.0F, 1.0F, false } }, { "window-padding", { &style.WindowPadding, 0.0F, 20.0F, true } }, @@ -263,12 +263,12 @@ namespace hex::plugin::builtin { { "selectable-text-align", { &style.SelectableTextAlign, 0.0F, 1.0F, false } }, }; - api::ThemeManager::addStyleHandler("imgui", ImGuiStyleMap); + ThemeManager::addStyleHandler("imgui", ImGuiStyleMap); } { auto &style = ImPlot::GetStyle(); - const static api::ThemeManager::StyleMap ImPlotStyleMap = { + const static ThemeManager::StyleMap ImPlotStyleMap = { { "line-weight", { &style.LineWeight, 0.0F, 5.0F, true } }, { "marker-size", { &style.MarkerSize, 2.0F, 10.0F, true } }, { "marker-weight", { &style.MarkerWeight, 0.0F, 5.0F, true } }, @@ -297,12 +297,12 @@ namespace hex::plugin::builtin { { "plot-min-size", { &style.PlotMinSize, 0.0F, 300.0F, true } }, }; - api::ThemeManager::addStyleHandler("implot", ImPlotStyleMap); + ThemeManager::addStyleHandler("implot", ImPlotStyleMap); } { auto &style = ImNodes::GetStyle(); - const static api::ThemeManager::StyleMap ImNodesStyleMap = { + const static ThemeManager::StyleMap ImNodesStyleMap = { { "grid-spacing", { &style.GridSpacing, 0.0F, 100.0F, true } }, { "node-corner-rounding", { &style.NodeCornerRounding, 0.0F, 12.0F, true } }, { "node-padding", { &style.NodePadding, 0.0F, 20.0F, true } }, @@ -320,7 +320,7 @@ namespace hex::plugin::builtin { { "mini-map-offset", { &style.MiniMapOffset, -10.0F, 10.0F, true } }, }; - api::ThemeManager::addStyleHandler("imnodes", ImNodesStyleMap); + ThemeManager::addStyleHandler("imnodes", ImNodesStyleMap); } }); } @@ -328,14 +328,14 @@ namespace hex::plugin::builtin { void registerThemes() { // Load built-in themes for (const auto &theme : romfs::list("themes")) { - api::ThemeManager::addTheme(std::string(romfs::get(theme).string())); + ThemeManager::addTheme(std::string(romfs::get(theme).string())); } // Load user themes for (const auto &themeFolder : fs::getDefaultPaths(fs::ImHexPath::Themes)) { for (const auto &theme : std::fs::directory_iterator(themeFolder)) { if (theme.is_regular_file()) - api::ThemeManager::addTheme(wolv::io::File(theme.path(), wolv::io::File::Mode::Read).readString()); + ThemeManager::addTheme(wolv::io::File(theme.path(), wolv::io::File::Mode::Read).readString()); } } } diff --git a/plugins/builtin/source/content/views/view_store.cpp b/plugins/builtin/source/content/views/view_store.cpp index bd0628ba1..7cec6cead 100644 --- a/plugins/builtin/source/content/views/view_store.cpp +++ b/plugins/builtin/source/content/views/view_store.cpp @@ -1,4 +1,5 @@ #include "content/views/view_store.hpp" +#include "hex/api/theme_manager.hpp" #include @@ -141,11 +142,17 @@ namespace hex::plugin::builtin { if (ImGui::BeginTabBar("storeTabs")) { drawTab("hex.builtin.view.store.tab.patterns"_lang, fs::ImHexPath::Patterns, this->m_patterns); drawTab("hex.builtin.view.store.tab.libraries"_lang, fs::ImHexPath::PatternsInclude, this->m_includes); - drawTab("hex.builtin.view.store.tab.magics"_lang, fs::ImHexPath::Magic, this->m_magics, magic::compile); + drawTab("hex.builtin.view.store.tab.magics"_lang, fs::ImHexPath::Magic, this->m_magics, []{ + magic::compile(); + }); drawTab("hex.builtin.view.store.tab.nodes"_lang, fs::ImHexPath::Nodes, this->m_nodes); drawTab("hex.builtin.view.store.tab.encodings"_lang, fs::ImHexPath::Encodings, this->m_encodings); drawTab("hex.builtin.view.store.tab.constants"_lang, fs::ImHexPath::Constants, this->m_constants); - drawTab("hex.builtin.view.store.tab.themes"_lang, fs::ImHexPath::Themes, this->m_themes); + drawTab("hex.builtin.view.store.tab.themes"_lang, fs::ImHexPath::Themes, this->m_themes, [this]{ + auto themeFile = wolv::io::File(this->m_downloadPath, wolv::io::File::Mode::Read); + + ThemeManager::addTheme(themeFile.readString()); + }); drawTab("hex.builtin.view.store.tab.yara"_lang, fs::ImHexPath::Yara, this->m_yara); ImGui::EndTabBar(); diff --git a/plugins/builtin/source/content/views/view_theme_manager.cpp b/plugins/builtin/source/content/views/view_theme_manager.cpp index 519a0354e..b774dd82e 100644 --- a/plugins/builtin/source/content/views/view_theme_manager.cpp +++ b/plugins/builtin/source/content/views/view_theme_manager.cpp @@ -18,7 +18,7 @@ namespace hex::plugin::builtin { ImGui::Header("hex.builtin.view.theme_manager.colors"_lang, true); ImGui::PushID(1); - const auto &themeHandlers = api::ThemeManager::getThemeHandlers(); + const auto &themeHandlers = ThemeManager::getThemeHandlers(); for (auto &[name, handler] : themeHandlers) { if (ImGui::CollapsingHeader(name.c_str())) { for (auto &[colorName, colorId] : handler.colorMap) { @@ -37,7 +37,7 @@ namespace hex::plugin::builtin { ImGui::Header("hex.builtin.view.theme_manager.styles"_lang); ImGui::PushID(2); - for (auto &[name, handler] : api::ThemeManager::getStyleHandlers()) { + for (auto &[name, handler] : ThemeManager::getStyleHandlers()) { if (ImGui::CollapsingHeader(name.c_str())) { for (auto &[styleName, style] : handler.styleMap) { auto &[value, min, max, needsScaling] = style; @@ -55,7 +55,7 @@ namespace hex::plugin::builtin { ImGui::InputTextIcon("hex.builtin.view.theme_manager.export.name"_lang, ICON_VS_SYMBOL_KEY, this->m_themeName); if (ImGui::Button("hex.builtin.view.theme_manager.save_theme"_lang, ImVec2(ImGui::GetContentRegionAvail().x, 0))) { fs::openFileBrowser(fs::DialogMode::Save, { { "ImHex Theme", "json" } }, [this](const std::fs::path &path){ - auto json = api::ThemeManager::exportCurrentTheme(this->m_themeName); + auto json = ThemeManager::exportCurrentTheme(this->m_themeName); wolv::io::File outputFile(path, wolv::io::File::Mode::Create); outputFile.writeString(json.dump(4)); diff --git a/plugins/builtin/source/content/welcome_screen.cpp b/plugins/builtin/source/content/welcome_screen.cpp index a1f53b2db..a3010863e 100644 --- a/plugins/builtin/source/content/welcome_screen.cpp +++ b/plugins/builtin/source/content/welcome_screen.cpp @@ -442,9 +442,9 @@ namespace hex::plugin::builtin { (void)EventManager::subscribe([]() { { - auto theme = ContentRegistry::Settings::read("hex.builtin.setting.interface", "hex.builtin.setting.interface.color", api::ThemeManager::NativeTheme); + auto theme = ContentRegistry::Settings::read("hex.builtin.setting.interface", "hex.builtin.setting.interface.color", ThemeManager::NativeTheme); - if (theme != api::ThemeManager::NativeTheme) { + if (theme != ThemeManager::NativeTheme) { static std::string lastTheme; if (theme != lastTheme) { @@ -474,9 +474,9 @@ namespace hex::plugin::builtin { return ImGui::Texture(reinterpret_cast(textureData.data()), textureData.size()); }; - api::ThemeManager::changeTheme(theme); - s_bannerTexture = changeTexture(hex::format("banner{}.png", api::ThemeManager::getThemeImagePostfix())); - s_backdropTexture = changeTexture(hex::format("backdrop{}.png", api::ThemeManager::getThemeImagePostfix())); + ThemeManager::changeTheme(theme); + s_bannerTexture = changeTexture(hex::format("banner{}.png", ThemeManager::getThemeImagePostfix())); + s_backdropTexture = changeTexture(hex::format("backdrop{}.png", ThemeManager::getThemeImagePostfix())); if (!s_bannerTexture.isValid()) { log::error("Failed to load banner texture!"); diff --git a/plugins/windows/source/plugin_windows.cpp b/plugins/windows/source/plugin_windows.cpp index 68f04c3af..84725a4a0 100644 --- a/plugins/windows/source/plugin_windows.cpp +++ b/plugins/windows/source/plugin_windows.cpp @@ -22,7 +22,7 @@ namespace hex::plugin::windows { static void detectSystemTheme() { // Setup system theme change detector EventManager::subscribe([] { - bool themeFollowSystem = ContentRegistry::Settings::read("hex.builtin.setting.interface", "hex.builtin.setting.interface.color", api::ThemeManager::NativeTheme) == api::ThemeManager::NativeTheme; + bool themeFollowSystem = ContentRegistry::Settings::read("hex.builtin.setting.interface", "hex.builtin.setting.interface.color", ThemeManager::NativeTheme) == ThemeManager::NativeTheme; if (!themeFollowSystem) return; @@ -43,7 +43,7 @@ static void detectSystemTheme() { }); EventManager::subscribe([=] { - bool themeFollowSystem = ContentRegistry::Settings::read("hex.builtin.setting.interface", "hex.builtin.setting.interface.color", api::ThemeManager::NativeTheme) == api::ThemeManager::NativeTheme; + bool themeFollowSystem = ContentRegistry::Settings::read("hex.builtin.setting.interface", "hex.builtin.setting.interface.color", ThemeManager::NativeTheme) == ThemeManager::NativeTheme; if (themeFollowSystem) EventManager::post();