Skip to content

Commit 9772322

Browse files
BlockMenPilzAdam
authored andcommittedDec 14, 2013
Add alpha setting to font shadow
1 parent 7a4c1e7 commit 9772322

File tree

5 files changed

+12
-4
lines changed

5 files changed

+12
-4
lines changed
 

‎minetest.conf.example

+3
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,16 @@
213213
#font_size = 13
214214
# Font shadow offset, if 0 then shadow will not be drawn.
215215
#font_shadow = 1
216+
# Font shadow alpha (opaqueness, between 0 and 255)
217+
#font_shadow_alpha = 128
216218
#mono_font_path = fonts/liberationmono.ttf
217219
#mono_font_size = 13
218220

219221
# This font will be used for certain languages
220222
#fallback_font_path = fonts/DroidSansFallbackFull.ttf
221223
#fallback_font_size = 13
222224
#fallback_font_shadow = 1
225+
#fallback_font_shadow_alpha = 128
223226

224227
#
225228
# Server stuff

‎src/cguittfont/CGUITTFont.cpp

+3-2
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, const u32 shadow)
202+
CGUITTFont* CGUITTFont::createTTFont(IGUIEnvironment *env, const io::path& filename, const u32 size, const bool antialias, const bool transparency, const u32 shadow, const u32 shadow_alpha)
203203
{
204204
if (!c_libraryLoaded)
205205
{
@@ -217,6 +217,7 @@ CGUITTFont* CGUITTFont::createTTFont(IGUIEnvironment *env, const io::path& filen
217217
}
218218

219219
font->shadow_offset = shadow;
220+
font->shadow_alpha = shadow_alpha;
220221

221222
return font;
222223
}
@@ -631,7 +632,7 @@ void CGUITTFont::draw(const core::stringw& text, const core::rect<s32>& position
631632
if (shadow_offset) {
632633
for (size_t i = 0; i < page->render_positions.size(); ++i)
633634
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+
Driver->draw2DImageBatch(page->texture, page->render_positions, page->render_source_rects, clip, video::SColor(shadow_alpha,0,0,0), true);
635636
for (size_t i = 0; i < page->render_positions.size(); ++i)
636637
page->render_positions[i] -= core::vector2di(shadow_offset, shadow_offset);
637638
}

‎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, const u32 shadow = 0);
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, const u32 shadow_alpha = 255);
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);
@@ -370,6 +370,7 @@ namespace gui
370370
s32 GlobalKerningHeight;
371371
core::ustring Invisible;
372372
u32 shadow_offset;
373+
u32 shadow_alpha;
373374
};
374375

375376
} // end namespace gui

‎src/defaultsettings.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,13 @@ void set_default_settings(Settings *settings)
155155
settings->setDefault("font_path", porting::getDataPath("fonts" DIR_DELIM "liberationsans.ttf"));
156156
settings->setDefault("font_size", "13");
157157
settings->setDefault("font_shadow", "1");
158+
settings->setDefault("font_shadow_alpha", "128");
158159
settings->setDefault("mono_font_path", porting::getDataPath("fonts" DIR_DELIM "liberationmono.ttf"));
159160
settings->setDefault("mono_font_size", "13");
160161
settings->setDefault("fallback_font_path", porting::getDataPath("fonts" DIR_DELIM "DroidSansFallbackFull.ttf"));
161162
settings->setDefault("fallback_font_size", "13");
162163
settings->setDefault("fallback_font_shadow", "1");
164+
settings->setDefault("fallback_font_shadow_alpha", "128");
163165
#else
164166
settings->setDefault("freetype", "false");
165167
settings->setDefault("font_path", porting::getDataPath("fonts" DIR_DELIM "fontlucida.png"));

‎src/main.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1477,7 +1477,8 @@ int main(int argc, char *argv[])
14771477
u16 font_size = g_settings->getU16(fallback + "font_size");
14781478
font_path = g_settings->get(fallback + "font_path");
14791479
u32 font_shadow = g_settings->getU16(fallback + "font_shadow");
1480-
font = gui::CGUITTFont::createTTFont(guienv, font_path.c_str(), font_size, true, true, font_shadow);
1480+
u32 font_shadow_alpha = g_settings->getU16(fallback + "font_shadow_alpha");
1481+
font = gui::CGUITTFont::createTTFont(guienv, font_path.c_str(), font_size, true, true, font_shadow, font_shadow_alpha);
14811482
} else {
14821483
font = guienv->getFont(font_path.c_str());
14831484
}

0 commit comments

Comments
 (0)
Please sign in to comment.