mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-02 05:27:41 -05:00
feat: Added a new division by invariant multiplication tool
This commit is contained in:
@@ -1316,6 +1316,63 @@ namespace hex::plugin::builtin {
|
||||
}
|
||||
}
|
||||
|
||||
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)) {
|
||||
static const u64 min = 1, max = 64;
|
||||
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();
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void registerToolEntries() {
|
||||
@@ -1330,6 +1387,7 @@ namespace hex::plugin::builtin {
|
||||
ContentRegistry::Tools::add("hex.builtin.tools.wiki_explain", drawWikiExplainer);
|
||||
ContentRegistry::Tools::add("hex.builtin.tools.file_tools", drawFileTools);
|
||||
ContentRegistry::Tools::add("hex.builtin.tools.ieee754", drawIEEE754Decoder);
|
||||
ContentRegistry::Tools::add("hex.builtin.tools.invariant_multiplication", drawInvariantMultiplicationDecoder);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user