You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
2.5 KiB
97 lines
2.5 KiB
|
7 years ago
|
#include "DiabloUI/fonts.h"
|
||
|
5 years ago
|
|
||
|
|
#include "diablo.h"
|
||
|
5 years ago
|
#include "utils/file_util.h"
|
||
|
|
#include "utils/paths.h"
|
||
|
7 years ago
|
|
||
|
5 years ago
|
namespace devilution {
|
||
|
7 years ago
|
|
||
|
6 years ago
|
TTF_Font *font = NULL;
|
||
|
7 years ago
|
BYTE *FontTables[4];
|
||
|
|
Art ArtFonts[4][2];
|
||
|
6 years ago
|
/** This is so we know ttf has been init when we get to the diablo_deinit() function */
|
||
|
5 years ago
|
bool was_fonts_init = false;
|
||
|
7 years ago
|
|
||
|
|
namespace {
|
||
|
|
|
||
|
6 years ago
|
void LoadArtFont(const char *pszFile, int size, int color)
|
||
|
7 years ago
|
{
|
||
|
|
LoadMaskedArt(pszFile, &ArtFonts[size][color], 256, 32);
|
||
|
|
}
|
||
|
|
|
||
|
|
} // namespace
|
||
|
|
|
||
|
|
void LoadArtFonts()
|
||
|
|
{
|
||
|
|
FontTables[AFT_SMALL] = LoadFileInMem("ui_art\\font16.bin", 0);
|
||
|
|
FontTables[AFT_MED] = LoadFileInMem("ui_art\\font24.bin", 0);
|
||
|
|
FontTables[AFT_BIG] = LoadFileInMem("ui_art\\font30.bin", 0);
|
||
|
|
FontTables[AFT_HUGE] = LoadFileInMem("ui_art\\font42.bin", 0);
|
||
|
|
LoadArtFont("ui_art\\font16s.pcx", AFT_SMALL, AFC_SILVER);
|
||
|
|
LoadArtFont("ui_art\\font16g.pcx", AFT_SMALL, AFC_GOLD);
|
||
|
|
LoadArtFont("ui_art\\font24s.pcx", AFT_MED, AFC_SILVER);
|
||
|
|
LoadArtFont("ui_art\\font24g.pcx", AFT_MED, AFC_GOLD);
|
||
|
|
LoadArtFont("ui_art\\font30s.pcx", AFT_BIG, AFC_SILVER);
|
||
|
|
LoadArtFont("ui_art\\font30g.pcx", AFT_BIG, AFC_GOLD);
|
||
|
|
LoadArtFont("ui_art\\font42g.pcx", AFT_HUGE, AFC_GOLD);
|
||
|
|
}
|
||
|
|
|
||
|
|
void UnloadArtFonts()
|
||
|
|
{
|
||
|
|
ArtFonts[AFT_SMALL][AFC_SILVER].Unload();
|
||
|
|
ArtFonts[AFT_SMALL][AFC_GOLD].Unload();
|
||
|
|
ArtFonts[AFT_MED][AFC_SILVER].Unload();
|
||
|
|
ArtFonts[AFT_MED][AFC_GOLD].Unload();
|
||
|
|
ArtFonts[AFT_BIG][AFC_SILVER].Unload();
|
||
|
|
ArtFonts[AFT_BIG][AFC_GOLD].Unload();
|
||
|
|
ArtFonts[AFT_HUGE][AFC_GOLD].Unload();
|
||
|
|
mem_free_dbg(FontTables[AFT_SMALL]);
|
||
|
6 years ago
|
FontTables[AFT_SMALL] = NULL;
|
||
|
7 years ago
|
mem_free_dbg(FontTables[AFT_MED]);
|
||
|
6 years ago
|
FontTables[AFT_MED] = NULL;
|
||
|
7 years ago
|
mem_free_dbg(FontTables[AFT_BIG]);
|
||
|
6 years ago
|
FontTables[AFT_BIG] = NULL;
|
||
|
7 years ago
|
mem_free_dbg(FontTables[AFT_HUGE]);
|
||
|
6 years ago
|
FontTables[AFT_HUGE] = NULL;
|
||
|
7 years ago
|
}
|
||
|
|
|
||
|
5 years ago
|
void LoadTtfFont()
|
||
|
|
{
|
||
|
7 years ago
|
if (!TTF_WasInit()) {
|
||
|
|
if (TTF_Init() == -1) {
|
||
|
6 years ago
|
SDL_Log("TTF_Init: %s", TTF_GetError());
|
||
|
6 years ago
|
diablo_quit(1);
|
||
|
7 years ago
|
}
|
||
|
6 years ago
|
was_fonts_init = true;
|
||
|
7 years ago
|
}
|
||
|
|
|
||
|
5 years ago
|
std::string ttf_font_path = GetTtfPath() + GetTtfName();
|
||
|
6 years ago
|
#ifdef __linux__
|
||
|
5 years ago
|
if (!FileExists(ttf_font_path.c_str())) {
|
||
|
5 years ago
|
ttf_font_path = "/usr/share/fonts/truetype/" + GetTtfName();
|
||
|
6 years ago
|
}
|
||
|
|
#endif
|
||
|
5 years ago
|
font = TTF_OpenFont(ttf_font_path.c_str(), 17);
|
||
|
7 years ago
|
if (font == NULL) {
|
||
|
6 years ago
|
SDL_Log("TTF_OpenFont: %s", TTF_GetError());
|
||
|
7 years ago
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
TTF_SetFontKerning(font, false);
|
||
|
|
TTF_SetFontHinting(font, TTF_HINTING_MONO);
|
||
|
|
}
|
||
|
|
|
||
|
5 years ago
|
void UnloadTtfFont()
|
||
|
|
{
|
||
|
7 years ago
|
if (font && TTF_WasInit())
|
||
|
7 years ago
|
TTF_CloseFont(font);
|
||
|
6 years ago
|
font = NULL;
|
||
|
7 years ago
|
}
|
||
|
|
|
||
|
5 years ago
|
void FontsCleanup()
|
||
|
|
{
|
||
|
|
TTF_Quit();
|
||
|
6 years ago
|
}
|
||
|
|
|
||
|
5 years ago
|
} // namespace devilution
|