dump(core.setting_getbool("enable_damage")) .. "]"..
"checkbox[0.5,1.15;cb_server_announce;".. fgettext("Public") .. ";" ..
dump(core.setting_getbool("server_announce")) .. "]"..
- "field[0.8,3.2;3.5,0.5;te_playername;".. fgettext("Name") .. ";" ..
+ "field[0.8,3.0;3.5,0.5;te_playername;".. fgettext("Name") .. ";" ..
core.setting_get("name") .. "]" ..
- "pwdfield[0.8,4.2;3.5,0.5;te_passwd;".. fgettext("Password") .. "]"
+ "pwdfield[0.8,4.1;3.5,0.5;te_passwd;".. fgettext("Password") .. "]"
local bind_addr = core.setting_get("bind_address")
if bind_addr ~= nil and bind_addr ~= "" then
#directional_colored_fog = true
#tooltip_show_delay = 400
# Delay showing tooltips, in miliseconds
+#screen_dpi = 72
+# adjust dpi configuration to your screen (PC/MAC only) e.g. for 4k screens
# Default timeout for cURL, in milliseconds
# Only has an effect if compiled with cURL
client.cpp
clientmedia.cpp
filecache.cpp
+ fontengine.cpp
tile.cpp
shader.cpp
game.cpp
* GUI related things
*/
#define LEGACY_SCALING (2./3.)
-#define DEFAULT_FONT_SIZE (13.0 / LEGACY_SCALING)
+#define TTF_DEFAULT_FONT_SIZE (13.0 / LEGACY_SCALING)
+#define DEFAULT_FONT_SIZE (14)
#define DEFAULT_IMGSIZE (48.0)
#define DEFAULT_XSPACING ((15.0 + (1.0 / 3.0)))
#define DEFAULT_YSPACING (9.0)
settings->setDefault("fallback_font_shadow", "1");
settings->setDefault("fallback_font_shadow_alpha", "128");
+
+ std::stringstream fontsize;
+ fontsize << TTF_DEFAULT_FONT_SIZE;
+
+ settings->setDefault("font_size", fontsize.str());
+ settings->setDefault("mono_font_size", fontsize.str());
+ settings->setDefault("fallback_font_size", fontsize.str());
#else
settings->setDefault("freetype", "false");
settings->setDefault("font_path", porting::getDataPath("fonts" DIR_DELIM "fontlucida.png"));
settings->setDefault("mono_font_path", porting::getDataPath("fonts" DIR_DELIM "fontdejavusansmono.png"));
+
+ std::stringstream fontsize;
+ fontsize << DEFAULT_FONT_SIZE;
+
+ settings->setDefault("font_size", fontsize.str());
+ settings->setDefault("mono_font_size", fontsize.str());
#endif
// Server stuff
settings->setDefault("gui_scaling", "0.7");
}
settings->setDefault("curl_verify_cert","false");
-#endif
-}
-
-void late_init_default_settings(Settings* settings)
-{
-#ifndef SERVER
- std::stringstream fontsize;
- fontsize << floor(
- DEFAULT_FONT_SIZE *
- porting::getDisplayDensity() *
- settings->getFloat("gui_scaling")
- );
-
- settings->setDefault("font_size", fontsize.str());
- settings->setDefault("mono_font_size", fontsize.str());
- settings->setDefault("fallback_font_size", fontsize.str());
+#else
+ settings->setDefault("screen_dpi", "72");
#endif
}
*/
void set_default_settings(Settings *settings);
-/**
- * initialize default values which require knowledge about gui
- * @param settings pointer to settings
- */
-void late_init_default_settings(Settings* settings);
-
/**
* override a default settings by settings from another settings element
* @param settings target settings pointer
--- /dev/null
+/*
+Minetest
+Copyright (C) 2010-2014 sapier <sapier at gmx dot net>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+#include "fontengine.h"
+#include "log.h"
+#include "main.h"
+#include "config.h"
+#include "porting.h"
+#include "constants.h"
+#if USE_FREETYPE
+#include "gettext.h"
+#include "filesys.h"
+#include "xCGUITTFont.h"
+#endif
+
+
+/** minimum font size supported */
+#define MIN_FONT_SIZE 4
+
+/** maximum size distance for getting a "similar" font size */
+#define MAX_FONT_SIZE_OFFSET 10
+
+/** reference to access font engine, has to be initialized by main */
+FontEngine* fe = NULL;
+
+/** callback to be used on change of font size setting */
+static void font_setting_changed() {
+ fe->readSettings();
+}
+
+/******************************************************************************/
+FontEngine::FontEngine(Settings* main_settings, gui::IGUIEnvironment* env) :
+ m_settings(NULL),
+ m_env(NULL),
+ m_font_cache(),
+ m_default_size(),
+ m_currentMode(Standard),
+ m_lastMode(),
+ m_lastSize(0),
+ m_lastFont(NULL)
+{
+
+ for ( unsigned int i = 0; i < MaxMode; i++) {
+ m_default_size[i] = (FontMode) FONT_SIZE_UNSPECIFIED;
+ }
+
+ m_settings = main_settings;
+ m_env = env;
+
+ assert(m_settings != NULL);
+ assert(m_env != NULL);
+ assert(m_env->getSkin() != NULL);
+
+ m_currentMode = Simple;
+
+#if USE_FREETYPE
+ if (g_settings->getBool("freetype")) {
+ m_default_size[Standard] = m_settings->getU16("font_size");
+ m_default_size[Fallback] = m_settings->getU16("fallback_font_size");
+ m_default_size[Mono] = m_settings->getU16("mono_font_size");
+
+ if (is_yes(gettext("needs_fallback_font"))) {
+ m_currentMode = Fallback;
+ }
+ else {
+ m_currentMode = Standard;
+ }
+ }
+
+ // having freetype but not using it is quite a strange case so we need to do
+ // special handling for it
+ if (m_currentMode == Simple) {
+ std::stringstream fontsize;
+ fontsize << DEFAULT_FONT_SIZE;
+ m_settings->setDefault("font_size", fontsize.str());
+ m_settings->setDefault("mono_font_size", fontsize.str());
+ }
+#endif
+
+ m_default_size[Simple] = m_settings->getU16("font_size");
+ m_default_size[SimpleMono] = m_settings->getU16("mono_font_size");
+
+ updateSkin();
+
+ if (m_currentMode == Standard) {
+ m_settings->registerChangedCallback("font_size", font_setting_changed);
+ m_settings->registerChangedCallback("font_path", font_setting_changed);
+ m_settings->registerChangedCallback("font_shadow", font_setting_changed);
+ m_settings->registerChangedCallback("font_shadow_alpha", font_setting_changed);
+ }
+ else if (m_currentMode == Fallback) {
+ m_settings->registerChangedCallback("fallback_font_size", font_setting_changed);
+ m_settings->registerChangedCallback("fallback_font_path", font_setting_changed);
+ m_settings->registerChangedCallback("fallback_font_shadow", font_setting_changed);
+ m_settings->registerChangedCallback("fallback_font_shadow_alpha", font_setting_changed);
+ }
+
+ m_settings->registerChangedCallback("mono_font_path", font_setting_changed);
+ m_settings->registerChangedCallback("mono_font_size", font_setting_changed);
+ m_settings->registerChangedCallback("screen_dpi", font_setting_changed);
+ m_settings->registerChangedCallback("gui_scaling", font_setting_changed);
+}
+
+/******************************************************************************/
+FontEngine::~FontEngine()
+{
+ cleanCache();
+}
+
+/******************************************************************************/
+void FontEngine::cleanCache()
+{
+ for ( unsigned int i = 0; i < MaxMode; i++) {
+
+ for (std::map<unsigned int, irr::gui::IGUIFont*>::iterator iter
+ = m_font_cache[i].begin();
+ iter != m_font_cache[i].end(); iter++) {
+ iter->second->drop();
+ iter->second = NULL;
+ }
+ m_font_cache[i].clear();
+ }
+}
+
+/******************************************************************************/
+irr::gui::IGUIFont* FontEngine::getFont(unsigned int font_size, FontMode mode)
+{
+ if (mode == Unspecified) {
+ mode = m_currentMode;
+ }
+ else if ((mode == Mono) && (m_currentMode == Simple)) {
+ mode = SimpleMono;
+ }
+
+ if (font_size == FONT_SIZE_UNSPECIFIED) {
+ font_size = m_default_size[mode];
+ }
+
+ if ((font_size == m_lastSize) && (mode == m_lastMode)) {
+ return m_lastFont;
+ }
+
+ if (m_font_cache[mode].find(font_size) == m_font_cache[mode].end()) {
+ initFont(font_size, mode);
+ }
+
+ if (m_font_cache[mode].find(font_size) == m_font_cache[mode].end()) {
+ return NULL;
+ }
+
+ m_lastSize = font_size;
+ m_lastMode = mode;
+ m_lastFont = m_font_cache[mode][font_size];
+
+ return m_font_cache[mode][font_size];
+}
+
+/******************************************************************************/
+unsigned int FontEngine::getTextHeight(unsigned int font_size, FontMode mode)
+{
+ irr::gui::IGUIFont* font = getFont(font_size,mode);
+
+ if (font == NULL) return MIN_FONT_SIZE;
+
+ return font->getDimension(L"Some unimportant example String").Height;
+}
+
+/******************************************************************************/
+unsigned int FontEngine::getDefaultFontSize()
+{
+ return m_default_size[m_currentMode];
+}
+
+/******************************************************************************/
+void FontEngine::readSettings()
+{
+#if USE_FREETYPE
+ if (g_settings->getBool("freetype")) {
+ m_default_size[Standard] = m_settings->getU16("font_size");
+ m_default_size[Fallback] = m_settings->getU16("fallback_font_size");
+ m_default_size[Mono] = m_settings->getU16("mono_font_size");
+
+ if (is_yes(gettext("needs_fallback_font"))) {
+ m_currentMode = Fallback;
+ }
+ else {
+ m_currentMode = Standard;
+ }
+ }
+#endif
+ m_default_size[Simple] = m_settings->getU16("font_size");
+ m_default_size[SimpleMono] = m_settings->getU16("mono_font_size");
+
+ cleanCache();
+ updateFontCache();
+ updateSkin();
+}
+
+/******************************************************************************/
+void FontEngine::updateSkin()
+{
+ gui::IGUIFont *font = getFont();
+
+ if (font)
+ m_env->getSkin()->setFont(font);
+ else
+ errorstream << "WARNING: Font file was not found."
+ << " Using irrlicht default font." << std::endl;
+
+ // If we did fail to create a font our own make irrlicht find a default one
+ font = m_env->getSkin()->getFont();
+ assert(font);
+
+ u32 text_height = font->getDimension(L"Hello, world!").Height;
+ infostream << "text_height=" << text_height << std::endl;
+}
+
+/******************************************************************************/
+void FontEngine::updateFontCache()
+{
+ for (unsigned int i = 0; i < MaxMode; i++) {
+ /* only font to be initialized is default one,
+ * all others are re-initialized on demand */
+ initFont(m_default_size[i], (FontMode) i);
+ }
+
+ /* reset font quick access */
+ m_lastMode = Unspecified;
+ m_lastSize = 0;
+ m_lastFont = NULL;
+}
+
+/******************************************************************************/
+void FontEngine::initFont(unsigned int basesize, FontMode mode)
+{
+
+ std::string font_config_prefix;
+
+ if (mode == Unspecified) {
+ mode = m_currentMode;
+ }
+
+ switch (mode) {
+
+ case Standard:
+ font_config_prefix = "";
+ break;
+
+ case Fallback:
+ font_config_prefix = "fallback_";
+ break;
+
+ case Mono:
+ font_config_prefix = "mono_";
+ if (m_currentMode == Simple)
+ mode = SimpleMono;
+ break;
+
+ case Simple: /* Fallthrough */
+ case SimpleMono: /* Fallthrough */
+ default:
+ font_config_prefix = "";
+
+ }
+
+ if (m_font_cache[mode].find(basesize) != m_font_cache[mode].end())
+ return;
+
+ if ((mode == Simple) || (mode == SimpleMono)) {
+ initSimpleFont(basesize, mode);
+ return;
+ }
+#if USE_FREETYPE
+ else {
+ if (! is_yes(m_settings->get("freetype"))) {
+ return;
+ }
+ unsigned int size = floor(
+ porting::getDisplayDensity() *
+ m_settings->getFloat("gui_scaling") *
+ basesize);
+ u32 font_shadow = 0;
+ u32 font_shadow_alpha = 0;
+
+ try {
+ g_settings->getU16(font_config_prefix + "font_shadow");
+ } catch (SettingNotFoundException&) {}
+ try {
+ g_settings->getU16(font_config_prefix + "font_shadow_alpha");
+ } catch (SettingNotFoundException&) {}
+
+ std::string font_path = g_settings->get(font_config_prefix + "font_path");
+
+ irr::gui::IGUIFont* font = gui::CGUITTFont::createTTFont(m_env,
+ font_path.c_str(), size, true, true, font_shadow,
+ font_shadow_alpha);
+
+ if (font != NULL) {
+ font->grab();
+ m_font_cache[mode][basesize] = font;
+ }
+ else {
+ errorstream << "FontEngine: failed to load freetype font: "
+ << font_path << std::endl;
+ }
+ }
+#endif
+}
+
+/** initialize a font without freetype */
+void FontEngine::initSimpleFont(unsigned int basesize, FontMode mode)
+{
+ assert((mode == Simple) || (mode == SimpleMono));
+
+ std::string font_path = "";
+ if (mode == Simple) {
+ font_path = m_settings->get("font_path");
+ } else {
+ font_path = m_settings->get("mono_font_path");
+ }
+ std::string basename = font_path;
+ std::string ending = font_path.substr(font_path.length() -4);
+
+ if ((ending == ".xml") || ( ending == ".png") || ( ending == ".ttf")) {
+ basename = font_path.substr(0,font_path.length()-4);
+ }
+
+ if (basesize == FONT_SIZE_UNSPECIFIED)
+ basesize = DEFAULT_FONT_SIZE;
+
+ unsigned int size = floor(
+ porting::getDisplayDensity() *
+ m_settings->getFloat("gui_scaling") *
+ basesize);
+
+ irr::gui::IGUIFont* font = NULL;
+
+ for(unsigned int offset = 0; offset < MAX_FONT_SIZE_OFFSET; offset++) {
+
+ // try opening positive offset
+ std::stringstream fontsize_plus_png;
+ fontsize_plus_png << basename << "_" << (size + offset) << ".png";
+
+ if (fs::PathExists(fontsize_plus_png.str())) {
+ font = m_env->getFont(fontsize_plus_png.str().c_str());
+
+ if (font) {
+ verbosestream << "FontEngine: found font: " << fontsize_plus_png.str() << std::endl;
+ break;
+ }
+ }
+
+ std::stringstream fontsize_plus_xml;
+ fontsize_plus_xml << basename << "_" << (size + offset) << ".xml";
+
+ if (fs::PathExists(fontsize_plus_xml.str())) {
+ font = m_env->getFont(fontsize_plus_xml.str().c_str());
+
+ if (font) {
+ verbosestream << "FontEngine: found font: " << fontsize_plus_xml.str() << std::endl;
+ break;
+ }
+ }
+
+ // try negative offset
+ std::stringstream fontsize_minus_png;
+ fontsize_minus_png << basename << "_" << (size - offset) << ".png";
+
+ if (fs::PathExists(fontsize_minus_png.str())) {
+ font = m_env->getFont(fontsize_minus_png.str().c_str());
+
+ if (font) {
+ verbosestream << "FontEngine: found font: " << fontsize_minus_png.str() << std::endl;
+ break;
+ }
+ }
+
+ std::stringstream fontsize_minus_xml;
+ fontsize_minus_xml << basename << "_" << (size - offset) << ".xml";
+
+ if (fs::PathExists(fontsize_minus_xml.str())) {
+ font = m_env->getFont(fontsize_minus_xml.str().c_str());
+
+ if (font) {
+ verbosestream << "FontEngine: found font: " << fontsize_minus_xml.str() << std::endl;
+ break;
+ }
+ }
+ }
+
+ // try name direct
+ if (font == NULL) {
+ if (fs::PathExists(font_path)) {
+ font = m_env->getFont(font_path.c_str());
+ if (font)
+ verbosestream << "FontEngine: found font: " << font_path << std::endl;
+ }
+ }
+
+ if (font != NULL) {
+ font->grab();
+ m_font_cache[mode][basesize] = font;
+ }
+}
--- /dev/null
+/*
+Minetest
+Copyright (C) 2010-2014 sapier <sapier at gmx dot net>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+#ifndef __FONTENGINE_H__
+#define __FONTENGINE_H__
+
+#include <map>
+#include <vector>
+#include "IGUIFont.h"
+#include "IGUISkin.h"
+#include "IGUIEnvironment.h"
+#include "settings.h"
+
+#define FONT_SIZE_UNSPECIFIED 0xFFFFFFFF
+
+enum FontMode {
+ Standard = 0,
+ Mono,
+ Fallback,
+ Simple,
+ SimpleMono,
+ MaxMode,
+ Unspecified
+};
+
+class FontEngine
+{
+public:
+
+ FontEngine(Settings* main_settings, gui::IGUIEnvironment* env);
+
+ ~FontEngine();
+
+ /** get Font */
+ irr::gui::IGUIFont* getFont(unsigned int font_size=FONT_SIZE_UNSPECIFIED,
+ FontMode mode=Unspecified);
+
+ /** get text height for a specific font */
+ unsigned int getTextHeight(unsigned int font_size=FONT_SIZE_UNSPECIFIED,
+ FontMode mode=Unspecified);
+
+ /** get default font size */
+ unsigned int getDefaultFontSize();
+
+ /** initialize font engine */
+ void initialize(Settings* main_settings, gui::IGUIEnvironment* env);
+
+ /** update internal parameters from settings */
+ void readSettings();
+
+private:
+ /** disable copy constructor */
+ FontEngine() :
+ m_settings(NULL),
+ m_env(NULL),
+ m_font_cache(),
+ m_default_size(),
+ m_currentMode(Standard),
+ m_lastMode(),
+ m_lastSize(0),
+ m_lastFont(NULL)
+ {};
+
+ /** update content of font cache in case of a setting change made it invalid */
+ void updateFontCache();
+
+ /** initialize a new font */
+ void initFont(unsigned int basesize, FontMode mode=Unspecified);
+
+ /** initialize a font without freetype */
+ void initSimpleFont(unsigned int basesize, FontMode mode);
+
+ /** update current minetest skin with font changes */
+ void updateSkin();
+
+ /** clean cache */
+ void cleanCache();
+
+ /** pointer to settings for registering callbacks or reading config */
+ Settings* m_settings;
+
+ /** pointer to irrlicht gui environment */
+ gui::IGUIEnvironment* m_env;
+
+ /** internal storage for caching fonts of different size */
+ std::map<unsigned int, irr::gui::IGUIFont*> m_font_cache[MaxMode];
+
+ /** default font size to use */
+ unsigned int m_default_size[MaxMode];
+
+ /** current font engine mode */
+ FontMode m_currentMode;
+
+ /** font mode of last request */
+ FontMode m_lastMode;
+
+ /** size of last request */
+ unsigned int m_lastSize;
+
+ /** last font returned */
+ irr::gui::IGUIFont* m_lastFont;
+
+};
+
+/** interface to access main font engine*/
+extern FontEngine* fe;
+
+#endif
#include "util/pointedthing.h"
#include "drawscene.h"
#include "content_cao.h"
+#include "fontengine.h"
#ifdef HAVE_TOUCHSCREENGUI
#include "touchscreengui.h"
/******************************************************************************/
void the_game(bool &kill, bool random_input, InputHandler *input,
- IrrlichtDevice *device, gui::IGUIFont* font, std::string map_dir,
+ IrrlichtDevice *device, std::string map_dir,
std::string playername, std::string password,
std::string address /* If "", local server is used */,
u16 port, std::wstring &error_message, ChatBackend &chat_backend,
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
- // Calculate text height using the font
- u32 text_height = font->getDimension(L"Random test string").Height;
-
/*
Draw "Loading" screen
*/
{
wchar_t* text = wgettext("Loading...");
- draw_load_screen(text, device, guienv, font, 0, 0);
+ draw_load_screen(text, device, guienv, fe->getFont(), 0, 0);
delete[] text;
}
if(address == ""){
wchar_t* text = wgettext("Creating server....");
- draw_load_screen(text, device, guienv, font, 0, 25);
+ draw_load_screen(text, device, guienv, fe->getFont(), 0, 25);
delete[] text;
infostream<<"Creating server"<<std::endl;
{
wchar_t* text = wgettext("Creating client...");
- draw_load_screen(text, device, guienv, font, 0, 50);
+ draw_load_screen(text, device, guienv, fe->getFont(), 0, 50);
delete[] text;
}
infostream<<"Creating client"<<std::endl;
{
wchar_t* text = wgettext("Resolving address...");
- draw_load_screen(text, device, guienv, font, 0, 75);
+ draw_load_screen(text, device, guienv, fe->getFont(), 0, 75);
delete[] text;
}
Address connect_address(0,0,0,0, port);
// Display status
{
wchar_t* text = wgettext("Connecting to server...");
- draw_load_screen(text, device, guienv, font, dtime, 100);
+ draw_load_screen(text, device, guienv, fe->getFont(), dtime, 100);
delete[] text;
}
{
wchar_t* text = wgettext("Item definitions...");
progress = 0;
- draw_load_screen(text, device, guienv, font, dtime, progress);
+ draw_load_screen(text, device, guienv, fe->getFont(), dtime, progress);
delete[] text;
}
else if (!client.nodedefReceived())
{
wchar_t* text = wgettext("Node definitions...");
progress = 25;
- draw_load_screen(text, device, guienv, font, dtime, progress);
+ draw_load_screen(text, device, guienv, fe->getFont(), dtime, progress);
delete[] text;
}
else
}
progress = 50+client.mediaReceiveProgress()*50+0.5;
draw_load_screen(narrow_to_wide(message.str().c_str()), device,
- guienv, font, dtime, progress);
+ guienv, fe->getFont(), dtime, progress);
}
// On some computers framerate doesn't seem to be
After all content has been received:
Update cached textures, meshes and materials
*/
- client.afterContentReceived(device,font);
+ client.afterContentReceived(device, fe->getFont());
/*
Create the camera node
// Object infos are shown in this
gui::IGUIStaticText *guitext_info = guienv->addStaticText(
L"",
- core::rect<s32>(0,0,400,text_height*5+5) + v2s32(100,200),
+ core::rect<s32>(0,0,400, (fe->getTextHeight() * 5) + 5) + v2s32(100,200),
false, true);
// Status text (displays info when showing and hiding GUI stuff, etc.)
/*
HUD object
*/
- Hud hud(driver, smgr, guienv, font, text_height,
+ Hud hud(driver, smgr, guienv, fe->getFont(), fe->getTextHeight(),
gamedef, player, &local_inventory);
core::stringw str = L"Minetest [";
g_profiler->print(infostream);
}
- update_profiler_gui(guitext_profiler, font, text_height,
- show_profiler, show_profiler_max);
+ update_profiler_gui(guitext_profiler, fe->getFont(),
+ fe->getTextHeight(), show_profiler, show_profiler_max);
g_profiler->clear();
}
show_profiler = (show_profiler + 1) % (show_profiler_max + 1);
// FIXME: This updates the profiler with incomplete values
- update_profiler_gui(guitext_profiler, font, text_height,
- show_profiler, show_profiler_max);
+ update_profiler_gui(guitext_profiler, fe->getFont(),
+ fe->getTextHeight(), show_profiler, show_profiler_max);
if(show_profiler != 0)
{
5,
5,
screensize.X,
- 5 + text_height
+ 5 + fe->getTextHeight()
);
guitext->setRelativePosition(rect);
}
core::rect<s32> rect(
5,
- 5 + text_height,
+ 5 + fe->getTextHeight(),
screensize.X,
- 5 + (text_height * 2)
+ 5 + (fe->getTextHeight() * 2)
);
guitext2->setRelativePosition(rect);
}
guitext_chat->setText(recent_chat.c_str());
// Update gui element size and position
- s32 chat_y = 5+(text_height+5);
+ s32 chat_y = 5+(fe->getTextHeight() + 5);
if(show_debug)
- chat_y += (text_height+5);
+ chat_y += (fe->getTextHeight() + 5);
core::rect<s32> rect(
10,
chat_y,
*/
if(show_profiler_graph)
{
- graph.draw(10, screensize.Y - 10, driver, font);
+ graph.draw(10, screensize.Y - 10, driver, fe->getFont());
}
/*
*/
{
wchar_t* text = wgettext("Shutting down stuff...");
- draw_load_screen(text, device, guienv, font, 0, -1, false);
+ draw_load_screen(text, device, guienv, fe->getFont(), 0, -1, false);
delete[] text;
}
bool random_input,
InputHandler *input,
IrrlichtDevice *device,
- gui::IGUIFont* font,
std::string map_dir,
std::string playername,
std::string password,
#include "main.h" // for g_settings
#include "porting.h"
#include "tile.h"
-#include "IGUIFont.h"
+#include "fontengine.h"
#include <string>
#include "gettext.h"
m_background_color.setBlue(255);
}
- // load the font
- // FIXME should a custom texture_path be searched too?
- std::string font_name = g_settings->get("mono_font_path");
- #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
- m_font = env->getFont(font_name.c_str());
- #endif
+ m_font = fe->getFont(FONT_SIZE_UNSPECIFIED, Mono);
if (m_font == NULL)
{
- dstream << "Unable to load font: " << font_name << std::endl;
+ errorstream << "GUIChatConsole: Unable to load mono font ";
}
else
{
GUIChatConsole::~GUIChatConsole()
{
-#if USE_FREETYPE
- if (m_use_freetype)
- m_font->drop();
-#endif
}
void GUIChatConsole::openConsole(f32 height)
m_form_src(fsrc),
m_text_dst(tdst),
m_ext_ptr(ext_ptr),
- m_font(dev->getGUIEnvironment()->getSkin()->getFont()),
m_formspec_version(0)
#ifdef __ANDROID__
,m_JavaDialogFieldName(L"")
m_doubleclickdetect[1].pos = v2s32(0, 0);
m_tooltip_show_delay = (u32)g_settings->getS32("tooltip_show_delay");
-
- m_btn_height = g_settings->getS32("font_size") +2;
- assert(m_btn_height > 0);
}
GUIFormSpecMenu::~GUIFormSpecMenu()
std::wstring wlabel = narrow_to_wide(label.c_str());
+ gui::IGUIFont *font = NULL;
+ gui::IGUISkin* skin = Environment->getSkin();
+ if (skin)
+ font = skin->getFont();
+
core::rect<s32> rect = core::rect<s32>(
pos.X, pos.Y + ((imgsize.Y/2) - m_btn_height),
- pos.X + m_font->getDimension(wlabel.c_str()).Width + 25, // text size + size of checkbox
+ pos.X + font->getDimension(wlabel.c_str()).Width + 25, // text size + size of checkbox
pos.Y + ((imgsize.Y/2) + m_btn_height));
FieldSpec spec(
std::wstring wlabel = narrow_to_wide(text.c_str());
+ gui::IGUIFont *font = NULL;
+ gui::IGUISkin* skin = Environment->getSkin();
+ if (skin)
+ font = skin->getFont();
+
core::rect<s32> rect = core::rect<s32>(
pos.X, pos.Y+((imgsize.Y/2) - m_btn_height),
- pos.X + m_font->getDimension(wlabel.c_str()).Width,
+ pos.X + font->getDimension(wlabel.c_str()).Width,
pos.Y+((imgsize.Y/2) + m_btn_height));
FieldSpec spec(
pos.X += stof(v_pos[0]) * (float)spacing.X;
pos.Y += stof(v_pos[1]) * (float)spacing.Y;
+ gui::IGUIFont *font = NULL;
+ gui::IGUISkin* skin = Environment->getSkin();
+ if (skin)
+ font = skin->getFont();
+
core::rect<s32> rect = core::rect<s32>(
pos.X, pos.Y+((imgsize.Y/2)- m_btn_height),
pos.X+15, pos.Y +
- (m_font->getKerningHeight() +
- m_font->getDimension(text.c_str()).Height)
- * (text.length()+1));
+ (font->getKerningHeight() +
+ font->getDimension(text.c_str()).Height)
+ * (text.length()+1)
+ +((imgsize.Y/2)- m_btn_height));
//actually text.length() would be correct but adding +1 avoids to break all mods
if(data->bp_set != 2)
return;
}
+ gui::IGUIFont *font = NULL;
+ gui::IGUISkin* skin = Environment->getSkin();
+ if (skin)
+ font = skin->getFont();
+
+ m_btn_height = font->getDimension(L"Some unimportant test String").Height;
+ assert(m_btn_height > 0);
+
parserData mydata;
//preserve tables
{
video::IVideoDriver* driver = Environment->getVideoDriver();
- // Get font
gui::IGUIFont *font = NULL;
gui::IGUISkin* skin = Environment->getSkin();
if (skin)
updateSelectedItem();
- gui::IGUISkin* skin = Environment->getSkin();
- if (!skin)
- return;
video::IVideoDriver* driver = Environment->getVideoDriver();
v2u32 screenSize = driver->getScreenSize();
IFormSource *m_form_src;
TextDest *m_text_dst;
GUIFormSpecMenu **m_ext_ptr;
- gui::IGUIFont *m_font;
unsigned int m_formspec_version;
typedef struct {
#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"
#include "httpfetch.h"
#include "guiEngine.h"
#include "mapsector.h"
+#include "fontengine.h"
#include "database-sqlite3.h"
#ifdef USE_LEVELDB
irr_logger->setLogLevel(irr_log_level[loglevel]);
porting::initIrrlicht(device);
- late_init_default_settings(g_settings);
/*
Continue initialization
guienv = device->getGUIEnvironment();
gui::IGUISkin* skin = guienv->getSkin();
- std::string font_path = g_settings->get("font_path");
- gui::IGUIFont *font;
- #if USE_FREETYPE
- bool use_freetype = g_settings->getBool("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;
- // If font was not found, this will get us one
- font = skin->getFont();
- assert(font);
- u32 text_height = font->getDimension(L"Hello, world!").Height;
- infostream << "text_height=" << text_height << std::endl;
+ fe = new FontEngine(g_settings, guienv);
+ assert(fe != NULL);
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));
random_input,
input,
device,
- font,
worldspec.path,
current_playername,
current_password,
g_menucloudsmgr->drop();
delete input;
+ delete fe;
/*
In the end, delete the Irrlicht device.
*/
device->drop();
-#if USE_FREETYPE
- if (use_freetype)
- font->drop();
-#endif
delete receiver;
#endif // !SERVER
#ifndef __ANDROID__
float getDisplayDensity() {
- float gui_scaling = g_settings->getFloat("gui_scaling");
- // using Y here feels like a bug, this needs to be discussed later!
- if (getWindowSize().Y <= 800) {
- return (2.0/3.0) * gui_scaling;
- }
- if (getWindowSize().Y <= 1280) {
- return 1.0 * gui_scaling;
- }
-
- return (4.0/3.0) * gui_scaling;
+ return g_settings->getFloat("screen_dpi")/96.0;
}
v2u32 getDisplaySize() {
const char *help;
};
+/** function type to register a changed callback */
+typedef void (*setting_changed_callback)();
+
class Settings
{
public:
void set(std::string name, std::string value)
{
- JMutexAutoLock lock(m_mutex);
+ {
+ JMutexAutoLock lock(m_mutex);
- m_settings[name] = value;
+ m_settings[name] = value;
+ }
+ doCallbacks(name);
}
void set(std::string name, const char *value)
{
- JMutexAutoLock lock(m_mutex);
+ {
+ JMutexAutoLock lock(m_mutex);
- m_settings[name] = value;
+ m_settings[name] = value;
+ }
+ doCallbacks(name);
}
return *this;
}
+ void registerChangedCallback(std::string name, setting_changed_callback cbf)
+ {
+ m_callbacks[name].push_back(cbf);
+ }
+
private:
+
+ void doCallbacks(std::string name)
+ {
+ std::vector<setting_changed_callback> tempvector;
+ {
+ JMutexAutoLock lock(m_mutex);
+ if (m_callbacks.find(name) != m_callbacks.end()) {
+
+ tempvector = m_callbacks[name];
+ }
+ }
+
+ for (std::vector<setting_changed_callback>::iterator iter = tempvector.begin();
+ iter != tempvector.end(); iter ++)
+ {
+ (*iter)();
+ }
+ }
+
std::map<std::string, std::string> m_settings;
std::map<std::string, std::string> m_defaults;
+ std::map<std::string, std::vector<setting_changed_callback> > m_callbacks;
// All methods that access m_settings/m_defaults directly should lock this.
JMutex m_mutex;
};