1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Implement proper font handling

This commit is contained in:
sapier 2014-11-23 13:40:43 +01:00
parent 25945dc539
commit dceb9f7d60
91 changed files with 902 additions and 194 deletions

View file

@ -69,9 +69,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "profiler.h"
#include "log.h"
#include "mods.h"
#if USE_FREETYPE
#include "xCGUITTFont.h"
#endif
#include "util/string.h"
#include "subgame.h"
#include "quicktune.h"
@ -80,6 +77,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "guiEngine.h"
#include "mapsector.h"
#include "player.h"
#include "fontengine.h"
#include "database-sqlite3.h"
#ifdef USE_LEVELDB
@ -1571,13 +1569,11 @@ ClientLauncher::~ClientLauncher()
if (input)
delete input;
if (glb_fontengine)
delete glb_fontengine;
if (device)
device->drop();
#if USE_FREETYPE
if (use_freetype && font != NULL)
font->drop();
#endif
}
bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
@ -1593,8 +1589,6 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
return false;
}
late_init_default_settings(g_settings);
// Speed tests (done after irrlicht is loaded to get timer)
if (cmd_args.getFlag("speedtests")) {
dstream << "Running speed tests" << std::endl;
@ -1630,45 +1624,15 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
guienv = device->getGUIEnvironment();
skin = guienv->getSkin();
std::string font_path = g_settings->get("font_path");
#if USE_FREETYPE
if (use_freetype) {
std::string fallback;
if (is_yes(gettext("needs_fallback_font")))
fallback = "fallback_";
u16 font_size = g_settings->getU16(fallback + "font_size");
font_path = g_settings->get(fallback + "font_path");
u32 font_shadow = g_settings->getU16(fallback + "font_shadow");
u32 font_shadow_alpha = g_settings->getU16(fallback + "font_shadow_alpha");
font = gui::CGUITTFont::createTTFont(guienv,
font_path.c_str(), font_size, true, true,
font_shadow, font_shadow_alpha);
} else {
font = guienv->getFont(font_path.c_str());
}
#else
font = guienv->getFont(font_path.c_str());
#endif
if (font)
skin->setFont(font);
else
errorstream << "WARNING: Font file was not found. Using default font."
<< std::endl;
font = skin->getFont(); // If font was not found, this will get us one
assert(font);
u32 text_height = font->getDimension(L"Hello, world!").Height;
infostream << "text_height=" << text_height << std::endl;
skin->setColor(gui::EGDC_BUTTON_TEXT, video::SColor(255, 255, 255, 255));
skin->setColor(gui::EGDC_3D_HIGH_LIGHT, video::SColor(255, 0, 0, 0));
skin->setColor(gui::EGDC_3D_SHADOW, video::SColor(255, 0, 0, 0));
skin->setColor(gui::EGDC_HIGH_LIGHT, video::SColor(255, 70, 100, 50));
skin->setColor(gui::EGDC_HIGH_LIGHT_TEXT, video::SColor(255, 255, 255, 255));
glb_fontengine = new FontEngine(g_settings, guienv);
assert(glb_fontengine != NULL);
#if (IRRLICHT_VERSION_MAJOR >= 1 && IRRLICHT_VERSION_MINOR >= 8) || IRRLICHT_VERSION_MAJOR >= 2
// Irrlicht 1.8 input colours
skin->setColor(gui::EGDC_EDITABLE, video::SColor(255, 128, 128, 128));
@ -1764,7 +1728,6 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
random_input,
input,
device,
font,
worldspec.path,
current_playername,
current_password,