2021-08-29 14:18:45 +02:00
|
|
|
|
#include <hex/api/content_registry.hpp>
|
2021-09-21 02:29:54 +02:00
|
|
|
|
#include <hex/api/imhex_api.hpp>
|
2021-01-22 18:01:39 +01:00
|
|
|
|
|
2023-03-23 11:23:07 +01:00
|
|
|
|
#include <hex/helpers/http_requests.hpp>
|
2021-08-29 22:15:18 +02:00
|
|
|
|
#include <hex/helpers/utils.hpp>
|
|
|
|
|
#include <hex/helpers/fmt.hpp>
|
2021-09-22 17:56:06 +02:00
|
|
|
|
#include <hex/helpers/literals.hpp>
|
2022-03-04 11:36:37 +01:00
|
|
|
|
#include <hex/helpers/fs.hpp>
|
2022-02-01 18:09:40 +01:00
|
|
|
|
#include <hex/api/localization.hpp>
|
|
|
|
|
|
|
|
|
|
#include <hex/ui/view.hpp>
|
2021-08-28 00:45:59 +02:00
|
|
|
|
|
2021-09-22 17:56:06 +02:00
|
|
|
|
#include <algorithm>
|
2021-08-28 00:45:59 +02:00
|
|
|
|
#include <chrono>
|
2021-09-22 17:56:06 +02:00
|
|
|
|
#include <random>
|
|
|
|
|
#include <regex>
|
2021-01-22 18:01:39 +01:00
|
|
|
|
|
|
|
|
|
#include <llvm/Demangle/Demangle.h>
|
2022-09-07 23:11:24 +02:00
|
|
|
|
#include <content/helpers/math_evaluator.hpp>
|
2021-01-22 18:01:39 +01:00
|
|
|
|
|
2021-08-29 14:18:45 +02:00
|
|
|
|
#include <imgui.h>
|
2023-11-11 00:54:16 +01:00
|
|
|
|
#include <implot.h>
|
|
|
|
|
|
2022-02-01 18:09:40 +01:00
|
|
|
|
#include <hex/ui/imgui_imhex_extensions.h>
|
2023-05-19 21:18:38 +02:00
|
|
|
|
#include <content/popups/popup_notification.hpp>
|
2021-08-29 14:18:45 +02:00
|
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
|
|
2023-03-12 18:27:29 +01:00
|
|
|
|
#include <wolv/io/file.hpp>
|
|
|
|
|
#include <wolv/utils/guards.hpp>
|
2023-10-22 00:46:45 +02:00
|
|
|
|
#include <wolv/net/socket_client.hpp>
|
|
|
|
|
#include <wolv/net/socket_server.hpp>
|
|
|
|
|
|
2021-01-22 18:01:39 +01:00
|
|
|
|
namespace hex::plugin::builtin {
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
2021-08-28 16:02:53 +02:00
|
|
|
|
using namespace std::literals::string_literals;
|
2021-08-28 00:45:59 +02:00
|
|
|
|
using namespace std::literals::chrono_literals;
|
2021-09-22 17:56:06 +02:00
|
|
|
|
using namespace hex::literals;
|
2021-08-28 00:45:59 +02:00
|
|
|
|
|
2021-01-22 18:01:39 +01:00
|
|
|
|
void drawDemangler() {
|
2022-08-09 13:51:03 +02:00
|
|
|
|
static std::string mangledName, demangledName;
|
2021-01-22 18:01:39 +01:00
|
|
|
|
|
2022-08-09 13:51:03 +02:00
|
|
|
|
if (ImGui::InputTextWithHint("hex.builtin.tools.demangler.mangled"_lang, "Itanium, MSVC, Dlang & Rust", mangledName)) {
|
|
|
|
|
demangledName = llvm::demangle(mangledName);
|
|
|
|
|
|
|
|
|
|
if (demangledName == mangledName) {
|
|
|
|
|
demangledName = "???";
|
|
|
|
|
}
|
2021-01-22 18:01:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-09 13:51:03 +02:00
|
|
|
|
ImGui::Header("hex.builtin.tools.demangler.demangled"_lang);
|
|
|
|
|
if (ImGui::BeginChild("demangled", ImVec2(0, 200_scaled), true)) {
|
2023-08-13 21:51:05 +02:00
|
|
|
|
ImGui::TextFormattedWrappedSelectable("{}", demangledName);
|
2022-08-09 13:51:03 +02:00
|
|
|
|
}
|
|
|
|
|
ImGui::EndChild();
|
2021-01-22 18:01:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void drawASCIITable() {
|
|
|
|
|
static bool asciiTableShowOctal = false;
|
|
|
|
|
|
|
|
|
|
ImGui::BeginTable("##asciitable", 4);
|
|
|
|
|
ImGui::TableSetupColumn("");
|
|
|
|
|
ImGui::TableSetupColumn("");
|
|
|
|
|
ImGui::TableSetupColumn("");
|
|
|
|
|
ImGui::TableSetupColumn("");
|
|
|
|
|
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
|
|
|
|
|
for (u8 tablePart = 0; tablePart < 4; tablePart++) {
|
|
|
|
|
ImGui::BeginTable("##asciitablepart", asciiTableShowOctal ? 4 : 3, ImGuiTableFlags_BordersInnerV | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_RowBg);
|
|
|
|
|
ImGui::TableSetupColumn("dec");
|
|
|
|
|
if (asciiTableShowOctal)
|
|
|
|
|
ImGui::TableSetupColumn("oct");
|
|
|
|
|
ImGui::TableSetupColumn("hex");
|
|
|
|
|
ImGui::TableSetupColumn("char");
|
|
|
|
|
|
|
|
|
|
ImGui::TableHeadersRow();
|
|
|
|
|
|
|
|
|
|
for (u8 i = 0; i < 0x80 / 4; i++) {
|
2022-09-29 20:46:50 +02:00
|
|
|
|
ImGui::TableNextRow();
|
2021-01-22 18:01:39 +01:00
|
|
|
|
|
|
|
|
|
ImGui::TableNextColumn();
|
2021-12-31 01:10:06 +01:00
|
|
|
|
ImGui::TextFormatted("{0:03d}", i + 32 * tablePart);
|
2021-01-22 18:01:39 +01:00
|
|
|
|
|
|
|
|
|
if (asciiTableShowOctal) {
|
|
|
|
|
ImGui::TableNextColumn();
|
2021-12-31 01:10:06 +01:00
|
|
|
|
ImGui::TextFormatted("0o{0:03o}", i + 32 * tablePart);
|
2021-01-22 18:01:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::TableNextColumn();
|
2021-12-31 01:10:06 +01:00
|
|
|
|
ImGui::TextFormatted("0x{0:02X}", i + 32 * tablePart);
|
2021-01-22 18:01:39 +01:00
|
|
|
|
|
|
|
|
|
ImGui::TableNextColumn();
|
2021-12-31 01:10:06 +01:00
|
|
|
|
ImGui::TextFormatted("{0}", hex::makePrintable(i + 32 * tablePart));
|
2021-01-22 18:01:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::EndTable();
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
}
|
|
|
|
|
ImGui::EndTable();
|
|
|
|
|
|
2021-02-11 23:09:45 +01:00
|
|
|
|
ImGui::Checkbox("hex.builtin.tools.ascii_table.octal"_lang, &asciiTableShowOctal);
|
2021-01-22 18:01:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void drawRegexReplacer() {
|
2022-02-01 22:09:44 +01:00
|
|
|
|
static auto regexInput = [] { std::string s; s.reserve(0xFFF); return s; }();
|
|
|
|
|
static auto regexPattern = [] { std::string s; s.reserve(0xFFF); return s; }();
|
2022-01-24 20:53:17 +01:00
|
|
|
|
static auto replacePattern = [] { std::string s; s.reserve(0xFFF); return s; }();
|
2022-02-01 22:09:44 +01:00
|
|
|
|
static auto regexOutput = [] { std::string s; s.reserve(0xFFF); return s; }();
|
2021-01-22 18:01:39 +01:00
|
|
|
|
|
2023-11-11 22:43:27 +01:00
|
|
|
|
ImGui::PushItemWidth(-150_scaled);
|
2022-09-19 11:29:51 +02:00
|
|
|
|
bool changed1 = ImGui::InputTextIcon("hex.builtin.tools.regex_replacer.pattern"_lang, ICON_VS_REGEX, regexPattern);
|
|
|
|
|
bool changed2 = ImGui::InputTextIcon("hex.builtin.tools.regex_replacer.replace"_lang, ICON_VS_REGEX, replacePattern);
|
2022-03-03 09:24:09 +01:00
|
|
|
|
bool changed3 = ImGui::InputTextMultiline("hex.builtin.tools.regex_replacer.input"_lang, regexInput, ImVec2(0, 0));
|
2021-01-22 18:01:39 +01:00
|
|
|
|
|
2021-09-20 23:50:37 +02:00
|
|
|
|
if (changed1 || changed2 || changed3) {
|
2021-01-22 18:01:39 +01:00
|
|
|
|
try {
|
|
|
|
|
regexOutput = std::regex_replace(regexInput.data(), std::regex(regexPattern.data()), replacePattern.data());
|
2022-01-24 20:53:17 +01:00
|
|
|
|
} catch (std::regex_error &) { }
|
2021-01-22 18:01:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-20 23:50:37 +02:00
|
|
|
|
ImGui::InputTextMultiline("hex.builtin.tools.regex_replacer.output"_lang, regexOutput.data(), regexOutput.size(), ImVec2(0, 0), ImGuiInputTextFlags_ReadOnly);
|
2023-11-11 22:43:27 +01:00
|
|
|
|
|
|
|
|
|
ImGui::PopItemWidth();
|
2021-01-22 18:01:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void drawColorPicker() {
|
|
|
|
|
static std::array<float, 4> pickedColor = { 0 };
|
2023-11-11 20:56:50 +01:00
|
|
|
|
static std::string rgba8;
|
|
|
|
|
|
|
|
|
|
struct BitValue {
|
|
|
|
|
int bits;
|
|
|
|
|
float color;
|
|
|
|
|
float saturationMultiplier;
|
|
|
|
|
char name;
|
|
|
|
|
u8 index;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static std::array bitValues = {
|
|
|
|
|
BitValue{ 8, 0.00F, 1.0F, 'R', 0 },
|
|
|
|
|
BitValue{ 8, 0.33F, 1.0F, 'G', 1 },
|
|
|
|
|
BitValue{ 8, 0.66F, 1.0F, 'B', 2 },
|
|
|
|
|
BitValue{ 8, 0.00F, 0.0F, 'A', 3 }
|
|
|
|
|
};
|
|
|
|
|
|
2023-11-11 22:43:27 +01:00
|
|
|
|
if (ImGui::BeginTable("##color_picker_table", 3, ImGuiTableFlags_BordersInnerV)) {
|
|
|
|
|
ImGui::TableSetupColumn(" Color Picker", ImGuiTableColumnFlags_WidthFixed | ImGuiTableColumnFlags_NoResize, 300_scaled);
|
|
|
|
|
ImGui::TableSetupColumn(" Components", ImGuiTableColumnFlags_WidthFixed | ImGuiTableColumnFlags_NoResize, 105_scaled);
|
|
|
|
|
ImGui::TableSetupColumn(" Formats", ImGuiTableColumnFlags_WidthStretch | ImGuiTableColumnFlags_NoResize);
|
|
|
|
|
|
|
|
|
|
ImGui::TableHeadersRow();
|
2023-11-11 20:56:50 +01:00
|
|
|
|
|
|
|
|
|
ImGui::TableNextRow();
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
|
|
|
|
|
// Draw main color picker widget
|
|
|
|
|
ImVec2 startCursor, endCursor;
|
|
|
|
|
{
|
|
|
|
|
ImGui::PushItemWidth(-1);
|
|
|
|
|
startCursor = ImGui::GetCursorPos();
|
2023-11-11 22:43:27 +01:00
|
|
|
|
ImGui::ColorPicker4("hex.builtin.tools.color"_lang, pickedColor.data(), ImGuiColorEditFlags_Uint8 | ImGuiColorEditFlags_AlphaBar | ImGuiColorEditFlags_NoSidePreview | ImGuiColorEditFlags_NoSmallPreview | ImGuiColorEditFlags_DisplayRGB | ImGuiColorEditFlags_DisplayHSV | ImGuiColorEditFlags_DisplayHex);
|
2023-11-11 20:56:50 +01:00
|
|
|
|
endCursor = ImGui::GetCursorPos();
|
|
|
|
|
ImGui::ColorButton("##color_button", ImColor(pickedColor[0], pickedColor[1], pickedColor[2], pickedColor[3]), ImGuiColorEditFlags_NoPicker | ImGuiColorEditFlags_NoDragDrop | ImGuiColorEditFlags_AlphaPreviewHalf, ImVec2(300_scaled, 0));
|
|
|
|
|
ImGui::PopItemWidth();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
|
|
|
|
|
const auto colorName = hex::format("{}{}{}{}", bitValues[0].name, bitValues[1].name, bitValues[2].name, bitValues[3].name);
|
|
|
|
|
|
|
|
|
|
// Draw color bit count sliders
|
|
|
|
|
{
|
2023-11-11 22:43:27 +01:00
|
|
|
|
ImGui::Indent();
|
|
|
|
|
|
2023-11-11 20:56:50 +01:00
|
|
|
|
static auto drawBitsSlider = [&](BitValue *bitValue) {
|
|
|
|
|
// Change slider color
|
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_FrameBg, ImColor::HSV(bitValue->color, 0.5f * bitValue->saturationMultiplier, 0.5f).Value);
|
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, ImColor::HSV(bitValue->color, 0.6f * bitValue->saturationMultiplier, 0.5f).Value);
|
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_FrameBgActive, ImColor::HSV(bitValue->color, 0.7f * bitValue->saturationMultiplier, 0.5f).Value);
|
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_SliderGrab, ImColor::HSV(bitValue->color, 0.9f * bitValue->saturationMultiplier, 0.9f).Value);
|
|
|
|
|
|
|
|
|
|
// Draw slider
|
|
|
|
|
ImGui::PushID(&bitValue->bits);
|
|
|
|
|
auto format = hex::format("%d\n{}", bitValue->name);
|
|
|
|
|
ImGui::VSliderInt("##slider", ImVec2(18_scaled, (endCursor - startCursor).y - 3_scaled), &bitValue->bits, 0, 16, format.c_str(), ImGuiSliderFlags_AlwaysClamp);
|
|
|
|
|
ImGui::PopID();
|
|
|
|
|
|
|
|
|
|
ImGui::PopStyleColor(4);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Force sliders closer together
|
|
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(4, 4));
|
|
|
|
|
|
|
|
|
|
// Draw a slider for each color component
|
|
|
|
|
for (u32 index = 0; auto &bitValue : bitValues) {
|
|
|
|
|
// Draw slider
|
|
|
|
|
drawBitsSlider(&bitValue);
|
|
|
|
|
|
|
|
|
|
// Configure drag and drop source and target
|
|
|
|
|
if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_None)) {
|
|
|
|
|
// Set the current slider index as the payload
|
|
|
|
|
ImGui::SetDragDropPayload("BIT_VALUE", &index, sizeof(u32));
|
|
|
|
|
|
|
|
|
|
// Draw a color button to show the color being dragged
|
|
|
|
|
ImGui::ColorButton("##color_button", ImColor::HSV(bitValue.color, 0.5f * bitValue.saturationMultiplier, 0.5f).Value);
|
|
|
|
|
|
|
|
|
|
ImGui::EndDragDropSource();
|
|
|
|
|
}
|
|
|
|
|
if (ImGui::BeginDragDropTarget()) {
|
|
|
|
|
if (const ImGuiPayload *payload = ImGui::AcceptDragDropPayload("BIT_VALUE"); payload != nullptr) {
|
|
|
|
|
auto otherIndex = *static_cast<const u32 *>(payload->Data);
|
|
|
|
|
|
|
|
|
|
// Swap the currently hovered slider with the one being dragged
|
|
|
|
|
std::swap(bitValues[index], bitValues[otherIndex]);
|
|
|
|
|
}
|
|
|
|
|
ImGui::EndDragDropTarget();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
|
|
|
|
|
index += 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::NewLine();
|
|
|
|
|
|
|
|
|
|
// Draw color name below sliders
|
|
|
|
|
ImGui::TextFormatted("{}", colorName);
|
|
|
|
|
|
|
|
|
|
ImGui::PopStyleVar();
|
2023-11-11 22:43:27 +01:00
|
|
|
|
|
|
|
|
|
ImGui::Unindent();
|
2023-11-11 20:56:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
|
|
|
|
|
// Draw encoded color values
|
|
|
|
|
{
|
|
|
|
|
// Calculate int and float representations of the selected color
|
|
|
|
|
std::array<u32, 4> intColor = {};
|
|
|
|
|
std::array<float, 4> floatColor = {};
|
|
|
|
|
for (u32 index = 0; auto &bitValue : bitValues) {
|
|
|
|
|
intColor[index] = u64(std::round(static_cast<long double>(pickedColor[bitValue.index]) * std::numeric_limits<u32>::max())) >> (32 - bitValue.bits);
|
|
|
|
|
floatColor[index] = pickedColor[bitValue.index];
|
|
|
|
|
|
|
|
|
|
index += 1;
|
|
|
|
|
}
|
2021-01-22 18:01:39 +01:00
|
|
|
|
|
2023-11-11 20:56:50 +01:00
|
|
|
|
// Draw a table with the color values
|
2023-11-11 22:43:27 +01:00
|
|
|
|
if (ImGui::BeginTable("##value_table", 2, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_NoHostExtendX , ImVec2(0, 0))) {
|
|
|
|
|
ImGui::TableSetupColumn("name", ImGuiTableColumnFlags_WidthFixed);
|
|
|
|
|
ImGui::TableSetupColumn("value", ImGuiTableColumnFlags_WidthStretch);
|
|
|
|
|
|
2023-11-11 20:56:50 +01:00
|
|
|
|
const static auto drawValue = [](const char *name, auto formatter) {
|
|
|
|
|
ImGui::TableNextRow();
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
|
|
|
|
|
// Draw name of the formatting
|
|
|
|
|
ImGui::TextUnformatted(name);
|
|
|
|
|
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
|
|
|
|
|
// Draw value
|
|
|
|
|
ImGui::PushID(name);
|
|
|
|
|
ImGui::TextFormattedSelectable("{}", formatter());
|
|
|
|
|
ImGui::PopID();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const u32 bitCount = bitValues[0].bits + bitValues[1].bits + bitValues[2].bits + bitValues[3].bits;
|
|
|
|
|
|
|
|
|
|
// Draw the different representations
|
|
|
|
|
|
|
|
|
|
drawValue("HEX", [&] {
|
|
|
|
|
u64 hexValue = 0;
|
|
|
|
|
for (u32 index = 0; auto &bitValue : bitValues) {
|
|
|
|
|
hexValue <<= bitValue.bits;
|
|
|
|
|
hexValue |= u64(intColor[index]) & hex::bitmask(bitValue.bits);
|
|
|
|
|
index += 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return hex::format("#{0:0{1}X}", hexValue, bitCount / 4);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
drawValue(colorName.c_str(), [&] {
|
|
|
|
|
return hex::format("{}({}, {}, {}, {})", colorName, intColor[0], intColor[1], intColor[2], intColor[3]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
drawValue("Vector4f", [&] {
|
|
|
|
|
return hex::format("{{ {:.2}F, {:.2}F, {:.2}F, {:.2}F }}", floatColor[0], floatColor[1], floatColor[2], floatColor[3]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
drawValue("Percentage", [&] {
|
|
|
|
|
return hex::format("{{ {}%, {}%, {}%, {}% }}", u32(floatColor[0] * 100), u32(floatColor[1] * 100), u32(floatColor[2] * 100), u32(floatColor[3] * 100));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ImGui::EndTable();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::EndTable();
|
|
|
|
|
}
|
2021-01-22 18:01:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void drawMathEvaluator() {
|
|
|
|
|
static std::vector<long double> mathHistory;
|
|
|
|
|
static std::string lastMathError;
|
2022-03-03 09:27:27 +01:00
|
|
|
|
static std::string mathInput;
|
2021-08-28 18:15:20 +02:00
|
|
|
|
bool evaluate = false;
|
2021-01-22 18:01:39 +01:00
|
|
|
|
|
2022-05-27 20:42:07 +02:00
|
|
|
|
static MathEvaluator<long double> mathEvaluator = [&] {
|
|
|
|
|
MathEvaluator<long double> evaluator;
|
2021-01-22 18:01:39 +01:00
|
|
|
|
|
|
|
|
|
evaluator.registerStandardVariables();
|
|
|
|
|
evaluator.registerStandardFunctions();
|
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
|
evaluator.setFunction(
|
|
|
|
|
"clear", [&](auto args) -> std::optional<long double> {
|
2022-03-27 00:01:28 +01:00
|
|
|
|
hex::unused(args);
|
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
|
mathHistory.clear();
|
|
|
|
|
lastMathError.clear();
|
|
|
|
|
mathEvaluator.getVariables().clear();
|
|
|
|
|
mathEvaluator.registerStandardVariables();
|
|
|
|
|
mathInput.clear();
|
2021-01-22 18:01:39 +01:00
|
|
|
|
|
2022-01-30 12:43:43 +01:00
|
|
|
|
return std::nullopt;
|
2022-01-24 20:53:17 +01:00
|
|
|
|
},
|
|
|
|
|
0,
|
|
|
|
|
0);
|
2021-01-22 18:01:39 +01:00
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
|
evaluator.setFunction(
|
|
|
|
|
"read", [](auto args) -> std::optional<long double> {
|
|
|
|
|
u8 value = 0;
|
2021-01-22 18:01:39 +01:00
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
|
auto provider = ImHexApi::Provider::get();
|
|
|
|
|
if (!ImHexApi::Provider::isValid() || !provider->isReadable() || args[0] >= provider->getActualSize())
|
2022-01-30 12:43:43 +01:00
|
|
|
|
return std::nullopt;
|
2021-01-22 18:01:39 +01:00
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
|
provider->read(args[0], &value, sizeof(u8));
|
2021-01-22 18:01:39 +01:00
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
|
return value;
|
|
|
|
|
},
|
|
|
|
|
1,
|
|
|
|
|
1);
|
2021-01-22 18:01:39 +01:00
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
|
evaluator.setFunction(
|
|
|
|
|
"write", [](auto args) -> std::optional<long double> {
|
|
|
|
|
auto provider = ImHexApi::Provider::get();
|
|
|
|
|
if (!ImHexApi::Provider::isValid() || !provider->isWritable() || args[0] >= provider->getActualSize())
|
2022-01-30 12:43:43 +01:00
|
|
|
|
return std::nullopt;
|
2021-01-22 18:01:39 +01:00
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
|
if (args[1] > 0xFF)
|
2022-01-30 12:43:43 +01:00
|
|
|
|
return std::nullopt;
|
2021-01-22 18:01:39 +01:00
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
|
u8 value = args[1];
|
|
|
|
|
provider->write(args[0], &value, sizeof(u8));
|
2021-01-22 18:01:39 +01:00
|
|
|
|
|
2022-01-30 12:43:43 +01:00
|
|
|
|
return std::nullopt;
|
2022-01-24 20:53:17 +01:00
|
|
|
|
},
|
|
|
|
|
2,
|
|
|
|
|
2);
|
2021-01-22 18:01:39 +01:00
|
|
|
|
|
2022-03-27 00:01:28 +01:00
|
|
|
|
return evaluator;
|
2021-01-22 18:01:39 +01:00
|
|
|
|
}();
|
|
|
|
|
|
2022-03-27 00:01:28 +01:00
|
|
|
|
enum class MathDisplayType : u8 {
|
2022-01-24 20:53:17 +01:00
|
|
|
|
Standard,
|
|
|
|
|
Scientific,
|
|
|
|
|
Engineering,
|
|
|
|
|
Programmer
|
2022-03-27 00:01:28 +01:00
|
|
|
|
} mathDisplayType = MathDisplayType::Standard;
|
|
|
|
|
|
2021-01-22 18:01:39 +01:00
|
|
|
|
if (ImGui::BeginTabBar("##mathFormatTabBar")) {
|
2021-02-11 23:09:45 +01:00
|
|
|
|
if (ImGui::BeginTabItem("hex.builtin.tools.format.standard"_lang)) {
|
2021-01-22 18:01:39 +01:00
|
|
|
|
mathDisplayType = MathDisplayType::Standard;
|
|
|
|
|
ImGui::EndTabItem();
|
|
|
|
|
}
|
2021-02-11 23:09:45 +01:00
|
|
|
|
if (ImGui::BeginTabItem("hex.builtin.tools.format.scientific"_lang)) {
|
2021-01-22 18:01:39 +01:00
|
|
|
|
mathDisplayType = MathDisplayType::Scientific;
|
|
|
|
|
ImGui::EndTabItem();
|
|
|
|
|
}
|
2021-02-11 23:09:45 +01:00
|
|
|
|
if (ImGui::BeginTabItem("hex.builtin.tools.format.engineering"_lang)) {
|
2021-01-22 18:01:39 +01:00
|
|
|
|
mathDisplayType = MathDisplayType::Engineering;
|
|
|
|
|
ImGui::EndTabItem();
|
|
|
|
|
}
|
2021-02-11 23:09:45 +01:00
|
|
|
|
if (ImGui::BeginTabItem("hex.builtin.tools.format.programmer"_lang)) {
|
2021-01-22 18:01:39 +01:00
|
|
|
|
mathDisplayType = MathDisplayType::Programmer;
|
|
|
|
|
ImGui::EndTabItem();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::EndTabBar();
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-28 18:15:20 +02:00
|
|
|
|
if (ImGui::BeginTable("##mathWrapper", 3)) {
|
|
|
|
|
ImGui::TableSetupColumn("##keypad", ImGuiTableColumnFlags_WidthFixed | ImGuiTableColumnFlags_NoResize);
|
|
|
|
|
ImGui::TableSetupColumn("##results", ImGuiTableColumnFlags_WidthStretch, 0.666);
|
|
|
|
|
ImGui::TableSetupColumn("##variables", ImGuiTableColumnFlags_WidthStretch, 0.666);
|
2021-01-22 18:01:39 +01:00
|
|
|
|
|
|
|
|
|
ImGui::TableNextRow();
|
|
|
|
|
ImGui::TableNextColumn();
|
2021-08-28 18:15:20 +02:00
|
|
|
|
|
|
|
|
|
auto buttonSize = ImVec2(3, 2) * ImGui::GetTextLineHeightWithSpacing();
|
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
|
if (ImGui::Button("Ans", buttonSize)) mathInput += "ans";
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::Button("Pi", buttonSize)) mathInput += "pi";
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::Button("e", buttonSize)) mathInput += "e";
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::Button("CE", buttonSize)) mathInput.clear();
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::Button(ICON_FA_BACKSPACE, buttonSize)) mathInput.clear();
|
2022-03-27 00:01:28 +01:00
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
|
ImGui::SameLine();
|
2021-08-28 18:15:20 +02:00
|
|
|
|
ImGui::NewLine();
|
2022-03-27 00:01:28 +01:00
|
|
|
|
|
2021-08-28 18:15:20 +02:00
|
|
|
|
switch (mathDisplayType) {
|
2022-02-01 22:09:44 +01:00
|
|
|
|
case MathDisplayType::Standard:
|
|
|
|
|
case MathDisplayType::Scientific:
|
|
|
|
|
case MathDisplayType::Engineering:
|
|
|
|
|
if (ImGui::Button("x²", buttonSize)) mathInput += "** 2";
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::Button("1/x", buttonSize)) mathInput += "1/";
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::Button("|x|", buttonSize)) mathInput += "abs";
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::Button("exp", buttonSize)) mathInput += "e ** ";
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::Button("%", buttonSize)) mathInput += "%";
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
break;
|
|
|
|
|
case MathDisplayType::Programmer:
|
|
|
|
|
if (ImGui::Button("<<", buttonSize)) mathInput += "<<";
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::Button(">>", buttonSize)) mathInput += ">>";
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::Button("&", buttonSize)) mathInput += "&";
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::Button("|", buttonSize)) mathInput += "|";
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::Button("^", buttonSize)) mathInput += "^";
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
break;
|
2021-08-28 18:15:20 +02:00
|
|
|
|
}
|
|
|
|
|
ImGui::NewLine();
|
2022-01-24 20:53:17 +01:00
|
|
|
|
if (ImGui::Button("sqrt", buttonSize)) mathInput += "sqrt";
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::Button("(", buttonSize)) mathInput += "(";
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::Button(")", buttonSize)) mathInput += ")";
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::Button("sign", buttonSize)) mathInput += "sign";
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::Button("÷", buttonSize)) mathInput += "/";
|
|
|
|
|
ImGui::SameLine();
|
2021-08-28 18:15:20 +02:00
|
|
|
|
ImGui::NewLine();
|
2022-01-24 20:53:17 +01:00
|
|
|
|
if (ImGui::Button("xª", buttonSize)) mathInput += "**";
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::Button("7", buttonSize)) mathInput += "7";
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::Button("8", buttonSize)) mathInput += "8";
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::Button("9", buttonSize)) mathInput += "9";
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::Button("×", buttonSize)) mathInput += "*";
|
|
|
|
|
ImGui::SameLine();
|
2021-08-28 18:15:20 +02:00
|
|
|
|
ImGui::NewLine();
|
2022-01-24 20:53:17 +01:00
|
|
|
|
if (ImGui::Button("log", buttonSize)) mathInput += "log";
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::Button("4", buttonSize)) mathInput += "4";
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::Button("5", buttonSize)) mathInput += "5";
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::Button("6", buttonSize)) mathInput += "6";
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::Button("-", buttonSize)) mathInput += "-";
|
|
|
|
|
ImGui::SameLine();
|
2021-08-28 18:15:20 +02:00
|
|
|
|
ImGui::NewLine();
|
2022-01-24 20:53:17 +01:00
|
|
|
|
if (ImGui::Button("ln", buttonSize)) mathInput += "ln";
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::Button("1", buttonSize)) mathInput += "1";
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::Button("2", buttonSize)) mathInput += "2";
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::Button("3", buttonSize)) mathInput += "3";
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::Button("+", buttonSize)) mathInput += "+";
|
|
|
|
|
ImGui::SameLine();
|
2021-08-28 18:15:20 +02:00
|
|
|
|
ImGui::NewLine();
|
2022-01-24 20:53:17 +01:00
|
|
|
|
if (ImGui::Button("lb", buttonSize)) mathInput += "lb";
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::Button("x=", buttonSize)) mathInput += "=";
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::Button("0", buttonSize)) mathInput += "0";
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::Button(".", buttonSize)) mathInput += ".";
|
|
|
|
|
ImGui::SameLine();
|
2021-08-28 18:15:20 +02:00
|
|
|
|
|
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_Button, ImGui::GetCustomColorVec4(ImGuiCustomCol_DescButtonHovered));
|
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImGui::GetCustomColorVec4(ImGuiCustomCol_DescButton));
|
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImGui::GetCustomColorVec4(ImGuiCustomCol_DescButtonActive));
|
2022-01-24 20:53:17 +01:00
|
|
|
|
if (ImGui::Button("=", buttonSize)) evaluate = true;
|
|
|
|
|
ImGui::SameLine();
|
2021-08-28 18:15:20 +02:00
|
|
|
|
ImGui::PopStyleColor(3);
|
|
|
|
|
|
|
|
|
|
ImGui::NewLine();
|
|
|
|
|
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
|
|
|
|
|
if (ImGui::BeginTable("##mathHistory", 1, ImGuiTableFlags_ScrollY | ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg, ImVec2(0, 300))) {
|
2021-02-11 23:09:45 +01:00
|
|
|
|
ImGui::TableSetupColumn("hex.builtin.tools.history"_lang);
|
2023-11-12 00:10:16 +01:00
|
|
|
|
ImGui::TableSetupScrollFreeze(0, 1);
|
2021-01-22 18:01:39 +01:00
|
|
|
|
|
|
|
|
|
ImGuiListClipper clipper;
|
|
|
|
|
clipper.Begin(mathHistory.size());
|
|
|
|
|
|
|
|
|
|
ImGui::TableHeadersRow();
|
|
|
|
|
while (clipper.Step()) {
|
2022-03-27 00:01:28 +01:00
|
|
|
|
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
|
2021-01-22 18:01:39 +01:00
|
|
|
|
if (i == 0)
|
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_Text, ImU32(ImColor(0xA5, 0x45, 0x45)));
|
|
|
|
|
|
|
|
|
|
ImGui::TableNextRow();
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
|
|
|
|
|
switch (mathDisplayType) {
|
2022-02-01 22:09:44 +01:00
|
|
|
|
case MathDisplayType::Standard:
|
|
|
|
|
ImGui::TextFormatted("{0:.3Lf}", mathHistory[(mathHistory.size() - 1) - i]);
|
|
|
|
|
break;
|
|
|
|
|
case MathDisplayType::Scientific:
|
2022-08-05 09:36:04 +02:00
|
|
|
|
ImGui::TextFormatted("{0:.6Lg}", mathHistory[(mathHistory.size() - 1) - i]);
|
2022-02-01 22:09:44 +01:00
|
|
|
|
break;
|
|
|
|
|
case MathDisplayType::Engineering:
|
|
|
|
|
ImGui::TextFormatted("{0}", hex::toEngineeringString(mathHistory[(mathHistory.size() - 1) - i]).c_str());
|
|
|
|
|
break;
|
|
|
|
|
case MathDisplayType::Programmer:
|
|
|
|
|
ImGui::TextFormatted("0x{0:X} ({1})",
|
|
|
|
|
u64(mathHistory[(mathHistory.size() - 1) - i]),
|
|
|
|
|
u64(mathHistory[(mathHistory.size() - 1) - i]));
|
|
|
|
|
break;
|
2021-01-22 18:01:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (i == 0)
|
|
|
|
|
ImGui::PopStyleColor();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
clipper.End();
|
|
|
|
|
|
|
|
|
|
ImGui::EndTable();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::TableNextColumn();
|
2021-08-28 18:15:20 +02:00
|
|
|
|
if (ImGui::BeginTable("##mathVariables", 2, ImGuiTableFlags_ScrollY | ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg, ImVec2(0, 300))) {
|
2021-02-11 23:09:45 +01:00
|
|
|
|
ImGui::TableSetupColumn("hex.builtin.tools.name"_lang);
|
|
|
|
|
ImGui::TableSetupColumn("hex.builtin.tools.value"_lang);
|
2023-11-12 00:10:16 +01:00
|
|
|
|
ImGui::TableSetupScrollFreeze(0, 1);
|
2021-01-22 18:01:39 +01:00
|
|
|
|
|
|
|
|
|
ImGui::TableHeadersRow();
|
2022-10-02 14:18:56 +02:00
|
|
|
|
for (const auto &[name, variable] : mathEvaluator.getVariables()) {
|
|
|
|
|
const auto &[value, constant] = variable;
|
|
|
|
|
|
|
|
|
|
if (constant)
|
|
|
|
|
continue;
|
|
|
|
|
|
2021-01-22 18:01:39 +01:00
|
|
|
|
ImGui::TableNextRow();
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
ImGui::TextUnformatted(name.c_str());
|
|
|
|
|
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
switch (mathDisplayType) {
|
2022-02-01 22:09:44 +01:00
|
|
|
|
case MathDisplayType::Standard:
|
|
|
|
|
ImGui::TextFormatted("{0:.3Lf}", value);
|
|
|
|
|
break;
|
|
|
|
|
case MathDisplayType::Scientific:
|
2022-08-05 09:36:04 +02:00
|
|
|
|
ImGui::TextFormatted("{0:.6Lg}", value);
|
2022-02-01 22:09:44 +01:00
|
|
|
|
break;
|
|
|
|
|
case MathDisplayType::Engineering:
|
|
|
|
|
ImGui::TextFormatted("{}", hex::toEngineeringString(value));
|
|
|
|
|
break;
|
|
|
|
|
case MathDisplayType::Programmer:
|
|
|
|
|
ImGui::TextFormatted("0x{0:X} ({1})", u64(value), u64(value));
|
|
|
|
|
break;
|
2021-01-22 18:01:39 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::EndTable();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::EndTable();
|
|
|
|
|
}
|
2021-08-28 18:15:20 +02:00
|
|
|
|
|
2022-08-03 23:32:34 +02:00
|
|
|
|
ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x);
|
2022-09-19 11:29:51 +02:00
|
|
|
|
if (ImGui::InputTextIcon("##input", ICON_VS_SYMBOL_OPERATOR, mathInput, ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll)) {
|
2021-08-28 18:15:20 +02:00
|
|
|
|
ImGui::SetKeyboardFocusHere();
|
|
|
|
|
evaluate = true;
|
|
|
|
|
}
|
|
|
|
|
ImGui::PopItemWidth();
|
|
|
|
|
|
|
|
|
|
if (!lastMathError.empty())
|
2022-01-15 14:14:53 +01:00
|
|
|
|
ImGui::TextFormattedColored(ImColor(0xA00040FF), "hex.builtin.tools.error"_lang, lastMathError);
|
2021-08-28 18:15:20 +02:00
|
|
|
|
else
|
|
|
|
|
ImGui::NewLine();
|
|
|
|
|
|
|
|
|
|
if (evaluate) {
|
|
|
|
|
try {
|
2022-05-17 20:46:42 +02:00
|
|
|
|
auto result = mathEvaluator.evaluate(mathInput);
|
2022-10-02 14:18:56 +02:00
|
|
|
|
mathInput.clear();
|
2022-05-17 20:46:42 +02:00
|
|
|
|
if (result.has_value()) {
|
|
|
|
|
mathHistory.push_back(result.value());
|
|
|
|
|
lastMathError.clear();
|
|
|
|
|
}
|
2021-08-28 18:15:20 +02:00
|
|
|
|
} catch (std::invalid_argument &e) {
|
|
|
|
|
lastMathError = e.what();
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-01-22 18:01:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
2023-11-11 00:54:16 +01:00
|
|
|
|
void drawGraphingCalculator() {
|
|
|
|
|
static std::array<long double, 1000> 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);
|
2023-11-11 21:22:28 +01:00
|
|
|
|
ImGui::InputTextIcon("##graphing_math_input", ICON_VS_SYMBOL_OPERATOR, mathInput, ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll);
|
2023-11-11 00:54:16 +01:00
|
|
|
|
ImGui::PopItemWidth();
|
|
|
|
|
|
|
|
|
|
if ((prevPos != limits.X.Min && (ImGui::IsMouseReleased(ImGuiMouseButton_Left) || ImGui::GetIO().MouseWheel != 0)) || (ImGui::IsItemFocused() && ImGui::IsKeyPressed(ImGuiKey_Enter))) {
|
|
|
|
|
MathEvaluator<long double> evaluator;
|
|
|
|
|
|
2023-11-11 22:43:27 +01:00
|
|
|
|
y = {};
|
|
|
|
|
|
|
|
|
|
u32 i = 0;
|
|
|
|
|
evaluator.setFunction("y", [&](auto args) -> std::optional<long double> {
|
|
|
|
|
i32 index = i + args[0];
|
|
|
|
|
if (index < 0 || u32(index) >= y.size())
|
|
|
|
|
return 0;
|
|
|
|
|
else
|
|
|
|
|
return y[index];
|
|
|
|
|
}, 1, 1);
|
|
|
|
|
|
2023-11-11 00:54:16 +01:00
|
|
|
|
evaluator.registerStandardVariables();
|
|
|
|
|
evaluator.registerStandardFunctions();
|
|
|
|
|
|
|
|
|
|
stepSize = (limits.X.Size()) / x.size();
|
|
|
|
|
|
2023-11-11 22:43:27 +01:00
|
|
|
|
for (i = 0; i < x.size(); i++) {
|
2023-11-11 00:54:16 +01:00
|
|
|
|
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];
|
2023-11-11 22:43:27 +01:00
|
|
|
|
|
2023-11-11 00:54:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
limits.X.Max = limits.X.Min + x.size() * stepSize;
|
|
|
|
|
prevPos = limits.X.Min;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-05 00:17:56 +01:00
|
|
|
|
void drawBaseConverter() {
|
2022-09-19 11:29:51 +02:00
|
|
|
|
static std::array<std::string, 4> buffers;
|
2021-02-05 00:17:56 +01:00
|
|
|
|
|
|
|
|
|
static auto ConvertBases = [](u8 base) {
|
|
|
|
|
u64 number;
|
|
|
|
|
|
|
|
|
|
switch (base) {
|
2022-02-01 22:09:44 +01:00
|
|
|
|
case 16:
|
2022-09-19 11:29:51 +02:00
|
|
|
|
number = std::strtoull(buffers[1].c_str(), nullptr, base);
|
2022-02-01 22:09:44 +01:00
|
|
|
|
break;
|
|
|
|
|
case 10:
|
2022-09-19 11:29:51 +02:00
|
|
|
|
number = std::strtoull(buffers[0].c_str(), nullptr, base);
|
2022-02-01 22:09:44 +01:00
|
|
|
|
break;
|
|
|
|
|
case 8:
|
2022-09-19 11:29:51 +02:00
|
|
|
|
number = std::strtoull(buffers[2].c_str(), nullptr, base);
|
2022-02-01 22:09:44 +01:00
|
|
|
|
break;
|
|
|
|
|
case 2:
|
2022-09-19 11:29:51 +02:00
|
|
|
|
number = std::strtoull(buffers[3].c_str(), nullptr, base);
|
2022-02-01 22:09:44 +01:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return;
|
2021-02-05 00:17:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
2022-09-19 11:29:51 +02:00
|
|
|
|
buffers[0] = std::to_string(number);
|
|
|
|
|
buffers[1] = hex::format("0x{0:X}", number);
|
|
|
|
|
buffers[2] = hex::format("{0:#o}", number);
|
|
|
|
|
buffers[3] = hex::toBinaryString(number);
|
2021-02-05 00:17:56 +01:00
|
|
|
|
};
|
|
|
|
|
|
2022-09-19 11:29:51 +02:00
|
|
|
|
if (ImGui::InputTextIcon("hex.builtin.tools.base_converter.dec"_lang, ICON_VS_SYMBOL_NUMERIC, buffers[0]))
|
|
|
|
|
ConvertBases(10);
|
2021-02-05 00:17:56 +01:00
|
|
|
|
|
2022-09-19 11:29:51 +02:00
|
|
|
|
if (ImGui::InputTextIcon("hex.builtin.tools.base_converter.hex"_lang, ICON_VS_SYMBOL_NUMERIC, buffers[1]))
|
|
|
|
|
ConvertBases(16);
|
2021-02-05 00:17:56 +01:00
|
|
|
|
|
2022-09-19 11:29:51 +02:00
|
|
|
|
if (ImGui::InputTextIcon("hex.builtin.tools.base_converter.oct"_lang, ICON_VS_SYMBOL_NUMERIC, buffers[2]))
|
|
|
|
|
ConvertBases(8);
|
2021-02-05 00:17:56 +01:00
|
|
|
|
|
2022-09-19 11:29:51 +02:00
|
|
|
|
if (ImGui::InputTextIcon("hex.builtin.tools.base_converter.bin"_lang, ICON_VS_SYMBOL_NUMERIC, buffers[3]))
|
|
|
|
|
ConvertBases(2);
|
2021-02-05 00:17:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-20 22:25:27 +01:00
|
|
|
|
void drawByteSwapper() {
|
|
|
|
|
static std::string input, buffer, output;
|
|
|
|
|
|
|
|
|
|
if (ImGui::InputTextIcon("hex.builtin.tools.input"_lang, ICON_VS_SYMBOL_NUMERIC, input, ImGuiInputTextFlags_CharsHexadecimal)) {
|
|
|
|
|
auto nextAlignedSize = std::max<size_t>(2, std::bit_ceil(input.size()));
|
|
|
|
|
|
|
|
|
|
buffer.clear();
|
|
|
|
|
buffer.resize(nextAlignedSize - input.size(), '0');
|
|
|
|
|
buffer += input;
|
|
|
|
|
|
|
|
|
|
output.clear();
|
|
|
|
|
for (u32 i = 0; i < buffer.size(); i += 2) {
|
|
|
|
|
output += buffer[buffer.size() - i - 2];
|
|
|
|
|
output += buffer[buffer.size() - i - 1];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().DisabledAlpha);
|
|
|
|
|
ImGui::InputTextIcon("hex.builtin.tools.output"_lang, ICON_VS_SYMBOL_NUMERIC, output, ImGuiInputTextFlags_ReadOnly);
|
|
|
|
|
ImGui::PopStyleVar();
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
void drawPermissionsCalculator() {
|
|
|
|
|
static bool setuid, setgid, sticky;
|
|
|
|
|
static bool r[3], w[3], x[3];
|
2021-01-22 18:01:39 +01:00
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
ImGui::TextUnformatted("hex.builtin.tools.permissions.perm_bits"_lang);
|
|
|
|
|
ImGui::Separator();
|
2021-07-27 22:46:37 +02:00
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
if (ImGui::BeginTable("Permissions", 4, ImGuiTableFlags_Borders)) {
|
|
|
|
|
ImGui::TableSetupColumn("Special", ImGuiTableColumnFlags_NoSort);
|
|
|
|
|
ImGui::TableSetupColumn("User", ImGuiTableColumnFlags_NoSort);
|
|
|
|
|
ImGui::TableSetupColumn("Group", ImGuiTableColumnFlags_NoSort);
|
|
|
|
|
ImGui::TableSetupColumn("Other", ImGuiTableColumnFlags_NoSort);
|
2023-11-12 00:10:16 +01:00
|
|
|
|
ImGui::TableSetupScrollFreeze(0, 1);
|
2021-07-27 22:46:37 +02:00
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
ImGui::TableHeadersRow();
|
2021-07-27 22:46:37 +02:00
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
ImGui::TableNextRow();
|
|
|
|
|
ImGui::TableNextColumn();
|
2021-07-27 22:46:37 +02:00
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
ImGui::Checkbox("setuid", &setuid);
|
|
|
|
|
ImGui::Checkbox("setgid", &setgid);
|
|
|
|
|
ImGui::Checkbox("Sticky bit", &sticky);
|
2021-07-27 22:46:37 +02:00
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
for (u8 i = 0; i < 3; i++) {
|
|
|
|
|
ImGui::TableNextColumn();
|
2021-07-27 22:46:37 +02:00
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
ImGui::PushID(i);
|
|
|
|
|
ImGui::Checkbox("Read", &r[i]);
|
|
|
|
|
ImGui::Checkbox("Write", &w[i]);
|
|
|
|
|
ImGui::Checkbox("Execute", &x[i]);
|
|
|
|
|
ImGui::PopID();
|
|
|
|
|
}
|
2021-07-27 22:46:37 +02:00
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
ImGui::EndTable();
|
2021-07-27 22:46:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
ImGui::NewLine();
|
|
|
|
|
ImGui::TextUnformatted("hex.builtin.tools.permissions.absolute"_lang);
|
|
|
|
|
ImGui::Separator();
|
|
|
|
|
|
|
|
|
|
auto result = hex::format("{}{}{}{}",
|
|
|
|
|
(setuid << 2) | (setgid << 1) | (sticky << 0),
|
|
|
|
|
(r[0] << 2) | (w[0] << 1) | (x[0] << 0),
|
|
|
|
|
(r[1] << 2) | (w[1] << 1) | (x[1] << 0),
|
|
|
|
|
(r[2] << 2) | (w[2] << 1) | (x[2] << 0));
|
|
|
|
|
ImGui::InputText("##permissions_absolute", result.data(), result.size(), ImGuiInputTextFlags_ReadOnly);
|
|
|
|
|
|
|
|
|
|
ImGui::NewLine();
|
|
|
|
|
|
2023-11-10 20:47:08 +01:00
|
|
|
|
constexpr static auto WarningColor = ImColor(0.92F, 0.25F, 0.2F, 1.0F);
|
2022-05-29 14:57:59 +02:00
|
|
|
|
if (setuid && !x[0])
|
|
|
|
|
ImGui::TextFormattedColored(WarningColor, "{}", "hex.builtin.tools.permissions.setuid_error"_lang);
|
|
|
|
|
if (setgid && !x[1])
|
|
|
|
|
ImGui::TextFormattedColored(WarningColor, "{}", "hex.builtin.tools.permissions.setgid_error"_lang);
|
|
|
|
|
if (sticky && !x[2])
|
|
|
|
|
ImGui::TextFormattedColored(WarningColor, "{}", "hex.builtin.tools.permissions.sticky_error"_lang);
|
2021-07-27 22:46:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-17 09:27:14 +02:00
|
|
|
|
/*void drawFileUploader() {
|
2022-05-29 14:57:59 +02:00
|
|
|
|
struct UploadedFile {
|
|
|
|
|
std::string fileName, link, size;
|
|
|
|
|
};
|
2021-07-27 22:46:37 +02:00
|
|
|
|
|
2023-03-23 11:23:07 +01:00
|
|
|
|
static HttpRequest request("POST", "https://api.anonfiles.com/upload");
|
|
|
|
|
static std::future<HttpRequest::Result<std::string>> uploadProcess;
|
2022-05-29 14:57:59 +02:00
|
|
|
|
static std::fs::path currFile;
|
|
|
|
|
static std::vector<UploadedFile> links;
|
|
|
|
|
|
|
|
|
|
bool uploading = uploadProcess.valid() && uploadProcess.wait_for(0s) != std::future_status::ready;
|
|
|
|
|
|
|
|
|
|
ImGui::Header("hex.builtin.tools.file_uploader.control"_lang, true);
|
|
|
|
|
if (!uploading) {
|
|
|
|
|
if (ImGui::Button("hex.builtin.tools.file_uploader.upload"_lang)) {
|
|
|
|
|
fs::openFileBrowser(fs::DialogMode::Open, {}, [&](auto path) {
|
2023-03-23 11:23:07 +01:00
|
|
|
|
uploadProcess = request.uploadFile(path);
|
2022-05-29 14:57:59 +02:00
|
|
|
|
currFile = path;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (ImGui::Button("hex.builtin.common.cancel"_lang)) {
|
2023-03-23 11:23:07 +01:00
|
|
|
|
request.cancel();
|
2022-05-29 14:57:59 +02:00
|
|
|
|
}
|
2021-08-28 00:45:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
ImGui::SameLine();
|
2021-08-28 00:45:59 +02:00
|
|
|
|
|
2023-03-23 11:23:07 +01:00
|
|
|
|
ImGui::ProgressBar(request.getProgress(), ImVec2(0, 0), uploading ? nullptr : "Done!");
|
2021-08-28 00:45:59 +02:00
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
ImGui::Header("hex.builtin.tools.file_uploader.recent"_lang);
|
2021-08-28 00:45:59 +02:00
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
if (ImGui::BeginTable("##links", 3, ImGuiTableFlags_ScrollY | ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable | ImGuiTableFlags_RowBg, ImVec2(0, 200))) {
|
|
|
|
|
ImGui::TableSetupColumn("hex.builtin.common.file"_lang);
|
|
|
|
|
ImGui::TableSetupColumn("hex.builtin.common.link"_lang);
|
|
|
|
|
ImGui::TableSetupColumn("hex.builtin.common.size"_lang);
|
2023-11-12 00:10:16 +01:00
|
|
|
|
ImGui::TableSetupScrollFreeze(0, 1);
|
2022-05-29 14:57:59 +02:00
|
|
|
|
ImGui::TableHeadersRow();
|
2021-08-28 00:45:59 +02:00
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
ImGuiListClipper clipper;
|
|
|
|
|
clipper.Begin(links.size());
|
2021-08-28 00:45:59 +02:00
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
while (clipper.Step()) {
|
|
|
|
|
for (i32 i = clipper.DisplayEnd - 1; i >= clipper.DisplayStart; i--) {
|
|
|
|
|
auto &[fileName, link, size] = links[i];
|
2021-08-28 00:45:59 +02:00
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
ImGui::TableNextRow();
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
ImGui::TextUnformatted(fileName.c_str());
|
2021-08-28 00:45:59 +02:00
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
if (ImGui::Hyperlink(link.c_str())) {
|
2022-08-03 23:32:34 +02:00
|
|
|
|
if (ImGui::IsKeyDown(ImGuiKey_LeftCtrl))
|
2022-05-29 14:57:59 +02:00
|
|
|
|
hex::openWebpage(link);
|
|
|
|
|
else
|
|
|
|
|
ImGui::SetClipboardText(link.c_str());
|
|
|
|
|
}
|
2021-08-28 00:45:59 +02:00
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
ImGui::InfoTooltip("hex.builtin.tools.file_uploader.tooltip"_lang);
|
2021-08-28 00:45:59 +02:00
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
ImGui::TextUnformatted(size.c_str());
|
|
|
|
|
}
|
2021-08-28 00:45:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
clipper.End();
|
2021-08-28 00:45:59 +02:00
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
ImGui::EndTable();
|
|
|
|
|
}
|
2021-08-28 00:45:59 +02:00
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
if (uploadProcess.valid() && uploadProcess.wait_for(0s) == std::future_status::ready) {
|
|
|
|
|
auto response = uploadProcess.get();
|
2023-03-23 11:23:07 +01:00
|
|
|
|
if (response.getStatusCode() == 200) {
|
2022-05-29 14:57:59 +02:00
|
|
|
|
try {
|
2023-03-23 11:23:07 +01:00
|
|
|
|
auto json = nlohmann::json::parse(response.getData());
|
2022-10-04 09:10:58 +02:00
|
|
|
|
links.push_back({
|
2023-03-12 18:43:05 +01:00
|
|
|
|
wolv::util::toUTF8String(currFile.filename()),
|
2023-05-16 11:33:00 +02:00
|
|
|
|
json.at("data").at("file").at("url").at("short"),
|
|
|
|
|
json.at("data").at("file").at("metadata").at("size").at("readable")
|
2022-10-04 09:10:58 +02:00
|
|
|
|
});
|
2022-05-29 14:57:59 +02:00
|
|
|
|
} catch (...) {
|
2023-04-08 00:58:53 +02:00
|
|
|
|
PopupError::open("hex.builtin.tools.file_uploader.invalid_response"_lang);
|
2022-05-29 14:57:59 +02:00
|
|
|
|
}
|
2023-03-23 11:23:07 +01:00
|
|
|
|
} else if (response.getStatusCode() == 0) {
|
2022-05-29 14:57:59 +02:00
|
|
|
|
// Canceled by user, no action needed
|
2023-04-08 00:58:53 +02:00
|
|
|
|
} else PopupError::open(hex::format("hex.builtin.tools.file_uploader.error"_lang, response.getStatusCode()));
|
2021-08-28 00:45:59 +02:00
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
uploadProcess = {};
|
|
|
|
|
currFile.clear();
|
|
|
|
|
}
|
2023-08-17 09:27:14 +02:00
|
|
|
|
}*/
|
2021-08-28 00:45:59 +02:00
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
std::string getWikipediaApiUrl() {
|
2023-10-22 00:46:45 +02:00
|
|
|
|
std::string setting = ContentRegistry::Settings::read("hex.builtin.setting.interface", "hex.builtin.setting.interface.wiki_explain_language", "en").get<std::string>();
|
2023-03-21 15:33:43 +01:00
|
|
|
|
return "https://" + setting + ".wikipedia.org/w/api.php?format=json&action=query&prop=extracts&explaintext&redirects=10&formatversion=2";
|
2022-05-29 14:57:59 +02:00
|
|
|
|
}
|
2022-05-22 23:26:46 +02:00
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
void drawWikiExplainer() {
|
2023-03-23 11:23:07 +01:00
|
|
|
|
static HttpRequest request("GET", "");
|
2021-08-28 18:15:47 +02:00
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
static std::string resultTitle, resultExtract;
|
2023-03-23 11:23:07 +01:00
|
|
|
|
static std::future<HttpRequest::Result<std::string>> searchProcess;
|
2022-05-29 14:57:59 +02:00
|
|
|
|
static bool extendedSearch = false;
|
2023-10-12 20:35:44 +02:00
|
|
|
|
static std::string searchString;
|
2021-08-28 18:15:47 +02:00
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
ImGui::Header("hex.builtin.tools.wiki_explain.control"_lang, true);
|
2021-08-28 16:02:53 +02:00
|
|
|
|
|
2023-10-12 20:35:44 +02:00
|
|
|
|
bool startSearch = ImGui::InputTextIcon("##search", ICON_VS_SYMBOL_KEY, searchString, ImGuiInputTextFlags_EnterReturnsTrue);
|
2021-08-28 16:02:53 +02:00
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
ImGui::SameLine();
|
2021-08-28 16:02:53 +02:00
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
ImGui::BeginDisabled((searchProcess.valid() && searchProcess.wait_for(0s) != std::future_status::ready) || searchString.empty());
|
|
|
|
|
startSearch = ImGui::Button("hex.builtin.tools.wiki_explain.search"_lang) || startSearch;
|
|
|
|
|
ImGui::EndDisabled();
|
2021-08-28 16:02:53 +02:00
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
if (startSearch && !searchString.empty()) {
|
2023-03-23 11:23:07 +01:00
|
|
|
|
request.setUrl(getWikipediaApiUrl() + "&exintro"s + "&titles="s + request.urlEncode(searchString));
|
|
|
|
|
searchProcess = request.execute();
|
2022-05-29 14:57:59 +02:00
|
|
|
|
}
|
2021-08-28 16:02:53 +02:00
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
ImGui::Header("hex.builtin.tools.wiki_explain.results"_lang);
|
2021-08-28 16:02:53 +02:00
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
if (ImGui::BeginChild("##summary", ImVec2(0, 300), true)) {
|
|
|
|
|
if (!resultTitle.empty() && !resultExtract.empty()) {
|
|
|
|
|
ImGui::HeaderColored(resultTitle.c_str(), ImGui::GetCustomColorVec4(ImGuiCustomCol_Highlight), true);
|
|
|
|
|
ImGui::TextFormattedWrapped("{}", resultExtract.c_str());
|
|
|
|
|
}
|
2021-08-28 16:02:53 +02:00
|
|
|
|
}
|
2022-05-29 14:57:59 +02:00
|
|
|
|
ImGui::EndChild();
|
2021-08-28 16:02:53 +02:00
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
if (searchProcess.valid() && searchProcess.wait_for(0s) == std::future_status::ready) {
|
|
|
|
|
try {
|
|
|
|
|
auto response = searchProcess.get();
|
2023-03-23 11:23:07 +01:00
|
|
|
|
if (response.getStatusCode() != 200) throw std::runtime_error("Invalid response");
|
2021-08-28 16:02:53 +02:00
|
|
|
|
|
2023-03-23 11:23:07 +01:00
|
|
|
|
auto json = nlohmann::json::parse(response.getData());
|
2021-08-28 16:02:53 +02:00
|
|
|
|
|
2023-05-16 11:33:00 +02:00
|
|
|
|
resultTitle = json.at("query").at("pages").at(0).at("title").get<std::string>();
|
|
|
|
|
resultExtract = json.at("query").at("pages").at(0).at("extract").get<std::string>();
|
2022-05-29 14:57:59 +02:00
|
|
|
|
|
|
|
|
|
if (!extendedSearch && resultExtract.ends_with(':')) {
|
|
|
|
|
extendedSearch = true;
|
2023-03-23 11:23:07 +01:00
|
|
|
|
|
|
|
|
|
request.setUrl(getWikipediaApiUrl() + "&titles="s + request.urlEncode(searchString));
|
|
|
|
|
searchProcess = request.execute();
|
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
resultTitle.clear();
|
|
|
|
|
resultExtract.clear();
|
2023-10-12 20:35:44 +02:00
|
|
|
|
searchString.clear();
|
2022-05-29 14:57:59 +02:00
|
|
|
|
} else {
|
|
|
|
|
extendedSearch = false;
|
|
|
|
|
searchString.clear();
|
|
|
|
|
}
|
|
|
|
|
} catch (...) {
|
2023-10-12 20:35:44 +02:00
|
|
|
|
searchString.clear();
|
2021-08-28 16:02:53 +02:00
|
|
|
|
resultTitle.clear();
|
|
|
|
|
resultExtract.clear();
|
|
|
|
|
extendedSearch = false;
|
2022-05-29 14:57:59 +02:00
|
|
|
|
searchProcess = {};
|
|
|
|
|
|
|
|
|
|
resultTitle = "???";
|
|
|
|
|
resultExtract = "hex.builtin.tools.wiki_explain.invalid_response"_lang.get();
|
2021-08-28 16:02:53 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-22 17:56:06 +02:00
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
void drawFileToolShredder() {
|
2022-07-05 00:00:00 +02:00
|
|
|
|
static std::u8string selectedFile;
|
2022-05-29 14:57:59 +02:00
|
|
|
|
static bool fastMode = false;
|
2022-08-17 16:15:36 +02:00
|
|
|
|
static TaskHolder shredderTask;
|
2021-09-22 17:56:06 +02:00
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
ImGui::TextUnformatted("hex.builtin.tools.file_tools.shredder.warning"_lang);
|
|
|
|
|
ImGui::NewLine();
|
2021-09-22 17:56:06 +02:00
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
if (ImGui::BeginChild("settings", { 0, ImGui::GetTextLineHeightWithSpacing() * 4 }, true, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse)) {
|
2022-08-17 16:15:36 +02:00
|
|
|
|
ImGui::BeginDisabled(shredderTask.isRunning());
|
2022-05-29 14:57:59 +02:00
|
|
|
|
{
|
|
|
|
|
ImGui::TextUnformatted("hex.builtin.tools.file_tools.shredder.input"_lang);
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
ImGui::InputText("##path", selectedFile);
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::Button("...")) {
|
|
|
|
|
fs::openFileBrowser(fs::DialogMode::Open, {}, [](const auto &path) {
|
2022-07-05 00:00:00 +02:00
|
|
|
|
selectedFile = path.u8string();
|
2022-05-29 14:57:59 +02:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::Checkbox("hex.builtin.tools.file_tools.shredder.fast"_lang, &fastMode);
|
2021-09-22 17:56:06 +02:00
|
|
|
|
}
|
2022-05-29 14:57:59 +02:00
|
|
|
|
ImGui::EndDisabled();
|
|
|
|
|
}
|
|
|
|
|
ImGui::EndChild();
|
|
|
|
|
|
2022-08-17 16:15:36 +02:00
|
|
|
|
if (shredderTask.isRunning())
|
2022-05-29 14:57:59 +02:00
|
|
|
|
ImGui::TextSpinner("hex.builtin.tools.file_tools.shredder.shredding"_lang);
|
|
|
|
|
else {
|
|
|
|
|
ImGui::BeginDisabled(selectedFile.empty());
|
|
|
|
|
{
|
|
|
|
|
if (ImGui::Button("hex.builtin.tools.file_tools.shredder.shred"_lang)) {
|
2022-08-17 16:15:36 +02:00
|
|
|
|
shredderTask = TaskManager::createTask("hex.builtin.tools.file_tools.shredder.shredding", 0, [](auto &task) {
|
2022-05-29 14:57:59 +02:00
|
|
|
|
ON_SCOPE_EXIT {
|
|
|
|
|
selectedFile.clear();
|
|
|
|
|
};
|
2023-03-12 18:27:29 +01:00
|
|
|
|
wolv::io::File file(selectedFile, wolv::io::File::Mode::Write);
|
2022-05-29 14:57:59 +02:00
|
|
|
|
|
|
|
|
|
if (!file.isValid()) {
|
2023-04-08 00:58:53 +02:00
|
|
|
|
PopupError::open("hex.builtin.tools.file_tools.shredder.error.open"_lang);
|
2022-05-29 14:57:59 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-17 16:15:36 +02:00
|
|
|
|
task.setMaxValue(file.getSize());
|
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
std::vector<std::array<u8, 3>> overwritePattern;
|
|
|
|
|
if (fastMode) {
|
|
|
|
|
/* Should be sufficient for modern disks */
|
|
|
|
|
overwritePattern.push_back({ 0x00, 0x00, 0x00 });
|
|
|
|
|
overwritePattern.push_back({ 0xFF, 0xFF, 0xFF });
|
|
|
|
|
} else {
|
|
|
|
|
/* Gutmann's method. Secure for magnetic storage */
|
|
|
|
|
std::random_device rd;
|
|
|
|
|
std::uniform_int_distribution<u8> dist(0x00, 0xFF);
|
|
|
|
|
|
|
|
|
|
/* Fill fixed patterns */
|
|
|
|
|
overwritePattern = {
|
2022-08-17 16:15:36 +02:00
|
|
|
|
{ },
|
|
|
|
|
{ },
|
|
|
|
|
{},
|
|
|
|
|
{},
|
|
|
|
|
{ 0x55, 0x55, 0x55 },
|
|
|
|
|
{ 0xAA, 0xAA, 0xAA },
|
|
|
|
|
{ 0x92, 0x49, 0x24 },
|
|
|
|
|
{ 0x49, 0x24, 0x92 },
|
|
|
|
|
{ 0x24, 0x92, 0x49 },
|
|
|
|
|
{ 0x00, 0x00, 0x00 },
|
|
|
|
|
{ 0x11, 0x11, 0x11 },
|
|
|
|
|
{ 0x22, 0x22, 0x22 },
|
|
|
|
|
{ 0x33, 0x33, 0x44 },
|
|
|
|
|
{ 0x55, 0x55, 0x55 },
|
|
|
|
|
{ 0x66, 0x66, 0x66 },
|
|
|
|
|
{ 0x77, 0x77, 0x77 },
|
|
|
|
|
{ 0x88, 0x88, 0x88 },
|
|
|
|
|
{ 0x99, 0x99, 0x99 },
|
|
|
|
|
{ 0xAA, 0xAA, 0xAA },
|
|
|
|
|
{ 0xBB, 0xBB, 0xBB },
|
|
|
|
|
{ 0xCC, 0xCC, 0xCC },
|
|
|
|
|
{ 0xDD, 0xDD, 0xDD },
|
|
|
|
|
{ 0xEE, 0xEE, 0xEE },
|
|
|
|
|
{ 0xFF, 0xFF, 0xFF },
|
|
|
|
|
{ 0x92, 0x49, 0x24 },
|
|
|
|
|
{ 0x49, 0x24, 0x92 },
|
|
|
|
|
{ 0x24, 0x92, 0x49 },
|
|
|
|
|
{ 0x6D, 0xB6, 0xDB },
|
|
|
|
|
{ 0xB6, 0xDB, 0x6D },
|
|
|
|
|
{ 0xBD, 0x6D, 0xB6 },
|
|
|
|
|
{},
|
|
|
|
|
{},
|
|
|
|
|
{},
|
|
|
|
|
{}
|
2022-05-29 14:57:59 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Fill random patterns */
|
|
|
|
|
for (u8 i = 0; i < 4; i++)
|
|
|
|
|
overwritePattern[i] = { dist(rd), dist(rd), dist(rd) };
|
|
|
|
|
for (u8 i = 0; i < 4; i++)
|
|
|
|
|
overwritePattern[overwritePattern.size() - 1 - i] = { dist(rd), dist(rd), dist(rd) };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t fileSize = file.getSize();
|
|
|
|
|
|
|
|
|
|
for (const auto &pattern : overwritePattern) {
|
|
|
|
|
for (u64 offset = 0; offset < fileSize; offset += 3) {
|
2023-03-23 11:23:07 +01:00
|
|
|
|
file.writeBuffer(pattern.data(), std::min<u64>(pattern.size(), fileSize - offset));
|
2022-05-29 14:57:59 +02:00
|
|
|
|
task.update(offset);
|
|
|
|
|
}
|
2021-09-22 17:56:06 +02:00
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
file.flush();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
file.remove();
|
|
|
|
|
|
2023-04-08 00:58:53 +02:00
|
|
|
|
PopupInfo::open("hex.builtin.tools.file_tools.shredder.success"_lang);
|
2022-08-17 16:15:36 +02:00
|
|
|
|
});
|
2022-05-29 14:57:59 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ImGui::EndDisabled();
|
2021-09-22 17:56:06 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
void drawFileToolSplitter() {
|
|
|
|
|
std::array sizeText = {
|
2023-11-10 20:47:08 +01:00
|
|
|
|
static_cast<const char*>("hex.builtin.tools.file_tools.splitter.sizes.5_75_floppy"_lang),
|
|
|
|
|
static_cast<const char*>("hex.builtin.tools.file_tools.splitter.sizes.3_5_floppy"_lang),
|
|
|
|
|
static_cast<const char*>("hex.builtin.tools.file_tools.splitter.sizes.zip100"_lang),
|
|
|
|
|
static_cast<const char*>("hex.builtin.tools.file_tools.splitter.sizes.zip200"_lang),
|
|
|
|
|
static_cast<const char*>("hex.builtin.tools.file_tools.splitter.sizes.cdrom650"_lang),
|
|
|
|
|
static_cast<const char*>("hex.builtin.tools.file_tools.splitter.sizes.cdrom700"_lang),
|
|
|
|
|
static_cast<const char*>("hex.builtin.tools.file_tools.splitter.sizes.fat32"_lang),
|
|
|
|
|
static_cast<const char*>("hex.builtin.tools.file_tools.splitter.sizes.custom"_lang)
|
2022-05-29 14:57:59 +02:00
|
|
|
|
};
|
|
|
|
|
std::array<u64, sizeText.size()> sizes = {
|
|
|
|
|
1200_KiB,
|
|
|
|
|
1400_KiB,
|
|
|
|
|
100_MiB,
|
|
|
|
|
200_MiB,
|
|
|
|
|
650_MiB,
|
|
|
|
|
700_MiB,
|
|
|
|
|
4_GiB,
|
|
|
|
|
1
|
|
|
|
|
};
|
|
|
|
|
|
2022-07-05 00:00:00 +02:00
|
|
|
|
static std::u8string selectedFile;
|
|
|
|
|
static std::u8string baseOutputPath;
|
|
|
|
|
static u64 splitSize = sizes[0];
|
|
|
|
|
static int selectedItem = 0;
|
2022-08-17 16:15:36 +02:00
|
|
|
|
static TaskHolder splitterTask;
|
2022-05-29 14:57:59 +02:00
|
|
|
|
|
|
|
|
|
if (ImGui::BeginChild("split_settings", { 0, ImGui::GetTextLineHeightWithSpacing() * 7 }, true, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse)) {
|
2022-08-17 16:15:36 +02:00
|
|
|
|
ImGui::BeginDisabled(splitterTask.isRunning());
|
2022-05-29 14:57:59 +02:00
|
|
|
|
{
|
|
|
|
|
ImGui::InputText("##path", selectedFile);
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::Button("...##input")) {
|
|
|
|
|
fs::openFileBrowser(fs::DialogMode::Open, {}, [](const auto &path) {
|
2022-07-05 00:00:00 +02:00
|
|
|
|
selectedFile = path.u8string();
|
2022-05-29 14:57:59 +02:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
ImGui::TextUnformatted("hex.builtin.tools.file_tools.splitter.input"_lang);
|
|
|
|
|
|
|
|
|
|
ImGui::InputText("##base_path", baseOutputPath);
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::Button("...##output")) {
|
|
|
|
|
fs::openFileBrowser(fs::DialogMode::Save, {}, [](const auto &path) {
|
2022-07-05 00:00:00 +02:00
|
|
|
|
baseOutputPath = path.u8string();
|
2022-05-29 14:57:59 +02:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
ImGui::TextUnformatted("hex.builtin.tools.file_tools.splitter.output"_lang);
|
2021-09-22 17:56:06 +02:00
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
ImGui::Separator();
|
|
|
|
|
|
|
|
|
|
if (ImGui::Combo("###part_size", &selectedItem, sizeText.data(), sizeText.size())) {
|
|
|
|
|
splitSize = sizes[selectedItem];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ImGui::EndDisabled();
|
2022-08-17 16:15:36 +02:00
|
|
|
|
ImGui::BeginDisabled(splitterTask.isRunning() || selectedItem != sizes.size() - 1);
|
2022-05-29 14:57:59 +02:00
|
|
|
|
{
|
|
|
|
|
ImGui::InputScalar("###custom_size", ImGuiDataType_U64, &splitSize);
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
ImGui::TextUnformatted("Bytes");
|
|
|
|
|
}
|
|
|
|
|
ImGui::EndDisabled();
|
|
|
|
|
}
|
|
|
|
|
ImGui::EndChild();
|
|
|
|
|
|
|
|
|
|
ImGui::BeginDisabled(selectedFile.empty() || baseOutputPath.empty() || splitSize == 0);
|
|
|
|
|
{
|
2022-08-17 16:15:36 +02:00
|
|
|
|
if (splitterTask.isRunning())
|
2022-12-29 15:07:43 +01:00
|
|
|
|
ImGui::TextSpinner("hex.builtin.tools.file_tools.splitter.picker.splitting"_lang);
|
2022-05-29 14:57:59 +02:00
|
|
|
|
else {
|
2022-12-29 15:07:43 +01:00
|
|
|
|
if (ImGui::Button("hex.builtin.tools.file_tools.splitter.picker.split"_lang)) {
|
|
|
|
|
splitterTask = TaskManager::createTask("hex.builtin.tools.file_tools.splitter.picker.splitting", 0, [](auto &task) {
|
2022-05-29 14:57:59 +02:00
|
|
|
|
ON_SCOPE_EXIT {
|
|
|
|
|
selectedFile.clear();
|
|
|
|
|
baseOutputPath.clear();
|
2021-09-22 17:56:06 +02:00
|
|
|
|
};
|
2023-01-30 11:11:30 +01:00
|
|
|
|
|
2023-03-12 18:27:29 +01:00
|
|
|
|
wolv::io::File file(selectedFile, wolv::io::File::Mode::Read);
|
2021-09-22 17:56:06 +02:00
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
if (!file.isValid()) {
|
2023-04-08 00:58:53 +02:00
|
|
|
|
PopupError::open("hex.builtin.tools.file_tools.splitter.picker.error.open"_lang);
|
2022-05-29 14:57:59 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2021-09-22 17:56:06 +02:00
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
if (file.getSize() < splitSize) {
|
2023-04-08 00:58:53 +02:00
|
|
|
|
PopupError::open("hex.builtin.tools.file_tools.splitter.picker.error.size"_lang);
|
2022-05-29 14:57:59 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2021-12-16 23:48:52 +01:00
|
|
|
|
|
2022-08-17 16:15:36 +02:00
|
|
|
|
task.setMaxValue(file.getSize());
|
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
u32 index = 1;
|
|
|
|
|
for (u64 offset = 0; offset < file.getSize(); offset += splitSize) {
|
2021-12-16 23:48:52 +01:00
|
|
|
|
task.update(offset);
|
2021-10-09 23:07:58 +02:00
|
|
|
|
|
2022-07-05 00:00:00 +02:00
|
|
|
|
std::fs::path path = baseOutputPath;
|
|
|
|
|
path += hex::format(".{:05}", index);
|
|
|
|
|
|
2023-03-12 18:27:29 +01:00
|
|
|
|
wolv::io::File partFile(path, wolv::io::File::Mode::Create);
|
2022-05-29 14:57:59 +02:00
|
|
|
|
|
|
|
|
|
if (!partFile.isValid()) {
|
2023-04-08 00:58:53 +02:00
|
|
|
|
PopupError::open(hex::format("hex.builtin.tools.file_tools.splitter.picker.error.create"_lang, index));
|
2022-05-29 14:57:59 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2021-09-22 17:56:06 +02:00
|
|
|
|
|
2022-09-12 21:28:02 +02:00
|
|
|
|
constexpr static auto BufferSize = 0xFF'FFFF;
|
2022-05-29 14:57:59 +02:00
|
|
|
|
for (u64 partOffset = 0; partOffset < splitSize; partOffset += BufferSize) {
|
2023-03-23 11:23:07 +01:00
|
|
|
|
partFile.writeVector(file.readVector(std::min<u64>(BufferSize, splitSize - partOffset)));
|
2022-05-29 14:57:59 +02:00
|
|
|
|
partFile.flush();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
index++;
|
|
|
|
|
}
|
2021-09-22 17:56:06 +02:00
|
|
|
|
|
2023-04-08 00:58:53 +02:00
|
|
|
|
PopupInfo::open("hex.builtin.tools.file_tools.splitter.picker.success"_lang);
|
2022-08-17 16:15:36 +02:00
|
|
|
|
});
|
2022-05-29 14:57:59 +02:00
|
|
|
|
}
|
2021-09-22 17:56:06 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ImGui::EndDisabled();
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
void drawFileToolCombiner() {
|
2022-07-05 00:00:00 +02:00
|
|
|
|
static std::vector<std::fs::path> files;
|
|
|
|
|
static std::u8string outputPath;
|
2022-05-29 14:57:59 +02:00
|
|
|
|
static u32 selectedIndex;
|
2022-08-17 16:15:36 +02:00
|
|
|
|
static TaskHolder combinerTask;
|
2022-05-29 14:57:59 +02:00
|
|
|
|
|
|
|
|
|
if (ImGui::BeginTable("files_table", 2, ImGuiTableFlags_SizingStretchProp)) {
|
|
|
|
|
ImGui::TableSetupColumn("file list", ImGuiTableColumnFlags_NoHeaderLabel, 10);
|
|
|
|
|
ImGui::TableSetupColumn("buttons", ImGuiTableColumnFlags_NoHeaderLabel, 1);
|
|
|
|
|
ImGui::TableNextRow();
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
|
|
|
|
|
if (ImGui::BeginListBox("##files", { -FLT_MIN, 10 * ImGui::GetTextLineHeightWithSpacing() })) {
|
|
|
|
|
u32 index = 0;
|
|
|
|
|
for (auto &file : files) {
|
2023-03-12 18:43:05 +01:00
|
|
|
|
if (ImGui::Selectable(wolv::util::toUTF8String(file).c_str(), index == selectedIndex))
|
2022-05-29 14:57:59 +02:00
|
|
|
|
selectedIndex = index;
|
|
|
|
|
index++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::EndListBox();
|
2021-09-22 17:56:06 +02:00
|
|
|
|
}
|
2021-12-20 22:04:10 +01:00
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
|
|
|
|
|
ImGui::BeginDisabled(selectedIndex <= 0);
|
|
|
|
|
{
|
|
|
|
|
if (ImGui::ArrowButton("move_up", ImGuiDir_Up)) {
|
|
|
|
|
std::iter_swap(files.begin() + selectedIndex, files.begin() + selectedIndex - 1);
|
|
|
|
|
selectedIndex--;
|
|
|
|
|
}
|
2021-09-22 17:56:06 +02:00
|
|
|
|
}
|
2022-05-29 14:57:59 +02:00
|
|
|
|
ImGui::EndDisabled();
|
2021-09-22 17:56:06 +02:00
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
ImGui::BeginDisabled(files.empty() || selectedIndex >= files.size() - 1);
|
|
|
|
|
{
|
|
|
|
|
if (ImGui::ArrowButton("move_down", ImGuiDir_Down)) {
|
|
|
|
|
std::iter_swap(files.begin() + selectedIndex, files.begin() + selectedIndex + 1);
|
|
|
|
|
selectedIndex++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ImGui::EndDisabled();
|
2021-09-22 17:56:06 +02:00
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
ImGui::TableNextRow();
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
|
2022-08-17 16:15:36 +02:00
|
|
|
|
ImGui::BeginDisabled(combinerTask.isRunning());
|
2022-05-29 14:57:59 +02:00
|
|
|
|
{
|
|
|
|
|
if (ImGui::Button("hex.builtin.tools.file_tools.combiner.add"_lang)) {
|
|
|
|
|
fs::openFileBrowser(fs::DialogMode::Open, {}, [](const auto &path) {
|
2022-07-05 00:00:00 +02:00
|
|
|
|
files.push_back(path);
|
2023-08-19 19:11:38 +02:00
|
|
|
|
}, "", true);
|
2022-05-29 14:57:59 +02:00
|
|
|
|
}
|
|
|
|
|
ImGui::SameLine();
|
2023-08-19 19:18:57 +02:00
|
|
|
|
ImGui::BeginDisabled(files.empty() || selectedIndex >= files.size());
|
2022-05-29 14:57:59 +02:00
|
|
|
|
if (ImGui::Button("hex.builtin.tools.file_tools.combiner.delete"_lang)) {
|
|
|
|
|
files.erase(files.begin() + selectedIndex);
|
2023-08-19 19:18:57 +02:00
|
|
|
|
|
|
|
|
|
if (selectedIndex > 0)
|
|
|
|
|
selectedIndex--;
|
2022-05-29 14:57:59 +02:00
|
|
|
|
}
|
2023-08-19 19:18:57 +02:00
|
|
|
|
ImGui::EndDisabled();
|
2022-05-29 14:57:59 +02:00
|
|
|
|
ImGui::SameLine();
|
2023-08-19 19:18:57 +02:00
|
|
|
|
ImGui::BeginDisabled(files.empty());
|
2022-05-29 14:57:59 +02:00
|
|
|
|
if (ImGui::Button("hex.builtin.tools.file_tools.combiner.clear"_lang)) {
|
|
|
|
|
files.clear();
|
|
|
|
|
}
|
2023-08-19 19:18:57 +02:00
|
|
|
|
ImGui::EndDisabled();
|
2021-09-22 17:56:06 +02:00
|
|
|
|
}
|
2022-05-29 14:57:59 +02:00
|
|
|
|
ImGui::EndDisabled();
|
|
|
|
|
|
|
|
|
|
ImGui::EndTable();
|
2021-09-22 17:56:06 +02:00
|
|
|
|
}
|
2022-05-29 14:57:59 +02:00
|
|
|
|
|
2022-08-17 16:15:36 +02:00
|
|
|
|
ImGui::BeginDisabled(combinerTask.isRunning());
|
2021-09-22 17:56:06 +02:00
|
|
|
|
{
|
2022-05-29 14:57:59 +02:00
|
|
|
|
ImGui::InputText("##output_path", outputPath);
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::Button("...")) {
|
|
|
|
|
fs::openFileBrowser(fs::DialogMode::Save, {}, [](const auto &path) {
|
2022-07-05 00:00:00 +02:00
|
|
|
|
outputPath = path.u8string();
|
2022-05-29 14:57:59 +02:00
|
|
|
|
});
|
|
|
|
|
}
|
2021-09-22 17:56:06 +02:00
|
|
|
|
ImGui::SameLine();
|
2022-05-29 14:57:59 +02:00
|
|
|
|
ImGui::TextUnformatted("hex.builtin.tools.file_tools.combiner.output"_lang);
|
2021-09-22 17:56:06 +02:00
|
|
|
|
}
|
|
|
|
|
ImGui::EndDisabled();
|
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
ImGui::BeginDisabled(files.empty() || outputPath.empty());
|
|
|
|
|
{
|
2022-08-17 16:15:36 +02:00
|
|
|
|
if (combinerTask.isRunning())
|
2022-05-29 14:57:59 +02:00
|
|
|
|
ImGui::TextSpinner("hex.builtin.tools.file_tools.combiner.combining"_lang);
|
|
|
|
|
else {
|
|
|
|
|
if (ImGui::Button("hex.builtin.tools.file_tools.combiner.combine"_lang)) {
|
2022-08-17 16:15:36 +02:00
|
|
|
|
combinerTask = TaskManager::createTask("hex.builtin.tools.file_tools.combiner.combining", 0, [](auto &task) {
|
2023-03-12 18:27:29 +01:00
|
|
|
|
wolv::io::File output(outputPath, wolv::io::File::Mode::Create);
|
2021-09-22 17:56:06 +02:00
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
if (!output.isValid()) {
|
2023-04-08 00:58:53 +02:00
|
|
|
|
PopupError::open("hex.builtin.tools.file_tools.combiner.error.open_output"_lang);
|
2021-09-22 17:56:06 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-17 16:15:36 +02:00
|
|
|
|
task.setMaxValue(files.size());
|
2022-05-29 14:57:59 +02:00
|
|
|
|
|
|
|
|
|
u64 fileIndex = 0;
|
|
|
|
|
for (const auto &file : files) {
|
|
|
|
|
task.update(fileIndex);
|
|
|
|
|
fileIndex++;
|
|
|
|
|
|
2023-03-12 18:27:29 +01:00
|
|
|
|
wolv::io::File input(file, wolv::io::File::Mode::Read);
|
2022-05-29 14:57:59 +02:00
|
|
|
|
if (!input.isValid()) {
|
2023-04-08 00:58:53 +02:00
|
|
|
|
PopupError::open(hex::format("hex.builtin.tools.file_tools.combiner.open_input"_lang, wolv::util::toUTF8String(file)));
|
2022-05-29 14:57:59 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-12 21:28:02 +02:00
|
|
|
|
constexpr static auto BufferSize = 0xFF'FFFF;
|
2023-03-12 18:27:29 +01:00
|
|
|
|
auto inputSize = input.getSize();
|
2022-05-29 14:57:59 +02:00
|
|
|
|
for (u64 inputOffset = 0; inputOffset < inputSize; inputOffset += BufferSize) {
|
2023-03-23 11:23:07 +01:00
|
|
|
|
output.writeVector(input.readVector(std::min<u64>(BufferSize, inputSize - inputOffset)));
|
2022-05-29 14:57:59 +02:00
|
|
|
|
output.flush();
|
|
|
|
|
}
|
2021-09-22 17:56:06 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
files.clear();
|
|
|
|
|
selectedIndex = 0;
|
|
|
|
|
outputPath.clear();
|
2021-09-22 17:56:06 +02:00
|
|
|
|
|
2023-04-08 00:58:53 +02:00
|
|
|
|
PopupInfo::open("hex.builtin.tools.file_tools.combiner.success"_lang);
|
2022-08-17 16:15:36 +02:00
|
|
|
|
});
|
2022-05-29 14:57:59 +02:00
|
|
|
|
}
|
2021-09-22 17:56:06 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-05-29 14:57:59 +02:00
|
|
|
|
ImGui::EndDisabled();
|
2021-09-22 17:56:06 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
void drawFileTools() {
|
|
|
|
|
if (ImGui::BeginTabBar("file_tools_tabs")) {
|
|
|
|
|
if (ImGui::BeginTabItem("hex.builtin.tools.file_tools.shredder"_lang)) {
|
|
|
|
|
drawFileToolShredder();
|
|
|
|
|
ImGui::EndTabItem();
|
|
|
|
|
}
|
2021-09-22 17:56:06 +02:00
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
if (ImGui::BeginTabItem("hex.builtin.tools.file_tools.splitter"_lang)) {
|
|
|
|
|
drawFileToolSplitter();
|
|
|
|
|
ImGui::EndTabItem();
|
2021-09-22 17:56:06 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
if (ImGui::BeginTabItem("hex.builtin.tools.file_tools.combiner"_lang)) {
|
|
|
|
|
drawFileToolCombiner();
|
|
|
|
|
ImGui::EndTabItem();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::EndTabBar();
|
2021-09-22 17:56:06 +02:00
|
|
|
|
}
|
2022-05-29 14:57:59 +02:00
|
|
|
|
}
|
2021-09-22 17:56:06 +02:00
|
|
|
|
|
2023-10-04 12:00:32 +02:00
|
|
|
|
// Tool for converting between different number formats.
|
|
|
|
|
// There are three places where input can be changed; the bit checkboxes, the hex input, and the decimal input.
|
2023-05-19 21:18:38 +02:00
|
|
|
|
// The bit checkboxes and the hex input are directly related and can be converted between each other easily.
|
|
|
|
|
// The decimal input is a bit more complicated. IEEE 754 floating point numbers are represented as a sign bit,
|
|
|
|
|
// an exponent and a mantissa. For details see https://en.wikipedia.org/wiki/IEEE_754.
|
|
|
|
|
// Workflow is as follows:
|
|
|
|
|
// From the bit checkboxes determine the integer hex value. This is straightforward.
|
2023-10-04 12:00:32 +02:00
|
|
|
|
// From the hex value determine the binary floating point value by extracting the sign, exponent, and mantissa.
|
|
|
|
|
// From the binary floating point value determine the decimal floating point value using a third party library.
|
2023-05-19 21:18:38 +02:00
|
|
|
|
// From the decimal floating point we reconstruct the binary floating point value using internal hardware.
|
2023-10-04 12:00:32 +02:00
|
|
|
|
// If the format is non-standard, the reconstruction is done using properties of the format.
|
2023-01-19 17:01:19 +01:00
|
|
|
|
void drawIEEE754Decoder() {
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
|
|
|
|
constexpr static auto flags = ImGuiInputTextFlags_EnterReturnsTrue;
|
|
|
|
|
|
2023-10-15 22:07:51 +02:00
|
|
|
|
class IEEE754STATICS {
|
|
|
|
|
public:
|
|
|
|
|
IEEE754STATICS() {
|
|
|
|
|
value = 0;
|
|
|
|
|
exponentBitCount = 8;
|
|
|
|
|
mantissaBitCount = 23;
|
|
|
|
|
resultFloat = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
u128 value;
|
2023-11-10 20:47:08 +01:00
|
|
|
|
i32 exponentBitCount;
|
|
|
|
|
i32 mantissaBitCount;
|
2023-10-15 22:07:51 +02:00
|
|
|
|
long double resultFloat;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static IEEE754STATICS ieee754statics;
|
|
|
|
|
|
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
enum class NumberType {
|
2023-05-19 21:18:38 +02:00
|
|
|
|
Normal,
|
|
|
|
|
Zero,
|
|
|
|
|
Denormal,
|
|
|
|
|
Infinity,
|
|
|
|
|
NaN,
|
2023-09-20 10:48:44 +02:00
|
|
|
|
};
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
enum class InputType {
|
2023-11-10 20:47:08 +01:00
|
|
|
|
Infinity,
|
|
|
|
|
NotANumber,
|
|
|
|
|
QuietNotANumber,
|
|
|
|
|
SignalingNotANumber,
|
|
|
|
|
Regular,
|
|
|
|
|
Invalid
|
2023-09-20 10:48:44 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum class ValueType {
|
2023-05-19 21:18:38 +02:00
|
|
|
|
Regular,
|
|
|
|
|
SignalingNaN,
|
|
|
|
|
QuietNaN,
|
|
|
|
|
NegativeInfinity,
|
|
|
|
|
PositiveInfinity,
|
2023-09-20 10:48:44 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class IEEE754 {
|
|
|
|
|
public:
|
|
|
|
|
ValueType valueType;
|
|
|
|
|
NumberType numberType;
|
|
|
|
|
i64 exponentBias;
|
|
|
|
|
long double signValue;
|
|
|
|
|
long double exponentValue;
|
|
|
|
|
long double mantissaValue;
|
|
|
|
|
i64 signBits;
|
|
|
|
|
i64 exponentBits;
|
|
|
|
|
i64 mantissaBits;
|
|
|
|
|
i64 precision;
|
2023-11-10 20:47:08 +01:00
|
|
|
|
} ieee754 = {};
|
2023-09-20 10:48:44 +02:00
|
|
|
|
|
|
|
|
|
std::string specialNumbers[] = {
|
|
|
|
|
"inf" , "Inf", "INF" , "nan" , "Nan" , "NAN",
|
|
|
|
|
"qnan","Qnan", "QNAN", "snan", "Snan", "SNAN"
|
|
|
|
|
};
|
2021-09-22 17:56:06 +02:00
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
const auto totalBitCount = ieee754statics.exponentBitCount + ieee754statics.mantissaBitCount;
|
2022-05-29 14:57:59 +02:00
|
|
|
|
const auto signBitPosition = totalBitCount - 0;
|
|
|
|
|
const auto exponentBitPosition = totalBitCount - 1;
|
2023-09-20 10:48:44 +02:00
|
|
|
|
const auto mantissaBitPosition = totalBitCount - 1 - ieee754statics.exponentBitCount;
|
2022-05-29 14:57:59 +02:00
|
|
|
|
|
2023-10-15 22:07:51 +02:00
|
|
|
|
const static auto ExtractBits = [](u32 startBit, u32 count) {
|
|
|
|
|
return hex::extract(startBit, startBit - (count - 1), ieee754statics.value);
|
2023-05-19 21:18:38 +02:00
|
|
|
|
};
|
|
|
|
|
|
2023-10-15 22:07:51 +02:00
|
|
|
|
ieee754.signBits = ExtractBits(signBitPosition, 1);
|
|
|
|
|
ieee754.exponentBits = ExtractBits(exponentBitPosition, ieee754statics.exponentBitCount);
|
|
|
|
|
ieee754.mantissaBits = ExtractBits(mantissaBitPosition, ieee754statics.mantissaBitCount);
|
2023-09-20 10:48:44 +02:00
|
|
|
|
|
|
|
|
|
|
2023-10-15 22:07:51 +02:00
|
|
|
|
static i64 inputFieldWidth = 0;
|
|
|
|
|
ImGui::TextFormattedWrapped("{}", "hex.builtin.tools.ieee754.description"_lang);
|
|
|
|
|
ImGui::NewLine();
|
2023-09-20 10:48:44 +02:00
|
|
|
|
|
2023-10-15 22:07:51 +02:00
|
|
|
|
static i64 displayMode = ContentRegistry::Settings::read("hex.builtin.tools.ieee754.settings", "display_mode", 0);
|
|
|
|
|
i64 displayModeTemp = displayMode;
|
|
|
|
|
ImGui::RadioButton("hex.builtin.tools.ieee754.settings.display_mode.detailed"_lang, reinterpret_cast<int *>(&displayMode), 0);
|
|
|
|
|
ImGui::SameLine();
|
2023-09-20 10:48:44 +02:00
|
|
|
|
|
2023-10-15 22:07:51 +02:00
|
|
|
|
ImGui::RadioButton("hex.builtin.tools.ieee754.settings.display_mode.simplified"_lang, reinterpret_cast<int *>(&displayMode), 1);
|
|
|
|
|
if (displayModeTemp != displayMode) {
|
|
|
|
|
ContentRegistry::Settings::write("hex.builtin.tools.ieee754.settings", "display_mode", displayMode);
|
|
|
|
|
displayModeTemp = displayMode;
|
|
|
|
|
}
|
2023-09-20 10:48:44 +02:00
|
|
|
|
|
2023-10-15 22:07:51 +02:00
|
|
|
|
auto tableFlags = ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_NoKeepColumnsVisible |
|
|
|
|
|
ImGuiTableFlags_ScrollX | ImGuiTableFlags_NoPadInnerX;
|
2023-09-20 10:48:44 +02:00
|
|
|
|
|
2023-11-10 20:47:08 +01:00
|
|
|
|
const static auto IndentBoxOrLabel = [](u32 startBit, u32 bitIndex, u32 count, bool isLabel) {
|
|
|
|
|
auto checkBoxWidth = ImGui::CalcTextSize("0").x + ImGui::GetStyle().FramePadding.x * 2.0f;
|
2023-10-15 22:07:51 +02:00
|
|
|
|
auto columnWidth = ImGui::GetColumnWidth();
|
|
|
|
|
float boxesPerColumn=columnWidth/checkBoxWidth;
|
|
|
|
|
float result;
|
2023-09-20 10:48:44 +02:00
|
|
|
|
if (isLabel) {
|
2023-10-15 22:07:51 +02:00
|
|
|
|
std::string labelString = fmt::format("{}", bitIndex);
|
2023-09-20 10:48:44 +02:00
|
|
|
|
auto labelWidth = ImGui::CalcTextSize(labelString.c_str()).x;
|
2023-10-15 22:07:51 +02:00
|
|
|
|
auto leadingBoxes = (boxesPerColumn-count)/2.0f;
|
|
|
|
|
if (leadingBoxes < 0.0f)
|
|
|
|
|
leadingBoxes = 0.0f;
|
|
|
|
|
result = checkBoxWidth*(leadingBoxes + startBit - bitIndex + 0.5f)-labelWidth/2.0f;
|
|
|
|
|
} else {
|
2023-11-10 20:47:08 +01:00
|
|
|
|
if (count < boxesPerColumn)
|
2023-10-15 22:07:51 +02:00
|
|
|
|
result = (columnWidth - count * checkBoxWidth) / 2.0f;
|
|
|
|
|
else
|
|
|
|
|
result = 0.0;
|
2023-09-20 10:48:44 +02:00
|
|
|
|
}
|
2023-10-15 22:07:51 +02:00
|
|
|
|
if (result <= 0.0f)
|
|
|
|
|
result = 0.05;
|
|
|
|
|
return result;
|
2023-09-20 10:48:44 +02:00
|
|
|
|
};
|
2022-05-29 14:57:59 +02:00
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
const static auto DisplayBitLabels = [](int startBit, int count) {
|
2023-11-10 20:47:08 +01:00
|
|
|
|
static i32 lastLabelAdded = -1;
|
|
|
|
|
i32 labelIndex;
|
2023-09-20 10:48:44 +02:00
|
|
|
|
if (lastLabelAdded == -1 || count < 4)
|
|
|
|
|
labelIndex = startBit - (count >> 1);
|
2023-10-15 22:07:51 +02:00
|
|
|
|
else
|
2023-09-20 10:48:44 +02:00
|
|
|
|
labelIndex = lastLabelAdded - 4;
|
|
|
|
|
|
|
|
|
|
while (labelIndex + count > startBit) {
|
|
|
|
|
auto indentSize = IndentBoxOrLabel(startBit, labelIndex, count, true);
|
|
|
|
|
ImGui::Indent(indentSize );
|
|
|
|
|
ImGui::TextFormatted("{}", labelIndex);
|
|
|
|
|
lastLabelAdded = labelIndex;
|
|
|
|
|
ImGui::Unindent(indentSize );
|
|
|
|
|
labelIndex -= 4;
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2023-11-10 20:47:08 +01:00
|
|
|
|
const static auto FormatBitLabels = [](i32 totalBitCount, i32 exponentBitPosition, i32 mantissaBitPosition) {
|
2023-05-19 21:18:38 +02:00
|
|
|
|
// Row for bit labels. Due to font size constrains each bit cannot have its own label.
|
|
|
|
|
// Instead, we label each 4 bits and then use the bit position to determine the bit label.
|
2023-10-15 22:07:51 +02:00
|
|
|
|
// Result.
|
2023-05-19 21:18:38 +02:00
|
|
|
|
ImGui::TableNextColumn();
|
2023-10-15 22:07:51 +02:00
|
|
|
|
// Equals.
|
2023-05-19 21:18:38 +02:00
|
|
|
|
ImGui::TableNextColumn();
|
2023-10-15 22:07:51 +02:00
|
|
|
|
// Sign bit label is always shown.
|
2023-05-19 21:18:38 +02:00
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
DisplayBitLabels(totalBitCount + 1, 1);
|
2023-10-15 22:07:51 +02:00
|
|
|
|
// Times.
|
2023-05-19 21:18:38 +02:00
|
|
|
|
ImGui::TableNextColumn();
|
2023-10-15 22:07:51 +02:00
|
|
|
|
// Exponent.
|
2023-05-19 21:18:38 +02:00
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
DisplayBitLabels(exponentBitPosition + 1, ieee754statics.exponentBitCount);
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
2023-10-15 22:07:51 +02:00
|
|
|
|
// Times.
|
2023-05-19 21:18:38 +02:00
|
|
|
|
ImGui::TableNextColumn();
|
2023-10-15 22:07:51 +02:00
|
|
|
|
// Mantissa.
|
2023-05-19 21:18:38 +02:00
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
DisplayBitLabels(mantissaBitPosition + 1, ieee754statics.mantissaBitCount);
|
|
|
|
|
};
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
2023-10-15 22:07:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const static auto BitCheckbox = [](u8 bit) {
|
|
|
|
|
bool checkbox = false;
|
|
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f);
|
|
|
|
|
checkbox = (ieee754statics.value & (u128(1) << bit)) != 0;
|
|
|
|
|
ImGui::BitCheckbox("##checkbox", &checkbox);
|
|
|
|
|
ieee754statics.value = (ieee754statics.value & ~(u128(1) << bit)) | (u128(checkbox) << bit);
|
|
|
|
|
ImGui::PopStyleVar();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const static auto BitCheckboxes = [](u32 startBit, u32 count) {
|
|
|
|
|
for (u32 i = 0; i < count; i++) {
|
|
|
|
|
ImGui::PushID(startBit - i);
|
|
|
|
|
BitCheckbox(startBit - i);
|
|
|
|
|
ImGui::SameLine(0, 0);
|
|
|
|
|
ImGui::PopID();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2023-11-10 20:47:08 +01:00
|
|
|
|
const static auto FormatBits = [](i32 signBitPosition, i32 exponentBitPosition, i32 mantissaBitPosition) {
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
2023-10-15 22:07:51 +02:00
|
|
|
|
// Sign.
|
2022-05-29 14:57:59 +02:00
|
|
|
|
ImGui::TableNextColumn();
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
|
|
|
|
ImVec4 signColor = ImGui::GetCustomColorVec4(ImGuiCustomCol_IEEEToolSign);
|
|
|
|
|
ImVec4 expColor = ImGui::GetCustomColorVec4(ImGuiCustomCol_IEEEToolExp);
|
|
|
|
|
ImVec4 mantColor = ImGui::GetCustomColorVec4(ImGuiCustomCol_IEEEToolMantissa);
|
|
|
|
|
ImVec4 black = ImVec4(0.0, 0.0, 0.0, 1.0);
|
|
|
|
|
|
2023-10-15 22:07:51 +02:00
|
|
|
|
float indent = IndentBoxOrLabel(signBitPosition,signBitPosition, 1, false);
|
2023-09-20 10:48:44 +02:00
|
|
|
|
ImGui::Indent(indent);
|
2023-05-19 21:18:38 +02:00
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_FrameBg, signColor);
|
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_Border, black);
|
|
|
|
|
|
2022-05-29 14:57:59 +02:00
|
|
|
|
BitCheckboxes(signBitPosition, 1);
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
|
|
|
|
ImGui::PopStyleColor();
|
|
|
|
|
ImGui::PopStyleColor();
|
2023-09-20 10:48:44 +02:00
|
|
|
|
ImGui::Unindent(indent);
|
2022-05-29 14:57:59 +02:00
|
|
|
|
|
2023-10-15 22:07:51 +02:00
|
|
|
|
// Times.
|
2023-05-19 21:18:38 +02:00
|
|
|
|
ImGui::TableNextColumn();
|
2023-10-15 22:07:51 +02:00
|
|
|
|
// Exponent.
|
2022-05-29 14:57:59 +02:00
|
|
|
|
ImGui::TableNextColumn();
|
2023-09-20 10:48:44 +02:00
|
|
|
|
indent = IndentBoxOrLabel(exponentBitPosition,exponentBitPosition, ieee754statics.exponentBitCount, false);
|
|
|
|
|
ImGui::Indent(indent);
|
2023-05-19 21:18:38 +02:00
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_FrameBg, expColor);
|
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_Border, black);
|
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
BitCheckboxes(exponentBitPosition, ieee754statics.exponentBitCount);
|
2022-05-29 14:57:59 +02:00
|
|
|
|
|
2023-05-19 21:18:38 +02:00
|
|
|
|
ImGui::PopStyleColor();
|
|
|
|
|
ImGui::PopStyleColor();
|
2023-09-20 10:48:44 +02:00
|
|
|
|
ImGui::Unindent(indent);
|
2023-10-15 22:07:51 +02:00
|
|
|
|
// Times.
|
2023-05-19 21:18:38 +02:00
|
|
|
|
ImGui::TableNextColumn();
|
2023-10-15 22:07:51 +02:00
|
|
|
|
// Mantissa.
|
2022-05-29 14:57:59 +02:00
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
indent = IndentBoxOrLabel(mantissaBitPosition,mantissaBitPosition, ieee754statics.mantissaBitCount, false);
|
|
|
|
|
ImGui::Indent(indent);
|
2023-05-19 21:18:38 +02:00
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_FrameBg, mantColor);
|
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_Border, black);
|
2021-09-22 17:56:06 +02:00
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
BitCheckboxes(mantissaBitPosition, ieee754statics.mantissaBitCount);
|
2021-09-22 17:56:06 +02:00
|
|
|
|
|
2023-05-19 21:18:38 +02:00
|
|
|
|
ImGui::PopStyleColor();
|
|
|
|
|
ImGui::PopStyleColor();
|
2023-09-20 10:48:44 +02:00
|
|
|
|
ImGui::Unindent(indent);
|
|
|
|
|
};
|
2021-09-22 17:56:06 +02:00
|
|
|
|
|
2023-10-15 22:07:51 +02:00
|
|
|
|
const static auto BitsToFloat = [](IEEE754 &ieee754) {
|
|
|
|
|
// Zero or denormal.
|
|
|
|
|
if (ieee754.exponentBits == 0) {
|
|
|
|
|
// Result doesn't fit in 128 bits.
|
|
|
|
|
if ((ieee754.exponentBias - 1) > 128)
|
|
|
|
|
ieee754.exponentValue = std::pow(2.0L, static_cast<long double>(-ieee754.exponentBias + 1));
|
|
|
|
|
else {
|
|
|
|
|
if (ieee754.exponentBias == 0) {
|
|
|
|
|
// Exponent is zero.
|
|
|
|
|
if (ieee754.mantissaBits == 0)
|
|
|
|
|
ieee754.exponentValue = 1.0;
|
|
|
|
|
else
|
|
|
|
|
// Exponent is one.
|
|
|
|
|
ieee754.exponentValue = 2.0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
ieee754.exponentValue = 1.0 / static_cast<long double>(u128(1) << (ieee754.exponentBias - 1));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Normal.
|
|
|
|
|
else {
|
|
|
|
|
// Result doesn't fit in 128 bits.
|
|
|
|
|
if (std::abs(ieee754.exponentBits - ieee754.exponentBias) > 128)
|
|
|
|
|
ieee754.exponentValue = std::pow(2.0L, static_cast<long double>(ieee754.exponentBits - ieee754.exponentBias));
|
|
|
|
|
//Result fits in 128 bits.
|
|
|
|
|
else {
|
|
|
|
|
// Exponent is positive.
|
|
|
|
|
if (ieee754.exponentBits > ieee754.exponentBias)
|
|
|
|
|
ieee754.exponentValue = static_cast<long double>(u128(1) << (ieee754.exponentBits - ieee754.exponentBias));
|
|
|
|
|
// Exponent is negative.
|
|
|
|
|
else if (ieee754.exponentBits < ieee754.exponentBias)
|
|
|
|
|
ieee754.exponentValue = 1.0 / static_cast<long double>(u128(1) << (ieee754.exponentBias - ieee754.exponentBits));
|
|
|
|
|
// Exponent is zero.
|
|
|
|
|
else ieee754.exponentValue = 1.0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ieee754.mantissaValue = static_cast<long double>(ieee754.mantissaBits) / static_cast<long double>(u128(1) << (ieee754statics.mantissaBitCount));
|
|
|
|
|
if (ieee754.exponentBits != 0)
|
|
|
|
|
ieee754.mantissaValue += 1.0;
|
|
|
|
|
|
|
|
|
|
// Check if all exponent bits are set.
|
|
|
|
|
if (std::popcount(static_cast<u64>(ieee754.exponentBits)) == static_cast<i64>(ieee754statics.exponentBitCount)) {
|
|
|
|
|
// If fraction is zero number is infinity,
|
|
|
|
|
if (ieee754.mantissaBits == 0) {
|
|
|
|
|
if (ieee754.signBits == 0) {
|
|
|
|
|
|
|
|
|
|
ieee754.valueType = ValueType::PositiveInfinity;
|
|
|
|
|
ieee754statics.resultFloat = std::numeric_limits<long double>::infinity();
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
ieee754.valueType = ValueType::NegativeInfinity;
|
|
|
|
|
ieee754statics.resultFloat = -std::numeric_limits<long double>::infinity();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
ieee754.numberType = NumberType::Infinity;
|
|
|
|
|
|
|
|
|
|
// otherwise number is NaN.
|
|
|
|
|
} else {
|
|
|
|
|
if (ieee754.mantissaBits & (u128(1) << (ieee754statics.mantissaBitCount - 1))) {
|
|
|
|
|
|
|
|
|
|
ieee754.valueType = ValueType::QuietNaN;
|
|
|
|
|
ieee754statics.resultFloat = std::numeric_limits<long double>::quiet_NaN();
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
ieee754.valueType = ValueType::SignalingNaN;
|
|
|
|
|
ieee754statics.resultFloat = std::numeric_limits<long double>::signaling_NaN();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
ieee754.numberType = NumberType::NaN;
|
|
|
|
|
}
|
|
|
|
|
// If all exponent bits are zero, but we have a non-zero fraction
|
|
|
|
|
// then the number is denormal which are smaller than regular numbers
|
|
|
|
|
// but not as precise.
|
|
|
|
|
} else if (ieee754.exponentBits == 0 && ieee754.mantissaBits != 0) {
|
|
|
|
|
|
|
|
|
|
ieee754.numberType = NumberType::Denormal;
|
|
|
|
|
ieee754.valueType = ValueType::Regular;
|
|
|
|
|
ieee754statics.resultFloat = ieee754.signValue * ieee754.exponentValue * ieee754.mantissaValue;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
ieee754.numberType = NumberType::Normal;
|
|
|
|
|
ieee754.valueType = ValueType::Regular;
|
|
|
|
|
ieee754statics.resultFloat = ieee754.signValue * ieee754.exponentValue * ieee754.mantissaValue;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2023-10-04 12:00:32 +02:00
|
|
|
|
const static auto FloatToBits = [&specialNumbers](IEEE754 &ieee754, std::string decimalFloatingPointNumberString, int totalBitCount) {
|
2021-09-22 17:56:06 +02:00
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
// Always obtain sign first.
|
|
|
|
|
if (decimalFloatingPointNumberString[0] == '-') {
|
2023-10-04 12:00:32 +02:00
|
|
|
|
// And remove it from the string.
|
2023-09-20 10:48:44 +02:00
|
|
|
|
ieee754.signBits = 1;
|
|
|
|
|
decimalFloatingPointNumberString.erase(0, 1);
|
|
|
|
|
} else
|
2023-10-04 12:00:32 +02:00
|
|
|
|
// Important to switch from - to +.
|
2023-09-20 10:48:44 +02:00
|
|
|
|
ieee754.signBits = 0;
|
|
|
|
|
|
2023-11-10 20:47:08 +01:00
|
|
|
|
InputType inputType = InputType::Regular;
|
2023-09-20 10:48:44 +02:00
|
|
|
|
bool matchFound = false;
|
2023-11-10 20:47:08 +01:00
|
|
|
|
|
2023-10-04 12:00:32 +02:00
|
|
|
|
// Detect and use special numbers.
|
2023-11-10 20:47:08 +01:00
|
|
|
|
for (u32 i = 0; i < 12; i++) {
|
2023-09-20 10:48:44 +02:00
|
|
|
|
if (decimalFloatingPointNumberString == specialNumbers[i]) {
|
|
|
|
|
inputType = InputType(i/3);
|
|
|
|
|
matchFound = true;
|
|
|
|
|
break;
|
2023-05-19 21:18:38 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-09-22 17:56:06 +02:00
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
if (!matchFound)
|
2023-11-10 20:47:08 +01:00
|
|
|
|
inputType = InputType::Regular;
|
2022-08-04 13:24:53 +02:00
|
|
|
|
|
2023-11-10 20:47:08 +01:00
|
|
|
|
if (inputType == InputType::Regular) {
|
2023-10-04 12:00:32 +02:00
|
|
|
|
try {
|
|
|
|
|
ieee754statics.resultFloat = stod(decimalFloatingPointNumberString);
|
|
|
|
|
} catch(const std::invalid_argument& _) {
|
2023-11-10 20:47:08 +01:00
|
|
|
|
inputType = InputType::Invalid;
|
2023-09-20 10:48:44 +02:00
|
|
|
|
}
|
2023-11-10 20:47:08 +01:00
|
|
|
|
} else if (inputType == InputType::Infinity) {
|
2023-09-20 10:48:44 +02:00
|
|
|
|
ieee754statics.resultFloat = std::numeric_limits<long double>::infinity();
|
|
|
|
|
ieee754statics.resultFloat *= (ieee754.signBits == 1 ? -1 : 1);
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
2023-11-10 20:47:08 +01:00
|
|
|
|
} else if (inputType == InputType::NotANumber)
|
2023-09-20 10:48:44 +02:00
|
|
|
|
ieee754statics.resultFloat = std::numeric_limits<long double>::quiet_NaN();
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
2023-11-10 20:47:08 +01:00
|
|
|
|
else if (inputType == InputType::QuietNotANumber)
|
2023-09-20 10:48:44 +02:00
|
|
|
|
ieee754statics.resultFloat = std::numeric_limits<long double>::quiet_NaN();
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
2023-11-10 20:47:08 +01:00
|
|
|
|
else if (inputType == InputType::SignalingNotANumber)
|
2023-09-20 10:48:44 +02:00
|
|
|
|
ieee754statics.resultFloat = std::numeric_limits<long double>::signaling_NaN();
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
|
|
|
|
|
2023-11-10 20:47:08 +01:00
|
|
|
|
if (inputType != InputType::Invalid) {
|
2023-10-04 12:00:32 +02:00
|
|
|
|
// Deal with zero first so we can use log2.
|
2023-09-20 10:48:44 +02:00
|
|
|
|
if (ieee754statics.resultFloat == 0.0) {
|
|
|
|
|
if (ieee754.signBits == 1)
|
|
|
|
|
ieee754statics.resultFloat = -0.0;
|
|
|
|
|
else
|
|
|
|
|
ieee754statics.resultFloat = 0.0;
|
|
|
|
|
ieee754.numberType = NumberType::Zero;
|
|
|
|
|
ieee754.valueType = ValueType::Regular;
|
|
|
|
|
ieee754.exponentBits = 0;
|
|
|
|
|
ieee754.mantissaBits = 0;
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
} else {
|
2023-11-10 20:47:08 +01:00
|
|
|
|
long double log2Result = std::log2(ieee754statics.resultFloat);
|
2023-09-20 10:48:44 +02:00
|
|
|
|
// 2^(bias+1)-2^(bias-prec) is the largest number that can be represented.
|
|
|
|
|
// If the number entered is larger than this then the input is set to infinity.
|
2023-11-10 20:47:08 +01:00
|
|
|
|
if (ieee754statics.resultFloat > (std::pow(2.0L, ieee754.exponentBias + 1) - std::pow(2.0L, ieee754.exponentBias - ieee754statics.mantissaBitCount)) || inputType == InputType::Infinity ) {
|
2023-09-20 10:48:44 +02:00
|
|
|
|
|
|
|
|
|
ieee754statics.resultFloat = std::numeric_limits<long double>::infinity();
|
|
|
|
|
ieee754.numberType = NumberType::Infinity;
|
|
|
|
|
ieee754.valueType = ieee754.signBits == 1 ? ValueType::NegativeInfinity : ValueType::PositiveInfinity;
|
|
|
|
|
ieee754.exponentBits = (u128(1) << ieee754statics.exponentBitCount) - 1;
|
|
|
|
|
ieee754.mantissaBits = 0;
|
|
|
|
|
|
|
|
|
|
} else if (-std::rint(log2Result) > ieee754.exponentBias + ieee754statics.mantissaBitCount - 1) {
|
|
|
|
|
|
|
|
|
|
// 1/2^(bias-1+prec) is the smallest number that can be represented.
|
|
|
|
|
// If the number entered is smaller than this then the input is set to zero.
|
|
|
|
|
if (ieee754.signBits == 1)
|
|
|
|
|
ieee754statics.resultFloat = -0.0;
|
|
|
|
|
else
|
|
|
|
|
ieee754statics.resultFloat = 0.0;
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
ieee754.numberType = NumberType::Zero;
|
|
|
|
|
ieee754.valueType = ValueType::Regular;
|
|
|
|
|
ieee754.exponentBits = 0;
|
|
|
|
|
ieee754.mantissaBits = 0;
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
2023-11-10 20:47:08 +01:00
|
|
|
|
} else if (inputType == InputType::SignalingNotANumber) {
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
ieee754statics.resultFloat = std::numeric_limits<long double>::signaling_NaN();
|
|
|
|
|
ieee754.valueType = ValueType::SignalingNaN;
|
|
|
|
|
ieee754.numberType = NumberType::NaN;
|
|
|
|
|
ieee754.exponentBits = (u128(1) << ieee754statics.exponentBitCount) - 1;
|
|
|
|
|
ieee754.mantissaBits = 1;
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
2023-11-10 20:47:08 +01:00
|
|
|
|
} else if (inputType == InputType::QuietNotANumber || inputType == InputType::NotANumber ) {
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
ieee754statics.resultFloat = std::numeric_limits<long double>::quiet_NaN();
|
|
|
|
|
ieee754.valueType = ValueType::QuietNaN;
|
|
|
|
|
ieee754.numberType = NumberType::NaN;
|
|
|
|
|
ieee754.exponentBits = (u128(1) << ieee754statics.exponentBitCount) - 1;
|
|
|
|
|
ieee754.mantissaBits = (u128(1) << (ieee754statics.mantissaBitCount - 1));
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
} else if (static_cast<i64>(std::floor(log2Result)) + ieee754.exponentBias <= 0) {
|
2022-08-04 13:24:53 +02:00
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
ieee754.numberType = NumberType::Denormal;
|
|
|
|
|
ieee754.valueType = ValueType::Regular;
|
|
|
|
|
ieee754.exponentBits = 0;
|
|
|
|
|
auto mantissaExp = log2Result + ieee754.exponentBias + ieee754statics.mantissaBitCount - 1;
|
|
|
|
|
ieee754.mantissaBits = static_cast<i64>(std::round(std::pow(2.0L, mantissaExp)));
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
} else {
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
ieee754.valueType = ValueType::Regular;
|
|
|
|
|
ieee754.numberType = NumberType::Normal;
|
|
|
|
|
i64 unBiasedExponent = static_cast<i64>(std::floor(log2Result));
|
|
|
|
|
ieee754.exponentBits = unBiasedExponent + ieee754.exponentBias;
|
|
|
|
|
ieee754.mantissaValue = ieee754statics.resultFloat * std::pow(2.0L, -unBiasedExponent) - 1;
|
|
|
|
|
ieee754.mantissaBits = static_cast<i64>(std::round( static_cast<long double>(u128(1) << (ieee754statics.mantissaBitCount)) * ieee754.mantissaValue));
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-20 10:48:44 +02:00
|
|
|
|
// Put the bits together.
|
|
|
|
|
ieee754statics.value = (ieee754.signBits << (totalBitCount)) | (ieee754.exponentBits << (totalBitCount - ieee754statics.exponentBitCount)) | ieee754.mantissaBits;
|
|
|
|
|
}
|
|
|
|
|
};
|
2021-12-16 23:48:52 +01:00
|
|
|
|
|
2023-10-15 22:07:51 +02:00
|
|
|
|
const static auto DisplayDecimal = [](IEEE754 &ieee754) {
|
|
|
|
|
|
|
|
|
|
unsigned signColorU32 = ImGui::GetCustomColorU32(ImGuiCustomCol_IEEEToolSign);
|
|
|
|
|
unsigned expColorU32 = ImGui::GetCustomColorU32(ImGuiCustomCol_IEEEToolExp);
|
|
|
|
|
unsigned mantColorU32 = ImGui::GetCustomColorU32(ImGuiCustomCol_IEEEToolMantissa);
|
|
|
|
|
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
|
|
|
|
|
ImGui::Text("=");
|
|
|
|
|
|
|
|
|
|
// Sign.
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
|
|
|
|
|
// This has the effect of dimming the color of the numbers so user doesn't try
|
|
|
|
|
// to interact with them.
|
|
|
|
|
ImVec4 textColor = ImGui::GetStyleColorVec4(ImGuiCol_Text);
|
|
|
|
|
ImGui::BeginDisabled();
|
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_Text, textColor);
|
|
|
|
|
|
|
|
|
|
ImGui::Indent(10_scaled);
|
|
|
|
|
ImGui::TableSetBgColor(ImGuiTableBgTarget_CellBg, signColorU32);
|
|
|
|
|
if (ieee754.signBits == 1)
|
|
|
|
|
ImGui::Text("-1");
|
|
|
|
|
else
|
|
|
|
|
ImGui::Text("+1");
|
|
|
|
|
ImGui::Unindent(10_scaled);
|
|
|
|
|
|
|
|
|
|
// Times.
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
ImGui::Text("x");
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
|
|
|
|
|
// Exponent.
|
|
|
|
|
ImGui::TableSetBgColor(ImGuiTableBgTarget_CellBg, expColorU32);
|
|
|
|
|
|
|
|
|
|
ImGui::Indent(20_scaled);
|
|
|
|
|
if (ieee754.numberType == NumberType::NaN) {
|
|
|
|
|
if (ieee754.valueType == ValueType::QuietNaN)
|
|
|
|
|
ImGui::Text("qNaN");
|
|
|
|
|
else
|
|
|
|
|
ImGui::Text("sNaN");
|
|
|
|
|
|
|
|
|
|
} else if (ieee754.numberType == NumberType::Infinity)
|
|
|
|
|
ImGui::Text("Inf");
|
|
|
|
|
else if (ieee754.numberType == NumberType::Zero)
|
|
|
|
|
ImGui::Text("0");
|
|
|
|
|
else if (ieee754.numberType == NumberType::Denormal)
|
|
|
|
|
ImGui::TextFormatted("2^{0}", 1 - ieee754.exponentBias);
|
|
|
|
|
else
|
|
|
|
|
ImGui::TextFormatted("2^{0}", ieee754.exponentBits - ieee754.exponentBias);
|
|
|
|
|
|
|
|
|
|
ImGui::Unindent(20_scaled);
|
|
|
|
|
|
|
|
|
|
// Times.
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
ImGui::Text("x");
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
|
|
|
|
|
// Mantissa.
|
|
|
|
|
ImGui::TableSetBgColor(ImGuiTableBgTarget_CellBg, mantColorU32);
|
|
|
|
|
ImGui::Indent(20_scaled);
|
|
|
|
|
ImGui::TextFormatted("{:.{}}", ieee754.mantissaValue,ieee754.precision);
|
|
|
|
|
ImGui::Unindent(20_scaled);
|
|
|
|
|
|
|
|
|
|
ImGui::PopStyleColor();
|
|
|
|
|
ImGui::EndDisabled();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
const static auto ToolMenu = [](i64 &inputFieldWidth) {
|
2023-10-15 22:07:51 +02:00
|
|
|
|
// If precision and exponent match one of the IEEE 754 formats the format is highlighted
|
|
|
|
|
// and remains highlighted until user changes to a different format. Matching formats occur when
|
2023-09-20 10:48:44 +02:00
|
|
|
|
// the user clicks on one of the selections or if the slider values match the format in question.
|
2023-10-04 12:00:32 +02:00
|
|
|
|
// When a new format is selected, it may have a smaller number of digits than
|
2023-09-20 10:48:44 +02:00
|
|
|
|
// the previous selection. Since the largest of the hexadecimal and the decimal
|
2023-10-04 12:00:32 +02:00
|
|
|
|
// representation widths set both field widths to the same value, we need to
|
2023-09-20 10:48:44 +02:00
|
|
|
|
// reset it here when a new choice is set.
|
|
|
|
|
|
|
|
|
|
auto exponentBitCount = ieee754statics.exponentBitCount;
|
|
|
|
|
auto mantissaBitCount = ieee754statics.mantissaBitCount;
|
|
|
|
|
if (ImGui::SliderInt("hex.builtin.tools.ieee754.exponent_size"_lang, &exponentBitCount, 1, 63 - mantissaBitCount)) {
|
|
|
|
|
inputFieldWidth = 0;
|
|
|
|
|
ieee754statics.exponentBitCount = exponentBitCount;
|
|
|
|
|
}
|
|
|
|
|
if (ImGui::SliderInt("hex.builtin.tools.ieee754.mantissa_size"_lang, &mantissaBitCount, 1, 63 - exponentBitCount)) {
|
|
|
|
|
inputFieldWidth = 0;
|
|
|
|
|
ieee754statics.mantissaBitCount = mantissaBitCount;
|
|
|
|
|
}
|
|
|
|
|
ImGui::Separator();
|
2021-09-22 17:56:06 +02:00
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
auto color = ImGui::GetColorU32(ImGuiCol_ButtonActive);
|
2021-09-22 17:56:06 +02:00
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
bool needsPop = false;
|
|
|
|
|
if (ieee754statics.exponentBitCount == 5 && ieee754statics.mantissaBitCount == 10) {
|
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_Button, color);
|
|
|
|
|
needsPop = true;
|
|
|
|
|
}
|
|
|
|
|
if (ImGui::Button("hex.builtin.tools.ieee754.half_precision"_lang)) {
|
|
|
|
|
ieee754statics.exponentBitCount = 5;
|
|
|
|
|
ieee754statics.mantissaBitCount = 10;
|
|
|
|
|
inputFieldWidth = 0;
|
|
|
|
|
}
|
|
|
|
|
if (needsPop) ImGui::PopStyleColor();
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
ImGui::SameLine();
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
needsPop = false;
|
|
|
|
|
if (ieee754statics.exponentBitCount == 8 && ieee754statics.mantissaBitCount == 23) {
|
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_Button, color);
|
|
|
|
|
needsPop = true;
|
|
|
|
|
}
|
|
|
|
|
if (ImGui::Button("hex.builtin.tools.ieee754.single_precision"_lang)) {
|
|
|
|
|
ieee754statics.exponentBitCount = 8;
|
|
|
|
|
ieee754statics.mantissaBitCount = 23;
|
|
|
|
|
inputFieldWidth = 0;
|
|
|
|
|
}
|
|
|
|
|
if (needsPop) ImGui::PopStyleColor();
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
ImGui::SameLine();
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
needsPop = false;
|
|
|
|
|
if (ieee754statics.exponentBitCount == 11 && ieee754statics.mantissaBitCount == 52) {
|
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_Button, color);
|
|
|
|
|
needsPop = true;
|
|
|
|
|
}
|
|
|
|
|
if (ImGui::Button("hex.builtin.tools.ieee754.double_precision"_lang)) {
|
|
|
|
|
ieee754statics.exponentBitCount = 11;
|
|
|
|
|
ieee754statics.mantissaBitCount = 52;
|
|
|
|
|
inputFieldWidth = 0;
|
|
|
|
|
}
|
|
|
|
|
if (needsPop) ImGui::PopStyleColor();
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
ImGui::SameLine();
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
needsPop = false;
|
|
|
|
|
if (ImGui::Button("hex.builtin.tools.ieee754.clear"_lang))
|
2023-10-04 12:00:32 +02:00
|
|
|
|
// This will reset all interactive widgets to zero.
|
2023-09-20 10:48:44 +02:00
|
|
|
|
ieee754statics.value = 0;
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
ImGui::Separator();
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
ImGui::NewLine();
|
|
|
|
|
};
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
if (ImGui::BeginTable("##outer", 7, tableFlags, ImVec2(0, ImGui::GetTextLineHeightWithSpacing() * 5.5 ))) {
|
|
|
|
|
ImGui::TableSetupColumn("hex.builtin.tools.ieee754.result.title"_lang);
|
|
|
|
|
ImGui::TableSetupColumn("##equals");
|
|
|
|
|
ImGui::TableSetupColumn("hex.builtin.tools.ieee754.sign"_lang);
|
|
|
|
|
ImGui::TableSetupColumn("##times");
|
|
|
|
|
ImGui::TableSetupColumn("hex.builtin.tools.ieee754.exponent"_lang);
|
|
|
|
|
ImGui::TableSetupColumn("##times");
|
|
|
|
|
ImGui::TableSetupColumn("hex.builtin.tools.ieee754.mantissa"_lang);
|
|
|
|
|
ImGui::TableHeadersRow();
|
|
|
|
|
ImGui::TableNextRow();
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
FormatBitLabels(totalBitCount, exponentBitPosition, mantissaBitPosition);
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
2021-09-22 17:56:06 +02:00
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
ImGui::TableNextRow();
|
|
|
|
|
// Row for bit checkboxes
|
2023-10-15 22:07:51 +02:00
|
|
|
|
// Result.
|
2023-09-20 10:48:44 +02:00
|
|
|
|
ImGui::TableNextColumn();
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
u64 mask = hex::bitmask(totalBitCount+1);
|
|
|
|
|
std::string maskString = hex::format("0x{:X} ", mask);
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
auto style = ImGui::GetStyle();
|
|
|
|
|
inputFieldWidth = std::fmax(inputFieldWidth,
|
2023-10-15 22:07:51 +02:00
|
|
|
|
ImGui::CalcTextSize(maskString.c_str()).x + style.FramePadding.x * 2.0f);
|
2023-09-20 10:48:44 +02:00
|
|
|
|
ImGui::PushItemWidth(inputFieldWidth);
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
u64 newValue = ieee754statics.value & mask;
|
|
|
|
|
if (ImGui::InputHexadecimal("##hex", &newValue, flags))
|
|
|
|
|
ieee754statics.value = newValue;
|
|
|
|
|
ImGui::PopItemWidth();
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
2023-10-15 22:07:51 +02:00
|
|
|
|
// Equals.
|
2023-09-20 10:48:44 +02:00
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
ImGui::Text("=");
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
FormatBits(signBitPosition, exponentBitPosition, mantissaBitPosition);
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
ImGui::TableNextRow();
|
|
|
|
|
ImGui::TableNextColumn();
|
2021-09-22 17:56:06 +02:00
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
ieee754.exponentBias = (u128(1) << (ieee754statics.exponentBitCount - 1)) - 1;
|
2021-09-22 17:56:06 +02:00
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
ieee754.signValue = ieee754.signBits == 0 ? 1.0 : -1.0;
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
BitsToFloat(ieee754);
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
if (ieee754.numberType == NumberType::Denormal)
|
|
|
|
|
ieee754.precision = std::ceil(1+ieee754statics.mantissaBitCount * std::log10(2.0L));
|
|
|
|
|
else
|
|
|
|
|
ieee754.precision = std::ceil(1+(ieee754statics.mantissaBitCount + 1) * std::log10(2.0L));
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
// For C++ from_chars is better than strtold.
|
2023-10-04 12:00:32 +02:00
|
|
|
|
// The main problem is that from_chars will not process special numbers
|
2023-10-15 22:07:51 +02:00
|
|
|
|
// like inf and nan, so we handle them manually.
|
2023-09-20 10:48:44 +02:00
|
|
|
|
static std::string decimalFloatingPointNumberString;
|
2023-10-04 12:00:32 +02:00
|
|
|
|
|
2023-10-15 22:07:51 +02:00
|
|
|
|
// Use qnan for quiet NaN and snan for signaling NaN.
|
2023-09-20 10:48:44 +02:00
|
|
|
|
if (ieee754.numberType == NumberType::NaN) {
|
|
|
|
|
if (ieee754.valueType == ValueType::QuietNaN)
|
|
|
|
|
decimalFloatingPointNumberString = "qnan";
|
|
|
|
|
else
|
|
|
|
|
decimalFloatingPointNumberString = "snan";
|
|
|
|
|
} else
|
|
|
|
|
decimalFloatingPointNumberString = fmt::format("{:.{}}", ieee754statics.resultFloat, ieee754.precision);
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
auto style1 = ImGui::GetStyle();
|
|
|
|
|
inputFieldWidth = std::fmax(inputFieldWidth, ImGui::CalcTextSize(decimalFloatingPointNumberString.c_str()).x + 2 * style1.FramePadding.x);
|
|
|
|
|
ImGui::PushItemWidth(inputFieldWidth);
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
// We allow any input in order to accept infinities and NaNs, all invalid entries
|
2023-10-15 22:07:51 +02:00
|
|
|
|
// are detected catching exceptions. You can also enter -0 or -inf.
|
2023-09-20 10:48:44 +02:00
|
|
|
|
if (ImGui::InputText("##resultFloat", decimalFloatingPointNumberString, flags)) {
|
2023-10-04 12:00:32 +02:00
|
|
|
|
FloatToBits(ieee754, decimalFloatingPointNumberString, totalBitCount);
|
2023-09-20 10:48:44 +02:00
|
|
|
|
}
|
|
|
|
|
ImGui::PopItemWidth();
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
if (displayMode == 0)
|
|
|
|
|
DisplayDecimal(ieee754);
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
ImGui::EndTable();
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-20 10:48:44 +02:00
|
|
|
|
ToolMenu(inputFieldWidth);
|
2021-09-22 17:56:06 +02:00
|
|
|
|
}
|
2022-05-29 14:57:59 +02:00
|
|
|
|
|
2023-05-19 21:18:38 +02:00
|
|
|
|
|
2023-01-19 17:01:41 +01:00
|
|
|
|
void drawInvariantMultiplicationDecoder() {
|
|
|
|
|
static u64 divisor = 1;
|
|
|
|
|
static u64 multiplier = 1;
|
|
|
|
|
static u64 numBits = 32;
|
|
|
|
|
|
|
|
|
|
ImGui::TextFormattedWrapped("{}", "hex.builtin.tools.invariant_multiplication.description"_lang);
|
|
|
|
|
|
|
|
|
|
ImGui::NewLine();
|
|
|
|
|
|
|
|
|
|
if (ImGui::BeginChild("##calculator", ImVec2(0, ImGui::GetTextLineHeightWithSpacing() * 5), true)) {
|
2023-11-10 20:47:08 +01:00
|
|
|
|
constexpr static u64 min = 1, max = 64;
|
2023-01-19 17:01:41 +01:00
|
|
|
|
ImGui::SliderScalar("hex.builtin.tools.invariant_multiplication.num_bits"_lang, ImGuiDataType_U64, &numBits, &min, &max);
|
|
|
|
|
ImGui::NewLine();
|
|
|
|
|
|
|
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0));
|
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImGui::GetStyleColorVec4(ImGuiCol_TableRowBgAlt));
|
|
|
|
|
if (ImGui::BeginChild("##calculator", ImVec2(0, ImGui::GetTextLineHeightWithSpacing() + 12_scaled), true)) {
|
|
|
|
|
ImGui::PushItemWidth(100_scaled);
|
|
|
|
|
|
|
|
|
|
ImGui::TextUnformatted("X /");
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::InputScalar("##divisor", ImGuiDataType_U64, &divisor)) {
|
|
|
|
|
if (divisor == 0)
|
|
|
|
|
divisor = 1;
|
|
|
|
|
|
|
|
|
|
multiplier = ((1LLU << (numBits + 1)) / divisor) + 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
|
|
|
|
|
ImGui::TextUnformatted(" <=> ");
|
|
|
|
|
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
ImGui::TextUnformatted("( X *");
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::InputHexadecimal("##multiplier", &multiplier)) {
|
|
|
|
|
if (multiplier == 0)
|
|
|
|
|
multiplier = 1;
|
|
|
|
|
divisor = ((1LLU << (numBits + 1)) / multiplier) + 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
ImGui::TextFormatted(") >> {}", numBits + 1);
|
|
|
|
|
|
|
|
|
|
ImGui::PopItemWidth();
|
|
|
|
|
}
|
|
|
|
|
ImGui::EndChild();
|
|
|
|
|
ImGui::PopStyleColor();
|
|
|
|
|
|
|
|
|
|
ImGui::PopStyleVar();
|
|
|
|
|
}
|
|
|
|
|
ImGui::EndChild();
|
|
|
|
|
}
|
2023-10-22 00:46:45 +02:00
|
|
|
|
|
|
|
|
|
void drawTCPClientServer() {
|
|
|
|
|
if (ImGui::BeginTabBar("##tcpTransceiver", ImGuiTabBarFlags_None)) {
|
|
|
|
|
if (ImGui::BeginTabItem("hex.builtin.tools.tcp_client_server.client"_lang)) {
|
|
|
|
|
static wolv::net::SocketClient client;
|
|
|
|
|
|
|
|
|
|
static std::string ipAddress;
|
|
|
|
|
static int port;
|
|
|
|
|
|
|
|
|
|
static std::vector<std::string> messages;
|
|
|
|
|
static std::string input;
|
|
|
|
|
static std::jthread receiverThread;
|
|
|
|
|
static std::mutex receiverMutex;
|
|
|
|
|
|
|
|
|
|
ImGui::Header("hex.builtin.tools.tcp_client_server.settings"_lang, true);
|
2023-11-05 00:10:59 +01:00
|
|
|
|
|
|
|
|
|
ImGui::BeginDisabled(client.isConnected());
|
|
|
|
|
{
|
|
|
|
|
ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x * 0.3F);
|
|
|
|
|
ImGui::InputText("##ipAddress", ipAddress);
|
|
|
|
|
ImGui::PopItemWidth();
|
|
|
|
|
ImGui::SameLine(0, 0);
|
|
|
|
|
ImGui::TextUnformatted(":");
|
|
|
|
|
ImGui::SameLine(0, 0);
|
|
|
|
|
ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x * 0.2F);
|
|
|
|
|
ImGui::InputInt("##port", &port, 0, 0);
|
|
|
|
|
ImGui::PopItemWidth();
|
|
|
|
|
}
|
|
|
|
|
ImGui::EndDisabled();
|
|
|
|
|
|
2023-10-22 00:46:45 +02:00
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
|
|
|
|
|
ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x * 0.2F);
|
|
|
|
|
if (client.isConnected()) {
|
|
|
|
|
if (ImGui::IconButton(ICON_VS_DEBUG_DISCONNECT, ImGui::GetCustomColorVec4(ImGuiCustomCol_ToolbarRed))) {
|
|
|
|
|
client.disconnect();
|
|
|
|
|
|
|
|
|
|
receiverThread.request_stop();
|
|
|
|
|
receiverThread.join();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (ImGui::IconButton(ICON_VS_PLAY, ImGui::GetCustomColorVec4(ImGuiCustomCol_ToolbarGreen))) {
|
|
|
|
|
client.connect(ipAddress, port);
|
|
|
|
|
|
|
|
|
|
receiverThread = std::jthread([](const std::stop_token& stopToken) {
|
|
|
|
|
while (!stopToken.stop_requested()) {
|
|
|
|
|
auto message = client.readString();
|
|
|
|
|
if (!message.empty()) {
|
|
|
|
|
std::scoped_lock lock(receiverMutex);
|
|
|
|
|
messages.push_back(message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ImGui::PopItemWidth();
|
|
|
|
|
|
|
|
|
|
if (port < 1)
|
|
|
|
|
port = 1;
|
|
|
|
|
else if (port > 65535)
|
|
|
|
|
port = 65535;
|
|
|
|
|
|
|
|
|
|
ImGui::Header("hex.builtin.tools.tcp_client_server.messages"_lang);
|
2023-11-05 21:52:12 +01:00
|
|
|
|
if (ImGui::BeginTable("##response", 1, ImGuiTableFlags_ScrollY | ImGuiTableFlags_RowBg | ImGuiTableFlags_Borders, ImVec2(0, 200_scaled))) {
|
2023-10-22 00:46:45 +02:00
|
|
|
|
{
|
|
|
|
|
std::scoped_lock lock(receiverMutex);
|
|
|
|
|
for (const auto &message : messages) {
|
|
|
|
|
ImGui::TableNextRow();
|
|
|
|
|
ImGui::TableNextColumn();
|
2023-10-22 21:52:55 +02:00
|
|
|
|
ImGui::TextFormattedSelectable("{}", message.c_str());
|
2023-10-22 00:46:45 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::EndTable();
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-05 00:00:32 +01:00
|
|
|
|
ImGui::BeginDisabled(!client.isConnected());
|
|
|
|
|
{
|
|
|
|
|
ImGui::PushItemWidth(-(50_scaled));
|
|
|
|
|
bool pressedEnter = ImGui::InputText("##input", input, ImGuiInputTextFlags_EnterReturnsTrue);
|
|
|
|
|
ImGui::PopItemWidth();
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
|
|
|
|
|
if (pressedEnter)
|
|
|
|
|
ImGui::SetKeyboardFocusHere(-1);
|
2023-10-22 00:46:45 +02:00
|
|
|
|
|
2023-11-05 00:00:32 +01:00
|
|
|
|
if (ImGui::IconButton(ICON_VS_DEBUG_STACKFRAME, ImGui::GetStyleColorVec4(ImGuiCol_Text)) || pressedEnter) {
|
|
|
|
|
client.writeString(input);
|
|
|
|
|
input.clear();
|
|
|
|
|
}
|
2023-10-22 00:46:45 +02:00
|
|
|
|
}
|
2023-11-05 00:00:32 +01:00
|
|
|
|
ImGui::EndDisabled();
|
2023-10-22 00:46:45 +02:00
|
|
|
|
|
|
|
|
|
ImGui::EndTabItem();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ImGui::BeginTabItem("hex.builtin.tools.tcp_client_server.server"_lang)) {
|
|
|
|
|
static wolv::net::SocketServer server;
|
|
|
|
|
static int port;
|
|
|
|
|
|
|
|
|
|
static std::vector<std::string> messages;
|
|
|
|
|
static std::mutex receiverMutex;
|
|
|
|
|
static std::jthread receiverThread;
|
|
|
|
|
|
|
|
|
|
ImGui::Header("hex.builtin.tools.tcp_client_server.settings"_lang, true);
|
|
|
|
|
|
2023-11-05 00:10:59 +01:00
|
|
|
|
ImGui::BeginDisabled(server.isActive());
|
|
|
|
|
{
|
|
|
|
|
ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x * 0.2F);
|
|
|
|
|
ImGui::InputInt("##port", &port, 0, 0);
|
|
|
|
|
ImGui::PopItemWidth();
|
|
|
|
|
}
|
|
|
|
|
ImGui::EndDisabled();
|
2023-10-22 00:46:45 +02:00
|
|
|
|
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
|
|
|
|
|
if (port < 1)
|
|
|
|
|
port = 1;
|
|
|
|
|
else if (port > 65535)
|
|
|
|
|
port = 65535;
|
|
|
|
|
|
|
|
|
|
ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x * 0.2F);
|
|
|
|
|
if (server.isActive()) {
|
|
|
|
|
if (ImGui::IconButton(ICON_VS_DEBUG_DISCONNECT, ImGui::GetCustomColorVec4(ImGuiCustomCol_ToolbarRed))) {
|
|
|
|
|
server.shutdown();
|
|
|
|
|
|
|
|
|
|
receiverThread.request_stop();
|
|
|
|
|
receiverThread.join();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (ImGui::IconButton(ICON_VS_PLAY, ImGui::GetCustomColorVec4(ImGuiCustomCol_ToolbarGreen))) {
|
|
|
|
|
receiverThread = std::jthread([](const std::stop_token& stopToken){
|
|
|
|
|
server = wolv::net::SocketServer(port);
|
|
|
|
|
|
|
|
|
|
while (!stopToken.stop_requested()) {
|
|
|
|
|
server.accept([](wolv::net::SocketHandle, const std::vector<u8> &data) -> std::vector<u8> {
|
|
|
|
|
std::scoped_lock lock(receiverMutex);
|
|
|
|
|
|
|
|
|
|
messages.emplace_back(data.begin(), data.end());
|
|
|
|
|
|
|
|
|
|
return {};
|
2023-10-22 21:52:55 +02:00
|
|
|
|
}, nullptr, true);
|
2023-11-05 00:00:32 +01:00
|
|
|
|
|
|
|
|
|
std::this_thread::sleep_for(100ms);
|
2023-10-22 00:46:45 +02:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ImGui::PopItemWidth();
|
|
|
|
|
|
|
|
|
|
ImGui::Header("hex.builtin.tools.tcp_client_server.messages"_lang);
|
|
|
|
|
|
2023-11-05 21:52:12 +01:00
|
|
|
|
if (ImGui::BeginTable("##response", 1, ImGuiTableFlags_ScrollY | ImGuiTableFlags_RowBg | ImGuiTableFlags_Borders, ImVec2(0, 200_scaled))) {
|
2023-10-22 00:46:45 +02:00
|
|
|
|
{
|
|
|
|
|
std::scoped_lock lock(receiverMutex);
|
2023-11-05 00:00:32 +01:00
|
|
|
|
u32 index = 0;
|
2023-10-22 00:46:45 +02:00
|
|
|
|
for (const auto &message : messages) {
|
|
|
|
|
ImGui::TableNextRow();
|
|
|
|
|
ImGui::TableNextColumn();
|
2023-11-05 00:00:32 +01:00
|
|
|
|
ImGui::PushID(index);
|
2023-10-22 21:52:55 +02:00
|
|
|
|
ImGui::TextFormattedSelectable("{}", message.c_str());
|
2023-11-05 00:00:32 +01:00
|
|
|
|
ImGui::PopID();
|
|
|
|
|
|
|
|
|
|
index += 1;
|
2023-10-22 00:46:45 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::EndTable();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::EndTabItem();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::EndTabBar();
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-07 00:47:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void drawEuclidianAlgorithm() {
|
2023-11-08 12:40:33 +01:00
|
|
|
|
static u64 a, b;
|
2023-11-07 00:47:10 +01:00
|
|
|
|
|
2023-11-08 11:54:57 +01:00
|
|
|
|
static i64 gcdResult = 0;
|
|
|
|
|
static i64 lcmResult = 0;
|
|
|
|
|
static i64 p = 0, q = 0;
|
2023-11-08 12:40:33 +01:00
|
|
|
|
static bool overflow = false;
|
2023-11-08 11:54:57 +01:00
|
|
|
|
|
|
|
|
|
constexpr static auto extendedGcd = []<typename T>(T a, T b) -> std::pair<T, T> {
|
|
|
|
|
T x = 1, y = 0;
|
|
|
|
|
|
|
|
|
|
T xLast = 0, yLast = 1;
|
|
|
|
|
|
|
|
|
|
while (b > 0) {
|
|
|
|
|
T quotient = a / b;
|
|
|
|
|
|
|
|
|
|
std::tie(x, xLast) = std::tuple { xLast, x - quotient * xLast };
|
|
|
|
|
std::tie(y, yLast) = std::tuple { yLast, y - quotient * yLast };
|
|
|
|
|
std::tie(a, b) = std::tuple { b, a - quotient * b };
|
2023-11-07 00:47:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
2023-11-08 11:54:57 +01:00
|
|
|
|
return { x, y };
|
2023-11-07 00:47:10 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ImGui::TextFormattedWrapped("{}", "hex.builtin.tools.euclidean_algorithm.description"_lang);
|
|
|
|
|
|
|
|
|
|
ImGui::NewLine();
|
|
|
|
|
|
|
|
|
|
if (ImGui::BeginBox()) {
|
|
|
|
|
bool hasChanged = false;
|
|
|
|
|
hasChanged = ImGui::InputScalar("A", ImGuiDataType_U64, &a) || hasChanged;
|
|
|
|
|
hasChanged = ImGui::InputScalar("B", ImGuiDataType_U64, &b) || hasChanged;
|
|
|
|
|
|
2023-11-08 12:46:47 +01:00
|
|
|
|
// Update results when input changed
|
|
|
|
|
if (hasChanged) {
|
|
|
|
|
|
|
|
|
|
// Detect overflow
|
|
|
|
|
const u64 multiplicationResult = a * b;
|
|
|
|
|
if (a != 0 && multiplicationResult / a != b) {
|
|
|
|
|
gcdResult = 0;
|
|
|
|
|
lcmResult = 0;
|
|
|
|
|
p = 0;
|
|
|
|
|
q = 0;
|
|
|
|
|
|
|
|
|
|
overflow = true;
|
|
|
|
|
} else {
|
2023-11-08 12:40:33 +01:00
|
|
|
|
gcdResult = std::gcd<i128, i128>(a, b);
|
|
|
|
|
lcmResult = std::lcm<i128, i128>(a, b);
|
|
|
|
|
std::tie(p, q) = extendedGcd(a, b);
|
|
|
|
|
|
2023-11-08 12:46:47 +01:00
|
|
|
|
overflow = false;
|
|
|
|
|
}
|
2023-11-07 00:47:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::Separator();
|
|
|
|
|
|
|
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().DisabledAlpha);
|
2023-11-08 11:54:57 +01:00
|
|
|
|
ImGui::InputScalar("gcd(A, B)", ImGuiDataType_S64, &gcdResult, nullptr, nullptr, "%llu", ImGuiInputTextFlags_ReadOnly);
|
|
|
|
|
|
|
|
|
|
ImGui::Indent();
|
|
|
|
|
ImGui::TextFormatted(ICON_VS_ARROW_RIGHT " a \u00D7 p + b \u00D7 q = ({0}) \u00D7 ({1}) + ({2}) \u00D7 ({3})", a, p, b, q);
|
|
|
|
|
ImGui::Unindent();
|
|
|
|
|
|
|
|
|
|
ImGui::InputScalar("lcm(A, B)", ImGuiDataType_S64, &lcmResult, nullptr, nullptr, "%llu", ImGuiInputTextFlags_ReadOnly);
|
2023-11-07 00:47:10 +01:00
|
|
|
|
ImGui::PopStyleVar();
|
|
|
|
|
|
|
|
|
|
ImGui::EndBox();
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-08 12:40:33 +01:00
|
|
|
|
if (overflow)
|
2023-11-08 12:51:39 +01:00
|
|
|
|
ImGui::TextFormattedColored(ImGui::GetCustomColorVec4(ImGuiCustomCol_ToolbarRed), "{}", "hex.builtin.tools.euclidean_algorithm.overflow"_lang);
|
2023-11-08 12:40:33 +01:00
|
|
|
|
else
|
|
|
|
|
ImGui::NewLine();
|
|
|
|
|
|
2023-11-07 00:47:10 +01:00
|
|
|
|
}
|
2021-09-22 17:56:06 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-22 18:01:39 +01:00
|
|
|
|
void registerToolEntries() {
|
2022-01-24 20:53:17 +01:00
|
|
|
|
ContentRegistry::Tools::add("hex.builtin.tools.demangler", drawDemangler);
|
|
|
|
|
ContentRegistry::Tools::add("hex.builtin.tools.ascii_table", drawASCIITable);
|
|
|
|
|
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);
|
2023-11-11 00:54:16 +01:00
|
|
|
|
ContentRegistry::Tools::add("hex.builtin.tools.graphing", drawGraphingCalculator);
|
2022-01-24 20:53:17 +01:00
|
|
|
|
ContentRegistry::Tools::add("hex.builtin.tools.base_converter", drawBaseConverter);
|
2023-03-20 22:25:27 +01:00
|
|
|
|
ContentRegistry::Tools::add("hex.builtin.tools.byte_swapper", drawByteSwapper);
|
2022-01-24 20:53:17 +01:00
|
|
|
|
ContentRegistry::Tools::add("hex.builtin.tools.permissions", drawPermissionsCalculator);
|
2023-08-17 09:27:14 +02:00
|
|
|
|
// ContentRegistry::Tools::add("hex.builtin.tools.file_uploader", drawFileUploader);
|
2022-01-24 20:53:17 +01:00
|
|
|
|
ContentRegistry::Tools::add("hex.builtin.tools.wiki_explain", drawWikiExplainer);
|
|
|
|
|
ContentRegistry::Tools::add("hex.builtin.tools.file_tools", drawFileTools);
|
2023-01-19 17:01:19 +01:00
|
|
|
|
ContentRegistry::Tools::add("hex.builtin.tools.ieee754", drawIEEE754Decoder);
|
2023-01-19 17:01:41 +01:00
|
|
|
|
ContentRegistry::Tools::add("hex.builtin.tools.invariant_multiplication", drawInvariantMultiplicationDecoder);
|
2023-10-22 00:46:45 +02:00
|
|
|
|
ContentRegistry::Tools::add("hex.builtin.tools.tcp_client_server", drawTCPClientServer);
|
2023-11-07 00:47:10 +01:00
|
|
|
|
ContentRegistry::Tools::add("hex.builtin.tools.euclidean_algorithm", drawEuclidianAlgorithm);
|
2021-01-22 18:01:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
2022-12-29 15:07:43 +01:00
|
|
|
|
}
|