Skip to content

Commit 76036ab

Browse files
author
Ilya Zhuravlev
committedDec 12, 2013
Add configurable font shadow.
1 parent 4ccaa6d commit 76036ab

File tree

5 files changed

+20
-3
lines changed

5 files changed

+20
-3
lines changed
 

‎minetest.conf.example

+3
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,15 @@
205205
# Path to TrueTypeFont or bitmap
206206
#font_path = fonts/liberationsans.ttf
207207
#font_size = 13
208+
# Font shadow offset, if 0 then shadow will not be drawn.
209+
#font_shadow = 1
208210
#mono_font_path = fonts/liberationmono.ttf
209211
#mono_font_size = 13
210212

211213
# This font will be used for certain languages
212214
#fallback_font_path = fonts/DroidSansFallbackFull.ttf
213215
#fallback_font_size = 13
216+
#fallback_font_shadow = 1
214217

215218
#
216219
# Server stuff

‎src/cguittfont/CGUITTFont.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ void SGUITTGlyph::unload()
199199

200200
//////////////////////
201201

202-
CGUITTFont* CGUITTFont::createTTFont(IGUIEnvironment *env, const io::path& filename, const u32 size, const bool antialias, const bool transparency)
202+
CGUITTFont* CGUITTFont::createTTFont(IGUIEnvironment *env, const io::path& filename, const u32 size, const bool antialias, const bool transparency, const u32 shadow)
203203
{
204204
if (!c_libraryLoaded)
205205
{
@@ -216,6 +216,8 @@ CGUITTFont* CGUITTFont::createTTFont(IGUIEnvironment *env, const io::path& filen
216216
return 0;
217217
}
218218

219+
font->shadow_offset = shadow;
220+
219221
return font;
220222
}
221223

@@ -625,6 +627,14 @@ void CGUITTFont::draw(const core::stringw& text, const core::rect<s32>& position
625627
CGUITTGlyphPage* page = n->getValue();
626628

627629
if (!use_transparency) color.color |= 0xff000000;
630+
631+
if (shadow_offset) {
632+
for (size_t i = 0; i < page->render_positions.size(); ++i)
633+
page->render_positions[i] += core::vector2di(shadow_offset, shadow_offset);
634+
Driver->draw2DImageBatch(page->texture, page->render_positions, page->render_source_rects, clip, video::SColor(255, 0, 0, 0), true);
635+
for (size_t i = 0; i < page->render_positions.size(); ++i)
636+
page->render_positions[i] -= core::vector2di(shadow_offset, shadow_offset);
637+
}
628638
Driver->draw2DImageBatch(page->texture, page->render_positions, page->render_source_rects, clip, color, true);
629639
}
630640
}

‎src/cguittfont/CGUITTFont.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ namespace gui
207207
//! \param antialias set the use_monochrome (opposite to antialias) flag
208208
//! \param transparency set the use_transparency flag
209209
//! \return Returns a pointer to a CGUITTFont. Will return 0 if the font failed to load.
210-
static CGUITTFont* createTTFont(IGUIEnvironment *env, const io::path& filename, const u32 size, const bool antialias = true, const bool transparency = true);
210+
static CGUITTFont* createTTFont(IGUIEnvironment *env, const io::path& filename, const u32 size, const bool antialias = true, const bool transparency = true, const u32 shadow = 0);
211211
static CGUITTFont* createTTFont(IrrlichtDevice *device, const io::path& filename, const u32 size, const bool antialias = true, const bool transparency = true);
212212
static CGUITTFont* create(IGUIEnvironment *env, const io::path& filename, const u32 size, const bool antialias = true, const bool transparency = true);
213213
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
369369
s32 GlobalKerningWidth;
370370
s32 GlobalKerningHeight;
371371
core::ustring Invisible;
372+
u32 shadow_offset;
372373
};
373374

374375
} // end namespace gui

‎src/defaultsettings.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,12 @@ void set_default_settings(Settings *settings)
153153
settings->setDefault("freetype", "true");
154154
settings->setDefault("font_path", porting::getDataPath("fonts" DIR_DELIM "liberationsans.ttf"));
155155
settings->setDefault("font_size", "13");
156+
settings->setDefault("font_shadow", "1");
156157
settings->setDefault("mono_font_path", porting::getDataPath("fonts" DIR_DELIM "liberationmono.ttf"));
157158
settings->setDefault("mono_font_size", "13");
158159
settings->setDefault("fallback_font_path", porting::getDataPath("fonts" DIR_DELIM "DroidSansFallbackFull.ttf"));
159160
settings->setDefault("fallback_font_size", "13");
161+
settings->setDefault("fallback_font_shadow", "1");
160162
#else
161163
settings->setDefault("freetype", "false");
162164
settings->setDefault("font_path", porting::getDataPath("fonts" DIR_DELIM "fontlucida.png"));

‎src/main.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1481,7 +1481,8 @@ int main(int argc, char *argv[])
14811481
fallback = "fallback_";
14821482
u16 font_size = g_settings->getU16(fallback + "font_size");
14831483
font_path = g_settings->get(fallback + "font_path");
1484-
font = gui::CGUITTFont::createTTFont(guienv, font_path.c_str(), font_size);
1484+
u32 font_shadow = g_settings->getU16(fallback + "font_shadow");
1485+
font = gui::CGUITTFont::createTTFont(guienv, font_path.c_str(), font_size, true, true, font_shadow);
14851486
} else {
14861487
font = guienv->getFont(font_path.c_str());
14871488
}

0 commit comments

Comments
 (0)
Please sign in to comment.