diff --git a/lib/external/imgui/include/imconfig.h b/lib/external/imgui/include/imconfig.h index 9039755b8..4dc2d6bb3 100644 --- a/lib/external/imgui/include/imconfig.h +++ b/lib/external/imgui/include/imconfig.h @@ -126,3 +126,7 @@ namespace ImGui void MyFunction(const char* name, const MyMatrix44& v); } */ + + +// IMPLOT CONFIG +#define IMPLOT_CUSTOM_NUMERIC_TYPES (ImS8)(ImU8)(ImS16)(ImU16)(ImS32)(ImU32)(ImS64)(ImU64)(float)(double)(long double) \ No newline at end of file diff --git a/main/gui/source/init/tasks.cpp b/main/gui/source/init/tasks.cpp index 3dea2e505..35e222d61 100644 --- a/main/gui/source/init/tasks.cpp +++ b/main/gui/source/init/tasks.cpp @@ -597,7 +597,7 @@ namespace hex::init { void runExitTasks() { for (const auto &[name, task, async] : init::getExitTasks()) { bool result = task(); - log::info("Exit task '{0}' finished {1}", result ? "successfully" : "unsuccessfully"); + log::info("Exit task '{0}' finished {1}", name, result ? "successfully" : "unsuccessfully"); } } diff --git a/plugins/builtin/romfs/lang/en_US.json b/plugins/builtin/romfs/lang/en_US.json index bd62ba42b..365e460c6 100644 --- a/plugins/builtin/romfs/lang/en_US.json +++ b/plugins/builtin/romfs/lang/en_US.json @@ -639,6 +639,7 @@ "hex.builtin.tools.format.programmer": "Programmer", "hex.builtin.tools.format.scientific": "Scientific", "hex.builtin.tools.format.standard": "Standard", + "hex.builtin.tools.graphing": "Graphing Calculator", "hex.builtin.tools.history": "History", "hex.builtin.tools.ieee754": "IEEE 754 Floating Point Encoder and Decoder", "hex.builtin.tools.ieee754.clear": "Clear", diff --git a/plugins/builtin/source/content/tools_entries.cpp b/plugins/builtin/source/content/tools_entries.cpp index 726f11574..324623453 100644 --- a/plugins/builtin/source/content/tools_entries.cpp +++ b/plugins/builtin/source/content/tools_entries.cpp @@ -19,6 +19,8 @@ #include #include +#include + #include #include #include @@ -442,6 +444,51 @@ namespace hex::plugin::builtin { } } + void drawGraphingCalculator() { + static std::array x, y; + static std::string mathInput; + static ImPlotRect limits; + static double prevPos = 0; + static long double stepSize = 0.1; + + if (ImPlot::BeginPlot("Function", ImVec2(-1, 0), ImPlotFlags_NoTitle | ImPlotFlags_NoMenus | ImPlotFlags_NoBoxSelect | ImPlotFlags_NoMouseText | ImPlotFlags_NoFrame)) { + ImPlot::SetupAxesLimits(-10, 10, -5, 5, ImPlotCond_Once); + + limits = ImPlot::GetPlotLimits(ImAxis_X1, ImAxis_Y1); + + ImPlot::PlotLine("f(x)", x.data(), y.data(), x.size()); + ImPlot::EndPlot(); + } + + ImGui::PushItemWidth(-1); + ImGui::InputTextIcon("##input", ICON_VS_SYMBOL_OPERATOR, mathInput, ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll); + ImGui::PopItemWidth(); + + if ((prevPos != limits.X.Min && (ImGui::IsMouseReleased(ImGuiMouseButton_Left) || ImGui::GetIO().MouseWheel != 0)) || (ImGui::IsItemFocused() && ImGui::IsKeyPressed(ImGuiKey_Enter))) { + MathEvaluator evaluator; + + evaluator.registerStandardVariables(); + evaluator.registerStandardFunctions(); + + stepSize = (limits.X.Size()) / x.size(); + + for (u32 i = 0; i < x.size(); i++) { + evaluator.setVariable("x", limits.X.Min + i * stepSize); + x[i] = limits.X.Min + i * stepSize; + y[i] = evaluator.evaluate(mathInput).value_or(0); + + if (y[i] < limits.Y.Min) + limits.Y.Min = y[i]; + if (y[i] > limits.Y.Max) + limits.X.Max = y[i]; + } + + limits.X.Max = limits.X.Min + x.size() * stepSize; + prevPos = limits.X.Min; + } + + } + void drawBaseConverter() { static std::array buffers; @@ -2148,6 +2195,7 @@ namespace hex::plugin::builtin { ContentRegistry::Tools::add("hex.builtin.tools.regex_replacer", drawRegexReplacer); ContentRegistry::Tools::add("hex.builtin.tools.color", drawColorPicker); ContentRegistry::Tools::add("hex.builtin.tools.calc", drawMathEvaluator); + ContentRegistry::Tools::add("hex.builtin.tools.graphing", drawGraphingCalculator); ContentRegistry::Tools::add("hex.builtin.tools.base_converter", drawBaseConverter); ContentRegistry::Tools::add("hex.builtin.tools.byte_swapper", drawByteSwapper); ContentRegistry::Tools::add("hex.builtin.tools.permissions", drawPermissionsCalculator);