mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-02 21:47:40 -05:00
sys: Add highlighting provider function support, move pattern highlighting code out of hex editor
This commit is contained in:
@@ -3,8 +3,9 @@
|
||||
#include <hex.hpp>
|
||||
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <hex/helpers/concepts.hpp>
|
||||
#include <hex/api/task.hpp>
|
||||
@@ -32,21 +33,32 @@ namespace hex {
|
||||
class Highlighting {
|
||||
public:
|
||||
Highlighting() = default;
|
||||
Highlighting(Region region, color_t color, const std::string &tooltip = "");
|
||||
Highlighting(Region region, color_t color, std::string tooltip = "");
|
||||
|
||||
[[nodiscard]] const Region &getRegion() const { return this->m_region; }
|
||||
[[nodiscard]] const color_t &getColor() const { return this->m_color; }
|
||||
[[nodiscard]] const std::string &getTooltip() const { return this->m_tooltip; }
|
||||
|
||||
private:
|
||||
Region m_region;
|
||||
color_t m_color;
|
||||
Region m_region = {};
|
||||
color_t m_color = 0x00;
|
||||
std::string m_tooltip;
|
||||
};
|
||||
|
||||
u32 addHighlight(const Region ®ion, color_t color, std::string tooltip = "");
|
||||
namespace impl {
|
||||
|
||||
using HighlightingFunction = std::function<std::optional<Highlighting>(u64)>;
|
||||
|
||||
std::map<u32, Highlighting> &getHighlights();
|
||||
std::map<u32, HighlightingFunction> &getHighlightingFunctions();
|
||||
|
||||
}
|
||||
|
||||
u32 addHighlight(const Region ®ion, color_t color, const std::string &tooltip = "");
|
||||
void removeHighlight(u32 id);
|
||||
std::map<u32, Highlighting> &getHighlights();
|
||||
|
||||
u32 addHighlightingProvider(const impl::HighlightingFunction &function);
|
||||
void removeHighlightingProvider(u32 id);
|
||||
|
||||
Region getSelection();
|
||||
void setSelection(const Region ®ion);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <hex/api/event.hpp>
|
||||
#include <hex/providers/provider.hpp>
|
||||
#include <utility>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
@@ -26,16 +27,29 @@ namespace hex {
|
||||
|
||||
namespace ImHexApi::HexEditor {
|
||||
|
||||
static std::map<u32, ImHexApi::HexEditor::Highlighting> s_highlights;
|
||||
|
||||
Highlighting::Highlighting(Region region, color_t color, const std::string &tooltip)
|
||||
: m_region(region), m_color(color), m_tooltip(tooltip) {
|
||||
Highlighting::Highlighting(Region region, color_t color, std::string tooltip)
|
||||
: m_region(region), m_color(color), m_tooltip(std::move(tooltip)) {
|
||||
}
|
||||
|
||||
u32 addHighlight(const Region ®ion, color_t color, std::string tooltip) {
|
||||
auto id = s_highlights.size();
|
||||
namespace impl {
|
||||
|
||||
s_highlights.insert({
|
||||
static std::map<u32, Highlighting> s_highlights;
|
||||
std::map<u32, Highlighting> &getHighlights() {
|
||||
return s_highlights;
|
||||
}
|
||||
|
||||
static std::map<u32, HighlightingFunction> s_highlightingFunctions;
|
||||
std::map<u32, HighlightingFunction> &getHighlightingFunctions() {
|
||||
return s_highlightingFunctions;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
u32 addHighlight(const Region ®ion, color_t color, const std::string &tooltip) {
|
||||
auto &highlights = impl::getHighlights();
|
||||
auto id = highlights.size();
|
||||
|
||||
highlights.insert({
|
||||
id, Highlighting {region, color, tooltip}
|
||||
});
|
||||
|
||||
@@ -45,13 +59,27 @@ namespace hex {
|
||||
}
|
||||
|
||||
void removeHighlight(u32 id) {
|
||||
s_highlights.erase(id);
|
||||
impl::getHighlights().erase(id);
|
||||
|
||||
EventManager::post<EventHighlightingChanged>();
|
||||
}
|
||||
|
||||
std::map<u32, Highlighting> &getHighlights() {
|
||||
return s_highlights;
|
||||
u32 addHighlightingProvider(const impl::HighlightingFunction &function) {
|
||||
auto &highlightFuncs = impl::getHighlightingFunctions();
|
||||
|
||||
auto id = highlightFuncs.size();
|
||||
|
||||
highlightFuncs.insert({ id, function });
|
||||
|
||||
EventManager::post<EventHighlightingChanged>();
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
void removeHighlightingProvider(u32 id) {
|
||||
impl::getHighlightingFunctions().erase(id);
|
||||
|
||||
EventManager::post<EventHighlightingChanged>();
|
||||
}
|
||||
|
||||
Region getSelection() {
|
||||
|
||||
Reference in New Issue
Block a user