Make freetype usage configureable by a setting

master
PilzAdam 2013-08-04 20:18:56 +02:00
parent 3fd84edb61
commit 2af5864534
8 changed files with 48 additions and 14 deletions

View File

Before

Width:  |  Height:  |  Size: 8.3 KiB

After

Width:  |  Height:  |  Size: 8.3 KiB

View File

Before

Width:  |  Height:  |  Size: 7.5 KiB

After

Width:  |  Height:  |  Size: 7.5 KiB

View File

@ -189,6 +189,9 @@
# File in client/serverlist/ that contains your favorite servers displayed in the Multiplayer Tab # File in client/serverlist/ that contains your favorite servers displayed in the Multiplayer Tab
#serverlist_file = favoriteservers.txt #serverlist_file = favoriteservers.txt
# Whether freetype fonts are used, requires freetype support to be compiled in
#freetype = true
# Path to TrueTypeFont or bitmap
#font_path = fonts/liberationsans.ttf #font_path = fonts/liberationsans.ttf
#font_size = 13 #font_size = 13
#mono_font_path = fonts/liberationmono.ttf #mono_font_path = fonts/liberationmono.ttf

View File

@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "settings.h" #include "settings.h"
#include "filesys.h" #include "filesys.h"
#include "config.h"
void set_default_settings(Settings *settings) void set_default_settings(Settings *settings)
{ {
@ -141,10 +142,17 @@ void set_default_settings(Settings *settings)
settings->setDefault("server_name", ""); settings->setDefault("server_name", "");
settings->setDefault("server_description", ""); settings->setDefault("server_description", "");
#if USE_FREETYPE
settings->setDefault("freetype", "true");
settings->setDefault("font_path", porting::getDataPath("fonts" DIR_DELIM "liberationsans.ttf")); settings->setDefault("font_path", porting::getDataPath("fonts" DIR_DELIM "liberationsans.ttf"));
settings->setDefault("font_size", "13"); settings->setDefault("font_size", "13");
settings->setDefault("mono_font_path", porting::getDataPath("fonts" DIR_DELIM "liberationmono.ttf")); settings->setDefault("mono_font_path", porting::getDataPath("fonts" DIR_DELIM "liberationmono.ttf"));
settings->setDefault("mono_font_size", "13"); settings->setDefault("mono_font_size", "13");
#else
settings->setDefault("freetype", "false");
settings->setDefault("font_path", porting::getDataPath("fonts" DIR_DELIM "fontlucida.png"));
settings->setDefault("mono_font_path", porting::getDataPath("textures" DIR_DELIM "fontdejavusansmono.png"));
#endif
// Server stuff // Server stuff
// "map-dir" doesn't exist by default. // "map-dir" doesn't exist by default.

View File

@ -94,13 +94,17 @@ GUIChatConsole::GUIChatConsole(
// load the font // load the font
// FIXME should a custom texture_path be searched too? // FIXME should a custom texture_path be searched too?
#if USE_FREETYPE
std::string font_name = g_settings->get("mono_font_path"); std::string font_name = g_settings->get("mono_font_path");
u16 font_size = g_settings->getU16("mono_font_size"); #if USE_FREETYPE
m_font = gui::CGUITTFont::createTTFont(env, font_name.c_str(), font_size); m_use_freetype = g_settings->getBool("freetype");
if (m_use_freetype) {
u16 font_size = g_settings->getU16("mono_font_size");
m_font = gui::CGUITTFont::createTTFont(env, font_name.c_str(), font_size);
} else {
m_font = env->getFont(font_name.c_str());
}
#else #else
std::string font_name = "fontdejavusansmono.png"; m_font = env->getFont(font_name.c_str());
m_font = env->getFont(getTexturePath(font_name).c_str());
#endif #endif
if (m_font == NULL) if (m_font == NULL)
{ {
@ -122,7 +126,8 @@ GUIChatConsole::GUIChatConsole(
GUIChatConsole::~GUIChatConsole() GUIChatConsole::~GUIChatConsole()
{ {
#if USE_FREETYPE #if USE_FREETYPE
m_font->drop(); if (m_use_freetype)
m_font->drop();
#endif #endif
} }

View File

@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "irrlichttypes_extrabloated.h" #include "irrlichttypes_extrabloated.h"
#include "chat.h" #include "chat.h"
#include "config.h"
class Client; class Client;
@ -121,6 +122,9 @@ private:
// font // font
gui::IGUIFont* m_font; gui::IGUIFont* m_font;
v2u32 m_fontsize; v2u32 m_fontsize;
#if USE_FREETYPE
bool m_use_freetype;
#endif
}; };

View File

@ -20,6 +20,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "guiTextInputMenu.h" #include "guiTextInputMenu.h"
#include "debug.h" #include "debug.h"
#include "serialization.h" #include "serialization.h"
#include "main.h" // for g_settings
#include "settings.h"
#include <string> #include <string>
#include <IGUICheckBox.h> #include <IGUICheckBox.h>
#include <IGUIEditBox.h> #include <IGUIEditBox.h>
@ -109,11 +111,16 @@ void GUITextInputMenu::regenerateGui(v2u32 screensize)
{ {
core::rect<s32> rect(0, 0, 300, 30); core::rect<s32> rect(0, 0, 300, 30);
rect = rect + v2s32(size.X/2-300/2, size.Y/2-30/2-25); rect = rect + v2s32(size.X/2-300/2, size.Y/2-30/2-25);
gui::IGUIElement *e;
#if USE_FREETYPE #if USE_FREETYPE
gui::IGUIElement *e = (gui::IGUIElement *) new gui::intlGUIEditBox(text.c_str(), true, Environment, this, 256, rect); if (g_settings->getBool("freetype")) {
e->drop(); e = (gui::IGUIElement *) new gui::intlGUIEditBox(text.c_str(), true, Environment, this, 256, rect);
e->drop();
} else {
e = Environment->addEditBox(text.c_str(), rect, true, this, 256);
}
#else #else
gui::IGUIElement *e = Environment->addEditBox(text.c_str(), rect, true, this, 256); e = Environment->addEditBox(text.c_str(), rect, true, this, 256);
#endif #endif
Environment->setFocus(e); Environment->setFocus(e);

View File

@ -1388,12 +1388,18 @@ int main(int argc, char *argv[])
guienv = device->getGUIEnvironment(); guienv = device->getGUIEnvironment();
gui::IGUISkin* skin = guienv->getSkin(); gui::IGUISkin* skin = guienv->getSkin();
#if USE_FREETYPE
std::string font_path = g_settings->get("font_path"); std::string font_path = g_settings->get("font_path");
u16 font_size = g_settings->getU16("font_size"); gui::IGUIFont *font;
gui::IGUIFont *font = gui::CGUITTFont::createTTFont(guienv, font_path.c_str(), font_size); bool use_freetype = g_settings->getBool("freetype");
#if USE_FREETYPE
if (use_freetype) {
u16 font_size = g_settings->getU16("font_size");
font = gui::CGUITTFont::createTTFont(guienv, font_path.c_str(), font_size);
} else {
font = guienv->getFont(font_path.c_str());
}
#else #else
gui::IGUIFont* font = guienv->getFont(getTexturePath("fontlucida.png").c_str()); font = guienv->getFont(font_path.c_str());
#endif #endif
if(font) if(font)
skin->setFont(font); skin->setFont(font);
@ -1736,7 +1742,8 @@ int main(int argc, char *argv[])
device->drop(); device->drop();
#if USE_FREETYPE #if USE_FREETYPE
font->drop(); if (use_freetype)
font->drop();
#endif #endif
#endif // !SERVER #endif // !SERVER