Example #1
0
 public override void DrawTexture()
 {
     if (!isInitialized)
     {
         if (!string.IsNullOrEmpty(TextInfo.Text))
         {
             Texture = TextInfo.Text.StringToBitmapSource(FontSize, Media.Colors.White, Media.Colors.Black,
                                                          this.FontFamily, this.FontWeight, this.FontStyle, Padding);
             Texture.Freeze();
             if (!predefinedSize)
             {
                 Width  = (float)Texture.Width;
                 Height = (float)Texture.Height;
             }
             DrawCharacter(TextInfo.Text, TextInfo.Origin, Width, Height, TextInfo);
         }
         else
         {
             Texture = null;
             if (!predefinedSize)
             {
                 Width  = 0;
                 Height = 0;
             }
             Positions.Clear();
             Colors.Clear();
             TextureCoordinates.Clear();
             TextInfo.Offsets.Clear();
         }
         isInitialized = true;
         UpdateBounds();
     }
 }
Example #2
0
        private void DrawCharacter(string text, Vector3 origin, float w, float h, TextInfo info)
        {
            Positions.Clear();
            Colors.Clear();
            TextureCoordinates.Clear();
            info.Offsets.Clear();
            // CCW from top left
            var a = new Vector2(-w / 2, -h / 2);
            var b = new Vector2(-w / 2, h / 2);
            var c = new Vector2(w / 2, -h / 2);
            var d = new Vector2(w / 2, h / 2);

            var uv_a = new Vector2(0, 0);
            var uv_b = new Vector2(0, 1);
            var uv_c = new Vector2(1, 0);
            var uv_d = new Vector2(1, 1);

            // Create foreground data
            Positions.Add(info.Origin);
            Positions.Add(info.Origin);
            Positions.Add(info.Origin);
            Positions.Add(info.Origin);

            Colors.Add(FontColor);
            Colors.Add(FontColor);
            Colors.Add(FontColor);
            Colors.Add(FontColor);

            TextureCoordinates.Add(uv_b);
            TextureCoordinates.Add(uv_d);
            TextureCoordinates.Add(uv_a);
            TextureCoordinates.Add(uv_c);

            info.Offsets.Add(a);
            info.Offsets.Add(c);
            info.Offsets.Add(b);
            info.Offsets.Add(d);

            // Create background data
            Positions.Add(info.Origin);
            Positions.Add(info.Origin);
            Positions.Add(info.Origin);
            Positions.Add(info.Origin);

            Colors.Add(BackgroundColor);
            Colors.Add(BackgroundColor);
            Colors.Add(BackgroundColor);
            Colors.Add(BackgroundColor);

            TextureCoordinates.Add(uv_a);
            TextureCoordinates.Add(uv_a);
            TextureCoordinates.Add(uv_a);
            TextureCoordinates.Add(uv_a);

            info.Offsets.Add(a);
            info.Offsets.Add(c);
            info.Offsets.Add(b);
            info.Offsets.Add(d);
        }
 protected override void OnClearAllGeometryData()
 {
     base.OnClearAllGeometryData();
     Normals?.Clear();
     Normals?.TrimExcess();
     TextureCoordinates?.Clear();
     TextureCoordinates?.TrimExcess();
     Tangents?.Clear();
     Tangents?.TrimExcess();
     BiTangents?.Clear();
     BiTangents?.TrimExcess();
 }
Example #4
0
        public override void DrawTexture()
        {
            Positions.Clear();
            Colors.Clear();
            TextureCoordinates.Clear();

            // http://www.cyotek.com/blog/angelcode-bitmap-font-parsing-using-csharp
            foreach (var textInfo in TextInfo)
            {
                textInfo.Offsets.Clear();
                int x = 0;
                int y = 0;
                var w = bmpFont.TextureSize.Width;
                var h = bmpFont.TextureSize.Height;

                char previousCharacter;

                previousCharacter = ' ';
                var normalizedText = textInfo.Text;

                foreach (char character in normalizedText)
                {
                    switch (character)
                    {
                    case '\n':
                        x  = 0;
                        y -= bmpFont.LineHeight;
                        break;

                    default:
                        Character data    = bmpFont[character];
                        int       kerning = bmpFont.GetKerning(previousCharacter, character);

                        //DrawCharacter(data, x + data.Offset.X + kerning, y + data.Offset.Y, builder);
                        DrawCharacter(data, new Vector3(x, y, 0), w, h, kerning, textInfo);

                        x += data.XAdvance + kerning;
                        break;
                    }

                    previousCharacter = character;
                }
            }
            UpdateBounds();
        }
        public override void DrawTexture()
        {
            Positions.Clear();
            Colors.Clear();
            TextureCoordinates.Clear();
            mTextInfoOffsets = new List <Vector2>(4);
            var w = Width;
            var h = Height;
            // CCW from top left
            var a = new Vector2(-w / 2, -h / 2);
            var b = new Vector2(-w / 2, h / 2);
            var c = new Vector2(w / 2, -h / 2);
            var d = new Vector2(w / 2, h / 2);

            var uv_a = new Vector2(0, 0);
            var uv_b = new Vector2(0, 1);
            var uv_c = new Vector2(1, 0);
            var uv_d = new Vector2(1, 1);

            // Create foreground data
            Positions.Add(Center);
            Positions.Add(Center);
            Positions.Add(Center);
            Positions.Add(Center);

            Colors.Add(MaskColor);
            Colors.Add(MaskColor);
            Colors.Add(MaskColor);
            Colors.Add(MaskColor);

            TextureCoordinates.Add(uv_b);
            TextureCoordinates.Add(uv_d);
            TextureCoordinates.Add(uv_a);
            TextureCoordinates.Add(uv_c);

            mTextInfoOffsets.Add(a);
            mTextInfoOffsets.Add(c);
            mTextInfoOffsets.Add(b);
            mTextInfoOffsets.Add(d);
            UpdateBounds();
        }
 public void DrawText()
 {
     if (!isInitialized)
     {
         if (!string.IsNullOrEmpty(TextInfo.Text))
         {
             Texture = TextInfo.Text.StringToBitmapSource(FontSize, System.Windows.Media.Colors.White, System.Windows.Media.Colors.Black);
             Width   = (float)Texture.Width;
             Height  = (float)Texture.Height;
             DrawCharacter(TextInfo.Text, TextInfo.Origin, (float)Texture.Width, (float)Texture.Height, TextInfo);
         }
         else
         {
             Texture = null;
             Width   = 0;
             Height  = 0;
             Positions.Clear();
             Colors.Clear();
             TextureCoordinates.Clear();
             TextInfo.Offsets.Clear();
         }
         isInitialized = true;
     }
 }