From fa754918febc8bb07451d83466d9a556dd5edb09 Mon Sep 17 00:00:00 2001 From: Stardust Date: Sun, 10 May 2026 22:43:33 +0930 Subject: [PATCH] UI: Update how pause panel works --- .../user_interface/sciter_main_window.cpp | 117 +++++++----------- src/nxemu/user_interface/sciter_main_window.h | 12 +- 2 files changed, 55 insertions(+), 74 deletions(-) diff --git a/src/nxemu/user_interface/sciter_main_window.cpp b/src/nxemu/user_interface/sciter_main_window.cpp index e028ffb4..305078df 100644 --- a/src/nxemu/user_interface/sciter_main_window.cpp +++ b/src/nxemu/user_interface/sciter_main_window.cpp @@ -151,6 +151,7 @@ SciterMainWindow::SciterMainWindow(ISciterUI & sciterUI, const char * windowTitl m_emulationRunning(false), m_pendingStartInFullscreen(false), m_hideUi(false), + m_shownFirstFrame(false), m_win32Fullscreen(std::make_unique()) { SettingsStore & settings = SettingsStore::GetInstance(); @@ -356,11 +357,7 @@ bool SciterMainWindow::Show() m_sciterUI.AttachHandler(m_rootElement, IID_ITIMERSINK, (ITimerSink *)this); m_rootElement.SetTimer(25, (uint32_t *)TIMER_UPDATE_INPUT); - SciterElement romBrowserPanel = m_rootElement.GetElementByID("RomBrowserPanel"); - if (romBrowserPanel.IsValid()) - { - romBrowserPanel.SetStyleAttribute("display", "block"); - } + ShowPanel(Panel::RomBrowser); SciterElement rombrowser = m_rootElement.FindFirst("rombrowser"); interfacePtr = rombrowser.IsValid() ? m_sciterUI.GetElementInterface(rombrowser, IID_ROMBROWSER) : nullptr; @@ -443,8 +440,6 @@ void SciterMainWindow::CreateRenderWindow() IVideo & video = m_modules.Modules().Video(); video.UpdateFramebufferLayout(rect.right - rect.left, rect.bottom - rect.top); } - - UpdatePausePanel(); } void SciterMainWindow::SetCaption(const std::string & caption) @@ -493,18 +488,29 @@ void SciterMainWindow::EmulationRunning(const char * /*setting*/, void * userDat impl->UpdateUIVisibility(); } -void SciterMainWindow::ApplyEmulationLoadingUi() +void SciterMainWindow::ShowPanel(Panel panel) { - SciterElement romBrowserPanel(m_rootElement.GetElementByID("RomBrowserPanel")); - if (romBrowserPanel.IsValid()) + struct PanelEntry { - romBrowserPanel.SetStyleAttribute("display", "none"); - } - SciterElement loadingPanel(m_rootElement.GetElementByID("LoadingPanel")); - if (loadingPanel.IsValid()) + Panel panel; + const char * id; + }; + static const PanelEntry panels[] = { + {Panel::RomBrowser, "RomBrowserPanel"}, + {Panel::Loading, "LoadingPanel"}, + {Panel::Pause, "PausePanel"}, + }; + + for (const PanelEntry & entry : panels) { - loadingPanel.SetStyleAttribute("display", "block"); + SciterElement elem(m_rootElement.GetElementByID(entry.id)); + if (!elem.IsValid()) + { + continue; + } + elem.SetStyleAttribute("display", panel == entry.panel ? "block" : "none"); } + ShowWindow((HWND)m_renderWindow, panel == Panel::Renderer ? SW_SHOW : SW_HIDE); m_sciterUI.UpdateWindow(m_rootElement.GetElementHwnd(true)); } @@ -513,9 +519,10 @@ void SciterMainWindow::EmulationStateChanged(const char * /*setting*/, void * us SciterMainWindow * impl = (SciterMainWindow *)userData; EmulationState state = (EmulationState)SettingsStore::GetInstance().GetInt(NXCoreSetting::EmulationState); - if (state == EmulationState::LoadingRom || state == EmulationState::Starting) + if (state == EmulationState::LoadingRom) { - impl->ApplyEmulationLoadingUi(); + impl->m_shownFirstFrame = false; + impl->ShowPanel(Panel::Loading); } else if (state == EmulationState::Running) { @@ -526,16 +533,21 @@ void SciterMainWindow::EmulationStateChanged(const char * /*setting*/, void * us } impl->m_rootElement.PostEvent(EVENT_EMULATION_RUNNING); impl->ResetMenu(); + if (impl->m_shownFirstFrame) + { + impl->ShowPanel(Panel::Renderer); + } } else if (state == EmulationState::Paused) { impl->ResetMenu(); + impl->ShowPanel(Panel::Pause); + impl->UpdateEmulationStatusText(); } else if (state == EmulationState::Stopped) { impl->m_rootElement.PostEvent(EVENT_EMULATION_STOPPED); } - impl->UpdatePausePanel(); } void SciterMainWindow::GameFileChanged(const char * /*setting*/, void * userData) @@ -584,8 +596,14 @@ void SciterMainWindow::GameNameChanged(const char * /*setting*/, void * userData void SciterMainWindow::DisplayedFramesChanged(const char * /*setting*/, void * userData) { + SettingsStore & settings = SettingsStore::GetInstance(); SciterMainWindow * impl = (SciterMainWindow *)userData; - impl->m_rootElement.PostEvent(EVENT_EMULATION_FIRST_FRAME); + + impl->m_shownFirstFrame = settings.GetBool(NXCoreSetting::DisplayedFrames); + if (impl->m_shownFirstFrame) + { + impl->m_rootElement.PostEvent(EVENT_EMULATION_FIRST_FRAME); + } } void SciterMainWindow::DiskCacheLoadChanged(const char * /*setting*/, void * userData) @@ -810,7 +828,10 @@ void SciterMainWindow::UpdateEmulationStatusText() parts.push_back(stdstr_f("Speed: %f", results.emulation_speed * 100.0)); } } - parts.push_back(stdstr_f("%.0f FPS (%.2f ms)%s", std::round(results.average_game_fps), std::isnan(results.frametime) ? 0.0 : (results.frametime * 1000.0), m_useSpeedLimit ? "" : " Unlocked")); + if (results.average_game_fps != 0) + { + parts.push_back(stdstr_f("%.0f FPS (%.2f ms)%s", std::round(results.average_game_fps), std::isnan(results.frametime) ? 0.0 : (results.frametime * 1000.0), m_useSpeedLimit ? "" : " Unlocked")); + } } else { @@ -1103,37 +1124,6 @@ void SciterMainWindow::LayoutRenderWindow() IVideo & video = m_modules.Modules().Video(); video.UpdateFramebufferLayout(width, height); } - UpdatePausePanel(); -} - -void SciterMainWindow::UpdatePausePanel() -{ - SciterElement panel(m_rootElement.GetElementByID("PausePanel")); - if (!panel.IsValid()) - { - return; - } - - const bool paused = - m_emulationRunning && m_modules.IsValid() && m_modules.Modules().OperatingSystem().IsEmulationPaused(); - - panel.SetStyleAttribute("display", paused ? "block" : "none"); - - if (m_renderWindow == nullptr || !m_emulationRunning) - { - return; - } - - if (paused) - { - ShowWindow((HWND)m_renderWindow, SW_HIDE); - } - else - { - SettingsStore & settings = SettingsStore::GetInstance(); - const bool showRender = settings.GetBool(NXCoreSetting::DisplayedFrames); - ShowWindow((HWND)m_renderWindow, showRender ? SW_SHOW : SW_HIDE); - } } void SciterMainWindow::UpdateUIVisibility() @@ -1466,7 +1456,7 @@ bool SciterMainWindow::OnEvent(SCITER_ELEMENT element, SCITER_ELEMENT /*source*/ } if (event_code == EVENT_EMULATION_LOADING) { - ApplyEmulationLoadingUi(); + ShowPanel(Panel::Loading); } else if (event_code == EVENT_EMULATION_RUNNING) { @@ -1475,33 +1465,16 @@ bool SciterMainWindow::OnEvent(SCITER_ELEMENT element, SCITER_ELEMENT /*source*/ } else if (event_code == EVENT_EMULATION_STOPPED) { - ShowWindow((HWND)m_renderWindow, SW_HIDE); - SciterElement LoadingPanel(m_rootElement.GetElementByID("LoadingPanel")); - if (LoadingPanel.IsValid()) - { - LoadingPanel.SetStyleAttribute("display", "none"); - } - - SciterElement romBrowserPanel(m_rootElement.GetElementByID("RomBrowserPanel")); - if (romBrowserPanel.IsValid()) - { - romBrowserPanel.SetStyleAttribute("display", "block"); - } - UpdatePausePanel(); + m_shownFirstFrame = false; + ShowPanel(Panel::RomBrowser); } else if (event_code == EVENT_EMULATION_FIRST_FRAME) { SettingsStore & settings = SettingsStore::GetInstance(); if (settings.GetBool(NXCoreSetting::DisplayedFrames)) { - ShowWindow((HWND)m_renderWindow, SW_SHOW); - SciterElement LoadingPanel(m_rootElement.GetElementByID("LoadingPanel")); - if (LoadingPanel.IsValid()) - { - LoadingPanel.SetStyleAttribute("display", "none"); - } + ShowPanel(Panel::Renderer); } - UpdatePausePanel(); } else if (event_code == EVENT_DISK_CACHE_STATUS) { diff --git a/src/nxemu/user_interface/sciter_main_window.h b/src/nxemu/user_interface/sciter_main_window.h index 957ead68..4b901f64 100644 --- a/src/nxemu/user_interface/sciter_main_window.h +++ b/src/nxemu/user_interface/sciter_main_window.h @@ -50,6 +50,14 @@ class SciterMainWindow : RecentFileMenuLast = RecentFileMenuFirst + 20, }; + enum class Panel + { + RomBrowser, + Loading, + Pause, + Renderer + }; + enum { TIMER_UPDATE_UI = 5000, @@ -115,8 +123,7 @@ private: void ResetWindowSize(uint32_t nominal_width, uint32_t nominal_height); #endif void LayoutRenderWindow(); - void UpdatePausePanel(); - void ApplyEmulationLoadingUi(); + void ShowPanel(Panel panel); void RefreshDiskCacheLoadingText(); void RegisterApplets(); @@ -168,5 +175,6 @@ private: bool m_pendingStartInFullscreen; std::string m_fullscreenMenuSvg; bool m_hideUi; + bool m_shownFirstFrame; std::unique_ptr m_win32Fullscreen; };