Esempio n. 1
0
 void Draw(Vector2 pos, Font.Symbol symbol, Color color)
 {
     VertexBuffer.Add(new Vertex()
     {
         Position = new Vector2(pos.X, pos.Y),
         UV       = symbol.UV.TopLeft,
         Color    = color
     });
     VertexBuffer.Add(new Vertex()
     {
         Position = new Vector2(pos.X + symbol.Size.Width, pos.Y),
         UV       = symbol.UV.TopRight,
         Color    = color
     });
     VertexBuffer.Add(new Vertex()
     {
         Position = new Vector2(pos.X + symbol.Size.Width, pos.Y + symbol.Size.Height),
         UV       = symbol.UV.BottomRight,
         Color    = color
     });
     VertexBuffer.Add(new Vertex()
     {
         Position = new Vector2(pos.X, pos.Y + symbol.Size.Height),
         UV       = symbol.UV.BottomLeft,
         Color    = color
     });
 }
Esempio n. 2
0
        public void Draw(System.Windows.Point originalPos, String text, System.Windows.Media.Color color, TextAlignment alignment = TextAlignment.Left, double maxWidth = double.MaxValue)
        {
            System.Windows.Point pos = new System.Windows.Point(originalPos.X * RenderSettings.DpiScale.X, originalPos.Y * RenderSettings.DpiScale.Y);
            Color textColor          = Utils.Convert(color);

            char[] str = text.ToCharArray();

            switch (alignment)
            {
            case TextAlignment.Center:
            {
                double totalWidth = 0.0;
                for (int i = 0; i < str.Length; ++i)
                {
                    totalWidth += SegoeUI.Symbols[str[i]].Advance;
                }

                double shift = Math.Max(0.0, (maxWidth - totalWidth) * 0.5);

                Vector2 origin = new Vector2((float)(pos.X + shift), (float)pos.Y);
                for (int i = 0; i < str.Length; ++i)
                {
                    Font.Symbol symbol = SegoeUI.Symbols[str[i]];

                    if (symbol.Size.Width > maxWidth)
                    {
                        break;
                    }

                    Draw(origin, symbol, textColor);
                    origin.X += symbol.Advance;
                    maxWidth -= symbol.Advance;
                }
            }
            break;

            case TextAlignment.Right:
            {
                Vector2 origin = new Vector2((float)(pos.X + maxWidth), (float)pos.Y);
                for (int i = str.Length - 1; i >= 0; --i)
                {
                    Font.Symbol symbol = SegoeUI.Symbols[str[i]];
                    origin.X -= symbol.Advance;

                    if (symbol.Size.Width > maxWidth)
                    {
                        break;
                    }

                    Draw(origin, symbol, textColor);
                    maxWidth -= symbol.Advance;
                }
            }
            break;

            default:
            {
                Vector2 origin = new Vector2((float)pos.X, (float)pos.Y);
                for (int i = 0; i < str.Length; ++i)
                {
                    Font.Symbol symbol = SegoeUI.Symbols[str[i]];

                    if (symbol.Size.Width > maxWidth)
                    {
                        break;
                    }

                    Draw(origin, symbol, textColor);
                    origin.X += symbol.Advance;
                    maxWidth -= symbol.Advance;
                }
            }
            break;
            }
        }