TilemapTextObject.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. using Microsoft.Xna.Framework;
  2. namespace MonoGame.Extended.Tilemaps
  3. {
  4. /// <summary>
  5. /// Represents a text object in a tilemap.
  6. /// </summary>
  7. /// <remarks>
  8. /// Text objects store text display information. Rendering is the user's responsibility.
  9. /// </remarks>
  10. public class TilemapTextObject : TilemapObject
  11. {
  12. /// <summary>
  13. /// Gets or sets the bounding size for the text.
  14. /// </summary>
  15. public Vector2 Size { get; set; }
  16. /// <summary>
  17. /// Gets or sets the text content.
  18. /// </summary>
  19. public string Text { get; set; }
  20. /// <summary>
  21. /// Gets or sets the font family name.
  22. /// </summary>
  23. public string FontFamily { get; set; }
  24. /// <summary>
  25. /// Gets or sets the font size in pixels.
  26. /// </summary>
  27. public int PixelSize { get; set; }
  28. /// <summary>
  29. /// Gets or sets a value indicating whether the text is bold.
  30. /// </summary>
  31. public bool Bold { get; set; }
  32. /// <summary>
  33. /// Gets or sets a value indicating whether the text is italic.
  34. /// </summary>
  35. public bool Italic { get; set; }
  36. /// <summary>
  37. /// Gets or sets a value indicating whether the text is underlined.
  38. /// </summary>
  39. public bool Underline { get; set; }
  40. /// <summary>
  41. /// Gets or sets a value indicating whether the text is struck through.
  42. /// </summary>
  43. public bool Strikethrough { get; set; }
  44. /// <summary>
  45. /// Gets or sets the text color.
  46. /// </summary>
  47. public Color Color { get; set; }
  48. /// <summary>
  49. /// Gets or sets a value indicating whether text wraps within the bounding box.
  50. /// </summary>
  51. public bool WordWrap { get; set; }
  52. /// <summary>
  53. /// Gets or sets the horizontal alignment of the text.
  54. /// </summary>
  55. public TilemapTextObjectHorizontalAlignment HorizontalAlign { get; set; }
  56. /// <summary>
  57. /// Gets or sets the vertical alignment of the text.
  58. /// </summary>
  59. public TilemapTextObjectVerticalAlignment VerticalAlign { get; set; }
  60. /// <inheritdoc/>
  61. public override RectangleF Bounds
  62. {
  63. get
  64. {
  65. return new RectangleF(Position.X, Position.Y, Size.X, Size.Y);
  66. }
  67. }
  68. // NOTE: Will use BoundingBox2D
  69. /// <summary>
  70. /// Initializes a new instance of the <see cref="TilemapTextObject"/> class.
  71. /// </summary>
  72. /// <param name="id">The unique identifier for the object.</param>
  73. /// <param name="position">The position of the text.</param>
  74. /// <param name="size">The bounding size for the text.</param>
  75. /// <param name="text">The text content.</param>
  76. public TilemapTextObject(int id, Vector2 position, Vector2 size, string text) : base(id, position)
  77. {
  78. Size = size;
  79. Text = text;
  80. FontFamily = "sans-serif";
  81. PixelSize = 16;
  82. Color = Color.Black;
  83. HorizontalAlign = TilemapTextObjectHorizontalAlignment.Left;
  84. VerticalAlign = TilemapTextObjectVerticalAlignment.Top;
  85. }
  86. }
  87. /// <summary>
  88. /// Specifies horizontal text alignment.
  89. /// </summary>
  90. public enum TilemapTextObjectHorizontalAlignment
  91. {
  92. /// <summary>
  93. /// Align text to the left.
  94. /// </summary>
  95. Left,
  96. /// <summary>
  97. /// Center text horizontally.
  98. /// </summary>
  99. Center,
  100. /// <summary>
  101. /// Align text to the right.
  102. /// </summary>
  103. Right,
  104. /// <summary>
  105. /// Justify text to fill the width.
  106. /// </summary>
  107. Justify
  108. }
  109. /// <summary>
  110. /// Specifies vertical text alignment.
  111. /// </summary>
  112. public enum TilemapTextObjectVerticalAlignment
  113. {
  114. /// <summary>
  115. /// Align text to the top.
  116. /// </summary>
  117. Top,
  118. /// <summary>
  119. /// Center text vertically.
  120. /// </summary>
  121. Center,
  122. /// <summary>
  123. /// Align text to the bottom.
  124. /// </summary>
  125. Bottom
  126. }
  127. }