Ejemplo n.º 1
0
        /// <summary>
        /// Draws a 3D text with the given font, style, color, transformation, horizontal align, and vertical
        /// align.
        /// </summary>
        /// <remarks>
        /// This 3D text won't be actually drawn until Flush() method is called. If this method is called before
        /// base.Draw(...) in your main Game class's Draw(...) function, then it's automatically flushed when
        /// base.Draw(...) is called. If this method is called after base.Draw(...) function, then you need to
        /// call Flush() function after calling one or more of this function. Otherwise, the 3D texts drawing will
        /// be deferred until the next base.Draw(...) or Flush() call.
        /// </remarks>
        /// <param name="text">Text string to be displayed in 3D.</param>
        /// <param name="font">Font to use for the 3D text.</param>
        /// <param name="style">3D text style (Outline, Fill, or Extrude).</param>
        /// <param name="color">Color of the 3D text.</param>
        /// <param name="transform">Transformation of the 3D text.</param>
        /// <param name="hAlign">The horizontal (x-axis) shifting</param>
        /// <param name="vAlign"></param>
        public static void Write3DText(String text, VectorFont font, Text3DStyle style, Color color,
                                       Matrix transform, GoblinEnums.HorizontalAlignment hAlign, GoblinEnums.VerticalAlignment vAlign)
        {
            if (queued3DTexts == null)
            {
                queued3DTexts = new List <Text3DInfo>();
            }

            Text3DInfo textInfo = new Text3DInfo();
            Text       text3d   = null;

            if (font == null)
            {
                throw new ArgumentException("'font' must be non-null value");
            }

            switch (style)
            {
            case Text3DStyle.Outline:
                text3d = font.Outline(text);
                break;

            case Text3DStyle.Fill:
                text3d = font.Fill(text);
                break;

            case Text3DStyle.Extrude:
                text3d = font.Extrude(text);
                break;
            }

            textInfo.text3d = text3d;
            textInfo.color  = color;

            Matrix shiftTransform = Matrix.Identity;

            switch (hAlign)
            {
            case GoblinEnums.HorizontalAlignment.None:
            case GoblinEnums.HorizontalAlignment.Left:
                // The default is aligned to left, so nothing to do
                break;

            case GoblinEnums.HorizontalAlignment.Center:
                shiftTransform.Translation -= Vector3.UnitX * text3d.Width / 2;
                break;

            case GoblinEnums.HorizontalAlignment.Right:
                shiftTransform.Translation -= Vector3.UnitX * text3d.Width;
                break;
            }

            switch (vAlign)
            {
            case GoblinEnums.VerticalAlignment.None:
            case GoblinEnums.VerticalAlignment.Bottom:
                // The default is aligned to bottom, so nothing to do
                break;

            case GoblinEnums.VerticalAlignment.Center:
                shiftTransform.Translation -= Vector3.UnitY * text3d.Height / 2;
                break;

            case GoblinEnums.VerticalAlignment.Top:
                shiftTransform.Translation -= Vector3.UnitY * text3d.Height;
                break;
            }

            shiftTransform        *= MatrixHelper.GetRotationMatrix(transform);
            transform.Translation += shiftTransform.Translation;
            textInfo.transform     = transform;

            queued3DTexts.Add(textInfo);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Draws a 3D text with the given font, style, color, and transformation.
 /// </summary>
 /// <remarks>
 /// This 3D text won't be actually drawn until Flush() method is called. If this method is called before
 /// base.Draw(...) in your main Game class's Draw(...) function, then it's automatically flushed when
 /// base.Draw(...) is called. If this method is called after base.Draw(...) function, then you need to
 /// call Flush() function after calling one or more of this function. Otherwise, the 3D texts drawing will
 /// be deferred until the next base.Draw(...) or Flush() call.
 /// </remarks>
 /// <param name="text">Text string to be displayed in 3D.</param>
 /// <param name="font">Font to use for the 3D text.</param>
 /// <param name="style">3D text style (Outline, Fill, or Extrude).</param>
 /// <param name="color">Color of the 3D text.</param>
 /// <param name="transform">Transformation of the left-bottom corner of the 3D text.</param>
 public static void Write3DText(String text, VectorFont font, Text3DStyle style, Color color,
                                Matrix transform)
 {
     Write3DText(text, font, style, color, transform, GoblinEnums.HorizontalAlignment.None,
                 GoblinEnums.VerticalAlignment.None);
 }