MarkerStyleEditor.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. // See the LICENSE file in the project root for more information.
  4. //
  5. // Purpose: Design-time marker style editor class.
  6. //
  7. using System.ComponentModel;
  8. using System.Diagnostics.CodeAnalysis;
  9. using System.Drawing;
  10. using System.Drawing.Design;
  11. using FastReport.DataVisualization.Charting;
  12. namespace FastReport.Design.DataVisualization.Charting
  13. {
  14. #if DESIGNER
  15. /// <summary>
  16. /// AxisName editor for the marker style.
  17. /// Paints a rectangle with marker sample.
  18. /// </summary>
  19. internal class MarkerStyleEditor : UITypeEditor, IDisposable
  20. {
  21. #region Editor method and properties
  22. ChartGraphics _chartGraph = null;
  23. private bool _disposed;
  24. /// <summary>
  25. /// Override this function to support palette colors drawing
  26. /// </summary>
  27. /// <param name="context">Descriptor context.</param>
  28. /// <returns>Can paint values.</returns>
  29. public override bool GetPaintValueSupported(ITypeDescriptorContext context)
  30. {
  31. return true;
  32. }
  33. /// <summary>
  34. /// Override this function to support palette colors drawing
  35. /// </summary>
  36. /// <param name="e">Paint value event arguments.</param>
  37. [SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily",
  38. Justification = "Too large of a code change to justify making this change")]
  39. public override void PaintValue(PaintValueEventArgs e)
  40. {
  41. if(e.Value is MarkerStyle)
  42. {
  43. // Create chart graphics object
  44. if(_chartGraph == null)
  45. {
  46. _chartGraph = new ChartGraphics(null);
  47. }
  48. _chartGraph.Graphics = e.Graphics;
  49. // Get marker properties
  50. DataPointCustomProperties attributes = null;
  51. if(e.Context != null && e.Context.Instance != null)
  52. {
  53. // Check if several object selected
  54. object attrObject = e.Context.Instance;
  55. if(e.Context.Instance is Array)
  56. {
  57. Array array = (Array)e.Context.Instance;
  58. if(array.Length > 0)
  59. {
  60. attrObject = array.GetValue(0);
  61. }
  62. }
  63. // Check what kind of object is selected
  64. if(attrObject is Series)
  65. {
  66. attributes = (DataPointCustomProperties)attrObject;
  67. }
  68. else if(attrObject is DataPoint)
  69. {
  70. attributes = (DataPointCustomProperties)attrObject;
  71. }
  72. else if(attrObject is DataPointCustomProperties)
  73. {
  74. attributes = (DataPointCustomProperties)attrObject;
  75. }
  76. else if(attrObject is LegendItem)
  77. {
  78. attributes = new DataPointCustomProperties();
  79. attributes.MarkerColor = ((LegendItem)attrObject).markerColor;
  80. attributes.MarkerBorderColor = ((LegendItem)attrObject).markerBorderColor;
  81. attributes.MarkerSize = ((LegendItem)attrObject).markerSize;
  82. }
  83. }
  84. // Draw marker sample
  85. if(attributes != null && (MarkerStyle)e.Value != MarkerStyle.None)
  86. {
  87. PointF point = new PointF(e.Bounds.X + ((float)e.Bounds.Width)/2F - 0.5F, e.Bounds.Y + ((float)e.Bounds.Height)/2F - 0.5F);
  88. Color color = (attributes.MarkerColor == Color.Empty) ? Color.Black : attributes.MarkerColor;
  89. int size = attributes.MarkerSize;
  90. if(size > (e.Bounds.Height - 4))
  91. {
  92. size = e.Bounds.Height - 4;
  93. }
  94. _chartGraph.DrawMarkerAbs(
  95. point,
  96. (MarkerStyle)e.Value,
  97. size,
  98. color,
  99. attributes.MarkerBorderColor,
  100. attributes.MarkerBorderWidth,
  101. "",
  102. Color.Empty,
  103. 0,
  104. Color.Empty,
  105. RectangleF.Empty,
  106. true);
  107. }
  108. }
  109. }
  110. #endregion
  111. #region IDisposable Members
  112. /// <summary>
  113. /// Finalizer for the MarkerStyleEditor, disposes any remaining
  114. /// resources if it has not already been disposed.
  115. /// </summary>
  116. ~MarkerStyleEditor()
  117. {
  118. Dispose(false);
  119. }
  120. /// <summary>
  121. /// Disposes resources used by this object.
  122. /// </summary>
  123. /// <param name="disposing">Whether this method was called form Dispose() or the finalizer.</param>
  124. protected virtual void Dispose(bool disposing)
  125. {
  126. if (!_disposed)
  127. {
  128. if (disposing)
  129. {
  130. _chartGraph.Dispose();
  131. }
  132. _disposed = true;
  133. }
  134. }
  135. /// <summary>
  136. /// Disposes all resources used by this object
  137. /// </summary>
  138. public void Dispose()
  139. {
  140. Dispose(true);
  141. GC.SuppressFinalize(this);
  142. }
  143. #endregion
  144. }
  145. #endif
  146. }