From 82f7658574ee6b8fa0211c55ee8d0921cbdc9e66 Mon Sep 17 00:00:00 2001 From: BearOso Date: Sun, 7 May 2023 16:06:34 -0500 Subject: [PATCH] win32: Add imgui overlay to direct3d. memmap: Use multiline rom info message. --- gfx.cpp | 11 +++++++++++ memmap.cpp | 9 ++++++--- win32/CDirect3D.cpp | 36 ++++++++++++++++++++++++++++++++++++ win32/CVulkan.cpp | 4 ++-- 4 files changed, 55 insertions(+), 5 deletions(-) diff --git a/gfx.cpp b/gfx.cpp index 6be2fe4f..657ab47a 100644 --- a/gfx.cpp +++ b/gfx.cpp @@ -1792,6 +1792,9 @@ static void VariableDisplayChar(int x, int y, uint8 c, bool monospace = false, i void S9xVariableDisplayString(const char* string, int linesFromBottom, int pixelsFromLeft, bool allowWrap, int type) { + if (GFX.ScreenBuffer.empty() || IPPU.RenderedScreenWidth == 0) + return; + bool monospace = true; if (type == S9X_NO_INFO) { @@ -1812,6 +1815,14 @@ void S9xVariableDisplayString(const char* string, int linesFromBottom, int pixel monospace = false; } + int min_lines = 1; + std::string msg(string); + for (auto& c : msg) + if (c < 32) + min_lines++; + if (min_lines > linesFromBottom) + linesFromBottom = min_lines; + int dst_x = pixelsFromLeft; int dst_y = IPPU.RenderedScreenHeight - (font_height)*linesFromBottom; int len = strlen(string); diff --git a/memmap.cpp b/memmap.cpp index 4e5a2b9d..33479e65 100644 --- a/memmap.cpp +++ b/memmap.cpp @@ -2444,7 +2444,8 @@ void CMemory::InitROM (void) : ((Multi.cartType == 4) ? "no checksum" : "bad checksum"), MapType(), Size(), KartContents(), Settings.PAL ? "PAL" : "NTSC", StaticRAMSize(), ROMId, ROMCRC32); - S9xMessage(S9X_INFO, S9X_ROM_INFO, String); + + S9xMessage(S9X_INFO, S9X_ROM_INFO, GetMultilineROMInfo().c_str()); Settings.ForceLoROM = FALSE; Settings.ForceHiROM = FALSE; @@ -3389,7 +3390,8 @@ static std::string sjis_to_utf8(std::string in) out += "\357\276"; c -= 0x40; } - out += c; + else if (c >= 32) + out += c; } return out; @@ -3401,6 +3403,7 @@ std::string CMemory::GetMultilineROMInfo() (Memory.ROMChecksum == Memory.CalculatedChecksum); std::string utf8_romname = sjis_to_utf8(Memory.ROMName); std::string tvstandard = Settings.PAL ? "PAL" : "NTSC"; + std::string romid = sjis_to_utf8(Memory.ROMId); std::string checksum = isChecksumOK ? "Checksum OK" : Settings.IsPatched == 3 ? "UPS patched" : Settings.IsPatched == 2 ? "BPS patched" @@ -3410,7 +3413,7 @@ std::string CMemory::GetMultilineROMInfo() std::stringstream ss; ss << "\"" << utf8_romname << "\" (" + tvstandard + ") version " << Memory.Revision() << "\n"; ss << Memory.KartContents() << ": " << Memory.MapType() << ": " << Memory.Size() << ", SRAM: " << Memory.StaticRAMSize() << "\n"; - ss << "ID: " << Memory.ROMId << ", CRC32: " << std::setfill('0') << std::setw(8) << std::setbase(16) << Memory.ROMCRC32 << ", " << checksum; + ss << "ID: " << romid << ", CRC32: " << std::setfill('0') << std::setw(8) << std::setbase(16) << Memory.ROMCRC32 << ", " << checksum; return ss.str(); } diff --git a/win32/CDirect3D.cpp b/win32/CDirect3D.cpp index 122a101f..af6752c4 100644 --- a/win32/CDirect3D.cpp +++ b/win32/CDirect3D.cpp @@ -18,6 +18,9 @@ #include "../filter/hq2x.h" #include "../filter/2xsai.h" +#include "imgui_impl_dx9.h" +#include "snes9x_imgui.h" + #ifndef max #define max(a, b) (((a) > (b)) ? (a) : (b)) #endif @@ -138,6 +141,16 @@ bool CDirect3D::Initialize(HWND hWnd) init_done = true; + if (!Settings.AutoDisplayMessages) + { + auto defaults = S9xImGuiGetDefaults(); + defaults.font_size = GUI.OSDSize; + defaults.spacing = defaults.font_size / 2.4; + S9xImGuiInit(&defaults); + ImGui_ImplDX9_Init(pDevice); + Settings.DisplayIndicators = true; + } + ApplyDisplayChanges(); return true; @@ -146,6 +159,12 @@ bool CDirect3D::Initialize(HWND hWnd) void CDirect3D::DeInitialize() { + if (S9xImGuiRunning()) + { + ImGui_ImplDX9_Shutdown(); + S9xImGuiDeinit(); + } + DestroyDrawSurface(); SetShader(NULL); @@ -327,6 +346,13 @@ void CDirect3D::Render(SSurface Src) pDevice->BeginScene(); pDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2); + if (S9xImGuiRunning()) + { + ImGui_ImplDX9_NewFrame(); + if (S9xImGuiDraw(dPresentParams.BackBufferWidth, dPresentParams.BackBufferHeight)) + ImGui_ImplDX9_RenderDrawData(ImGui::GetDrawData()); + } + pDevice->EndScene(); WinThrottleFramerate(); @@ -530,6 +556,11 @@ bool CDirect3D::ResetDevice() HRESULT hr; + if (S9xImGuiRunning) + { + ImGui_ImplDX9_Shutdown(); + } + //release prior to reset DestroyDrawSurface(); @@ -579,6 +610,11 @@ bool CDirect3D::ResetDevice() SetViewport(); + if (S9xImGuiRunning) + { + ImGui_ImplDX9_Init(pDevice); + } + return true; } diff --git a/win32/CVulkan.cpp b/win32/CVulkan.cpp index 94357bf7..6f5178bf 100644 --- a/win32/CVulkan.cpp +++ b/win32/CVulkan.cpp @@ -105,9 +105,9 @@ void CVulkan::DeInitialize() context->wait_idle(); if (ImGui::GetCurrentContext()) { - imgui_descriptor_pool.reset(); ImGui_ImplVulkan_Shutdown(); - ImGui::DestroyContext(); + imgui_descriptor_pool.reset(); + S9xImGuiDeinit(); } } shaderchain.reset();