mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-30 13:05:25 -05:00
ui: Moved hex editor settings to settings menu
This commit is contained in:
@@ -45,7 +45,7 @@ namespace hex::prv {
|
||||
|
||||
void FileProvider::read(u64 offset, void *buffer, size_t size, bool overlays) {
|
||||
|
||||
if (((offset - this->getBaseAddress()) + size) > this->getSize() || buffer == nullptr || size == 0)
|
||||
if ((offset - this->getBaseAddress()) > (this->getSize() - size) || buffer == nullptr || size == 0)
|
||||
return;
|
||||
|
||||
std::memcpy(buffer, reinterpret_cast<u8*>(this->m_mappedFile) + PageSize * this->m_currPage + offset - this->getBaseAddress(), size);
|
||||
|
||||
@@ -14,19 +14,13 @@ namespace hex {
|
||||
EventManager::subscribe<EventRegionSelected>(this, [this](Region region) {
|
||||
auto provider = SharedData::currentProvider;
|
||||
|
||||
if (provider == nullptr) {
|
||||
if (provider == nullptr || region.address == (size_t)-1) {
|
||||
this->m_validBytes = 0;
|
||||
return;
|
||||
} else {
|
||||
this->m_validBytes = u64(provider->getSize() - region.address);
|
||||
this->m_startAddress = region.address;
|
||||
}
|
||||
|
||||
if (region.address == (size_t)-1) {
|
||||
this->m_validBytes = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
this->m_validBytes = u64(provider->getSize() - region.address);
|
||||
this->m_startAddress = region.address;
|
||||
|
||||
this->m_shouldInvalidate = true;
|
||||
});
|
||||
}
|
||||
@@ -56,7 +50,7 @@ namespace hex {
|
||||
if (ImGui::Begin(View::toWindowName("hex.view.data_inspector.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) {
|
||||
auto provider = SharedData::currentProvider;
|
||||
|
||||
if (provider != nullptr && provider->isReadable()) {
|
||||
if (provider != nullptr && provider->isReadable() && this->m_validBytes > 0) {
|
||||
if (ImGui::BeginTable("##datainspector", 2,
|
||||
ImGuiTableFlags_ScrollY | ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable | ImGuiTableFlags_RowBg,
|
||||
ImVec2(0, ImGui::GetTextLineHeightWithSpacing() * (this->m_cachedData.size() + 1)))) {
|
||||
@@ -112,6 +106,13 @@ namespace hex {
|
||||
this->m_numberDisplayStyle = NumberDisplayStyle::Octal;
|
||||
this->m_shouldInvalidate = true;
|
||||
}
|
||||
} else {
|
||||
std::string text = "hex.view.data_inspector.no_data"_lang;
|
||||
auto textSize = ImGui::CalcTextSize(text.c_str());
|
||||
auto availableSpace = ImGui::GetContentRegionAvail();
|
||||
|
||||
ImGui::SetCursorPos((availableSpace - textSize) / 2.0F);
|
||||
ImGui::TextUnformatted(text.c_str());
|
||||
}
|
||||
}
|
||||
ImGui::End();
|
||||
|
||||
@@ -19,8 +19,12 @@ namespace hex {
|
||||
|
||||
EventManager::subscribe<EventRegionSelected>(this, [this](Region region) {
|
||||
if (this->m_shouldMatchSelection) {
|
||||
this->m_codeRegion[0] = region.address;
|
||||
this->m_codeRegion[1] = region.address + region.size;
|
||||
if (region.address == size_t(-1)) {
|
||||
this->m_codeRegion[0] = this->m_codeRegion[1] = 0;
|
||||
} else {
|
||||
this->m_codeRegion[0] = region.address;
|
||||
this->m_codeRegion[1] = region.address + region.size;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -15,8 +15,12 @@ namespace hex {
|
||||
|
||||
EventManager::subscribe<EventRegionSelected>(this, [this](Region region) {
|
||||
if (this->m_shouldMatchSelection) {
|
||||
this->m_hashRegion[0] = region.address;
|
||||
this->m_hashRegion[1] = region.address + region.size;
|
||||
if (region.address == size_t(-1)) {
|
||||
this->m_hashRegion[0] = this->m_hashRegion[1] = 0;
|
||||
} else {
|
||||
this->m_hashRegion[0] = region.address;
|
||||
this->m_hashRegion[1] = region.address + region.size;
|
||||
}
|
||||
this->m_shouldInvalidate = true;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -204,10 +204,53 @@ namespace hex {
|
||||
});
|
||||
|
||||
EventManager::subscribe<EventSettingsChanged>(this, [this] {
|
||||
auto alpha = ContentRegistry::Settings::getSetting("hex.builtin.setting.interface", "hex.builtin.setting.interface.highlight_alpha");
|
||||
{
|
||||
auto alpha = ContentRegistry::Settings::getSetting("hex.builtin.setting.interface", "hex.builtin.setting.interface.highlight_alpha");
|
||||
|
||||
if (alpha.is_number())
|
||||
this->m_highlightAlpha = alpha;
|
||||
}
|
||||
|
||||
{
|
||||
auto columnCount = ContentRegistry::Settings::getSetting("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.column_count");
|
||||
|
||||
this->m_memoryEditor.Cols = static_cast<int>(columnCount);
|
||||
}
|
||||
|
||||
{
|
||||
auto hexii = ContentRegistry::Settings::getSetting("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.hexii");
|
||||
|
||||
this->m_memoryEditor.OptShowHexII = static_cast<int>(hexii);
|
||||
}
|
||||
|
||||
{
|
||||
auto ascii = ContentRegistry::Settings::getSetting("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.ascii");
|
||||
|
||||
this->m_memoryEditor.OptShowAscii = static_cast<int>(ascii);
|
||||
}
|
||||
|
||||
{
|
||||
auto advancedDecoding = ContentRegistry::Settings::getSetting("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.advanced_decoding");
|
||||
|
||||
this->m_memoryEditor.OptShowAdvancedDecoding = static_cast<int>(advancedDecoding);
|
||||
}
|
||||
|
||||
{
|
||||
auto greyOutZeros = ContentRegistry::Settings::getSetting("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.grey_zeros");
|
||||
|
||||
this->m_memoryEditor.OptGreyOutZeroes = static_cast<int>(greyOutZeros);
|
||||
}
|
||||
|
||||
{
|
||||
auto upperCaseHex = ContentRegistry::Settings::getSetting("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.uppercase_hex");
|
||||
|
||||
this->m_memoryEditor.OptUpperCaseHex = static_cast<int>(upperCaseHex);
|
||||
}
|
||||
|
||||
{
|
||||
auto showExtraInfo = ContentRegistry::Settings::getSetting("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.extra_info");
|
||||
|
||||
this->m_memoryEditor.OptShowExtraInfo = static_cast<int>(showExtraInfo);
|
||||
}
|
||||
});
|
||||
|
||||
EventManager::subscribe<QuerySelection>(this, [this](auto ®ion) {
|
||||
@@ -246,25 +289,26 @@ namespace hex {
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::Spacing();
|
||||
ImGui::SameLine();
|
||||
ImGui::TextUnformatted(hex::format("hex.view.hexeditor.page"_lang, provider->getCurrentPage() + 1, provider->getPageCount()).c_str());
|
||||
ImGui::SameLine();
|
||||
if (provider->getPageCount() > 1) {
|
||||
ImGui::TextUnformatted(hex::format("hex.view.hexeditor.page"_lang, provider->getCurrentPage() + 1, provider->getPageCount()).c_str());
|
||||
|
||||
if (ImGui::ArrowButton("prevPage", ImGuiDir_Left)) {
|
||||
provider->setCurrentPage(provider->getCurrentPage() - 1);
|
||||
ImGui::SameLine();
|
||||
|
||||
EventManager::post<EventRegionSelected>(Region { std::min(this->m_memoryEditor.DataPreviewAddr, this->m_memoryEditor.DataPreviewAddrEnd), 1 });
|
||||
if (ImGui::ArrowButton("prevPage", ImGuiDir_Left)) {
|
||||
provider->setCurrentPage(provider->getCurrentPage() - 1);
|
||||
|
||||
EventManager::post<EventRegionSelected>(Region { std::min(this->m_memoryEditor.DataPreviewAddr, this->m_memoryEditor.DataPreviewAddrEnd), 1 });
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
|
||||
if (ImGui::ArrowButton("nextPage", ImGuiDir_Right)) {
|
||||
provider->setCurrentPage(provider->getCurrentPage() + 1);
|
||||
|
||||
EventManager::post<EventRegionSelected>(Region { std::min(this->m_memoryEditor.DataPreviewAddr, this->m_memoryEditor.DataPreviewAddrEnd), 1 });
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
|
||||
if (ImGui::ArrowButton("nextPage", ImGuiDir_Right)) {
|
||||
provider->setCurrentPage(provider->getCurrentPage() + 1);
|
||||
|
||||
EventManager::post<EventRegionSelected>(Region { std::min(this->m_memoryEditor.DataPreviewAddr, this->m_memoryEditor.DataPreviewAddrEnd), 1 });
|
||||
}
|
||||
}
|
||||
ImGui::End();
|
||||
|
||||
|
||||
@@ -24,14 +24,22 @@ namespace hex {
|
||||
ImGui::SetNextWindowSizeConstraints(ImVec2(0, 0), ImVec2(FLT_MAX, FLT_MAX));
|
||||
|
||||
if (ImGui::BeginPopupModal(View::toWindowName("hex.view.settings.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_AlwaysAutoResize)) {
|
||||
for (auto &[category, entries] : ContentRegistry::Settings::getEntries()) {
|
||||
ImGui::TextUnformatted(LangEntry(category));
|
||||
ImGui::Separator();
|
||||
for (auto &[name, callback] : entries) {
|
||||
if (callback(LangEntry(name), ContentRegistry::Settings::getSettingsData()[category][name]))
|
||||
EventManager::post<EventSettingsChanged>();
|
||||
if (ImGui::BeginTabBar("settings")) {
|
||||
for (auto &[category, entries] : ContentRegistry::Settings::getEntries()) {
|
||||
if (ImGui::BeginTabItem(LangEntry(category))) {
|
||||
ImGui::TextUnformatted(LangEntry(category));
|
||||
ImGui::Separator();
|
||||
|
||||
for (auto &[name, callback] : entries) {
|
||||
if (callback(LangEntry(name), ContentRegistry::Settings::getSettingsData()[category][name]))
|
||||
EventManager::post<EventSettingsChanged>();
|
||||
}
|
||||
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
}
|
||||
ImGui::NewLine();
|
||||
|
||||
ImGui::EndTabBar();
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
} else
|
||||
|
||||
Reference in New Issue
Block a user