Skip to content

Instantly share code, notes, and snippets.

@PilzAdam
Last active December 20, 2015 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PilzAdam/6151207 to your computer and use it in GitHub Desktop.
Save PilzAdam/6151207 to your computer and use it in GitHub Desktop.
diff --git a/fonts/fontdejavusansmono.png b/fonts/fontdejavusansmono.png
new file mode 100644
index 0000000..02ad413
Binary files /dev/null and b/fonts/fontdejavusansmono.png differ
diff --git a/fonts/fontlucida.png b/fonts/fontlucida.png
new file mode 100644
index 0000000..ab7bb70
Binary files /dev/null and b/fonts/fontlucida.png differ
diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp
index 33adf10..aac2516 100644
--- a/src/defaultsettings.cpp
+++ b/src/defaultsettings.cpp
@@ -19,6 +19,7 @@
#include "settings.h"
#include "filesys.h"
+#include "config.h"
void set_default_settings(Settings *settings)
{
@@ -141,10 +142,17 @@ void set_default_settings(Settings *settings)
settings->setDefault("server_name", "");
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_size", "13");
settings->setDefault("mono_font_path", porting::getDataPath("fonts" DIR_DELIM "liberationmono.ttf"));
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
// "map-dir" doesn't exist by default.
diff --git a/src/guiChatConsole.cpp b/src/guiChatConsole.cpp
index daec18e..d8881db 100644
--- a/src/guiChatConsole.cpp
+++ b/src/guiChatConsole.cpp
@@ -94,13 +94,17 @@ inline u32 clamp_u8(s32 value)
// load the font
// FIXME should a custom texture_path be searched too?
- #if USE_FREETYPE
std::string font_name = g_settings->get("mono_font_path");
- u16 font_size = g_settings->getU16("mono_font_size");
- m_font = gui::CGUITTFont::createTTFont(env, font_name.c_str(), font_size);
+ #if USE_FREETYPE
+ 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
- std::string font_name = "fontdejavusansmono.png";
- m_font = env->getFont(getTexturePath(font_name).c_str());
+ m_font = env->getFont(font_name.c_str());
#endif
if (m_font == NULL)
{
@@ -122,7 +126,8 @@ inline u32 clamp_u8(s32 value)
GUIChatConsole::~GUIChatConsole()
{
#if USE_FREETYPE
- m_font->drop();
+ if (m_use_freetype)
+ m_font->drop();
#endif
}
diff --git a/src/guiChatConsole.h b/src/guiChatConsole.h
index 5991157..5b0db67 100644
--- a/src/guiChatConsole.h
+++ b/src/guiChatConsole.h
@@ -121,6 +121,7 @@ class GUIChatConsole : public gui::IGUIElement
// font
gui::IGUIFont* m_font;
v2u32 m_fontsize;
+ bool m_use_freetype;
};
diff --git a/src/guiTextInputMenu.cpp b/src/guiTextInputMenu.cpp
index d5229f4..9285aaa 100644
--- a/src/guiTextInputMenu.cpp
+++ b/src/guiTextInputMenu.cpp
@@ -20,6 +20,8 @@
#include "guiTextInputMenu.h"
#include "debug.h"
#include "serialization.h"
+#include "main.h" // for g_settings
+#include "settings.h"
#include <string>
#include <IGUICheckBox.h>
#include <IGUIEditBox.h>
@@ -109,11 +111,16 @@ void GUITextInputMenu::regenerateGui(v2u32 screensize)
{
core::rect<s32> rect(0, 0, 300, 30);
rect = rect + v2s32(size.X/2-300/2, size.Y/2-30/2-25);
+ gui::IGUIElement *e;
#if USE_FREETYPE
- gui::IGUIElement *e = (gui::IGUIElement *) new gui::intlGUIEditBox(text.c_str(), true, Environment, this, 256, rect);
- e->drop();
+ if (g_settings->getBool("freetype")) {
+ 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
- gui::IGUIElement *e = Environment->addEditBox(text.c_str(), rect, true, this, 256);
+ e = Environment->addEditBox(text.c_str(), rect, true, this, 256);
#endif
Environment->setFocus(e);
diff --git a/src/main.cpp b/src/main.cpp
index b3aa9c9..f495a6b 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1388,12 +1388,18 @@ int main(int argc, char *argv[])
guienv = device->getGUIEnvironment();
gui::IGUISkin* skin = guienv->getSkin();
- #if USE_FREETYPE
std::string font_path = g_settings->get("font_path");
- u16 font_size = g_settings->getU16("font_size");
- gui::IGUIFont *font = gui::CGUITTFont::createTTFont(guienv, font_path.c_str(), font_size);
+ gui::IGUIFont *font;
+ 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
- gui::IGUIFont* font = guienv->getFont(getTexturePath("fontlucida.png").c_str());
+ font = guienv->getFont(font_path.c_str());
#endif
if(font)
skin->setFont(font);
@@ -1736,7 +1742,8 @@ int main(int argc, char *argv[])
device->drop();
#if USE_FREETYPE
- font->drop();
+ if (use_freetype)
+ font->drop();
#endif
#endif // !SERVER
diff --git a/textures/base/pack/fontdejavusansmono.png b/textures/base/pack/fontdejavusansmono.png
deleted file mode 100644
index 02ad413..0000000
Binary files a/textures/base/pack/fontdejavusansmono.png and /dev/null differ
diff --git a/textures/base/pack/fontlucida.png b/textures/base/pack/fontlucida.png
deleted file mode 100644
index ab7bb70..0000000
Binary files a/textures/base/pack/fontlucida.png and /dev/null differ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment