コード例 #1
0
        internal void DrawWrappedOnWordText(GL gl, string text, Vector2 size)
        {
            var currentSize = Vector2.Zero;
            var current     = 0;

            while (current != -1 && current < text.Length)
            {
                var start = current;
                current = FindWordIndexFromBounds(current, size.X, text, out currentSize);

                if (current > 0)
                {
                    var p = gl.currentPosition;
                    for (int i = start; i < current; i++)
                    {
                        var      c = text[i];
                        FontChar fc;
                        if (_characterMap.TryGetValue(c, out fc))
                        {
                            var sourceRectangle = AxisAlignedBox2.FromRect(fc.X, fc.Y, fc.Width, fc.Height);
                            var destRectangle   = AxisAlignedBox2.FromRect(fc.XOffset, fc.YOffset, fc.Width, fc.Height);
                            gl.source(sourceRectangle);
                            gl.quad(destRectangle);
                            gl.translate(new Vector2(fc.XAdvance, 0));

                            //dx += fc.XAdvance;
                        }
                    }
                    gl.position(p);
                    gl.translate(new Vector2(0, MaxLineHeight));
                }

                size.Y += currentSize.Y;
            }
        }
コード例 #2
0
        internal void DrawText(GL gl, string text, float?width)
        {
            var dx = 0f;// Utility.Floor(pos.X);

            //var dy = Utility.Floor(pos.Y);
            foreach (char c in text)
            {
                FontChar fc;
                if (_characterMap.TryGetValue(c, out fc))
                {
                    if (width.HasValue && dx + fc.XAdvance > width.Value)
                    {
                        break;
                    }

                    var sourceRectangle = AxisAlignedBox2.FromRect(fc.X, fc.Y, fc.Width, fc.Height);
                    var destRectangle   = AxisAlignedBox2.FromRect(fc.XOffset, fc.YOffset, fc.Width, fc.Height);

                    gl.source(sourceRectangle);
                    gl.quad(destRectangle);
                    gl.translate(new Vector2(fc.XAdvance, 0));

                    dx += fc.XAdvance;
                }
            }
        }