mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-30 21:05:56 -05:00
ui/ux: Rewrite of the entire hex editor view to make it more flexible (#512)
* ui/ux: Initial recreation of the hex editor view * ui/ux: Added back support for editing cells * ux: Make scrolling and selecting bytes feel nice again * ui/ux: Improved byte selecting, added footer * sys: Make math evaluator more generic to support integer only calculations * patterns: Moved value formatting into pattern language * ui/ux: Added Goto and Search popups, improved selection * ui: Added better tooltips for bookmarks and patterns * sys: Use worse hex search algorithm on macOS Sadly it still doesn't support `std::boyer_moore_horsepool_searcher` * ui: Added back missing events, menu items and shortcuts * fix: Bookmark highlighting being rendered off by one * fix: Various macOS build errors * fix: size_t is not u64 on macos * fix: std::fmod and std::pow not working with integer types on macos * fix: Missing semicolons * sys: Added proper integer pow function * ui: Added back support for custom encodings * fix: Editor not jumping to selection when selection gets changed * ui: Turn Hexii setting into a data visualizer * sys: Added back remaining shortcuts * sys: Remove old hex editor files * sys: Moved more legacy things away from the hex editor view, updated localization * fix: Hex editor scrolling behaving weirdly and inconsistently * sys: Cleaned up Hex editor code * sys: Added selection color setting, localized all new settings * fix: Search feature not working correctly * ui: Replace custom ImGui::Disabled function with native ImGui ones * ui: Fix bookmark tooltip rendering issues * fix: Another size_t not being 64 bit issue on MacOS
This commit is contained in:
@@ -29,32 +29,55 @@ namespace hex {
|
||||
|
||||
namespace ImHexApi::HexEditor {
|
||||
|
||||
Highlighting::Highlighting(Region region, color_t color, std::string tooltip)
|
||||
: m_region(region), m_color(color), m_tooltip(std::move(tooltip)) {
|
||||
Highlighting::Highlighting(Region region, color_t color)
|
||||
: m_region(region), m_color(color) {
|
||||
}
|
||||
|
||||
Tooltip::Tooltip(Region region, std::string value, color_t color) : m_region(region), m_value(std::move(value)), m_color(color) {
|
||||
|
||||
}
|
||||
|
||||
namespace impl {
|
||||
|
||||
static std::map<u32, Highlighting> s_highlights;
|
||||
std::map<u32, Highlighting> &getHighlights() {
|
||||
return s_highlights;
|
||||
static std::map<u32, Highlighting> s_backgroundHighlights;
|
||||
std::map<u32, Highlighting> &getBackgroundHighlights() {
|
||||
return s_backgroundHighlights;
|
||||
}
|
||||
|
||||
static std::map<u32, HighlightingFunction> s_highlightingFunctions;
|
||||
std::map<u32, HighlightingFunction> &getHighlightingFunctions() {
|
||||
return s_highlightingFunctions;
|
||||
static std::map<u32, HighlightingFunction> s_backgroundHighlightingFunctions;
|
||||
std::map<u32, HighlightingFunction> &getBackgroundHighlightingFunctions() {
|
||||
return s_backgroundHighlightingFunctions;
|
||||
}
|
||||
|
||||
static std::map<u32, Highlighting> s_foregroundHighlights;
|
||||
std::map<u32, Highlighting> &getForegroundHighlights() {
|
||||
return s_foregroundHighlights;
|
||||
}
|
||||
|
||||
static std::map<u32, HighlightingFunction> s_foregroundHighlightingFunctions;
|
||||
std::map<u32, HighlightingFunction> &getForegroundHighlightingFunctions() {
|
||||
return s_foregroundHighlightingFunctions;
|
||||
}
|
||||
|
||||
static std::map<u32, Tooltip> s_tooltips;
|
||||
std::map<u32, Tooltip> &getTooltips() {
|
||||
return s_tooltips;
|
||||
}
|
||||
|
||||
static std::map<u32, TooltipFunction> s_tooltipFunctions;
|
||||
std::map<u32, TooltipFunction> &getTooltipFunctions() {
|
||||
return s_tooltipFunctions;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
u32 addHighlight(const Region ®ion, color_t color, const std::string &tooltip) {
|
||||
auto &highlights = impl::getHighlights();
|
||||
static u64 id = 0;
|
||||
u32 addBackgroundHighlight(const Region ®ion, color_t color) {
|
||||
static u32 id = 0;
|
||||
|
||||
id++;
|
||||
|
||||
highlights.insert({
|
||||
id, Highlighting {region, color, tooltip}
|
||||
impl::getBackgroundHighlights().insert({
|
||||
id, Highlighting {region, color}
|
||||
});
|
||||
|
||||
EventManager::post<EventHighlightingChanged>();
|
||||
@@ -62,37 +85,101 @@ namespace hex {
|
||||
return id;
|
||||
}
|
||||
|
||||
void removeHighlight(u32 id) {
|
||||
impl::getHighlights().erase(id);
|
||||
void removeBackgroundHighlight(u32 id) {
|
||||
impl::getBackgroundHighlights().erase(id);
|
||||
|
||||
EventManager::post<EventHighlightingChanged>();
|
||||
}
|
||||
|
||||
u32 addHighlightingProvider(const impl::HighlightingFunction &function) {
|
||||
auto &highlightFuncs = impl::getHighlightingFunctions();
|
||||
u32 addBackgroundHighlightingProvider(const impl::HighlightingFunction &function) {
|
||||
static u32 id = 0;
|
||||
|
||||
auto id = highlightFuncs.size();
|
||||
id++;
|
||||
|
||||
highlightFuncs.insert({ id, function });
|
||||
impl::getBackgroundHighlightingFunctions().insert({ id, function });
|
||||
|
||||
EventManager::post<EventHighlightingChanged>();
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
void removeHighlightingProvider(u32 id) {
|
||||
impl::getHighlightingFunctions().erase(id);
|
||||
void removeBackgroundHighlightingProvider(u32 id) {
|
||||
impl::getBackgroundHighlightingFunctions().erase(id);
|
||||
|
||||
EventManager::post<EventHighlightingChanged>();
|
||||
}
|
||||
|
||||
Region getSelection() {
|
||||
static Region selectedRegion;
|
||||
EventManager::subscribe<EventRegionSelected>([](const Region ®ion) {
|
||||
selectedRegion = region;
|
||||
u32 addForegroundHighlight(const Region ®ion, color_t color) {
|
||||
static u32 id = 0;
|
||||
|
||||
id++;
|
||||
|
||||
impl::getForegroundHighlights().insert({
|
||||
id, Highlighting {region, color}
|
||||
});
|
||||
|
||||
return selectedRegion;
|
||||
EventManager::post<EventHighlightingChanged>();
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
void removeForegroundHighlight(u32 id) {
|
||||
impl::getForegroundHighlights().erase(id);
|
||||
|
||||
EventManager::post<EventHighlightingChanged>();
|
||||
}
|
||||
|
||||
u32 addForegroundHighlightingProvider(const impl::HighlightingFunction &function) {
|
||||
static u32 id = 0;
|
||||
|
||||
id++;
|
||||
|
||||
impl::getForegroundHighlightingFunctions().insert({ id, function });
|
||||
|
||||
EventManager::post<EventHighlightingChanged>();
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
void removeForegroundHighlightingProvider(u32 id) {
|
||||
impl::getForegroundHighlightingFunctions().erase(id);
|
||||
|
||||
EventManager::post<EventHighlightingChanged>();
|
||||
}
|
||||
|
||||
static u32 tooltipId = 0;
|
||||
u32 addTooltip(Region region, std::string value, color_t color) {
|
||||
tooltipId++;
|
||||
impl::getTooltips().insert({ tooltipId, { region, std::move(value), color } });
|
||||
|
||||
return tooltipId;
|
||||
}
|
||||
|
||||
void removeTooltip(u32 id) {
|
||||
impl::getTooltips().erase(id);
|
||||
}
|
||||
|
||||
static u32 tooltipFunctionId;
|
||||
u32 addTooltipProvider(TooltipFunction function) {
|
||||
tooltipFunctionId++;
|
||||
impl::getTooltipFunctions().insert({ tooltipFunctionId, std::move(function) });
|
||||
|
||||
return tooltipFunctionId;
|
||||
}
|
||||
|
||||
void removeTooltipProvider(u32 id) {
|
||||
impl::getTooltipFunctions().erase(id);
|
||||
}
|
||||
|
||||
bool isSelectionValid() {
|
||||
return getSelection().has_value();
|
||||
}
|
||||
|
||||
std::optional<Region> getSelection() {
|
||||
std::optional<Region> selection;
|
||||
EventManager::post<QuerySelection>(selection);
|
||||
|
||||
return selection;
|
||||
}
|
||||
|
||||
void setSelection(const Region ®ion) {
|
||||
@@ -210,7 +297,7 @@ namespace hex {
|
||||
}
|
||||
|
||||
|
||||
static float s_globalScale;
|
||||
static float s_globalScale = 1.0;
|
||||
void setGlobalScale(float scale) {
|
||||
s_globalScale = scale;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user