From d0fcb041dee03f6d324c09190d3fc31540bd4043 Mon Sep 17 00:00:00 2001 From: N3xoX1 Date: Sat, 5 Jul 2025 17:19:21 +0930 Subject: [PATCH] Add status bar --- external/sciterui | 2 +- lang/english/css/main_window.css | 31 +++++++ lang/english/html/main_window.html | 8 +- lang/english/html/system_config_audio.html | 2 +- .../user_interface/sciter_main_window.cpp | 86 ++++++++++++++++++- src/nxemu/user_interface/sciter_main_window.h | 24 +++++- 6 files changed, 146 insertions(+), 7 deletions(-) diff --git a/external/sciterui b/external/sciterui index 08cad1b7..0673473d 160000 --- a/external/sciterui +++ b/external/sciterui @@ -1 +1 @@ -Subproject commit 08cad1b78f43492200f279c302aed6243fe9057b +Subproject commit 0673473d16e19c24f7fbee96c268af22dd8302ed diff --git a/lang/english/css/main_window.css b/lang/english/css/main_window.css index 27ac2de1..112ecde6 100644 --- a/lang/english/css/main_window.css +++ b/lang/english/css/main_window.css @@ -207,4 +207,35 @@ hr { width: 100%%; height: 100%%; +} + +#StatusBar +{ + background: #31363b; + flow: horizontal; + color: #eff0f1; + padding: 0.2em 1em; + border-top: 1px solid #434242; + font-family: 'Segoe UI', Arial, sans-serif; + font-size: 0.8em; + font-weight: 100; +} + +#StatusBar #volume +{ + border: 1px solid transparent; + padding: 0.2em; + display: inline-block; +} + +#StatusBar #volume:hover +{ + border: 1px solid #76797c; +} + +#VolumePopup +{ + background: #31363b; + border: 1px solid #434242; + padding: 1em; } \ No newline at end of file diff --git a/lang/english/html/main_window.html b/lang/english/html/main_window.html index 9b794566..e75dab3a 100644 --- a/lang/english/html/main_window.html +++ b/lang/english/html/main_window.html @@ -13,4 +13,10 @@
- \ No newline at end of file +
+ + +
+ +
+
\ No newline at end of file diff --git a/lang/english/html/system_config_audio.html b/lang/english/html/system_config_audio.html index bb31d306..8f7d2583 100644 --- a/lang/english/html/system_config_audio.html +++ b/lang/english/html/system_config_audio.html @@ -18,7 +18,7 @@
-
100%
+
100%
diff --git a/src/nxemu/user_interface/sciter_main_window.cpp b/src/nxemu/user_interface/sciter_main_window.cpp index 5497fa6a..ee49e0dd 100644 --- a/src/nxemu/user_interface/sciter_main_window.cpp +++ b/src/nxemu/user_interface/sciter_main_window.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -17,13 +18,15 @@ SciterMainWindow::SciterMainWindow(ISciterUI & sciterUI, const char * windowTitl m_window(nullptr), m_renderWindow(nullptr), m_windowTitle(windowTitle), - m_systemConfig(sciterUI) + m_systemConfig(sciterUI), + m_volumePopup(false) { SettingsStore & settings = SettingsStore::GetInstance(); settings.RegisterCallback(NXCoreSetting::GameFile, SciterMainWindow::GameFileChanged, this); settings.RegisterCallback(NXCoreSetting::GameName, SciterMainWindow::GameNameChanged, this); settings.RegisterCallback(NXCoreSetting::RomLoading, SciterMainWindow::RomLoadingChanged, this); settings.RegisterCallback(NXCoreSetting::DisplayedFrames, SciterMainWindow::DisplayedFramesChanged, this); + settings.RegisterCallback(NXOsSetting::AudioVolume, SciterMainWindow::SettingChanged, this); } void SciterMainWindow::ResetMenu() @@ -111,6 +114,10 @@ bool SciterMainWindow::Show(void) IVideo & video = system->Video(); video.UpdateFramebufferLayout(rect.right - rect.left, rect.bottom - rect.top); } + UpdateStatusbar(); + m_sciterUI.AttachHandler(rootElement, IID_IMOUSEUPDOWNSINK, (IMouseUpDownSink*)this); + m_sciterUI.AttachHandler(rootElement.GetElementByID("volume"), IID_ICLICKSINK, (IClickSink*)this); + m_sciterUI.AttachHandler(rootElement.GetElementByID("audioVolume"), IID_ISTATECHANGESINK, (IStateChangeSink*)this); return true; } @@ -284,6 +291,36 @@ int32_t SciterMainWindow::SciterKeyToVKCode(SciterKeys key) return 0; } +void SciterMainWindow::UpdateStatusbar() +{ + SettingsStore & settings = SettingsStore::GetInstance(); + SciterElement rootElement(m_window->GetRootElement()); + SciterElement volume(rootElement.GetElementByID("volume")); + stdstr_f text("VOLUME: %d %%", settings.GetInt(NXOsSetting::AudioVolume)); + volume.SetHTML((const uint8_t *)text.c_str(), text.size()); +} + +void SciterMainWindow::DismissvolumePopup(SCITER_ELEMENT source, int32_t x, int32_t y) +{ + if (!m_volumePopup) + { + return; + } + SciterElement rootElement(m_window->GetRootElement()); + if (source == rootElement.GetElementByID("volume")) + { + return; + } + SciterElement volumePopup(rootElement.GetElementByID("VolumePopup")); + SciterElement::RECT rc = volumePopup.GetLocation(SciterElement::ROOT_RELATIVE | SciterElement::BORDER_BOX); + if (x >= rc.left && y >= rc.top && x <= rc.right && y <= rc.bottom) + { + return; + } + m_sciterUI.PopupHide(rootElement.GetElementByID("VolumePopup")); + m_volumePopup = false; +} + void SciterMainWindow::SetCaption(const std::string & caption) { SciterElement rootElement(m_window->GetRootElement()); @@ -478,3 +515,50 @@ bool SciterMainWindow::OnSizeChanged(SCITER_ELEMENT elem) } return false; } + +bool SciterMainWindow::OnClick(SCITER_ELEMENT /*element*/, SCITER_ELEMENT source, uint32_t /*reason*/) +{ + SciterElement rootElement(m_window->GetRootElement()); + if (source == rootElement.GetElementByID("volume")) + { + m_sciterUI.PopupShow(rootElement.GetElementByID("VolumePopup"), rootElement.GetElementByID("volume"), 8); + m_volumePopup = true; + } + return true; +} + +bool SciterMainWindow::OnMouseUp(SCITER_ELEMENT /*element*/, SCITER_ELEMENT source, uint32_t x, uint32_t y) +{ + DismissvolumePopup(source, x, y); + return false; +} + +bool SciterMainWindow::OnMouseDown(SCITER_ELEMENT /*element*/, SCITER_ELEMENT source, uint32_t x, uint32_t y) +{ + DismissvolumePopup(source, x, y); + return false; +} + +bool SciterMainWindow::OnStateChange(SCITER_ELEMENT elem, uint32_t /*eventReason*/, void * /*data*/) +{ + SciterElement rootElement(m_window->GetRootElement()); + if (rootElement.GetElementByID("audioVolume") == elem) + { + SciterValue value = SciterElement(elem).GetValue(); + if (value.isInt()) + { + SettingsStore& settings = SettingsStore::GetInstance(); + settings.SetInt(NXOsSetting::AudioVolume, value.GetValueInt()); + } + } + return false; +} + +void SciterMainWindow::SettingChanged(const char * setting, void * userData) +{ + SciterMainWindow * impl = (SciterMainWindow*)userData; + if (strcmp(setting, NXOsSetting::AudioVolume) == 0) + { + impl->UpdateStatusbar(); + } +} diff --git a/src/nxemu/user_interface/sciter_main_window.h b/src/nxemu/user_interface/sciter_main_window.h index 5574636e..49a25d44 100644 --- a/src/nxemu/user_interface/sciter_main_window.h +++ b/src/nxemu/user_interface/sciter_main_window.h @@ -11,7 +11,10 @@ class SciterMainWindow : public IMenuBarSink, public IRenderWindow, public IKeySink, - public IResizeSink + public IResizeSink, + public IClickSink, + public IMouseUpDownSink, + public IStateChangeSink { enum MainMenuID { @@ -47,7 +50,9 @@ private: void ShowLoadingScreen(void); int32_t SciterKeyToSwitchKey(SciterKeys key); int32_t SciterKeyToVKCode(SciterKeys vkcode); - + void UpdateStatusbar(); + void DismissvolumePopup(SCITER_ELEMENT source, int32_t x, int32_t y); + void OnOpenFile(void); void OnFileExit(void); void OnSystemConfig(void); @@ -70,7 +75,19 @@ private: bool OnKeyChar(SCITER_ELEMENT element, SCITER_ELEMENT item, SciterKeys keyCode, uint32_t keyboardState) override; // IResizeSink - bool OnSizeChanged(SCITER_ELEMENT elem); + bool OnSizeChanged(SCITER_ELEMENT elem) override; + + // IClickSink + bool OnClick(SCITER_ELEMENT element, SCITER_ELEMENT source, uint32_t reason) override; + + // IMouseUpDownSink + bool OnMouseUp(SCITER_ELEMENT element, SCITER_ELEMENT source, uint32_t x, uint32_t y) override; + bool OnMouseDown(SCITER_ELEMENT element, SCITER_ELEMENT source, uint32_t x, uint32_t y) override; + + // IStateChangeSink + bool OnStateChange(SCITER_ELEMENT elem, uint32_t eventReason, void* data) override; + + static void SettingChanged(const char* setting, void* userData); ISciterUI & m_sciterUI; ISciterWindow * m_window; @@ -78,4 +95,5 @@ private: void * m_renderWindow; std::string m_windowTitle; SystemConfig m_systemConfig; + bool m_volumePopup; };