BaseSeries.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics.CodeAnalysis;
  4. using System.Drawing;
  5. using System.Numerics;
  6. using System.Text;
  7. namespace Veldrid.Common.Plot
  8. {
  9. public abstract class BaseSeries:BaseDropRender,ISeries
  10. {
  11. private protected List<ICursor> cursors= new List<ICursor>();
  12. public event EventHandler<float> VerticalOffsetChanged;
  13. public event EventHandler<float> HorizontalOffsetChanged;
  14. private int selectindex = -1;
  15. public BaseSeries(IVeldridContent control) : base(control)
  16. {
  17. }
  18. public virtual float HorizontalOffset { get; set; }
  19. public virtual float VerticalOffset { get; set; }
  20. internal override void OnMouseDown(PointF point, ref bool handle)
  21. {
  22. base.OnMouseDown(point, ref handle);
  23. if (!handle)
  24. {
  25. for(int i=0;i<cursors.Count;i++)
  26. {
  27. cursors[i]?.OnMouseDown(point, ref handle);
  28. if (handle)
  29. {
  30. selectindex = i;
  31. break;
  32. }
  33. }
  34. }
  35. if (!handle) selectindex = -1;
  36. }
  37. internal override void OnMouseMove(PointF point, ref bool handle)
  38. {
  39. base.OnMouseMove(point, ref handle);
  40. if (!handle)
  41. {
  42. foreach (var cursor in cursors)
  43. {
  44. cursor?.OnMouseMove(point, ref handle);
  45. if (handle) return;
  46. }
  47. }
  48. }
  49. internal override void OnMouseUp(PointF point, ref bool handle)
  50. {
  51. base.OnMouseUp(point, ref handle);
  52. selectindex = -1;
  53. selected= false;
  54. IsDragged = false;
  55. if (!handle)
  56. {
  57. foreach (var cursor in cursors)
  58. {
  59. cursor?.OnMouseUp(point, ref handle);
  60. if (handle) return;
  61. }
  62. }
  63. }
  64. protected override void ActiveDragged(object sender, PointF point)
  65. {
  66. if(selectindex>=0&& selectindex<cursors.Count)
  67. {
  68. cursors[selectindex].OnDragged(point);
  69. }
  70. else base.ActiveDragged(sender, point);
  71. }
  72. public IReadOnlyList<ICursor> Cursors => cursors.AsReadOnly();
  73. public bool IsDragged { get; set; }
  74. protected void OnVerticalOffsetChanged(float e) => VerticalOffsetChanged?.Invoke(this, e);
  75. protected void OnHorizontalOffsetChanged(float e)=>HorizontalOffsetChanged?.Invoke(this, e);
  76. public override void Draw()
  77. {
  78. base.Draw();
  79. cursors.ForEach(x => x?.Draw());
  80. }
  81. protected override void SetWindowSizeState(bool state)
  82. {
  83. base.SetWindowSizeState(state);
  84. cursors.ForEach(x => x.WindowSizeState = state);
  85. }
  86. protected override void Dispose(bool disposing)
  87. {
  88. cursors?.ForEach(x => x?.Dispose());
  89. cursors?.Clear();
  90. base.Dispose(disposing);
  91. }
  92. }
  93. }