Esempio n. 1
0
 public GwenRenderer()
 {
     zCounter   = new ZCounter();
     _guiBuffer = new GUIGeometryBuffer(zCounter);
 }
Esempio n. 2
0
        internal static void DrawText(GUIGeometryBuffer geometryBuffer, Flood.GUI.Font font, Vector2 position, String text, Color color)
        {
            var ttfont = font.EngineFont.Resolve();

            for (var i = 0; i < text.Length; i++)
            {
                char c = text[i];

                Glyph glyph;
                var   foundGlyph = ttfont.GetGlyphInfo(c, font.Size, out glyph);
                if (!foundGlyph)
                {
                    Log.Warn("Glyph not found for character " + c);
                    continue;
                }

                bool       drawSubtexture = true;
                SubTexture subTexture;
                if (!glyphCache.TryGetGlyph(font, c, out subTexture))
                {
                    var imageHandle = ttfont.CreateGlyphImage(c, font.Size);
                    if (imageHandle.Id == ResourceHandle <Resource> .Invalid)
                    {
                        drawSubtexture = false;
                    }
                    else
                    {
                        var subTextureFound = textureAtlas.GetImageSubTexture(imageHandle, out subTexture);
                        if (!subTextureFound)
                        {
                            textureAtlas.AddImage(imageHandle);
                            subTextureFound = textureAtlas.GetImageSubTexture(imageHandle, out subTexture);
                            if (subTextureFound)
                            {
                                glyphCache.AddGlyph(font, c, subTexture);
                            }
                            else
                            {
                                Log.Warn("subTexture not Found\n");
                                continue;
                            }
                        }
                    }
                }

                if (drawSubtexture)
                {
                    var renderRect = new RectangleF(
                        position.X + glyph.XOffset,
                        position.Y + glyph.BaseLineOffset,
                        glyph.Width,
                        glyph.Height);

                    geometryBuffer.AddRectangle(renderRect, subTexture.LeftTopUV, subTexture.RightTopUV, subTexture.RightBottomUV, subTexture.LeftBottomUV, textMaterial, color);
                }

                if (i < text.Length - 1)
                {
                    var kern = ttfont.GetKerning(text[i], text[i + 1], font.Size);
                    position.X += glyph.Advance + kern.X;
                    position.Y += kern.Y;
                }
            }
        }