FutureDateSplit.xaml.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. using System;
  2. using System.Windows;
  3. using System.Windows.Controls;
  4. using System.Windows.Input;
  5. using System.Windows.Media;
  6. using Microsoft.VisualBasic;
  7. using MuchInfo.Chart.Infrastructure.Helpers;
  8. using MuchInfo.Chart.WPF.Primitives;
  9. namespace MuchInfo.Chart.WPF.Controls.DateScaling
  10. {
  11. public partial class FutureDateSplit : UserControl
  12. {
  13. #region Fields
  14. private AllDateScaler _allDateScaler;
  15. private Canvas _canvas;
  16. private Chart _chart;
  17. private Color _color;
  18. private DateTime _endDate;
  19. private bool _flag;
  20. private bool _flag2;
  21. private float _splitPercent;
  22. private double _x;
  23. #endregion Fields
  24. #region Constructors
  25. public FutureDateSplit(Canvas aParent, Chart aChart)
  26. {
  27. this._flag = false;
  28. this._splitPercent = 0f;
  29. this._flag2 = false;
  30. this.InitializeComponent();
  31. this._canvas = aParent;
  32. this._chart = aChart;
  33. }
  34. #endregion Constructors
  35. #region Methods
  36. #region Internal Methods
  37. internal void BuildFutureDateSplit(AllDateScaler aScaler, Color aColor, double aFontSize, bool isForex)
  38. {
  39. this._allDateScaler = aScaler;
  40. this._color = aColor;
  41. DateTime EndDateTime = this._allDateScaler.DateValue(this._allDateScaler.EndDateIndex);
  42. DateTime StartDateTime = this._allDateScaler.DateValue(this._allDateScaler.StartDateIndex);
  43. TimeSpan ts = EndDateTime - StartDateTime;
  44. if (ts.TotalMinutes > 0 && ts.TotalMinutes < 3600)
  45. {
  46. this.theLabel.Text = Strings.Format(EndDateTime, "yyyy-MM-dd");
  47. }
  48. else if (ts.Days > 1 && ts.Days < 30)
  49. {
  50. this.theLabel.Text = Strings.Format(EndDateTime, "yyyy-MM-dd");
  51. }
  52. else if (ts.Days > 30)
  53. {
  54. this.theLabel.Text = Strings.Format(EndDateTime, "yyyy-MM");
  55. }
  56. this.theLabel.Foreground = (new SolidColorBrush(this._color));
  57. this.theLabel.FontSize = aFontSize * 0.9;
  58. }
  59. #endregion Internal Methods
  60. #region Private Methods
  61. private void FutureDateSplit_2756(double inX)
  62. {
  63. double num = inX;
  64. bool flag = inX < (double)this._allDateScaler.WidthWithBarBuffer() * 0.1;
  65. if (flag)
  66. {
  67. num = (double)this._allDateScaler.WidthWithBarBuffer() * 0.1;
  68. }
  69. double num2 = num - this._x;
  70. double num3 = (double)this._allDateScaler.WidthWithBarBuffer();
  71. flag = (num3 > 0.0);
  72. if (flag)
  73. {
  74. double num4 = -1.0 * num2 / num3;
  75. this._allDateScaler.FutureSplitPercent = (float)((double)this._splitPercent + num4);
  76. flag = (this._splitPercent != this._allDateScaler.FutureSplitPercent && DateTime.Compare(this._endDate, DateTime.MaxValue) != 0);
  77. if (flag)
  78. {
  79. bool flag2 = (double)Math.Abs(this._splitPercent - this._allDateScaler.FutureSplitPercent) > 0.2;
  80. if (flag2)
  81. {
  82. //this.FutureDateSplit_796 = this.FutureDateSplit_796;
  83. }
  84. checked
  85. {
  86. int num5 = (int)Math.Round((double)unchecked((this._allDateScaler.FutureSplitPercent - this._splitPercent) * (float)this._allDateScaler.NumBars));
  87. flag2 = (num5 != 0);
  88. if (flag2)
  89. {
  90. int num6 = this._allDateScaler.IndexFromDate(this._endDate);
  91. num6 += num5;
  92. flag2 = (num6 >= 0 && num6 < this._allDateScaler.Count());
  93. if (flag2)
  94. {
  95. this._allDateScaler.DesiredEndDate = this._allDateScaler.DateValue(num6);
  96. }
  97. }
  98. }
  99. }
  100. this._chart.Refresh(true);
  101. }
  102. }
  103. private void FutureEnter()
  104. {
  105. bool flag = false;
  106. if (flag)
  107. {
  108. this.arrowLeft.Fill = (new SolidColorBrush(this._color));
  109. this.arrowRight.Fill = (new SolidColorBrush(this._color));
  110. this.arrowLeft.Stroke = (new SolidColorBrush(ColorHelper.SteelBlue));
  111. this.arrowRight.Stroke = (this.arrowLeft.Stroke);
  112. this.theBorder.Background = (new SolidColorBrush(ColorHelper.ColorFromString("#55AAAAAA")));
  113. }
  114. else
  115. {
  116. this.arrowLeft.Stroke = (new SolidColorBrush(Colors.Transparent));
  117. this.arrowRight.Stroke = (this.arrowLeft.Stroke);
  118. this.arrowLeft.Fill = (new SolidColorBrush(Color.FromArgb(100, this._color.R, this._color.G, this._color.B)));
  119. this.arrowRight.Fill = (this.arrowLeft.Fill);
  120. this.theBorder.Background = (new SolidColorBrush(Colors.Transparent));
  121. }
  122. }
  123. private void theBorder_LostMouseCapture(object sender, MouseEventArgs e)
  124. {
  125. this._flag2 = false;
  126. this.FutureEnter();
  127. }
  128. private void theBorder_MouseEnter(object sender, MouseEventArgs e)
  129. {
  130. if (_flag)
  131. {
  132. this.FutureEnter();
  133. }
  134. }
  135. private void theBorder_MouseLeave(object sender, MouseEventArgs e)
  136. {
  137. this.FutureEnter();
  138. }
  139. private void theBorder_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  140. {
  141. if (_flag)
  142. {
  143. this.theBorder.CaptureMouse();
  144. this._flag2 = true;
  145. this._x = e.GetPosition(this._canvas).X;
  146. this._splitPercent = this._allDateScaler.FutureSplitPercent;
  147. this._endDate = this._allDateScaler.DesiredEndDate;
  148. }
  149. }
  150. private void theBorder_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  151. {
  152. if (_flag2)
  153. {
  154. this._flag2 = false;
  155. this.FutureDateSplit_2756(e.GetPosition(this._canvas).X);
  156. }
  157. this.theBorder.ReleaseMouseCapture();
  158. }
  159. private void theBorder_MouseMove(object sender, MouseEventArgs e)
  160. {
  161. if (_flag2)
  162. {
  163. this.FutureDateSplit_2756(e.GetPosition(this._canvas).X);
  164. }
  165. }
  166. //private void UpdateControls()
  167. //{
  168. // int num = this._allDateScaler.IndexOfLastDataDate;
  169. // bool flag = this._allDateScaler.EndIndex > num;
  170. // bool flag2 = this._allDateScaler.EndIndex < num;
  171. // if (flag2)
  172. // {
  173. // num = this._allDateScaler.EndIndex;
  174. // this._flag = false;
  175. // }
  176. // else
  177. // {
  178. // this._flag = true;
  179. // }
  180. // this._flag = false;
  181. // flag2 = this._flag;
  182. // if (flag2)
  183. // {
  184. // this.Cursor = (Cursors.SizeWE);
  185. // this.arrowLeft.Visibility = Visibility.Visible;
  186. // this.arrowRight.Visibility = Visibility.Visible;
  187. // this.rightArrowDef.MinWidth = 10.0;
  188. // }
  189. // else
  190. // {
  191. // this.Cursor = (Cursors.Arrow);
  192. // this.arrowLeft.Visibility = Visibility.Collapsed;
  193. // this.arrowRight.Visibility = Visibility.Collapsed;
  194. // this.rightArrowDef.MinWidth = 0.0;
  195. // }
  196. // flag2 = !flag;
  197. // if (flag2)
  198. // {
  199. // this.arrowRight.Visibility = Visibility.Collapsed;
  200. // }
  201. //}
  202. #endregion Private Methods
  203. #endregion Methods
  204. }
  205. }