aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlya Zhuravlev <zhuravlevilya@ya.ru>2013-12-12 21:47:54 +0400
committerIlya Zhuravlev <zhuravlevilya@ya.ru>2013-12-12 21:47:54 +0400
commit76036abdb0d9cb2c971e5a69331c77872d38c56f (patch)
treee392c4035012806844c8565456281c1c7d7a11d1
parent4ccaa6d0af852d0aada01f341a61290a3760cffa (diff)
downloadminetest-76036abdb0d9cb2c971e5a69331c77872d38c56f.tar.gz
minetest-76036abdb0d9cb2c971e5a69331c77872d38c56f.tar.bz2
minetest-76036abdb0d9cb2c971e5a69331c77872d38c56f.zip
Add configurable font shadow.
-rw-r--r--minetest.conf.example3
-rw-r--r--src/cguittfont/CGUITTFont.cpp12
-rw-r--r--src/cguittfont/CGUITTFont.h3
-rw-r--r--src/defaultsettings.cpp2
-rw-r--r--src/main.cpp3
5 files changed, 20 insertions, 3 deletions
diff --git a/minetest.conf.example b/minetest.conf.example
index 4d6b76c84..3dbbd773e 100644
--- a/minetest.conf.example
+++ b/minetest.conf.example
@@ -205,12 +205,15 @@
# Path to TrueTypeFont or bitmap
#font_path = fonts/liberationsans.ttf
#font_size = 13
+# Font shadow offset, if 0 then shadow will not be drawn.
+#font_shadow = 1
#mono_font_path = fonts/liberationmono.ttf
#mono_font_size = 13
# This font will be used for certain languages
#fallback_font_path = fonts/DroidSansFallbackFull.ttf
#fallback_font_size = 13
+#fallback_font_shadow = 1
#
# Server stuff
diff --git a/src/cguittfont/CGUITTFont.cpp b/src/cguittfont/CGUITTFont.cpp
index fb8199e21..b9c979090 100644
--- a/src/cguittfont/CGUITTFont.cpp
+++ b/src/cguittfont/CGUITTFont.cpp
@@ -199,7 +199,7 @@ void SGUITTGlyph::unload()
//////////////////////
-CGUITTFont* CGUITTFont::createTTFont(IGUIEnvironment *env, const io::path& filename, const u32 size, const bool antialias, const bool transparency)
+CGUITTFont* CGUITTFont::createTTFont(IGUIEnvironment *env, const io::path& filename, const u32 size, const bool antialias, const bool transparency, const u32 shadow)
{
if (!c_libraryLoaded)
{
@@ -216,6 +216,8 @@ CGUITTFont* CGUITTFont::createTTFont(IGUIEnvironment *env, const io::path& filen
return 0;
}
+ font->shadow_offset = shadow;
+
return font;
}
@@ -625,6 +627,14 @@ void CGUITTFont::draw(const core::stringw& text, const core::rect<s32>& position
CGUITTGlyphPage* page = n->getValue();
if (!use_transparency) color.color |= 0xff000000;
+
+ if (shadow_offset) {
+ for (size_t i = 0; i < page->render_positions.size(); ++i)
+ page->render_positions[i] += core::vector2di(shadow_offset, shadow_offset);
+ Driver->draw2DImageBatch(page->texture, page->render_positions, page->render_source_rects, clip, video::SColor(255, 0, 0, 0), true);
+ for (size_t i = 0; i < page->render_positions.size(); ++i)
+ page->render_positions[i] -= core::vector2di(shadow_offset, shadow_offset);
+ }
Driver->draw2DImageBatch(page->texture, page->render_positions, page->render_source_rects, clip, color, true);
}
}
diff --git a/src/cguittfont/CGUITTFont.h b/src/cguittfont/CGUITTFont.h
index 12e25e0f3..a58873da6 100644
--- a/src/cguittfont/CGUITTFont.h
+++ b/src/cguittfont/CGUITTFont.h
@@ -207,7 +207,7 @@ namespace gui
//! \param antialias set the use_monochrome (opposite to antialias) flag
//! \param transparency set the use_transparency flag
//! \return Returns a pointer to a CGUITTFont. Will return 0 if the font failed to load.
- static CGUITTFont* createTTFont(IGUIEnvironment *env, const io::path& filename, const u32 size, const bool antialias = true, const bool transparency = true);
+ static CGUITTFont* createTTFont(IGUIEnvironment *env, const io::path& filename, const u32 size, const bool antialias = true, const bool transparency = true, const u32 shadow = 0);
static CGUITTFont* createTTFont(IrrlichtDevice *device, const io::path& filename, const u32 size, const bool antialias = true, const bool transparency = true);
static CGUITTFont* create(IGUIEnvironment *env, const io::path& filename, const u32 size, const bool antialias = true, const bool transparency = true);
static CGUITTFont* create(IrrlichtDevice *device, const io::path& filename, const u32 size, const bool antialias = true, const bool transparency = true);
@@ -369,6 +369,7 @@ namespace gui
s32 GlobalKerningWidth;
s32 GlobalKerningHeight;
core::ustring Invisible;
+ u32 shadow_offset;
};
} // end namespace gui
diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp
index 106e5d9c2..9b407b1c3 100644
--- a/src/defaultsettings.cpp
+++ b/src/defaultsettings.cpp
@@ -153,10 +153,12 @@ void set_default_settings(Settings *settings)
settings->setDefault("freetype", "true");
settings->setDefault("font_path", porting::getDataPath("fonts" DIR_DELIM "liberationsans.ttf"));
settings->setDefault("font_size", "13");
+ settings->setDefault("font_shadow", "1");
settings->setDefault("mono_font_path", porting::getDataPath("fonts" DIR_DELIM "liberationmono.ttf"));
settings->setDefault("mono_font_size", "13");
settings->setDefault("fallback_font_path", porting::getDataPath("fonts" DIR_DELIM "DroidSansFallbackFull.ttf"));
settings->setDefault("fallback_font_size", "13");
+ settings->setDefault("fallback_font_shadow", "1");
#else
settings->setDefault("freetype", "false");
settings->setDefault("font_path", porting::getDataPath("fonts" DIR_DELIM "fontlucida.png"));
diff --git a/src/main.cpp b/src/main.cpp
index d5a121e79..57c2f06a5 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1481,7 +1481,8 @@ int main(int argc, char *argv[])
fallback = "fallback_";
u16 font_size = g_settings->getU16(fallback + "font_size");
font_path = g_settings->get(fallback + "font_path");
- font = gui::CGUITTFont::createTTFont(guienv, font_path.c_str(), font_size);
+ u32 font_shadow = g_settings->getU16(fallback + "font_shadow");
+ font = gui::CGUITTFont::createTTFont(guienv, font_path.c_str(), font_size, true, true, font_shadow);
} else {
font = guienv->getFont(font_path.c_str());
}