mirror of https://github.com/OpenTTD/OpenTTD.git
Add: 'font' console command to configure fonts
This commit is contained in:
parent
e6c857cdba
commit
04ee86d3ac
|
@ -23,6 +23,7 @@
|
||||||
#include "settings_func.h"
|
#include "settings_func.h"
|
||||||
#include "fios.h"
|
#include "fios.h"
|
||||||
#include "fileio_func.h"
|
#include "fileio_func.h"
|
||||||
|
#include "fontcache.h"
|
||||||
#include "screenshot.h"
|
#include "screenshot.h"
|
||||||
#include "genworld.h"
|
#include "genworld.h"
|
||||||
#include "strings_func.h"
|
#include "strings_func.h"
|
||||||
|
@ -1982,6 +1983,82 @@ DEF_CONSOLE_CMD(ConContent)
|
||||||
}
|
}
|
||||||
#endif /* defined(WITH_ZLIB) */
|
#endif /* defined(WITH_ZLIB) */
|
||||||
|
|
||||||
|
DEF_CONSOLE_CMD(ConFont)
|
||||||
|
{
|
||||||
|
if (argc == 0) {
|
||||||
|
IConsolePrint(CC_HELP, "Manage the fonts configuration.");
|
||||||
|
IConsolePrint(CC_HELP, "Usage 'font'.");
|
||||||
|
IConsolePrint(CC_HELP, " Print out the fonts configuration.");
|
||||||
|
IConsolePrint(CC_HELP, "Usage 'font [medium|small|large|mono] [<name>] [<size>] [aa|noaa]'.");
|
||||||
|
IConsolePrint(CC_HELP, " Change the configuration for a font.");
|
||||||
|
IConsolePrint(CC_HELP, " Omitting an argument will keep the current value.");
|
||||||
|
IConsolePrint(CC_HELP, " Set <name> to \"\" for the sprite font (size and aa have no effect on sprite font).");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
FontSize argfs;
|
||||||
|
for (argfs = FS_BEGIN; argfs < FS_END; argfs++) {
|
||||||
|
if (argc > 1 && strcasecmp(argv[1], FontSizeToName(argfs)) == 0) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* First argument must be a FontSize. */
|
||||||
|
if (argc > 1 && argfs == FS_END) return false;
|
||||||
|
|
||||||
|
if (argc > 2) {
|
||||||
|
FontCacheSubSetting *setting = GetFontCacheSubSetting(argfs);
|
||||||
|
std::string font = setting->font;
|
||||||
|
uint size = setting->size;
|
||||||
|
bool aa = setting->aa;
|
||||||
|
|
||||||
|
byte arg_index = 2;
|
||||||
|
|
||||||
|
if (argc > arg_index) {
|
||||||
|
/* We may encounter "aa" or "noaa" but it must be the last argument. */
|
||||||
|
if (strcasecmp(argv[arg_index], "aa") == 0 || strcasecmp(argv[arg_index], "noaa") == 0) {
|
||||||
|
aa = strncasecmp(argv[arg_index++], "no", 2) != 0;
|
||||||
|
if (argc > arg_index) return false;
|
||||||
|
} else {
|
||||||
|
/* For <name> we want a string. */
|
||||||
|
uint v;
|
||||||
|
if (!GetArgumentInteger(&v, argv[arg_index])) {
|
||||||
|
font = argv[arg_index++];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argc > arg_index) {
|
||||||
|
/* For <size> we want a number. */
|
||||||
|
uint v;
|
||||||
|
if (GetArgumentInteger(&v, argv[arg_index])) {
|
||||||
|
size = v;
|
||||||
|
arg_index++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argc > arg_index) {
|
||||||
|
/* Last argument must be "aa" or "noaa". */
|
||||||
|
if (strcasecmp(argv[arg_index], "aa") != 0 && strcasecmp(argv[arg_index], "noaa") != 0) return false;
|
||||||
|
aa = strncasecmp(argv[arg_index++], "no", 2) != 0;
|
||||||
|
if (argc > arg_index) return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
SetFont(argfs, font, size, aa);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (FontSize fs = FS_BEGIN; fs < FS_END; fs++) {
|
||||||
|
FontCache *fc = FontCache::Get(fs);
|
||||||
|
FontCacheSubSetting *setting = GetFontCacheSubSetting(fs);
|
||||||
|
/* Make sure all non sprite fonts are loaded. */
|
||||||
|
if (!setting->font.empty() && !fc->HasParent()) {
|
||||||
|
InitFontCache(fs == FS_MONO);
|
||||||
|
fc = FontCache::Get(fs);
|
||||||
|
}
|
||||||
|
IConsolePrint(CC_DEFAULT, "{}: \"{}\" {} {} [\"{}\" {} {}]", FontSizeToName(fs), fc->GetFontName(), fc->GetFontSize(), GetFontAAState(fs), setting->font, setting->size, setting->aa);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
DEF_CONSOLE_CMD(ConSetting)
|
DEF_CONSOLE_CMD(ConSetting)
|
||||||
{
|
{
|
||||||
if (argc == 0) {
|
if (argc == 0) {
|
||||||
|
@ -2480,6 +2557,7 @@ void IConsoleStdLibRegister()
|
||||||
IConsole::CmdRegister("cd", ConChangeDirectory);
|
IConsole::CmdRegister("cd", ConChangeDirectory);
|
||||||
IConsole::CmdRegister("pwd", ConPrintWorkingDirectory);
|
IConsole::CmdRegister("pwd", ConPrintWorkingDirectory);
|
||||||
IConsole::CmdRegister("clear", ConClearBuffer);
|
IConsole::CmdRegister("clear", ConClearBuffer);
|
||||||
|
IConsole::CmdRegister("font", ConFont);
|
||||||
IConsole::CmdRegister("setting", ConSetting);
|
IConsole::CmdRegister("setting", ConSetting);
|
||||||
IConsole::CmdRegister("setting_newgame", ConSettingNewgame);
|
IConsole::CmdRegister("setting_newgame", ConSettingNewgame);
|
||||||
IConsole::CmdRegister("list_settings", ConListSettings);
|
IConsole::CmdRegister("list_settings", ConListSettings);
|
||||||
|
|
|
@ -13,6 +13,11 @@
|
||||||
#include "blitter/factory.hpp"
|
#include "blitter/factory.hpp"
|
||||||
#include "gfx_layout.h"
|
#include "gfx_layout.h"
|
||||||
#include "fontcache/spritefontcache.h"
|
#include "fontcache/spritefontcache.h"
|
||||||
|
#include "openttd.h"
|
||||||
|
#include "settings_func.h"
|
||||||
|
#include "strings_func.h"
|
||||||
|
#include "viewport_func.h"
|
||||||
|
#include "window_func.h"
|
||||||
|
|
||||||
#include "safeguards.h"
|
#include "safeguards.h"
|
||||||
|
|
||||||
|
@ -73,6 +78,49 @@ bool GetFontAAState(FontSize size, bool check_blitter)
|
||||||
return GetFontCacheSubSetting(size)->aa;
|
return GetFontCacheSubSetting(size)->aa;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetFont(FontSize fontsize, const std::string& font, uint size, bool aa)
|
||||||
|
{
|
||||||
|
FontCacheSubSetting *setting = GetFontCacheSubSetting(fontsize);
|
||||||
|
bool changed = false;
|
||||||
|
|
||||||
|
if (setting->font != font) {
|
||||||
|
setting->font = font;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (setting->size != size) {
|
||||||
|
setting->size = size;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (setting->aa != aa) {
|
||||||
|
setting->aa = aa;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!changed) return;
|
||||||
|
|
||||||
|
if (fontsize != FS_MONO) {
|
||||||
|
/* Try to reload only the modified font. */
|
||||||
|
FontCacheSettings backup = _fcsettings;
|
||||||
|
for (FontSize fs = FS_BEGIN; fs < FS_END; fs++) {
|
||||||
|
if (fs == fontsize) continue;
|
||||||
|
FontCache *fc = FontCache::Get(fs);
|
||||||
|
GetFontCacheSubSetting(fs)->font = fc->HasParent() ? fc->GetFontName() : "";
|
||||||
|
}
|
||||||
|
CheckForMissingGlyphs();
|
||||||
|
_fcsettings = backup;
|
||||||
|
} else {
|
||||||
|
InitFontCache(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
LoadStringWidthTable();
|
||||||
|
UpdateAllVirtCoords();
|
||||||
|
ReInitAllWindows(true);
|
||||||
|
|
||||||
|
if (_save_config) SaveToConfig();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (Re)initialize the font cache related things, i.e. load the non-sprite fonts.
|
* (Re)initialize the font cache related things, i.e. load the non-sprite fonts.
|
||||||
* @param monospace Whether to initialise the monospace or regular fonts.
|
* @param monospace Whether to initialise the monospace or regular fonts.
|
||||||
|
|
|
@ -239,5 +239,6 @@ void UninitFontCache();
|
||||||
bool HasAntialiasedFonts();
|
bool HasAntialiasedFonts();
|
||||||
|
|
||||||
bool GetFontAAState(FontSize size, bool check_blitter = true);
|
bool GetFontAAState(FontSize size, bool check_blitter = true);
|
||||||
|
void SetFont(FontSize fontsize, const std::string &font, uint size, bool aa);
|
||||||
|
|
||||||
#endif /* FONTCACHE_H */
|
#endif /* FONTCACHE_H */
|
||||||
|
|
Loading…
Reference in New Issue