1
0
mirror of https://github.com/blawar/GLideN64.git synced 2024-07-02 09:03:37 +00:00

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
This commit is contained in:
oddMLan 2020-04-21 06:30:41 -07:00 committed by Sergey Lipskiy
parent b0cf0ede8e
commit 29e0da3eb6
4 changed files with 61 additions and 34 deletions

View File

@ -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);

View File

@ -7,6 +7,7 @@
#include <vector>
class CEmulationTab;
class COsdTab;
class CConfigDlg :
public CDialogImpl<CConfigDlg>
@ -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;
};

View File

@ -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()

View File

@ -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();