2022-08-07 12:20:40 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <imgui.h>
|
|
|
|
#include <hex/ui/imgui_imhex_extensions.h>
|
|
|
|
|
2022-11-08 21:43:22 +01:00
|
|
|
namespace pl::ptrn { class Pattern; }
|
|
|
|
namespace hex::prv { class Provider; }
|
|
|
|
|
2022-08-07 12:20:40 +02:00
|
|
|
namespace hex::plugin::builtin::ui {
|
|
|
|
|
|
|
|
|
2023-04-10 14:08:21 +02:00
|
|
|
enum class RegionType : int {
|
2022-08-07 12:20:40 +02:00
|
|
|
EntireData,
|
2023-04-10 14:08:21 +02:00
|
|
|
Selection,
|
|
|
|
Region
|
2022-08-07 12:20:40 +02:00
|
|
|
};
|
|
|
|
|
2023-04-10 14:08:21 +02:00
|
|
|
inline void regionSelectionPicker(Region *region, prv::Provider *provider, RegionType *type, bool showHeader = true, bool firstEntry = false) {
|
2022-08-07 12:20:40 +02:00
|
|
|
if (showHeader)
|
|
|
|
ImGui::Header("hex.builtin.common.range"_lang, firstEntry);
|
|
|
|
|
2023-04-12 19:21:48 +02:00
|
|
|
if (ImGui::RadioButton("hex.builtin.common.range.entire_data"_lang, *type == RegionType::EntireData))
|
2023-04-10 14:08:21 +02:00
|
|
|
*type = RegionType::EntireData;
|
2023-04-12 19:21:48 +02:00
|
|
|
if (ImGui::RadioButton("hex.builtin.common.range.selection"_lang, *type == RegionType::Selection))
|
2023-04-10 14:08:21 +02:00
|
|
|
*type = RegionType::Selection;
|
2023-04-12 19:21:48 +02:00
|
|
|
if (ImGui::RadioButton("hex.builtin.common.region"_lang, *type == RegionType::Region))
|
2023-04-10 14:08:21 +02:00
|
|
|
*type = RegionType::Region;
|
|
|
|
|
2023-04-12 19:21:48 +02:00
|
|
|
switch (*type) {
|
|
|
|
case RegionType::EntireData:
|
|
|
|
*region = { provider->getBaseAddress(), provider->getActualSize() };
|
|
|
|
break;
|
|
|
|
case RegionType::Selection:
|
|
|
|
*region = ImHexApi::HexEditor::getSelection().value_or(ImHexApi::HexEditor::ProviderRegion { { 0, 1 }, provider });
|
|
|
|
break;
|
|
|
|
case RegionType::Region:
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
|
|
|
const auto width = ImGui::GetContentRegionAvail().x / 2 - ImGui::CalcTextSize(" - ").x / 2 - ImGui::GetStyle().FramePadding.x * 4;
|
|
|
|
u64 start = region->getStartAddress(), end = region->getEndAddress();
|
|
|
|
|
|
|
|
ImGui::PushItemWidth(width);
|
|
|
|
ImGui::InputHexadecimal("##start", &start);
|
|
|
|
ImGui::PopItemWidth();
|
|
|
|
ImGui::SameLine();
|
|
|
|
ImGui::TextUnformatted(" - ");
|
|
|
|
ImGui::SameLine();
|
|
|
|
ImGui::PushItemWidth(width);
|
|
|
|
ImGui::InputHexadecimal("##end", &end);
|
|
|
|
ImGui::PopItemWidth();
|
|
|
|
|
|
|
|
*region = { start, (end - start) + 1 };
|
|
|
|
break;
|
2023-04-10 14:08:21 +02:00
|
|
|
}
|
2022-08-07 12:20:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|