コード例 #1
0
        //TODO(later) try to remove the need transform parameter
        private IEnumerable <float> bufferText(string text, Dictionary <char, CharTextureInfo> characters, float textWidth, float adjustment, Matrix4 transform)
        {
            float charOffsetX = textWidth * adjustment;
            float charOffsetY = 0;

            foreach (char c in text)
            {
                if (!char.IsWhiteSpace(c))
                {
                    var charInfo = characters[c];

                    for (int v = 0; v < 6; v++)
                    {
                        var charPos = Vector4.Transform(
                            new Vector4(unitQuadTriangles[v].X * charInfo.Aspect + charOffsetX, unitQuadTriangles[v].Y + charOffsetY, 0, 1),
                            transform
                            );
                        foreach (var dataBit in SpriteHelpers.TexturedVertex(charPos.X, charPos.Y, charInfo.TextureCoords[v].X, charInfo.TextureCoords[v].Y))
                        {
                            yield return(dataBit);
                        }
                    }
                    charOffsetX += charInfo.Aspect;
                }
                else if (c == ' ')
                {
                    charOffsetX += SpaceUnitWidth;
                }
                else if (c == '\n')
                {
                    charOffsetX = textWidth * adjustment;
                    charOffsetY--;
                }
            }
        }
コード例 #2
0
ファイル: TextRenderUtil.cs プロジェクト: weshec/Stareater
        public Dictionary <float, IEnumerable <float> > BufferText(string text, float adjustment, float alignment, float z0, float zRange)
        {
            this.prepare(text);
            float textWidth = this.measureSize(text).X;

            float charOffsetX = textWidth * adjustment;
            float charOffsetY = 0;
            var   layers      = new List <float> [4];
            int   row         = 0;
            int   colunm      = 0;

            for (int i = 0; i < layers.Length; i++)
            {
                layers[i] = new List <float>();
            }

            foreach (var line in text.Split('\n'))
            {
                var lineWidth = line.Sum(c =>
                                         c == ' ' ? SpaceUnitWidth :
                                         !char.IsWhiteSpace(c) ? this.characterInfos[c].Width :
                                         0
                                         );
                charOffsetX = textWidth * adjustment + (textWidth - lineWidth) * alignment;

                foreach (char c in line)
                {
                    if (!char.IsWhiteSpace(c))
                    {
                        var charInfo = this.characterInfos[c];
                        var layer    = 2 * (row % 2) + colunm % 2;

                        for (int v = 0; v < 6; v++)
                        {
                            layers[layer].AddRange(SpriteHelpers.TexturedVertex(
                                                       charInfo.VertexCoords[v].X + charOffsetX,
                                                       charInfo.VertexCoords[v].Y + charOffsetY,
                                                       charInfo.TextureCoords[v].X, charInfo.TextureCoords[v].Y));
                        }

                        charOffsetX += charInfo.Width;
                        colunm++;
                    }
                    else if (c == ' ')
                    {
                        charOffsetX += SpaceUnitWidth;
                    }
                }

                charOffsetY -= this.lineScale;
                row++;
                colunm = 0;
            }

            return(Enumerable.Range(0, layers.Length).
                   ToDictionary(i => z0 - i * zRange / 4, i => (IEnumerable <float>)layers[i]));
        }