feat: Finish up work on new pl section system

This commit is contained in:
WerWolv
2022-11-08 21:43:22 +01:00
parent 23ce2ec271
commit 4c5d2f6ebb
22 changed files with 250 additions and 215 deletions

View File

@@ -12,9 +12,9 @@ namespace hex::plugin::builtin {
[[nodiscard]] bool isAvailable() const override { return true; }
[[nodiscard]] bool isReadable() const override { return true; }
[[nodiscard]] bool isWritable() const override { return true; }
[[nodiscard]] bool isResizable() const override { return true; }
[[nodiscard]] bool isSavable() const override { return true; }
[[nodiscard]] bool isWritable() const override { return !this->m_readOnly; }
[[nodiscard]] bool isResizable() const override { return !this->m_readOnly; }
[[nodiscard]] bool isSavable() const override { return !this->m_readOnly; }
[[nodiscard]] bool open() override;
void close() override { }
@@ -42,8 +42,11 @@ namespace hex::plugin::builtin {
void loadSettings(const nlohmann::json &settings) override { hex::unused(settings); }
[[nodiscard]] nlohmann::json storeSettings(nlohmann::json settings) const override { return settings; }
void setReadOnly(bool readOnly) { this->m_readOnly = readOnly; }
private:
std::vector<u8> m_data;
bool m_readOnly = false;
};
}

View File

@@ -33,6 +33,7 @@ namespace hex::plugin::builtin {
u64 m_startAddress = 0;
size_t m_validBytes = 0;
prv::Provider *m_selectedProvider = nullptr;
std::atomic<bool> m_dataValid = false;
std::vector<InspectorCacheEntry> m_cachedData, m_workData;
TaskHolder m_updateTask;

View File

@@ -7,7 +7,7 @@
#include <hex/helpers/encoding_file.hpp>
#include <content/helpers/provider_extra_data.hpp>
#include <content/helpers/hex_editor.hpp>
#include <ui/hex_editor.hpp>
namespace hex::plugin::builtin {
@@ -70,7 +70,7 @@ namespace hex::plugin::builtin {
void registerEvents();
void registerMenuItems();
HexEditor m_hexEditor;
ui::HexEditor m_hexEditor;
bool m_shouldOpenPopup = false;
std::unique_ptr<Popup> m_currPopup;

View File

@@ -3,7 +3,7 @@
#include <hex.hpp>
#include <hex/ui/view.hpp>
#include <content/helpers/pattern_drawer.hpp>
#include <ui/pattern_drawer.hpp>
#include <hex/providers/provider.hpp>
#include <vector>
@@ -20,7 +20,7 @@ namespace hex::plugin::builtin {
private:
std::map<hex::prv::Provider *, std::vector<pl::ptrn::Pattern*>> m_sortedPatterns;
hex::PatternDrawer m_patternDrawer;
ui::PatternDrawer m_patternDrawer;
};
}

View File

@@ -6,7 +6,8 @@
#include <hex/providers/provider.hpp>
#include <content/helpers/provider_extra_data.hpp>
#include <content/helpers/hex_editor.hpp>
#include <ui/hex_editor.hpp>
#include <ui/pattern_drawer.hpp>
#include <content/providers/memory_file_provider.hpp>
#include <cstring>
@@ -14,6 +15,7 @@
#include <string_view>
#include <thread>
#include <vector>
#include <functional>
#include <TextEditor.h>
@@ -63,9 +65,7 @@ namespace hex::plugin::builtin {
bool m_syncPatternSourceCode = false;
bool m_autoLoadPatterns = true;
std::unique_ptr<MemoryFileProvider> m_sectionProvider = nullptr;
HexEditor m_hexEditor;
std::map<prv::Provider*, std::move_only_function<void()>> m_sectionWindowDrawer;
private:
void drawConsole(ImVec2 size, const std::vector<std::pair<pl::core::LogConsole::Level, std::string>> &console);
void drawEnvVars(ImVec2 size, std::list<PlData::EnvVar> &envVars);

View File

@@ -17,21 +17,22 @@
#include <hex/providers/provider.hpp>
#include <hex/providers/buffered_reader.hpp>
namespace hex {
namespace hex::plugin::builtin::ui {
class HexEditor {
public:
HexEditor();
explicit HexEditor(prv::Provider *provider = nullptr);
~HexEditor();
void draw(prv::Provider *provider, float height = ImGui::GetContentRegionAvail().y);
void draw(float height = ImGui::GetContentRegionAvail().y);
void setProvider(prv::Provider *provider) { this->m_provider = provider; }
private:
enum class CellType { None, Hex, ASCII };
void drawCell(prv::Provider *provider, u64 address, u8 *data, size_t size, bool hovered, CellType cellType);
void drawCell(u64 address, u8 *data, size_t size, bool hovered, CellType cellType);
void drawSelectionFrame(u32 x, u32 y, u64 byteAddress, u16 bytesPerCell, const ImVec2 &cellPos, const ImVec2 &cellSize) const;
void drawEditor(prv::Provider *provider, const ImVec2 &size);
void drawFooter(prv::Provider *provider, const ImVec2 &size);
void drawEditor(const ImVec2 &size);
void drawFooter(const ImVec2 &size);
void drawTooltip(u64 address, const u8 *data, size_t size);
void handleSelection(u64 address, u32 bytesPerCell, const u8 *data, bool cellHovered);
@@ -47,9 +48,7 @@ namespace hex {
if (!ImHexApi::Provider::isValid())
return;
auto provider = ImHexApi::Provider::get();
const size_t maxAddress = provider->getActualSize() + provider->getBaseAddress() - 1;
const size_t maxAddress = this->m_provider->getActualSize() + this->m_provider->getBaseAddress() - 1;
this->m_selectionChanged = this->m_selectionStart != start || this->m_selectionEnd != end;
@@ -57,7 +56,8 @@ namespace hex {
this->m_selectionEnd = std::clamp<u128>(end, 0, maxAddress);
if (this->m_selectionChanged) {
EventManager::post<EventRegionSelected>(this->getSelection());
auto selection = this->getSelection();
EventManager::post<EventRegionSelected>(ImHexApi::HexEditor::ProviderRegion{ { selection.address, selection.size }, this->m_provider });
this->m_shouldModifyValue = true;
}
}
@@ -161,6 +161,8 @@ namespace hex {
}
private:
prv::Provider *m_provider;
std::optional<u64> m_selectionStart;
std::optional<u64> m_selectionEnd;
float m_scrollPosition = 0;

View File

@@ -4,14 +4,18 @@
#include <pl/pattern_visitor.hpp>
#include <hex/providers/provider.hpp>
namespace hex {
namespace hex::plugin::builtin::ui {
class PatternDrawer : public pl::PatternVisitor {
public:
PatternDrawer() = default;
void draw(const std::vector<std::shared_ptr<pl::ptrn::Pattern>> &patterns, float height = 0.0F);
private:
void draw(pl::ptrn::Pattern& pattern);
public:
void visit(pl::ptrn::PatternArrayDynamic& pattern) override;
void visit(pl::ptrn::PatternArrayStatic& pattern) override;
void visit(pl::ptrn::PatternBitfieldField& pattern) override;
@@ -39,5 +43,6 @@ namespace hex {
private:
std::map<const pl::ptrn::Pattern*, u64> m_displayEnd;
std::vector<pl::ptrn::Pattern*> m_sortedPatterns;
};
}

View File

@@ -3,6 +3,9 @@
#include <imgui.h>
#include <hex/ui/imgui_imhex_extensions.h>
namespace pl::ptrn { class Pattern; }
namespace hex::prv { class Provider; }
namespace hex::plugin::builtin::ui {