1
0
mirror of synced 2025-01-31 20:05:22 +01:00

ui: Added hex editor highlight opacity setting

This commit is contained in:
WerWolv 2021-03-29 23:07:18 +02:00
parent 147aefc7e5
commit 6223b26888
6 changed files with 30 additions and 5 deletions

View File

@ -55,6 +55,7 @@ namespace hex {
std::string m_loaderScriptFilePath; std::string m_loaderScriptFilePath;
hex::EncodingFile m_currEncodingFile; hex::EncodingFile m_currEncodingFile;
u8 m_highlightAlpha = 0x80;
void drawSearchPopup(); void drawSearchPopup();
void drawGotoPopup(); void drawGotoPopup();

View File

@ -72,6 +72,17 @@ namespace hex::plugin::builtin {
return false; return false;
}); });
ContentRegistry::Settings::add("hex.builtin.setting.interface", "hex.builtin.setting.interface.highlight_alpha", 0x80, [](auto name, nlohmann::json &setting) {
static int alpha = setting.is_number() ? static_cast<int>(setting) : 0x80;
if (ImGui::SliderInt(name.data(), &alpha, 0x00, 0xFF)) {
setting = alpha;
return true;
}
return false;
});
} }
} }

View File

@ -512,6 +512,7 @@ namespace hex::plugin::builtin {
{ "hex.builtin.setting.interface.color.classic", "Klassisch" }, { "hex.builtin.setting.interface.color.classic", "Klassisch" },
{ "hex.builtin.setting.interface.language", "Sprache" }, { "hex.builtin.setting.interface.language", "Sprache" },
{ "hex.builtin.setting.interface.fps", "FPS Limite" }, { "hex.builtin.setting.interface.fps", "FPS Limite" },
{ "hex.builtin.setting.interface.highlight_alpha", "Markierungssichtbarkeit" },
{ "hex.builtin.provider.file.path", "Dateipfad" }, { "hex.builtin.provider.file.path", "Dateipfad" },
{ "hex.builtin.provider.file.size", "Größe" }, { "hex.builtin.provider.file.size", "Größe" },

View File

@ -512,6 +512,7 @@ namespace hex::plugin::builtin {
{ "hex.builtin.setting.interface.color.classic", "Classic" }, { "hex.builtin.setting.interface.color.classic", "Classic" },
{ "hex.builtin.setting.interface.language", "Language" }, { "hex.builtin.setting.interface.language", "Language" },
{ "hex.builtin.setting.interface.fps", "FPS Limit" }, { "hex.builtin.setting.interface.fps", "FPS Limit" },
{ "hex.builtin.setting.interface.highlight_alpha", "Highlighting opacity" },
{ "hex.builtin.provider.file.path", "File path" }, { "hex.builtin.provider.file.path", "File path" },
{ "hex.builtin.provider.file.size", "Size" }, { "hex.builtin.provider.file.size", "Size" },

View File

@ -512,6 +512,7 @@ namespace hex::plugin::builtin {
{ "hex.builtin.setting.interface.color.classic", "Classico" }, { "hex.builtin.setting.interface.color.classic", "Classico" },
{ "hex.builtin.setting.interface.language", "Lingua" }, { "hex.builtin.setting.interface.language", "Lingua" },
{ "hex.builtin.setting.interface.fps", "Limite FPS" }, { "hex.builtin.setting.interface.fps", "Limite FPS" },
// { "hex.builtin.setting.interface.highlight_alpha", "" },
{ "hex.builtin.provider.file.path", "Percorso del File" }, { "hex.builtin.provider.file.path", "Percorso del File" },
{ "hex.builtin.provider.file.size", "Dimensione" }, { "hex.builtin.provider.file.size", "Dimensione" },

View File

@ -52,19 +52,21 @@ namespace hex {
off += SharedData::currentProvider->getBaseAddress(); off += SharedData::currentProvider->getBaseAddress();
u32 alpha = static_cast<u32>(_this->m_highlightAlpha) << 24;
for (const auto &[region, name, comment, color, locked] : ImHexApi::Bookmarks::getEntries()) { for (const auto &[region, name, comment, color, locked] : ImHexApi::Bookmarks::getEntries()) {
if (off >= region.address && off < (region.address + region.size)) if (off >= region.address && off < (region.address + region.size))
currColor = (color & 0x00FFFFFF) | 0x80000000; currColor = (color & 0x00FFFFFF) | alpha;
if ((off - 1) >= region.address && (off - 1) < (region.address + region.size)) if ((off - 1) >= region.address && (off - 1) < (region.address + region.size))
prevColor = (color & 0x00FFFFFF) | 0x80000000; prevColor = (color & 0x00FFFFFF) | alpha;
} }
if (_this->m_highlightedBytes.contains(off)) { if (_this->m_highlightedBytes.contains(off)) {
auto color = (_this->m_highlightedBytes[off] & 0x00FFFFFF) | 0x80000000; auto color = (_this->m_highlightedBytes[off] & 0x00FFFFFF) | alpha;
currColor = currColor.has_value() ? ImAlphaBlendColors(color, currColor.value()) : color; currColor = currColor.has_value() ? ImAlphaBlendColors(color, currColor.value()) : color;
} }
if (_this->m_highlightedBytes.contains(off - 1)) { if (_this->m_highlightedBytes.contains(off - 1)) {
auto color = (_this->m_highlightedBytes[off - 1] & 0x00FFFFFF) | 0x80000000; auto color = (_this->m_highlightedBytes[off - 1] & 0x00FFFFFF) | alpha;
prevColor = prevColor.has_value() ? ImAlphaBlendColors(color, prevColor.value()) : color; prevColor = prevColor.has_value() ? ImAlphaBlendColors(color, prevColor.value()) : color;
} }
@ -73,7 +75,7 @@ namespace hex {
} }
if (currColor.has_value() && (currColor.value() & 0x00FFFFFF) != 0x00) { if (currColor.has_value() && (currColor.value() & 0x00FFFFFF) != 0x00) {
_this->m_memoryEditor.HighlightColor = (currColor.value() & 0x00FFFFFF) | 0x40000000; _this->m_memoryEditor.HighlightColor = (currColor.value() & 0x00FFFFFF) | alpha;
return true; return true;
} }
@ -177,6 +179,12 @@ namespace hex {
EventManager::subscribe<EventFileLoaded>(this, [](std::string path) { EventManager::subscribe<EventFileLoaded>(this, [](std::string path) {
EventManager::post<RequestChangeWindowTitle>(std::filesystem::path(path).filename().string()); EventManager::post<RequestChangeWindowTitle>(std::filesystem::path(path).filename().string());
}); });
EventManager::subscribe<EventSettingsChanged>(this, [this] {
auto alpha = ContentRegistry::Settings::getSetting("hex.builtin.setting.interface", "hex.builtin.setting.interface.highlight_alpha");
this->m_highlightAlpha = alpha;
});
} }
ViewHexEditor::~ViewHexEditor() { ViewHexEditor::~ViewHexEditor() {
@ -186,6 +194,8 @@ namespace hex {
EventManager::unsubscribe<EventWindowClosing>(this); EventManager::unsubscribe<EventWindowClosing>(this);
EventManager::unsubscribe<EventPatternChanged>(this); EventManager::unsubscribe<EventPatternChanged>(this);
EventManager::unsubscribe<RequestOpenWindow>(this); EventManager::unsubscribe<RequestOpenWindow>(this);
EventManager::unsubscribe<EventFileLoaded>(this);
EventManager::unsubscribe<EventSettingsChanged>(this);
} }
void ViewHexEditor::drawContent() { void ViewHexEditor::drawContent() {