コード例 #1
0
ファイル: Renderer.Sprites.cs プロジェクト: Cryru/Emotion
        /// <summary>
        /// Render a string from an atlas.
        /// </summary>
        /// <param name="position">The top left position of where to start drawing the string.</param>
        /// <param name="color">The text color.</param>
        /// <param name="text">The text itself.</param>
        /// <param name="atlas">The font atlas to use.</param>
        /// <param name="layouter">The layouter to use.</param>
        /// <param name="effect">Effect to apply</param>
        /// <param name="effectAmount">The effect amount.</param>
        /// <param name="effectColor">The effect color.</param>
        public void RenderString(
            Vector3 position, Color color, string text, DrawableFontAtlas atlas, TextLayouter layouter = null,
            FontEffect effect = FontEffect.None, float effectAmount = 0f, Color?effectColor = null)
        {
            layouter ??= new TextLayouter(atlas);

            atlas.SetupDrawing(this, text, effect, effectAmount, effectColor);

            var reUsableVector = new Vector3();

            foreach (char c in text)
            {
                Vector2 gPos = layouter.AddLetter(c, out DrawableGlyph g);
                if (g == null || g.GlyphUV == Rectangle.Empty)
                {
                    continue;
                }

                reUsableVector.X = gPos.X;
                reUsableVector.Y = gPos.Y;
                atlas.DrawGlyph(this, g, position + reUsableVector, color);
            }

            atlas.FinishDrawing(this);
        }
コード例 #2
0
 /// <summary>
 /// Render a string from an atlas.
 /// </summary>
 /// <param name="position">The top left position of where to start drawing the string.</param>
 /// <param name="color">The text color.</param>
 /// <param name="text">The text itself.</param>
 /// <param name="atlas">The font atlas to use.</param>
 /// <param name="layouter">The layouter to use.</param>
 public void RenderString(Vector3 position, Color color, string text, DrawableFontAtlas atlas, TextLayouter layouter)
 {
     if (atlas?.Atlas?.Glyphs == null)
     {
         return;
     }
     position = position.RoundClosest();
     foreach (char c in text)
     {
         Vector2 gPos = layouter.AddLetter(c, out AtlasGlyph g);
         if (g == null)
         {
             continue;
         }
         var uv = new Rectangle(g.Location, g.UV);
         RenderSprite(new Vector3(position.X + gPos.X, position.Y + gPos.Y, position.Z), g.Size, color, atlas.Texture, uv);
     }
 }