DateMarginSplitter.xaml.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. using MuchInfo.Chart.Data.EnumTypes;
  2. using MuchInfo.Chart.WPF.Primitives;
  3. using System;
  4. using System.Windows;
  5. using System.Windows.Controls;
  6. using System.Windows.Input;
  7. using System.Windows.Media;
  8. namespace MuchInfo.Chart.WPF.Controls.DateScaling
  9. {
  10. /// <summary>
  11. /// DateMarginSplitter.xaml 的交互逻辑
  12. /// </summary>
  13. public partial class DateMarginSplitter : UserControl
  14. {
  15. private AllDateScaler dataScalers;
  16. private Canvas parentCanvas;
  17. private Chart _chart;
  18. private double _parentPosition;
  19. private float _futureSplitPercent;
  20. private bool _isMouseDown;
  21. private DateTime _desiredEndDate;
  22. private bool _isMouseEnter;
  23. //private bool DateMarginSplitter_755;
  24. public DateMarginSplitter(Canvas aParent, Chart aChart)
  25. {
  26. base.SizeChanged += (new SizeChangedEventHandler(this.DateMarginSplitter_SizeChanged));
  27. this._futureSplitPercent = 0f;
  28. this._isMouseDown = false;
  29. this._isMouseEnter = false;
  30. this.InitializeComponent();
  31. this.parentCanvas = aParent;
  32. this._chart = aChart;
  33. this.Cursor = Cursors.SizeWE;
  34. }
  35. internal void DateMarginSplitter_2672(AllDateScaler aScaler)
  36. {
  37. this.dataScalers = aScaler;
  38. this.SetCenterLineVisibility();
  39. }
  40. private void SetCenterLineVisibility()
  41. {
  42. this.centerLine.Visibility = (this._isMouseEnter || this._isMouseDown) ? Visibility.Visible : Visibility.Collapsed;
  43. }
  44. private void theBorder_LostMouseCapture(object sender, MouseEventArgs e)
  45. {
  46. this._isMouseDown = false;
  47. this.SetCenterLineVisibility();
  48. }
  49. private void theBorder_MouseEnter(object sender, MouseEventArgs e)
  50. {
  51. this._isMouseEnter = true;
  52. this.SetCenterLineVisibility();
  53. }
  54. private void theBorder_MouseLeave(object sender, MouseEventArgs e)
  55. {
  56. this._isMouseEnter = false;
  57. this.SetCenterLineVisibility();
  58. }
  59. private void theBorder_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  60. {
  61. bool flag = _chart.PointerType != PointerType.Drawing;
  62. if (flag)
  63. {
  64. this.theBorder.CaptureMouse();
  65. this._isMouseDown = true;
  66. this._parentPosition = e.GetPosition(this.parentCanvas).X;
  67. this._futureSplitPercent = this.dataScalers.FutureSplitPercent;
  68. this._desiredEndDate = this.dataScalers.DesiredEndDate;
  69. }
  70. }
  71. private void theBorder_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  72. {
  73. if (_isMouseDown)
  74. {
  75. this._isMouseDown = false;
  76. this.RefreshChart(e.GetPosition(this.parentCanvas).X);
  77. }
  78. this.theBorder.ReleaseMouseCapture();
  79. }
  80. private void theBorder_MouseMove(object sender, MouseEventArgs e)
  81. {
  82. if (_isMouseDown)
  83. {
  84. this.RefreshChart(e.GetPosition(this.parentCanvas).X);
  85. }
  86. }
  87. private void RefreshChart(double inX)
  88. {
  89. double num = inX;
  90. if (inX < (double)this.dataScalers.WidthWithBarBuffer() * 0.1)
  91. {
  92. num = (double)this.dataScalers.WidthWithBarBuffer() * 0.1;
  93. }
  94. double num2 = num - this._parentPosition;
  95. double num3 = (double)this.dataScalers.WidthWithBarBuffer();
  96. if (num3 > 0.0)
  97. {
  98. double num4 = -1.0 * num2 / num3;
  99. this.dataScalers.FutureSplitPercent = (float)((double)this._futureSplitPercent + num4);
  100. if (this._futureSplitPercent != this.dataScalers.FutureSplitPercent && DateTime.Compare(this._desiredEndDate, DateTime.MaxValue) != 0)
  101. {
  102. if (Math.Abs(this._futureSplitPercent - this.dataScalers.FutureSplitPercent) > 0.2)
  103. {
  104. //this._futureSplitPercent = this._futureSplitPercent;
  105. }
  106. int num5 = (int)Math.Round((this.dataScalers.FutureSplitPercent - this._futureSplitPercent) * this.dataScalers.NumBars);
  107. if (num5 != 0)
  108. {
  109. int num6 = this.dataScalers.IndexFromDate(this._desiredEndDate);
  110. num6 += num5;
  111. if (num6 >= 0 && num6 < this.dataScalers.Count())
  112. {
  113. this.dataScalers.DesiredEndDate = this.dataScalers.DateValue(num6);
  114. }
  115. }
  116. }
  117. this._chart.Refresh(true);
  118. }
  119. }
  120. private void DateMarginSplitter_SizeChanged(object sender, SizeChangedEventArgs e)
  121. {
  122. this.centerLine.Y2 = (this.lineRowDef.ActualHeight);
  123. }
  124. }
  125. }