GaugeScale.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. using System.ComponentModel;
  2. using System.Drawing;
  3. using System.Drawing.Design;
  4. using FastReport.Utils;
  5. namespace FastReport.Gauge
  6. {
  7. /// <summary>
  8. /// Represents a scale of a gauge.
  9. /// </summary>
  10. #if !DEBUG
  11. [DesignTimeVisible(false)]
  12. #endif
  13. public class GaugeScale : Component
  14. {
  15. #region Fields
  16. private GaugeObject parent;
  17. private Font font;
  18. private FillBase textFill;
  19. private ScaleTicks majorTicks;
  20. private ScaleTicks minorTicks;
  21. #endregion // Fields
  22. #region Properties
  23. /// <summary>
  24. /// Gets or sets major ticks of scale.
  25. /// </summary>
  26. [Browsable(true)]
  27. public ScaleTicks MajorTicks
  28. {
  29. get { return majorTicks; }
  30. set { majorTicks = value; }
  31. }
  32. /// <summary>
  33. /// Gets or sets minor ticks of scale.
  34. /// </summary>
  35. [Browsable(true)]
  36. public ScaleTicks MinorTicks
  37. {
  38. get { return minorTicks; }
  39. set { minorTicks = value; }
  40. }
  41. /// <summary>
  42. /// Gets or sets the parent gauge object.
  43. /// </summary>
  44. [Browsable(false)]
  45. public GaugeObject Parent
  46. {
  47. get { return parent; }
  48. set { parent = value; }
  49. }
  50. /// <summary>
  51. /// Gets or sets the font of scale.
  52. /// </summary>
  53. [Browsable(true)]
  54. public Font Font
  55. {
  56. get { return font; }
  57. set { font = value; }
  58. }
  59. /// <summary>
  60. /// Gets or sets the scale font color
  61. /// </summary>
  62. [Editor("FastReport.TypeEditors.FillEditor, FastReport", typeof(UITypeEditor))]
  63. public FillBase TextFill
  64. {
  65. get { return textFill; }
  66. set { textFill = value; }
  67. }
  68. #endregion // Properties
  69. #region Constructors
  70. /// <summary>
  71. /// Initializes a new instance of the <see cref="GaugeScale"/> class.
  72. /// </summary>
  73. /// <param name="parent">The parent gauge object.</param>
  74. public GaugeScale(GaugeObject parent)
  75. {
  76. this.parent = parent;
  77. font = new Font("Arial", 8.0f);
  78. TextFill = new SolidFill(Color.Black);
  79. majorTicks = new ScaleTicks();
  80. minorTicks = new ScaleTicks();
  81. }
  82. #endregion // Constructors
  83. #region Public Methods
  84. /// <summary>
  85. /// Copies the contents of another GaugeScale.
  86. /// </summary>
  87. /// <param name="src">The GaugeScale instance to copy the contents from.</param>
  88. public virtual void Assign(GaugeScale src)
  89. {
  90. Font = src.Font;
  91. TextFill = src.TextFill;
  92. }
  93. /// <summary>
  94. /// Draws the scale of gauge.
  95. /// </summary>
  96. /// <param name="e">Draw event arguments.</param>
  97. public virtual void Draw(FRPaintEventArgs e)
  98. {
  99. }
  100. /// <summary>
  101. /// Serializes the gauge scale.
  102. /// </summary>
  103. /// <param name="writer">Writer object.</param>
  104. /// <param name="prefix">Scale property name.</param>
  105. /// <param name="diff">Another GaugeScale to compare with.</param>
  106. /// <remarks>
  107. /// This method is for internal use only.
  108. /// </remarks>
  109. public virtual void Serialize(FRWriter writer, string prefix, GaugeScale diff)
  110. {
  111. TextFill.Serialize(writer, prefix + ".TextFill", diff.TextFill);
  112. if ((writer.SerializeTo != SerializeTo.Preview || !Font.Equals(diff.Font)) && writer.ItemName != "inherited")
  113. {
  114. writer.WriteValue(prefix + ".Font", Font);
  115. }
  116. }
  117. #endregion // Public Methods
  118. }
  119. /// <summary>
  120. /// Represents a scale ticks.
  121. /// </summary>
  122. [ToolboxItem(false)]
  123. public class ScaleTicks : Component
  124. {
  125. #region Fields
  126. private float length;
  127. private int width;
  128. private Color color;
  129. private int count;
  130. #endregion // Fields
  131. #region Properties
  132. /// <summary>
  133. /// Gets or sets the length of ticks.
  134. /// </summary>
  135. [Browsable(false)]
  136. public float Length
  137. {
  138. get { return length; }
  139. set { length = value; }
  140. }
  141. /// <summary>
  142. /// Gets or sets the width of ticks.
  143. /// </summary>
  144. [Browsable(true)]
  145. public int Width
  146. {
  147. get { return width; }
  148. set { width = value; }
  149. }
  150. /// <summary>
  151. /// Gets or sets the color of ticks.
  152. /// </summary>
  153. [Browsable(true)]
  154. public Color Color
  155. {
  156. get { return color; }
  157. set { color = value; }
  158. }
  159. /// <summary>
  160. /// Gets or sets the count of ticks
  161. /// </summary>
  162. [Browsable(false)]
  163. public int Count
  164. {
  165. get { return count; }
  166. set { count = value; }
  167. }
  168. #endregion // Properties
  169. #region Constructors
  170. /// <summary>
  171. /// Initializes a new instance of the <see cref="ScaleTicks"/> class.
  172. /// </summary>
  173. public ScaleTicks()
  174. {
  175. length = 8.0f;
  176. width = 1;
  177. color = Color.Black;
  178. count = 6;
  179. }
  180. /// <summary>
  181. /// Initializes a new instance of the <see cref="ScaleTicks"/> class.
  182. /// </summary>
  183. /// <param name="length">Ticks length.</param>
  184. /// <param name="width">Ticks width.</param>
  185. /// <param name="color">Ticks color.</param>
  186. public ScaleTicks(float length, int width, Color color)
  187. {
  188. this.length = length;
  189. this.width = width;
  190. this.color = color;
  191. }
  192. /// <summary>
  193. /// Initializes a new instance of the <see cref="ScaleTicks"/> class.
  194. /// </summary>
  195. /// <param name="length">Ticks length.</param>
  196. /// <param name="width">Ticks width.</param>
  197. /// <param name="color">Ticks color.</param>
  198. /// <param name="count">Ticks count.</param>
  199. public ScaleTicks(float length, int width, Color color, int count)
  200. {
  201. this.length = length;
  202. this.width = width;
  203. this.color = color;
  204. this.count = count;
  205. }
  206. #endregion // Constructors
  207. #region Public Methods
  208. /// <summary>
  209. /// Copies the contents of another ScaleTicks.
  210. /// </summary>
  211. /// <param name="src">The ScaleTicks instance to copy the contents from.</param>
  212. public virtual void Assign(ScaleTicks src)
  213. {
  214. Length = src.Length;
  215. Width = src.Width;
  216. Color = src.Color;
  217. }
  218. /// <summary>
  219. /// Serializes the scale ticks.
  220. /// </summary>
  221. /// <param name="writer">Writer object.</param>
  222. /// <param name="prefix">Scale ticks property name.</param>
  223. /// <param name="diff">Another ScaleTicks to compare with.</param>
  224. /// <remarks>
  225. /// This method is for internal use only.
  226. /// </remarks>
  227. public virtual void Serialize(FRWriter writer, string prefix, ScaleTicks diff)
  228. {
  229. if (Length != diff.Length)
  230. {
  231. writer.WriteFloat(prefix + ".Length", Length);
  232. }
  233. if (Width != diff.Width)
  234. {
  235. writer.WriteInt(prefix + ".Width", Width);
  236. }
  237. if (Color != diff.Color)
  238. {
  239. writer.WriteValue(prefix + ".Color", Color);
  240. }
  241. }
  242. #endregion // Public Methods
  243. }
  244. }