mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-01 21:17:44 -05:00
feat: Added option to highlight pattern parents in the hex editor when hovering
This commit is contained in:
@@ -73,15 +73,18 @@ namespace hex {
|
||||
namespace impl {
|
||||
|
||||
using HighlightingFunction = std::function<std::optional<color_t>(u64, const u8*, size_t, bool)>;
|
||||
using HoveringFunction = std::function<bool(const prv::Provider *, u64, const u8*, size_t)>;
|
||||
|
||||
const std::map<u32, Highlighting>& getBackgroundHighlights();
|
||||
const std::map<u32, HighlightingFunction>& getBackgroundHighlightingFunctions();
|
||||
const std::map<u32, Highlighting>& getForegroundHighlights();
|
||||
const std::map<u32, HighlightingFunction>& getForegroundHighlightingFunctions();
|
||||
const std::map<u32, HoveringFunction>& getHoveringFunctions();
|
||||
const std::map<u32, Tooltip>& getTooltips();
|
||||
const std::map<u32, TooltipFunction>& getTooltipFunctions();
|
||||
|
||||
void setCurrentSelection(const std::optional<ProviderRegion> ®ion);
|
||||
void setHoveredRegion(const prv::Provider *provider, const Region ®ion);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -170,6 +173,19 @@ namespace hex {
|
||||
*/
|
||||
void removeForegroundHighlightingProvider(u32 id);
|
||||
|
||||
/**
|
||||
* @brief Adds a hovering provider to the Hex Editor using a callback function
|
||||
* @param function Function that draws the highlighting based on the hovered region
|
||||
* @return Unique ID used to remove the highlighting again later
|
||||
*/
|
||||
u32 addHoverHighlightProvider(const impl::HoveringFunction &function);
|
||||
|
||||
/**
|
||||
* @brief Removes a hovering color highlighting from the Hex Editor
|
||||
* @param id The ID of the highlighting to remove
|
||||
*/
|
||||
void removeHoverHighlightProvider(u32 id);
|
||||
|
||||
/**
|
||||
* @brief Checks if there's a valid selection in the Hex Editor right now
|
||||
*/
|
||||
@@ -215,6 +231,12 @@ namespace hex {
|
||||
*/
|
||||
void addVirtualFile(const std::fs::path &path, std::vector<u8> data, Region region = Region::Invalid());
|
||||
|
||||
/**
|
||||
* @brief Gets the currently hovered cell region in the Hex Editor
|
||||
* @return
|
||||
*/
|
||||
const std::optional<Region>& getHoveredRegion(const prv::Provider *provider);
|
||||
|
||||
}
|
||||
|
||||
/* Functions to interact with Bookmarks */
|
||||
|
||||
@@ -32,19 +32,19 @@ namespace hex {
|
||||
return &this->get();
|
||||
}
|
||||
|
||||
T& get(prv::Provider *provider = ImHexApi::Provider::get()) {
|
||||
T& get(const prv::Provider *provider = ImHexApi::Provider::get()) {
|
||||
return m_data[provider];
|
||||
}
|
||||
|
||||
const T& get(prv::Provider *provider = ImHexApi::Provider::get()) const {
|
||||
const T& get(const prv::Provider *provider = ImHexApi::Provider::get()) const {
|
||||
return m_data.at(provider);
|
||||
}
|
||||
|
||||
void set(const T &data, prv::Provider *provider = ImHexApi::Provider::get()) {
|
||||
void set(const T &data, const prv::Provider *provider = ImHexApi::Provider::get()) {
|
||||
m_data[provider] = data;
|
||||
}
|
||||
|
||||
void set(T &&data, prv::Provider *provider = ImHexApi::Provider::get()) {
|
||||
void set(T &&data, const prv::Provider *provider = ImHexApi::Provider::get()) {
|
||||
m_data[provider] = std::move(data);
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace hex {
|
||||
return m_data | std::views::values;
|
||||
}
|
||||
|
||||
void setOnCreateCallback(std::function<void(prv::Provider *, T&)> callback) {
|
||||
void setOnCreateCallback(std::function<void(const prv::Provider *, T&)> callback) {
|
||||
m_onCreateCallback = std::move(callback);
|
||||
}
|
||||
|
||||
@@ -120,8 +120,8 @@ namespace hex {
|
||||
}
|
||||
|
||||
private:
|
||||
std::map<prv::Provider *, T> m_data;
|
||||
std::function<void(prv::Provider *, T&)> m_onCreateCallback;
|
||||
std::map<const prv::Provider *, T> m_data;
|
||||
std::function<void(const prv::Provider *, T&)> m_onCreateCallback;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -2,10 +2,11 @@
|
||||
|
||||
#include <hex/api/event_manager.hpp>
|
||||
#include <hex/api/task_manager.hpp>
|
||||
#include <hex/providers/provider.hpp>
|
||||
#include <hex/helpers/fmt.hpp>
|
||||
#include <hex/helpers/utils.hpp>
|
||||
#include <hex/helpers/auto_reset.hpp>
|
||||
#include <hex/providers/provider_data.hpp>
|
||||
#include <hex/providers/provider.hpp>
|
||||
|
||||
#include <wolv/utils/string.hpp>
|
||||
|
||||
@@ -67,11 +68,24 @@ namespace hex {
|
||||
return *s_tooltipFunctions;
|
||||
}
|
||||
|
||||
static AutoReset<std::map<u32, HoveringFunction>> s_hoveringFunctions;
|
||||
const std::map<u32, HoveringFunction>& getHoveringFunctions() {
|
||||
return *s_hoveringFunctions;
|
||||
}
|
||||
|
||||
static AutoReset<std::optional<ProviderRegion>> s_currentSelection;
|
||||
void setCurrentSelection(const std::optional<ProviderRegion> ®ion) {
|
||||
*s_currentSelection = region;
|
||||
}
|
||||
|
||||
static PerProvider<std::optional<Region>> s_hoveredRegion;
|
||||
void setHoveredRegion(const prv::Provider *provider, const Region ®ion) {
|
||||
if (region == Region::Invalid())
|
||||
s_hoveredRegion.get(provider).reset();
|
||||
else
|
||||
s_hoveredRegion.get(provider) = region;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
u32 addBackgroundHighlight(const Region ®ion, color_t color) {
|
||||
@@ -150,6 +164,20 @@ namespace hex {
|
||||
TaskManager::doLaterOnce([]{ EventHighlightingChanged::post(); });
|
||||
}
|
||||
|
||||
u32 addHoverHighlightProvider(const impl::HoveringFunction &function) {
|
||||
static u32 id = 0;
|
||||
|
||||
id++;
|
||||
|
||||
impl::s_hoveringFunctions->insert({ id, function });
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
void removeHoverHighlightProvider(u32 id) {
|
||||
impl::s_hoveringFunctions->erase(id);
|
||||
}
|
||||
|
||||
static u32 tooltipId = 0;
|
||||
u32 addTooltip(Region region, std::string value, color_t color) {
|
||||
tooltipId++;
|
||||
@@ -202,6 +230,11 @@ namespace hex {
|
||||
void addVirtualFile(const std::fs::path &path, std::vector<u8> data, Region region) {
|
||||
RequestAddVirtualFile::post(path, std::move(data), region);
|
||||
}
|
||||
|
||||
const std::optional<Region>& getHoveredRegion(const prv::Provider *provider) {
|
||||
return impl::s_hoveredRegion.get(provider);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user