2022-04-08 16:08:02 +02:00
|
|
|
#pragma once
|
|
|
|
|
2023-06-24 16:40:34 +02:00
|
|
|
#include <hex/api/task.hpp>
|
2023-07-04 22:18:06 +02:00
|
|
|
#include <hex/api/content_registry.hpp>
|
2023-06-24 16:40:34 +02:00
|
|
|
|
2022-04-17 16:57:30 +02:00
|
|
|
#include <pl/patterns/pattern.hpp>
|
|
|
|
#include <pl/pattern_visitor.hpp>
|
2023-06-05 11:57:26 +02:00
|
|
|
|
|
|
|
#include <pl/formatters.hpp>
|
|
|
|
|
2022-04-08 16:08:02 +02:00
|
|
|
#include <hex/providers/provider.hpp>
|
|
|
|
|
2022-11-08 21:43:22 +01:00
|
|
|
namespace hex::plugin::builtin::ui {
|
2022-04-08 16:08:02 +02:00
|
|
|
|
2022-04-17 16:57:30 +02:00
|
|
|
class PatternDrawer : public pl::PatternVisitor {
|
2022-04-08 16:08:02 +02:00
|
|
|
public:
|
2023-06-05 11:57:26 +02:00
|
|
|
PatternDrawer() {
|
|
|
|
this->m_formatters = pl::gen::fmt::createFormatters();
|
|
|
|
}
|
2022-04-08 16:08:02 +02:00
|
|
|
|
2023-06-05 11:57:26 +02:00
|
|
|
void draw(const std::vector<std::shared_ptr<pl::ptrn::Pattern>> &patterns, pl::PatternLanguage *runtime = nullptr, float height = 0.0F);
|
2022-11-08 21:43:22 +01:00
|
|
|
|
2023-01-08 16:06:26 +01:00
|
|
|
enum class TreeStyle {
|
|
|
|
Default = 0,
|
|
|
|
AutoExpanded = 1,
|
|
|
|
Flattened = 2
|
|
|
|
};
|
|
|
|
|
|
|
|
void setTreeStyle(TreeStyle style) { this->m_treeStyle = style; }
|
2023-02-17 14:53:15 +01:00
|
|
|
void setSelectionCallback(std::function<void(Region)> callback) { this->m_selectionCallback = std::move(callback); }
|
2023-01-24 23:27:15 +01:00
|
|
|
void reset();
|
2023-01-08 16:06:26 +01:00
|
|
|
|
2022-11-08 21:43:22 +01:00
|
|
|
private:
|
2022-10-12 14:49:48 +02:00
|
|
|
void draw(pl::ptrn::Pattern& pattern);
|
|
|
|
|
2022-11-08 21:43:22 +01:00
|
|
|
public:
|
2022-08-06 21:38:09 +02:00
|
|
|
void visit(pl::ptrn::PatternArrayDynamic& pattern) override;
|
|
|
|
void visit(pl::ptrn::PatternArrayStatic& pattern) override;
|
|
|
|
void visit(pl::ptrn::PatternBitfieldField& pattern) override;
|
2023-03-26 11:01:37 +02:00
|
|
|
void visit(pl::ptrn::PatternBitfieldArray& pattern) override;
|
2022-08-06 21:38:09 +02:00
|
|
|
void visit(pl::ptrn::PatternBitfield& pattern) override;
|
|
|
|
void visit(pl::ptrn::PatternBoolean& pattern) override;
|
|
|
|
void visit(pl::ptrn::PatternCharacter& pattern) override;
|
|
|
|
void visit(pl::ptrn::PatternEnum& pattern) override;
|
|
|
|
void visit(pl::ptrn::PatternFloat& pattern) override;
|
|
|
|
void visit(pl::ptrn::PatternPadding& pattern) override;
|
|
|
|
void visit(pl::ptrn::PatternPointer& pattern) override;
|
|
|
|
void visit(pl::ptrn::PatternSigned& pattern) override;
|
|
|
|
void visit(pl::ptrn::PatternString& pattern) override;
|
|
|
|
void visit(pl::ptrn::PatternStruct& pattern) override;
|
|
|
|
void visit(pl::ptrn::PatternUnion& pattern) override;
|
|
|
|
void visit(pl::ptrn::PatternUnsigned& pattern) override;
|
|
|
|
void visit(pl::ptrn::PatternWideCharacter& pattern) override;
|
|
|
|
void visit(pl::ptrn::PatternWideString& pattern) override;
|
2022-04-08 16:08:02 +02:00
|
|
|
|
|
|
|
private:
|
2022-09-19 14:16:23 +02:00
|
|
|
constexpr static auto ChunkSize = 512;
|
|
|
|
constexpr static auto DisplayEndStep = 64;
|
2022-04-08 16:08:02 +02:00
|
|
|
|
2023-06-04 18:30:47 +02:00
|
|
|
void drawArray(pl::ptrn::Pattern& pattern, pl::ptrn::IIterable &iterable, bool isInlined);
|
2022-08-06 21:38:09 +02:00
|
|
|
u64& getDisplayEnd(const pl::ptrn::Pattern& pattern);
|
2022-12-18 23:11:22 +01:00
|
|
|
void makeSelectable(const pl::ptrn::Pattern &pattern);
|
2023-01-25 10:16:31 +01:00
|
|
|
|
2023-06-04 18:30:47 +02:00
|
|
|
void drawValueColumn(pl::ptrn::Pattern& pattern);
|
2023-07-04 22:18:06 +02:00
|
|
|
void drawVisualizer(const std::map<std::string, ContentRegistry::PatternLanguage::impl::Visualizer> &visualizers, const std::vector<pl::core::Token::Literal> &arguments, pl::ptrn::Pattern &pattern, pl::ptrn::IIterable &iterable, bool reset);
|
2023-06-04 18:30:47 +02:00
|
|
|
void drawFavoriteColumn(const pl::ptrn::Pattern& pattern);
|
2023-01-08 16:06:26 +01:00
|
|
|
|
2023-06-04 18:30:47 +02:00
|
|
|
bool createTreeNode(const pl::ptrn::Pattern& pattern, bool leaf = false);
|
2022-12-18 23:11:22 +01:00
|
|
|
void createDefaultEntry(pl::ptrn::Pattern &pattern);
|
2023-01-08 16:06:26 +01:00
|
|
|
void closeTreeNode(bool inlined);
|
|
|
|
|
2023-01-28 00:03:20 +01:00
|
|
|
bool isEditingPattern(const pl::ptrn::Pattern& pattern) const;
|
|
|
|
void resetEditing();
|
2023-06-24 16:40:34 +02:00
|
|
|
bool matchesFilter(const std::vector<std::string> &filterPath, const std::vector<std::string> &patternPath, bool fullMatch);
|
|
|
|
void traversePatternTree(pl::ptrn::Pattern &pattern, std::vector<std::string> &patternPath, const std::function<void(pl::ptrn::Pattern&)> &callback);
|
2022-04-08 16:08:02 +02:00
|
|
|
|
|
|
|
private:
|
2022-08-06 21:38:09 +02:00
|
|
|
std::map<const pl::ptrn::Pattern*, u64> m_displayEnd;
|
2022-11-08 21:43:22 +01:00
|
|
|
std::vector<pl::ptrn::Pattern*> m_sortedPatterns;
|
2022-12-18 23:11:22 +01:00
|
|
|
|
|
|
|
const pl::ptrn::Pattern *m_editingPattern = nullptr;
|
2023-01-28 00:03:20 +01:00
|
|
|
u64 m_editingPatternOffset = 0;
|
|
|
|
|
2023-01-08 16:06:26 +01:00
|
|
|
TreeStyle m_treeStyle = TreeStyle::Default;
|
2023-01-18 17:17:34 +01:00
|
|
|
pl::ptrn::Pattern *m_currVisualizedPattern = nullptr;
|
2023-01-24 23:27:15 +01:00
|
|
|
|
|
|
|
std::set<pl::ptrn::Pattern*> m_visualizedPatterns;
|
2023-01-25 10:16:31 +01:00
|
|
|
std::string m_lastVisualizerError;
|
2023-02-17 14:53:15 +01:00
|
|
|
|
2023-06-04 16:13:46 +02:00
|
|
|
std::string m_filterText;
|
|
|
|
std::vector<std::string> m_filter;
|
2023-06-04 18:30:47 +02:00
|
|
|
std::vector<std::string> m_currPatternPath;
|
|
|
|
std::map<std::vector<std::string>, std::unique_ptr<pl::ptrn::Pattern>> m_favorites;
|
|
|
|
bool m_showFavoriteStars = false;
|
|
|
|
bool m_favoritesUpdated = false;
|
2023-06-24 16:40:34 +02:00
|
|
|
TaskHolder m_favoritesUpdateTask;
|
2023-06-04 18:30:47 +02:00
|
|
|
|
2023-02-17 14:53:15 +01:00
|
|
|
std::function<void(Region)> m_selectionCallback = [](Region) { };
|
2023-06-05 11:57:26 +02:00
|
|
|
|
|
|
|
pl::gen::fmt::FormatterArray m_formatters;
|
2022-04-08 16:08:02 +02:00
|
|
|
};
|
2022-10-02 17:30:26 +02:00
|
|
|
}
|