Add alpha setting to font shadow
authorBlockMen <nmuelll@web.de>
Thu, 12 Dec 2013 20:02:09 +0000 (21:02 +0100)
committerPilzAdam <pilzadam@minetest.net>
Sat, 14 Dec 2013 20:11:38 +0000 (21:11 +0100)
minetest.conf.example
src/cguittfont/CGUITTFont.cpp
src/cguittfont/CGUITTFont.h
src/defaultsettings.cpp
src/main.cpp

index f7dac6b7b5749d85ce24795522e9ad1537c65a1e..b7f4b24a76c1be41e245bc392d88ece96593270e 100644 (file)
 #font_size = 13
 # Font shadow offset, if 0 then shadow will not be drawn.
 #font_shadow = 1
+# Font shadow alpha (opaqueness, between 0 and 255)
+#font_shadow_alpha = 128
 #mono_font_path = fonts/liberationmono.ttf
 #mono_font_size = 13
 
 #fallback_font_path = fonts/DroidSansFallbackFull.ttf
 #fallback_font_size = 13
 #fallback_font_shadow = 1
+#fallback_font_shadow_alpha = 128
 
 #
 # Server stuff
index b9c979090b64cce974faddced142cb92b6016598..9a702cad7d79f5282b85bbe1c0aee63e4cc199fa 100644 (file)
@@ -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, const u32 shadow)
+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)
 {
        if (!c_libraryLoaded)
        {
@@ -217,6 +217,7 @@ CGUITTFont* CGUITTFont::createTTFont(IGUIEnvironment *env, const io::path& filen
        }
 
        font->shadow_offset = shadow;
+       font->shadow_alpha = shadow_alpha;
 
        return font;
 }
@@ -631,7 +632,7 @@ void CGUITTFont::draw(const core::stringw& text, const core::rect<s32>& position
                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);
+                       Driver->draw2DImageBatch(page->texture, page->render_positions, page->render_source_rects, clip, video::SColor(shadow_alpha,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);
                }
index a58873da6804e0c0d663d244309bacd4e736e579..e24d8f18b27499f17c95a323120781bc9252748f 100644 (file)
@@ -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, const u32 shadow = 0);
+                       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);
                        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);
@@ -370,6 +370,7 @@ namespace gui
                        s32 GlobalKerningHeight;
                        core::ustring Invisible;
                        u32 shadow_offset;
+                       u32 shadow_alpha;
        };
 
 } // end namespace gui
index a217fda40fee7fabe42d99951a8436e0a4012828..e93c1d4c8c0cb969b41ac1ef8623ae7212ce34ea 100644 (file)
@@ -155,11 +155,13 @@ void set_default_settings(Settings *settings)
        settings->setDefault("font_path", porting::getDataPath("fonts" DIR_DELIM "liberationsans.ttf"));
        settings->setDefault("font_size", "13");
        settings->setDefault("font_shadow", "1");
+       settings->setDefault("font_shadow_alpha", "128");
        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");
+       settings->setDefault("fallback_font_shadow_alpha", "128");
 #else
        settings->setDefault("freetype", "false");
        settings->setDefault("font_path", porting::getDataPath("fonts" DIR_DELIM "fontlucida.png"));
index 480e885c22f8a4dabccbec872b56d7bbcb090a0c..8186e26c8a70fcc6b7fd548c1d585a7385566356 100644 (file)
@@ -1477,7 +1477,8 @@ int main(int argc, char *argv[])
                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");
-               font = gui::CGUITTFont::createTTFont(guienv, font_path.c_str(), font_size, true, true, 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());
        }