OS X compatibility fixes
[oweals/minetest.git] / src / cguittfont / CGUITTFont.cpp
index fb8199e2104791f7644a4cdddf9b6073015f0eba..92a24784e41f3c524e481f0febe5ac198b46c918 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)
+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)
        {
@@ -216,6 +216,9 @@ CGUITTFont* CGUITTFont::createTTFont(IGUIEnvironment *env, const io::path& filen
                return 0;
        }
 
+       font->shadow_offset = shadow;
+       font->shadow_alpha = shadow_alpha;
+
        return font;
 }
 
@@ -565,32 +568,32 @@ void CGUITTFont::draw(const core::stringw& text, const core::rect<s32>& position
                uchar32_t currentChar = *iter;
                n = getGlyphIndexByChar(currentChar);
                bool visible = (Invisible.findFirst(currentChar) == -1);
-               if (n > 0 && visible)
+               bool lineBreak=false;
+               if (currentChar == L'\r') // Mac or Windows breaks
                {
-                       bool lineBreak=false;
-                       if (currentChar == L'\r') // Mac or Windows breaks
-                       {
-                               lineBreak = true;
-                               if (*(iter + 1) == (uchar32_t)'\n')     // Windows line breaks.
-                                       currentChar = *(++iter);
-                       }
-                       else if (currentChar == (uchar32_t)'\n') // Unix breaks
-                       {
-                               lineBreak = true;
-                       }
+                       lineBreak = true;
+                       if (*(iter + 1) == (uchar32_t)'\n')     // Windows line breaks.
+                               currentChar = *(++iter);
+               }
+               else if (currentChar == (uchar32_t)'\n') // Unix breaks
+               {
+                       lineBreak = true;
+               }
 
-                       if (lineBreak)
-                       {
-                               previousChar = 0;
-                               offset.Y += font_metrics.ascender / 64;
-                               offset.X = position.UpperLeftCorner.X;
+               if (lineBreak)
+               {
+                       previousChar = 0;
+                       offset.Y += font_metrics.height / 64;
+                       offset.X = position.UpperLeftCorner.X;
 
-                               if (hcenter)
-                                       offset.X += (position.getWidth() - textDimension.Width) >> 1;
-                               ++iter;
-                               continue;
-                       }
+                       if (hcenter)
+                               offset.X += (position.getWidth() - textDimension.Width) >> 1;
+                       ++iter;
+                       continue;
+               }
 
+               if (n > 0 && visible)
+               {
                        // Calculate the glyph offset.
                        s32 offx = Glyphs[n-1].offset.X;
                        s32 offy = (font_metrics.ascender / 64) - Glyphs[n-1].offset.Y;
@@ -625,6 +628,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(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);
+               }
                Driver->draw2DImageBatch(page->texture, page->render_positions, page->render_source_rects, clip, color, true);
        }
 }