From 29e0da3eb63617ae82d78dce10689d925ffdeb41 Mon Sep 17 00:00:00 2001 From: oddMLan Date: Tue, 21 Apr 2020 06:30:41 -0700 Subject: [PATCH] GLideNUI-wtl: Lazy load Fonts treeview of OSD tab Speeds up dialog creation a little bit. Fix bug in which creating a new profile would give a font with zeroed parameters --- src/GLideNUI-wtl/ConfigDlg.cpp | 7 ++- src/GLideNUI-wtl/ConfigDlg.h | 2 + src/GLideNUI-wtl/config-osd.cpp | 83 ++++++++++++++++++++------------- src/GLideNUI-wtl/config-osd.h | 3 ++ 4 files changed, 61 insertions(+), 34 deletions(-) diff --git a/src/GLideNUI-wtl/ConfigDlg.cpp b/src/GLideNUI-wtl/ConfigDlg.cpp index edab5fe6..54c7b752 100644 --- a/src/GLideNUI-wtl/ConfigDlg.cpp +++ b/src/GLideNUI-wtl/ConfigDlg.cpp @@ -44,13 +44,14 @@ LRESULT CConfigDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lPar SetIcon(hIconSmall, FALSE); m_EmulationTab = new CEmulationTab(*this); + m_OsdTab = new COsdTab(); m_Tabs.Attach(GetDlgItem(IDC_TABS)); AddTab(TAB_VIDEO, new CVideoTab(*this, m_strIniPath.c_str())); AddTab(TAB_EMULATION, m_EmulationTab); AddTab(TAB_FRAME_BUFFER, new CFrameBufferTab); AddTab(TAB_TEXTURE_ENHANCEMENT, new CTextureEnhancementTab); - AddTab(TAB_OSD, new COsdTab); + AddTab(TAB_OSD, m_OsdTab); #ifdef DEBUG_DUMP AddTab(TAB_DEBUG, new CDebugTab); #endif @@ -352,6 +353,10 @@ void CConfigDlg::AddTab(languageStringID caption, CConfigTab * tab) { } void CConfigDlg::ShowTab(int nPage) { + if (nPage == 4 && !m_OsdTab->m_FontsLoaded) { // OSD tab + m_OsdTab->LoadFonts(); + } + for (size_t i = 0; i < m_TabWindows.size(); i++) m_TabWindows[i]->ShowWindow(SW_HIDE); diff --git a/src/GLideNUI-wtl/ConfigDlg.h b/src/GLideNUI-wtl/ConfigDlg.h index 6b9c7a32..efd334ad 100644 --- a/src/GLideNUI-wtl/ConfigDlg.h +++ b/src/GLideNUI-wtl/ConfigDlg.h @@ -7,6 +7,7 @@ #include class CEmulationTab; +class COsdTab; class CConfigDlg : public CDialogImpl @@ -61,6 +62,7 @@ protected: const char * m_romName; bool m_blockReInit; CEmulationTab * m_EmulationTab; + COsdTab * m_OsdTab; uint32_t m_TabLeft, m_ProfileLeft; bool m_Saved; }; diff --git a/src/GLideNUI-wtl/config-osd.cpp b/src/GLideNUI-wtl/config-osd.cpp index 8e2f7b2d..bb3c3d88 100644 --- a/src/GLideNUI-wtl/config-osd.cpp +++ b/src/GLideNUI-wtl/config-osd.cpp @@ -17,6 +17,7 @@ COsdTab::COsdTab() : m_PosBottom(IDI_OSD_BOTTOM), m_PosBottomRight(IDI_OSD_BOTTOM_RIGHT) { + m_FontsLoaded = false; } BOOL COsdTab::OnInitDialog(CWindow /*wndFocus*/, LPARAM /*lInitParam*/) @@ -44,6 +45,11 @@ BOOL COsdTab::OnInitDialog(CWindow /*wndFocus*/, LPARAM /*lInitParam*/) m_PosCenter.EnableWindow(false); m_PosCenterRight.EnableWindow(false); + return true; +} + +void COsdTab::LoadFonts(void) +{ FontList fonts = GetFontFiles(); HTREEITEM hCurrentItem = TVI_ROOT; for (FontList::const_iterator itr = fonts.begin(); itr != fonts.end(); itr++) { @@ -86,7 +92,40 @@ BOOL COsdTab::OnInitDialog(CWindow /*wndFocus*/, LPARAM /*lInitParam*/) m_Fonts.SetItemState(hCurrentItem, TVIF_STATE | TVIS_SELECTED, TVIF_STATE | TVIS_SELECTED); m_Fonts.SetFocus(); } - return true; + m_FontsLoaded = true; + SelCurrentFont(); +} + +void COsdTab::SelCurrentFont(void) +{ + std::wstring CurrentFile = ToUTF16(config.font.name.c_str()); + TVINSERTSTRUCT tv = { 0 }; + wchar_t Item[500]; + tv.item.mask = TVIF_TEXT; + tv.item.pszText = Item; + tv.item.cchTextMax = sizeof(Item) / sizeof(Item[0]); + tv.item.hItem = m_Fonts.GetChildItem(TVI_ROOT); + HTREEITEM hCurrentItem = NULL; + while (hCurrentItem == NULL && tv.item.hItem) { + m_Fonts.GetItem(&tv.item); + HTREEITEM hChild = m_Fonts.GetChildItem(tv.item.hItem); + HTREEITEM NextItem = m_Fonts.GetNextSiblingItem(tv.item.hItem); + if (hCurrentItem == NULL && hChild != NULL) { + tv.item.hItem = hChild; + while (hCurrentItem == NULL && tv.item.hItem) { + m_Fonts.GetItem(&tv.item); + if (Item == CurrentFile) + hCurrentItem = tv.item.hItem; + tv.item.hItem = m_Fonts.GetNextSiblingItem(tv.item.hItem); + } + } + tv.item.hItem = NextItem; + } + if (hCurrentItem != TVI_ROOT) { + m_Fonts.SelectItem(hCurrentItem); + m_Fonts.SetItemState(hCurrentItem, TVIF_STATE | TVIS_SELECTED, TVIF_STATE | TVIS_SELECTED); + m_Fonts.SetFocus(); + } } void COsdTab::ApplyLanguage(void) @@ -190,10 +229,14 @@ LRESULT COsdTab::OnNotifyOsdColor(LPNMHDR /*pnmh*/) void COsdTab::LoadSettings(bool /*blockCustomSettings*/) { m_FontSizeTxt.SetWindowText(FormatStrW(L"%d", config.font.size).c_str()); - m_FontSizeSpin.SetPos(config.font.size); - m_OsdColor.SetColor(config.font.color[0], config.font.color[1], config.font.color[2]); - m_OsdPreview.SetColor(config.font.color[0], config.font.color[1], config.font.color[2]); - m_OsdPreview.SetFontSize(config.font.size); + if (config.font.size > 0) { + m_FontSizeSpin.SetPos(config.font.size); + m_OsdPreview.SetFontSize(config.font.size); + } + if (!(config.font.color[0] == NULL && config.font.color[1] == NULL && config.font.color[2] == NULL)) { + m_OsdColor.SetColor(config.font.color[0], config.font.color[1], config.font.color[2]); + m_OsdPreview.SetColor(config.font.color[0], config.font.color[1], config.font.color[2]); + } m_PosTopLeft.SetChecked(config.onScreenDisplay.pos == Config::posTopLeft); m_PosTop.SetChecked(config.onScreenDisplay.pos == Config::posTopCenter); @@ -208,34 +251,8 @@ void COsdTab::LoadSettings(bool /*blockCustomSettings*/) CButton(GetDlgItem(IDC_INTERNAL_RESOLUTION)).SetCheck(config.onScreenDisplay.internalResolution != 0 ? BST_CHECKED : BST_UNCHECKED); CButton(GetDlgItem(IDC_RENDERING_RESOLUTION)).SetCheck(config.onScreenDisplay.renderingResolution != 0 ? BST_CHECKED : BST_UNCHECKED); - std::wstring CurrentFile = ToUTF16(config.font.name.c_str()); - TVINSERTSTRUCT tv = { 0 }; - wchar_t Item[500]; - tv.item.mask = TVIF_TEXT; - tv.item.pszText = Item; - tv.item.cchTextMax = sizeof(Item) / sizeof(Item[0]); - tv.item.hItem = m_Fonts.GetChildItem(TVI_ROOT); - HTREEITEM hCurrentItem = NULL; - while (hCurrentItem == NULL && tv.item.hItem) { - m_Fonts.GetItem(&tv.item); - HTREEITEM hChild = m_Fonts.GetChildItem(tv.item.hItem); - HTREEITEM NextItem = m_Fonts.GetNextSiblingItem(tv.item.hItem); - if (hCurrentItem == NULL && hChild != NULL) { - tv.item.hItem = hChild; - while (hCurrentItem == NULL && tv.item.hItem) { - m_Fonts.GetItem(&tv.item); - if (Item == CurrentFile) - hCurrentItem = tv.item.hItem; - tv.item.hItem = m_Fonts.GetNextSiblingItem(tv.item.hItem); - } - } - tv.item.hItem = NextItem; - } - if (hCurrentItem != TVI_ROOT) { - m_Fonts.SelectItem(hCurrentItem); - m_Fonts.SetItemState(hCurrentItem, TVIF_STATE | TVIS_SELECTED, TVIF_STATE | TVIS_SELECTED); - m_Fonts.SetFocus(); - } + if (m_FontsLoaded) + SelCurrentFont(); } void COsdTab::SaveSettings() diff --git a/src/GLideNUI-wtl/config-osd.h b/src/GLideNUI-wtl/config-osd.h index 85131e6b..c637e009 100644 --- a/src/GLideNUI-wtl/config-osd.h +++ b/src/GLideNUI-wtl/config-osd.h @@ -28,6 +28,7 @@ public: COsdTab(); + bool m_FontsLoaded; BOOL OnInitDialog(CWindow /*wndFocus*/, LPARAM /*lInitParam*/); LRESULT OnScroll(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/); void ClearOsdChecked(); @@ -41,6 +42,8 @@ public: LRESULT OnColorStatic(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/); LRESULT OnNotifyOsdColor(LPNMHDR pnmh); void ApplyLanguage(void); + void LoadFonts(void); + void SelCurrentFont(void); void LoadSettings(bool blockCustomSettings); void SaveSettings();