SimpleProgressPointer.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. using FastReport.Utils;
  2. using System.Drawing;
  3. using System.Drawing.Drawing2D;
  4. using System.ComponentModel;
  5. namespace FastReport.Gauge.Simple.Progress
  6. {
  7. /// <summary>
  8. /// SimpleProgressGauge pointer types
  9. /// </summary>
  10. public enum SimpleProgressPointerType
  11. {
  12. /// <summary>
  13. /// Full sized pointer
  14. /// </summary>
  15. Full,
  16. /// <summary>
  17. /// Small pointer
  18. /// </summary>
  19. Small
  20. }
  21. /// <inheritdoc />
  22. #if !DEBUG
  23. [DesignTimeVisible(false)]
  24. #endif
  25. public class SimpleProgressPointer : SimplePointer
  26. {
  27. private SimpleProgressPointerType type;
  28. private float smallPointerWidthRatio;
  29. /// <summary>
  30. /// Gets or sets the pointer type
  31. /// </summary>
  32. public SimpleProgressPointerType Type
  33. {
  34. get { return type; }
  35. set { type = value; }
  36. }
  37. /// <summary>
  38. /// Gets or sets the small pointer width ratio
  39. /// </summary>
  40. public float SmallPointerWidthRatio
  41. {
  42. get { return smallPointerWidthRatio; }
  43. set
  44. {
  45. if (value > 1)
  46. smallPointerWidthRatio = 1;
  47. else if (value < 0)
  48. smallPointerWidthRatio = 0;
  49. else
  50. smallPointerWidthRatio = value;
  51. }
  52. }
  53. /// <inheritdoc />
  54. public SimpleProgressPointer(GaugeObject parent) : base(parent)
  55. {
  56. smallPointerWidthRatio = 0.1f;
  57. }
  58. internal override void DrawHorz(FRPaintEventArgs e)
  59. {
  60. IGraphics g = e.Graphics;
  61. Pen pen = e.Cache.GetPen(BorderColor, BorderWidth * e.ScaleX, DashStyle.Solid);
  62. Left = (Parent.AbsLeft + Parent.Border.Width / 2 + HorizontalOffset) * e.ScaleX;
  63. Top = (Parent.AbsTop + Parent.Border.Width / 2 + (Parent.Height - Parent.Border.Width) / 2 - (Parent.Height - Parent.Border.Width) * PointerRatio / 2) * e.ScaleY;
  64. Height = ((Parent.Height - Parent.Border.Width) * PointerRatio) * e.ScaleY;
  65. Width = (float)((Parent.Width - Parent.Border.Width - HorizontalOffset * 2) * (Parent.Value - Parent.Minimum) / (Parent.Maximum - Parent.Minimum) * e.ScaleX);
  66. if (type == SimpleProgressPointerType.Small)
  67. {
  68. float prntWidth = (Parent.Width - Parent.Border.Width + HorizontalOffset) * e.ScaleX;
  69. float widthSml = (Parent.Width - Parent.Border.Width - HorizontalOffset * 2) * smallPointerWidthRatio * e.ScaleX;
  70. float leftSml = Left + Width - prntWidth * smallPointerWidthRatio + widthSml / 2;
  71. if (leftSml >= Left && leftSml + widthSml < Left + prntWidth)
  72. Left = leftSml;
  73. else if (leftSml + widthSml >= Left + prntWidth)
  74. Left += prntWidth - widthSml;
  75. Width = widthSml;
  76. }
  77. Brush brush = Fill.CreateBrush(new RectangleF(Left, Top, Width, Height), e.ScaleX, e.ScaleY);
  78. g.FillAndDrawRectangle(pen, brush, Left, Top, Width, Height);
  79. }
  80. internal override void DrawVert(FRPaintEventArgs e)
  81. {
  82. IGraphics g = e.Graphics;
  83. Pen pen = e.Cache.GetPen(BorderColor, BorderWidth * e.ScaleY, DashStyle.Solid);
  84. Width = ((Parent.Width - Parent.Border.Width) * PointerRatio) * e.ScaleX;
  85. Height = (float)((Parent.Height - Parent.Border.Width - HorizontalOffset * 2) * (Parent.Value - Parent.Minimum) / (Parent.Maximum - Parent.Minimum) * e.ScaleY);
  86. Left = (Parent.AbsLeft + Parent.Border.Width / 2 + (Parent.Width - Parent.Border.Width) / 2 - (Parent.Width - Parent.Border.Width) * PointerRatio / 2) * e.ScaleX;
  87. Top = (Parent.AbsTop + Parent.Border.Width / 2 + Parent.Height - Parent.Border.Width) * e.ScaleY - Height;
  88. if (type == SimpleProgressPointerType.Small)
  89. {
  90. float prntTop = (Parent.AbsTop + Parent.Border.Width / 2) * e.ScaleY;
  91. float prntHeight = (Parent.Height - Parent.Border.Width) * e.ScaleY;
  92. float heightSml = (Parent.Height - Parent.Border.Width) * smallPointerWidthRatio * e.ScaleY;
  93. float topSml = Top - heightSml / 2;
  94. if (topSml + heightSml > prntTop + prntHeight)
  95. Top = prntTop + prntHeight - heightSml;
  96. else if (topSml < prntTop)
  97. Top = prntTop;
  98. else
  99. Top = topSml;
  100. Height = heightSml;
  101. }
  102. Brush brush = Fill.CreateBrush(new RectangleF(Left, Top, Width, Height), e.ScaleX, e.ScaleY);
  103. g.FillAndDrawRectangle(pen, brush, Left, Top, Width, Height);
  104. }
  105. /// <inheritdoc />
  106. public override void Assign(GaugePointer src)
  107. {
  108. base.Assign(src);
  109. SimpleProgressPointer s = src as SimpleProgressPointer;
  110. Type = s.Type;
  111. SmallPointerWidthRatio = s.SmallPointerWidthRatio;
  112. }
  113. /// <inheritdoc />
  114. public override void Serialize(FRWriter writer, string prefix, GaugePointer diff)
  115. {
  116. base.Serialize(writer, prefix, diff);
  117. SimpleProgressPointer dc = diff as SimpleProgressPointer;
  118. if (Type != dc.Type)
  119. {
  120. writer.WriteValue(prefix + ".Type", Type);
  121. }
  122. if (SmallPointerWidthRatio != dc.SmallPointerWidthRatio)
  123. {
  124. writer.WriteValue(prefix + ".SmallPointerWidthRatio", SmallPointerWidthRatio);
  125. }
  126. }
  127. }
  128. }