TextItem.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // TextItem.cs
  4. //
  5. // Microsoft XNA Community Game Platform
  6. // Copyright (C) Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #endregion
  9. #region Using Statements
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Text;
  13. using Microsoft.Xna.Framework;
  14. using Microsoft.Xna.Framework.Graphics;
  15. using RobotGameData.GameInterface;
  16. #endregion
  17. namespace RobotGameData.Text
  18. {
  19. /// <summary>
  20. /// a structure with text information to be drawn on screen.
  21. /// </summary>
  22. public class TextItem : IIdentity
  23. {
  24. #region Fields
  25. protected int id = 0;
  26. protected SpriteFont spriteFont = null;
  27. protected string stringText = String.Empty;
  28. protected Vector2 position = Vector2.Zero;
  29. protected Color textColor = Color.White;
  30. protected float rotation = 0.0f;
  31. protected float scale = 1.0f;
  32. protected bool visible = true;
  33. #endregion
  34. #region Properties
  35. public int Id
  36. {
  37. get
  38. {
  39. if (id == 0)
  40. {
  41. id = GetHashCode();
  42. }
  43. return id;
  44. }
  45. }
  46. public SpriteFont Font
  47. {
  48. get { return spriteFont; }
  49. set { spriteFont = value; }
  50. }
  51. public string Text
  52. {
  53. get { return stringText; }
  54. set { stringText = value; }
  55. }
  56. public int PosX
  57. {
  58. get { return (int)position.X; }
  59. set { position.X = (float)value; }
  60. }
  61. public int PosY
  62. {
  63. get { return (int)position.Y; }
  64. set { position.Y = (float)value; }
  65. }
  66. public Vector2 Position
  67. {
  68. get { return position; }
  69. set { position = value; }
  70. }
  71. public Color Color
  72. {
  73. get { return textColor; }
  74. set { textColor = value; }
  75. }
  76. public float Rotation
  77. {
  78. get { return rotation; }
  79. set { rotation = value; }
  80. }
  81. public float Scale
  82. {
  83. get { return scale; }
  84. set { scale = value; }
  85. }
  86. public bool Visible
  87. {
  88. get { return visible; }
  89. set { visible = value; }
  90. }
  91. #endregion
  92. /// <summary>
  93. /// Constructor.
  94. /// </summary>
  95. public TextItem() { }
  96. /// <summary>
  97. /// Constructor.
  98. /// </summary>
  99. /// <param name="font">sprite font</param>
  100. /// <param name="text">text</param>
  101. /// <param name="x">position x</param>
  102. /// <param name="y">position y</param>
  103. /// <param name="color">text color</param>
  104. public TextItem(SpriteFont font, string text, int x, int y, Color color)
  105. {
  106. if (font == null)
  107. {
  108. throw new ArgumentNullException("font");
  109. }
  110. if (String.IsNullOrEmpty(text))
  111. {
  112. throw new ArgumentNullException("text");
  113. }
  114. spriteFont = font;
  115. stringText = text;
  116. position.X = (int)x;
  117. position.Y = (int)y;
  118. textColor = color;
  119. }
  120. public void CopyTo(TextItem target)
  121. {
  122. target.Font = Font;
  123. target.Text = Text;
  124. target.PosX = PosX;
  125. target.PosY = PosY;
  126. target.Color = Color;
  127. }
  128. public bool IsSameValue(TextItem item)
  129. {
  130. if (Font != item.Font)
  131. return false;
  132. if (Text != item.Text)
  133. return false;
  134. if (PosX != item.PosX)
  135. return false;
  136. if (PosY != item.PosY)
  137. return false;
  138. if (Color != item.Color)
  139. return false;
  140. return true;
  141. }
  142. }
  143. }