1
0
mirror of synced 2025-02-17 18:59:21 +01:00

bookmarks: Added ability to lock bookmarks

This commit is contained in:
WerWolv 2021-02-24 21:42:18 +01:00
parent 209d33ca57
commit 4a1de5d1cb
5 changed files with 25 additions and 8 deletions

View File

@ -19,6 +19,7 @@ namespace hex {
std::vector<char> name;
std::vector<char> comment;
u32 color;
bool locked;
};
static void add(Region region, std::string_view name, std::string_view comment, u32 color = 0x00000000);

View File

@ -14,6 +14,7 @@ namespace hex {
entry.comment.reserve(comment.length());
std::copy(name.begin(), name.end(), std::back_inserter(entry.name));
std::copy(comment.begin(), comment.end(), std::back_inserter(entry.comment));
entry.locked = false;
entry.color = color;

View File

@ -8,7 +8,7 @@ using json = nlohmann::json;
namespace hex {
void to_json(json& j, const ImHexApi::Bookmarks::Entry& b) {
j = json{ { "address", b.region.address }, { "size", b.region.size }, { "name", b.name.data() }, { "comment", b.comment.data() } };
j = json{ { "address", b.region.address }, { "size", b.region.size }, { "name", b.name.data() }, { "comment", b.comment.data() }, { "locked", b.locked } };
}
void from_json(const json& j, ImHexApi::Bookmarks::Entry& b) {
@ -18,6 +18,7 @@ namespace hex {
j.at("size").get_to(b.region.size);
j.at("name").get_to(name);
j.at("comment").get_to(comment);
j.at("locked").get_to(b.locked);
std::copy(name.begin(), name.end(), std::back_inserter(b.name));
std::copy(comment.begin(), comment.end(), std::back_inserter(b.comment));

View File

@ -58,7 +58,7 @@ namespace hex {
u32 id = 1;
auto bookmarkToRemove = bookmarks.end();
for (auto iter = bookmarks.begin(); iter != bookmarks.end(); iter++) {
auto &[region, name, comment, color] = *iter;
auto &[region, name, comment, color, locked] = *iter;
auto headerColor = ImColor(color);
auto hoverColor = ImColor(color);
@ -95,18 +95,32 @@ namespace hex {
if (ImGui::Button("hex.view.bookmarks.button.remove"_lang))
bookmarkToRemove = iter;
ImGui::SameLine(0, 15);
ImGui::Checkbox("Locked", &locked);
ImGui::NewLine();
ImGui::TextUnformatted("hex.view.bookmarks.header.name"_lang);
ImGui::Separator();
ImGui::InputText("##nameInput", name.data(), 64);
ImGui::SameLine();
ImGui::ColorEdit4("hex.view.bookmarks.header.color"_lang, (float*)&headerColor.Value, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel | ImGuiColorEditFlags_NoAlpha);
ImGui::ColorEdit4("hex.view.bookmarks.header.color"_lang, (float*)&headerColor.Value, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel | ImGuiColorEditFlags_NoAlpha | (locked ? ImGuiColorEditFlags_NoPicker : ImGuiColorEditFlags_None));
color = headerColor;
ImGui::SameLine();
if (locked)
ImGui::TextUnformatted(name.data());
else
ImGui::InputText("##nameInput", name.data(), 64);
ImGui::NewLine();
ImGui::TextUnformatted("hex.view.bookmarks.header.comment"_lang);
ImGui::Separator();
ImGui::InputTextMultiline("##colorInput", comment.data(), 0xF'FFFF);
if (locked)
ImGui::TextWrapped("%s", comment.data());
else
ImGui::InputTextMultiline("##commentInput", comment.data(), 0xF'FFFF);
ImGui::NewLine();
}

View File

@ -56,7 +56,7 @@ namespace hex {
off += SharedData::currentProvider->getBaseAddress();
for (const auto &[region, name, comment, color] : ImHexApi::Bookmarks::getEntries()) {
for (const auto &[region, name, comment, color, locked] : ImHexApi::Bookmarks::getEntries()) {
if (off >= region.address && off < (region.address + region.size))
currColor = (color & 0x00FFFFFF) | 0x80000000;
if ((off - 1) >= region.address && (off - 1) < (region.address + region.size))
@ -90,7 +90,7 @@ namespace hex {
off += SharedData::currentProvider->getBaseAddress();
for (const auto &[region, name, comment, color] : ImHexApi::Bookmarks::getEntries()) {
for (const auto &[region, name, comment, color, locked] : ImHexApi::Bookmarks::getEntries()) {
if (off >= region.address && off < (region.address + region.size)) {
if (!tooltipShown) {
ImGui::BeginTooltip();