2023-11-21 14:38:01 +01:00
|
|
|
#include <hex/api/localization_manager.hpp>
|
2023-11-12 01:22:01 +01:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include <imgui.h>
|
|
|
|
#include <hex/ui/imgui_imhex_extensions.h>
|
|
|
|
|
2023-12-01 13:53:51 +01:00
|
|
|
#include <fonts/codicons_font.h>
|
|
|
|
|
2023-11-12 01:22:01 +01:00
|
|
|
namespace hex::plugin::builtin {
|
|
|
|
|
2023-12-01 13:53:51 +01:00
|
|
|
void drawByteSwapper() {
|
|
|
|
static std::string input, buffer, output;
|
|
|
|
|
|
|
|
if (ImGuiExt::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];
|
|
|
|
}
|
2023-11-12 01:22:01 +01:00
|
|
|
}
|
2023-12-01 13:53:51 +01:00
|
|
|
|
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().DisabledAlpha);
|
|
|
|
ImGuiExt::InputTextIcon("hex.builtin.tools.output"_lang, ICON_VS_SYMBOL_NUMERIC, output, ImGuiInputTextFlags_ReadOnly);
|
|
|
|
ImGui::PopStyleVar();
|
2023-11-12 01:22:01 +01:00
|
|
|
}
|
2023-12-01 13:53:51 +01:00
|
|
|
|
2023-11-12 01:22:01 +01:00
|
|
|
}
|