From e31636caec56b4062b8b36b8d1fc31da2a16f0d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 25 Nov 2024 00:03:06 +0100 Subject: [PATCH] Still use a fixed-width font for the disassembly (might change this) --- UI/ImDebugger/ImDebugger.cpp | 4 ---- UI/ImDebugger/ImDisasmView.cpp | 13 +++++++++---- UI/ImDebugger/ImDisasmView.h | 4 +++- ext/imgui/imgui_impl_thin3d.cpp | 21 +++++++++++++++++---- ext/imgui/imgui_impl_thin3d.h | 3 +++ 5 files changed, 32 insertions(+), 13 deletions(-) diff --git a/UI/ImDebugger/ImDebugger.cpp b/UI/ImDebugger/ImDebugger.cpp index f587b37ca6..5d9f67f0fd 100644 --- a/UI/ImDebugger/ImDebugger.cpp +++ b/UI/ImDebugger/ImDebugger.cpp @@ -368,10 +368,6 @@ void ImDebugger::Frame(MIPSDebugInterface *mipsDebug, GPUDebugInterface *gpuDebu Core_Break("Menu:Break"); } } - ImGui::Separator(); - if (ImGui::MenuItem("Toggle Breakpoint")) { - // TODO - } ImGui::EndMenu(); } if (ImGui::BeginMenu("CPU")) { diff --git a/UI/ImDebugger/ImDisasmView.cpp b/UI/ImDebugger/ImDisasmView.cpp index 586596236c..02bc68cd9c 100644 --- a/UI/ImDebugger/ImDisasmView.cpp +++ b/UI/ImDebugger/ImDisasmView.cpp @@ -1,5 +1,6 @@ #include "ext/imgui/imgui_internal.h" +#include "ext/imgui/imgui_impl_thin3d.h" #include "Common/StringUtils.h" #include "Common/Log.h" @@ -178,8 +179,7 @@ void ImDisasmView::drawBranchLine(ImDrawList *drawList, Rect rect, std::map rect.bottom && bottomY > rect.bottom)) - { + if ((topY < 0 && bottomY < 0) || (topY > rect.bottom && bottomY > rect.bottom)) { return; } @@ -316,6 +316,8 @@ void ImDisasmView::drawArguments(ImDrawList *drawList, Rect rc, const Disassembl void ImDisasmView::Draw(ImDrawList *drawList) { // TODO: Don't need to do these every frame. + ImGui_PushFixedFont(); + rowHeight_ = ImGui::GetTextLineHeightWithSpacing(); charWidth_ = ImGui::CalcTextSize("W", nullptr, false, -1.0f).x; @@ -482,10 +484,13 @@ void ImDisasmView::Draw(ImDrawList *drawList) { } } + ImGui_PopFont(); + ImGui::OpenPopupOnItemClick("context", ImGuiPopupFlags_MouseButtonRight); PopupMenu(); drawList->PopClipRect(); + } void ImDisasmView::ScrollRelative(int amount) { @@ -528,7 +533,7 @@ void ImDisasmView::onChar(int c) { } -void ImDisasmView::editBreakpoint() { +void ImDisasmView::editBreakpoint(ImConfig &cfg) { /* BreakpointWindow win(wnd, debugger); @@ -583,7 +588,7 @@ void ImDisasmView::ProcessKeyboardShortcuts() { // gotoAddr(addr); } if (ImGui::IsKeyPressed(ImGuiKey_E)) { - editBreakpoint(); + // editBreakpoint(); } if (ImGui::IsKeyPressed(ImGuiKey_D)) { toggleBreakpoint(true); diff --git a/UI/ImDebugger/ImDisasmView.h b/UI/ImDebugger/ImDisasmView.h index 5143b22af5..6de54b5098 100644 --- a/UI/ImDebugger/ImDisasmView.h +++ b/UI/ImDebugger/ImDisasmView.h @@ -11,6 +11,8 @@ #include "Core/Debugger/DisassemblyManager.h" #include "Core/Debugger/DebugInterface.h" +struct ImConfig; + // Corresponds to CtrlDisAsmView // TODO: Fold out common code. class ImDisasmView { @@ -77,7 +79,7 @@ public: showHex_ = s; } void toggleBreakpoint(bool toggleEnabled = false); - void editBreakpoint(); + void editBreakpoint(ImConfig &cfg); void setCurAddress(u32 newAddress, bool extend = false) { newAddress = manager.getStartAddress(newAddress); diff --git a/ext/imgui/imgui_impl_thin3d.cpp b/ext/imgui/imgui_impl_thin3d.cpp index 85d8049cd0..5eb8e57351 100644 --- a/ext/imgui/imgui_impl_thin3d.cpp +++ b/ext/imgui/imgui_impl_thin3d.cpp @@ -7,7 +7,10 @@ #include "Common/System/Display.h" #include "Common/Math/lin/matrix4x4.h" -Lin::Matrix4x4 g_drawMatrix; +static Lin::Matrix4x4 g_drawMatrix; + +static ImFont *g_proportionalFont = nullptr; +static ImFont *g_fixedFont = nullptr; struct ImGui_ImplThin3d_Data { Draw::SamplerState *fontSampler = nullptr; @@ -220,12 +223,14 @@ void ImGui_ImplThin3d_DestroyDeviceObjects() { bool ImGui_ImplThin3d_Init(Draw::DrawContext *draw, const uint8_t *ttf_font, size_t size) { ImGuiIO& io = ImGui::GetIO(); if (ttf_font) { - io.Fonts->AddFontFromMemoryTTF((void *)ttf_font, (int)size, 21.0f / g_display.dpi_scale_x, nullptr, io.Fonts->GetGlyphRangesDefault()); + g_proportionalFont = io.Fonts->AddFontFromMemoryTTF((void *)ttf_font, (int)size, 21.0f / g_display.dpi_scale_x, nullptr, io.Fonts->GetGlyphRangesDefault()); } else { - // necessary? - io.Fonts->AddFontDefault(); + // fallback + g_proportionalFont = g_fixedFont; } + g_fixedFont = io.Fonts->AddFontDefault(); ImGui::GetStyle().ScaleAllSizes(1.0f / g_display.dpi_scale_x); + ImGui::GetStyle().Colors[ImGuiCol_Border] = ImColor(IM_COL32(0x2A, 0x2F, 0x3B, 0xFF)); IMGUI_CHECKVERSION(); IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!"); @@ -239,6 +244,14 @@ bool ImGui_ImplThin3d_Init(Draw::DrawContext *draw, const uint8_t *ttf_font, siz return true; } +void ImGui_PushFixedFont() { + ImGui::PushFont(g_fixedFont); +} + +void ImGui_PopFont() { + ImGui::PopFont(); +} + void ImGui_ImplThin3d_Shutdown() { ImGui_ImplThin3d_Data* bd = ImGui_ImplThin3d_GetBackendData(); IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?"); diff --git a/ext/imgui/imgui_impl_thin3d.h b/ext/imgui/imgui_impl_thin3d.h index 697d12b3aa..6c86a4589c 100644 --- a/ext/imgui/imgui_impl_thin3d.h +++ b/ext/imgui/imgui_impl_thin3d.h @@ -44,6 +44,9 @@ IMGUI_IMPL_API void ImGui_ImplThin3d_DestroyDeviceObjects(); IMGUI_IMPL_API ImTextureID ImGui_ImplThin3d_AddTexture(Draw::Texture *texture); IMGUI_IMPL_API Draw::Texture *ImGui_ImplThin3d_RemoveTexture(ImTextureID texture); +void ImGui_PushFixedFont(); +void ImGui_PopFont(); + // Helper structure to hold the data needed by one rendering context into one OS window // (Used by example's main.cpp. Used by multi-viewport features. Probably NOT used by your own engine/app.) struct ImGui_ImplThin3dH_Window