Merge pull request #1545 from def-/pr-load-font

Move out common font loading into method
This commit is contained in:
Dennis Felsing 2019-03-28 23:38:24 +01:00 committed by GitHub
commit 138a9c6ff7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 34 deletions

View file

@ -112,6 +112,7 @@ public:
virtual void ToggleFullscreen() = 0;
virtual void ToggleWindowBordered() = 0;
virtual void ToggleWindowVSync() = 0;
virtual void LoadFont() = 0;
// networking
virtual void EnterGame() = 0;

View file

@ -3508,6 +3508,28 @@ void CClient::ToggleWindowVSync()
g_Config.m_GfxVsync ^= 1;
}
void CClient::LoadFont()
{
static CFont *pDefaultFont = 0;
char aFilename[512];
const char *pFontFile = "fonts/DejaVuSansCJKName.ttf";
if(str_find(g_Config.m_ClLanguagefile, "chinese") != NULL || str_find(g_Config.m_ClLanguagefile, "japanese") != NULL ||
str_find(g_Config.m_ClLanguagefile, "korean") != NULL)
pFontFile = "fonts/DejavuWenQuanYiMicroHei.ttf";
IOHANDLE File = Storage()->OpenFile(pFontFile, IOFLAG_READ, IStorage::TYPE_ALL, aFilename, sizeof(aFilename));
if(File)
{
io_close(File);
IEngineTextRender *pTextRender = Kernel()->RequestInterface<IEngineTextRender>();
pDefaultFont = pTextRender->GetFont(aFilename);
if(pDefaultFont == NULL)
pDefaultFont = pTextRender->LoadFont(aFilename);
Kernel()->RequestInterface<IEngineTextRender>()->SetDefaultFont(pDefaultFont);
}
if(!pDefaultFont)
m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "gameclient", "failed to load font. filename='%s'", pFontFile);
}
void CClient::ConchainWindowVSync(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData)
{
CClient *pSelf = (CClient *)pUserData;

View file

@ -391,6 +391,7 @@ public:
void ToggleFullscreen();
void ToggleWindowBordered();
void ToggleWindowVSync();
void LoadFont();
// DDRace

View file

@ -1346,24 +1346,7 @@ void CMenus::RenderLanguageSelection(CUIRect MainView)
{
str_copy(g_Config.m_ClLanguagefile, s_Languages[s_SelectedLanguage].m_FileName, sizeof(g_Config.m_ClLanguagefile));
g_Localization.Load(s_Languages[s_SelectedLanguage].m_FileName, Storage(), Console());
// Load Font
static CFont *pDefaultFont = 0;
char aFilename[512];
const char *pFontFile = "fonts/DejaVuSansCJKName.ttf";
if(str_find(g_Config.m_ClLanguagefile, "chinese") != NULL || str_find(g_Config.m_ClLanguagefile, "japanese") != NULL ||
str_find(g_Config.m_ClLanguagefile, "korean") != NULL)
pFontFile = "fonts/DejavuWenQuanYiMicroHei.ttf";
IOHANDLE File = Storage()->OpenFile(pFontFile, IOFLAG_READ, IStorage::TYPE_ALL, aFilename, sizeof(aFilename));
if(File)
{
io_close(File);
if((pDefaultFont = TextRender()->GetFont(aFilename)) == NULL)
pDefaultFont = TextRender()->LoadFont(aFilename);
TextRender()->SetDefaultFont(pDefaultFont);
}
if(!pDefaultFont)
Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "gameclient", "failed to load font. filename='%s'", pFontFile);
Client()->LoadFont();
}
}

View file

@ -290,22 +290,7 @@ void CGameClient::OnInit()
for(int i = 0; i < NUM_NETOBJTYPES; i++)
Client()->SnapSetStaticsize(i, m_NetObjHandler.GetObjSize(i));
// load default font
static CFont *pDefaultFont = 0;
char aFilename[512];
const char *pFontFile = "fonts/DejaVuSansCJKName.ttf";
if(str_find(g_Config.m_ClLanguagefile, "chinese") != NULL || str_find(g_Config.m_ClLanguagefile, "japanese") != NULL ||
str_find(g_Config.m_ClLanguagefile, "korean") != NULL)
pFontFile = "fonts/DejavuWenQuanYiMicroHei.ttf";
IOHANDLE File = Storage()->OpenFile(pFontFile, IOFLAG_READ, IStorage::TYPE_ALL, aFilename, sizeof(aFilename));
if(File)
{
io_close(File);
pDefaultFont = TextRender()->LoadFont(aFilename);
TextRender()->SetDefaultFont(pDefaultFont);
}
if(!pDefaultFont)
Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "gameclient", "failed to load font. filename='%s'", pFontFile);
Client()->LoadFont();
// init all components
for(int i = m_All.m_Num-1; i >= 0; --i)