diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 2fbb02f8b1bb..5c6d8372ef86 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -27,7 +27,7 @@ using namespace std::placeholders; #include "Common/Render/Text/draw_text.h" #include "Common/File/FileUtil.h" #include "Common/Battery/Battery.h" - +#include "Common/File/VFS/VFS.h" #include "Common/UI/Root.h" #include "Common/UI/UI.h" #include "Common/UI/Context.h" @@ -1646,7 +1646,13 @@ void EmuScreen::renderImDebugger() { if (!imguiInited_) { imguiInited_ = true; imDebugger_ = std::make_unique(); - ImGui_ImplThin3d_Init(draw); + + // Read the TTF font + size_t size = 0; + uint8_t *fontData = g_VFS.ReadFile("Roboto-Condensed.ttf", &size); + // This call works even if fontData is nullptr, in which case the font just won't get loaded. + // This takes ownership of the font array. + ImGui_ImplThin3d_Init(draw, fontData, size); } if (PSP_IsInited()) { diff --git a/UI/ImDebugger/ImDebugger.cpp b/UI/ImDebugger/ImDebugger.cpp index 022ec93b247b..5d9f67f0fd65 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")) { @@ -399,7 +395,8 @@ void ImDebugger::Frame(MIPSDebugInterface *mipsDebug, GPUDebugInterface *gpuDebu if (ImGui::MenuItem("Close Debugger")) { g_Config.bShowImDebugger = false; } - ImGui::MenuItem("Dear ImGUI Demo", nullptr, &cfg_.demoOpen); + ImGui::MenuItem("Dear ImGui Demo", nullptr, &cfg_.demoOpen); + ImGui::MenuItem("Dear ImGui Style editor", nullptr, &cfg_.styleEditorOpen); ImGui::EndMenu(); } ImGui::EndMainMenuBar(); @@ -409,6 +406,10 @@ void ImDebugger::Frame(MIPSDebugInterface *mipsDebug, GPUDebugInterface *gpuDebu ImGui::ShowDemoWindow(&cfg_.demoOpen); } + if (cfg_.styleEditorOpen) { + ImGui::ShowStyleEditor(); + } + if (cfg_.disasmOpen) { disasm_.Draw(mipsDebug, &cfg_.disasmOpen, coreState); } diff --git a/UI/ImDebugger/ImDebugger.h b/UI/ImDebugger/ImDebugger.h index 75aa976612d8..8d3368d1d667 100644 --- a/UI/ImDebugger/ImDebugger.h +++ b/UI/ImDebugger/ImDebugger.h @@ -65,6 +65,7 @@ struct ImConfig { bool atracOpen = true; bool structViewerOpen = false; bool framebuffersOpen = false; + bool styleEditorOpen = false; // HLE explorer settings // bool filterByUsed = true; diff --git a/UI/ImDebugger/ImDisasmView.cpp b/UI/ImDebugger/ImDisasmView.cpp index e7c7b0561fba..02bc68cd9c1f 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; @@ -435,17 +437,17 @@ void ImDisasmView::Draw(ImDrawList *drawList) { ImGuiIO& io = ImGui::GetIO(); ImVec2 mousePos = ImVec2(io.MousePos.x - canvas_p0.x, io.MousePos.y - canvas_p0.y); if (is_hovered && ImGui::IsMouseClicked(ImGuiMouseButton_Left)) { - INFO_LOG(Log::CPU, "Mousedown %f,%f active:%d hover:%d", mousePos.x, mousePos.y, is_active, is_hovered); + // INFO_LOG(Log::CPU, "Mousedown %f,%f active:%d hover:%d", mousePos.x, mousePos.y, is_active, is_hovered); onMouseDown(mousePos.x, mousePos.y, 1); } if (ImGui::IsMouseReleased(ImGuiMouseButton_Left)) { - INFO_LOG(Log::CPU, "Mouseup %f,%f active:%d hover:%d", mousePos.x, mousePos.y, is_active, is_hovered); + // INFO_LOG(Log::CPU, "Mouseup %f,%f active:%d hover:%d", mousePos.x, mousePos.y, is_active, is_hovered); if (is_hovered) { onMouseUp(mousePos.x, mousePos.y, 1); } } if (ImGui::IsMouseDragging(ImGuiMouseButton_Left)) { - INFO_LOG(Log::CPU, "Mousedrag %f,%f active:%d hover:%d", mousePos.x, mousePos.y, is_active, is_hovered); + // INFO_LOG(Log::CPU, "Mousedrag %f,%f active:%d hover:%d", mousePos.x, mousePos.y, is_active, is_hovered); if (is_hovered) { onMouseMove(mousePos.x, mousePos.y, 1); } @@ -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 5143b22af578..6de54b5098c3 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 @@ class ImDisasmView { 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 c4f9c888cf44..5eb8e57351f1 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; @@ -217,8 +220,18 @@ void ImGui_ImplThin3d_DestroyDeviceObjects() { } } -bool ImGui_ImplThin3d_Init(Draw::DrawContext *draw) { +bool ImGui_ImplThin3d_Init(Draw::DrawContext *draw, const uint8_t *ttf_font, size_t size) { ImGuiIO& io = ImGui::GetIO(); + if (ttf_font) { + g_proportionalFont = io.Fonts->AddFontFromMemoryTTF((void *)ttf_font, (int)size, 21.0f / g_display.dpi_scale_x, nullptr, io.Fonts->GetGlyphRangesDefault()); + } else { + // 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!"); @@ -231,6 +244,14 @@ bool ImGui_ImplThin3d_Init(Draw::DrawContext *draw) { 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 c06090d35cd7..6c86a4589cb9 100644 --- a/ext/imgui/imgui_impl_thin3d.h +++ b/ext/imgui/imgui_impl_thin3d.h @@ -33,8 +33,8 @@ #include "Common/GPU/thin3d.h" #include "Common/Math/lin/matrix4x4.h" -// Called by user code -IMGUI_IMPL_API bool ImGui_ImplThin3d_Init(Draw::DrawContext *draw); +// Called by user code. Takes ownership of the font buffer and later deletes it. +IMGUI_IMPL_API bool ImGui_ImplThin3d_Init(Draw::DrawContext *draw, const uint8_t *ttf_font, size_t size); IMGUI_IMPL_API void ImGui_ImplThin3d_Shutdown(); IMGUI_IMPL_API void ImGui_ImplThin3d_NewFrame(Draw::DrawContext *draw, Lin::Matrix4x4 drawMatrix); IMGUI_IMPL_API void ImGui_ImplThin3d_RenderDrawData(ImDrawData* draw_data, Draw::DrawContext *draw); @@ -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