impr: Allow visualizers to have optional parameters
This commit is contained in:
parent
4af66f7d3d
commit
9617212ef1
@ -371,7 +371,7 @@ namespace hex {
|
||||
};
|
||||
|
||||
struct Visualizer {
|
||||
u32 parameterCount;
|
||||
pl::api::FunctionParameterCount parameterCount;
|
||||
VisualizerFunctionCallback callback;
|
||||
};
|
||||
|
||||
@ -434,7 +434,7 @@ namespace hex {
|
||||
* @param func The function callback
|
||||
* @param parameterCount The amount of parameters the function takes
|
||||
*/
|
||||
void addVisualizer(const std::string &name, const impl::VisualizerFunctionCallback &func, u32 parameterCount);
|
||||
void addVisualizer(const std::string &name, const impl::VisualizerFunctionCallback &func, pl::api::FunctionParameterCount parameterCount);
|
||||
|
||||
/**
|
||||
* @brief Adds a new inline visualizer to the pattern language
|
||||
@ -443,7 +443,7 @@ namespace hex {
|
||||
* @param func The function callback
|
||||
* @param parameterCount The amount of parameters the function takes
|
||||
*/
|
||||
void addInlineVisualizer(const std::string &name, const impl::VisualizerFunctionCallback &func, u32 parameterCount);
|
||||
void addInlineVisualizer(const std::string &name, const impl::VisualizerFunctionCallback &func, pl::api::FunctionParameterCount parameterCount);
|
||||
|
||||
}
|
||||
|
||||
|
@ -493,12 +493,12 @@ namespace hex {
|
||||
}
|
||||
|
||||
|
||||
void addVisualizer(const std::string &name, const impl::VisualizerFunctionCallback &function, u32 parameterCount) {
|
||||
void addVisualizer(const std::string &name, const impl::VisualizerFunctionCallback &function, pl::api::FunctionParameterCount parameterCount) {
|
||||
log::debug("Registered new pattern visualizer function: {}", name);
|
||||
impl::getVisualizers()[name] = impl::Visualizer { parameterCount, function };
|
||||
}
|
||||
|
||||
void addInlineVisualizer(const std::string &name, const impl::VisualizerFunctionCallback &function, u32 parameterCount) {
|
||||
void addInlineVisualizer(const std::string &name, const impl::VisualizerFunctionCallback &function, pl::api::FunctionParameterCount parameterCount) {
|
||||
log::debug("Registered new inline pattern visualizer function: {}", name);
|
||||
impl::getInlineVisualizers()[name] = impl::Visualizer { parameterCount, function };
|
||||
}
|
||||
|
@ -60,9 +60,11 @@ namespace hex::plugin::builtin {
|
||||
}
|
||||
|
||||
void registerPatternLanguageInlineVisualizers() {
|
||||
ContentRegistry::PatternLanguage::addInlineVisualizer("color", drawColorInlineVisualizer, 4);
|
||||
ContentRegistry::PatternLanguage::addInlineVisualizer("gauge", drawGaugeInlineVisualizer, 1);
|
||||
ContentRegistry::PatternLanguage::addInlineVisualizer("button", drawButtonInlineVisualizer, 1);
|
||||
using ParamCount = pl::api::FunctionParameterCount;
|
||||
|
||||
ContentRegistry::PatternLanguage::addInlineVisualizer("color", drawColorInlineVisualizer, ParamCount::exactly(4));
|
||||
ContentRegistry::PatternLanguage::addInlineVisualizer("gauge", drawGaugeInlineVisualizer, ParamCount::exactly(1));
|
||||
ContentRegistry::PatternLanguage::addInlineVisualizer("button", drawButtonInlineVisualizer, ParamCount::exactly(1));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -722,17 +722,19 @@ namespace hex::plugin::builtin {
|
||||
}
|
||||
|
||||
void registerPatternLanguageVisualizers() {
|
||||
ContentRegistry::PatternLanguage::addVisualizer("line_plot", drawLinePlotVisualizer, 1);
|
||||
ContentRegistry::PatternLanguage::addVisualizer("scatter_plot", drawScatterPlotVisualizer, 2);
|
||||
ContentRegistry::PatternLanguage::addVisualizer("image", drawImageVisualizer, 1);
|
||||
ContentRegistry::PatternLanguage::addVisualizer("bitmap", drawBitmapVisualizer, 3);
|
||||
ContentRegistry::PatternLanguage::addVisualizer("disassembler", drawDisassemblyVisualizer, 4);
|
||||
ContentRegistry::PatternLanguage::addVisualizer("3d", draw3DVisualizer, 2);
|
||||
ContentRegistry::PatternLanguage::addVisualizer("sound", drawSoundVisualizer, 3);
|
||||
ContentRegistry::PatternLanguage::addVisualizer("chunk_entropy", drawChunkBasedEntropyVisualizer, 2);
|
||||
ContentRegistry::PatternLanguage::addVisualizer("hex_viewer", drawHexVisualizer, 1);
|
||||
ContentRegistry::PatternLanguage::addVisualizer("coordinates", drawCoordinateVisualizer, 2);
|
||||
ContentRegistry::PatternLanguage::addVisualizer("timestamp", drawTimestampVisualizer, 1);
|
||||
using ParamCount = pl::api::FunctionParameterCount;
|
||||
|
||||
ContentRegistry::PatternLanguage::addVisualizer("line_plot", drawLinePlotVisualizer, ParamCount::exactly(1));
|
||||
ContentRegistry::PatternLanguage::addVisualizer("scatter_plot", drawScatterPlotVisualizer, ParamCount::exactly(2));
|
||||
ContentRegistry::PatternLanguage::addVisualizer("image", drawImageVisualizer, ParamCount::exactly(1));
|
||||
ContentRegistry::PatternLanguage::addVisualizer("bitmap", drawBitmapVisualizer, ParamCount::exactly(3));
|
||||
ContentRegistry::PatternLanguage::addVisualizer("disassembler", drawDisassemblyVisualizer, ParamCount::exactly(4));
|
||||
ContentRegistry::PatternLanguage::addVisualizer("3d", draw3DVisualizer, ParamCount::exactly(2));
|
||||
ContentRegistry::PatternLanguage::addVisualizer("sound", drawSoundVisualizer, ParamCount::exactly(3));
|
||||
ContentRegistry::PatternLanguage::addVisualizer("chunk_entropy", drawChunkBasedEntropyVisualizer, ParamCount::exactly(2));
|
||||
ContentRegistry::PatternLanguage::addVisualizer("hex_viewer", drawHexVisualizer, ParamCount::exactly(1));
|
||||
ContentRegistry::PatternLanguage::addVisualizer("coordinates", drawCoordinateVisualizer, ParamCount::exactly(2));
|
||||
ContentRegistry::PatternLanguage::addVisualizer("timestamp", drawTimestampVisualizer, ParamCount::exactly(1));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -235,15 +235,18 @@ namespace hex::plugin::builtin::ui {
|
||||
|
||||
if (auto entry = visualizers.find(visualizerName); entry != visualizers.end()) {
|
||||
const auto &[name, visualizer] = *entry;
|
||||
if (visualizer.parameterCount != arguments.size() - 1) {
|
||||
ImGui::TextUnformatted("hex.builtin.pattern_drawer.visualizer.invalid_parameter_count"_lang);
|
||||
} else {
|
||||
|
||||
auto paramCount = arguments.size() - 1;
|
||||
auto [minParams, maxParams] = visualizer.parameterCount;
|
||||
|
||||
if (paramCount >= minParams && paramCount <= maxParams) {
|
||||
try {
|
||||
visualizer.callback(pattern, iterable, reset, { arguments.begin() + 1, arguments.end() });
|
||||
} catch (std::exception &e) {
|
||||
this->m_lastVisualizerError = e.what();
|
||||
}
|
||||
|
||||
} else {
|
||||
ImGui::TextUnformatted("hex.builtin.pattern_drawer.visualizer.invalid_parameter_count"_lang);
|
||||
}
|
||||
} else {
|
||||
ImGui::TextUnformatted("hex.builtin.pattern_drawer.visualizer.unknown"_lang);
|
||||
|
Loading…
Reference in New Issue
Block a user