using MuchInfo.Chart.Data.EnumTypes; using MuchInfo.Chart.WPF.Primitives; using System; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; namespace MuchInfo.Chart.WPF.Controls.DateScaling { /// /// DateMarginSplitter.xaml 的交互逻辑 /// public partial class DateMarginSplitter : UserControl { private AllDateScaler dataScalers; private Canvas parentCanvas; private Chart _chart; private double _parentPosition; private float _futureSplitPercent; private bool _isMouseDown; private DateTime _desiredEndDate; private bool _isMouseEnter; //private bool DateMarginSplitter_755; public DateMarginSplitter(Canvas aParent, Chart aChart) { base.SizeChanged += (new SizeChangedEventHandler(this.DateMarginSplitter_SizeChanged)); this._futureSplitPercent = 0f; this._isMouseDown = false; this._isMouseEnter = false; this.InitializeComponent(); this.parentCanvas = aParent; this._chart = aChart; this.Cursor = Cursors.SizeWE; } internal void DateMarginSplitter_2672(AllDateScaler aScaler) { this.dataScalers = aScaler; this.SetCenterLineVisibility(); } private void SetCenterLineVisibility() { this.centerLine.Visibility = (this._isMouseEnter || this._isMouseDown) ? Visibility.Visible : Visibility.Collapsed; } private void theBorder_LostMouseCapture(object sender, MouseEventArgs e) { this._isMouseDown = false; this.SetCenterLineVisibility(); } private void theBorder_MouseEnter(object sender, MouseEventArgs e) { this._isMouseEnter = true; this.SetCenterLineVisibility(); } private void theBorder_MouseLeave(object sender, MouseEventArgs e) { this._isMouseEnter = false; this.SetCenterLineVisibility(); } private void theBorder_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { bool flag = _chart.PointerType != PointerType.Drawing; if (flag) { this.theBorder.CaptureMouse(); this._isMouseDown = true; this._parentPosition = e.GetPosition(this.parentCanvas).X; this._futureSplitPercent = this.dataScalers.FutureSplitPercent; this._desiredEndDate = this.dataScalers.DesiredEndDate; } } private void theBorder_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { if (_isMouseDown) { this._isMouseDown = false; this.RefreshChart(e.GetPosition(this.parentCanvas).X); } this.theBorder.ReleaseMouseCapture(); } private void theBorder_MouseMove(object sender, MouseEventArgs e) { if (_isMouseDown) { this.RefreshChart(e.GetPosition(this.parentCanvas).X); } } private void RefreshChart(double inX) { double num = inX; if (inX < (double)this.dataScalers.WidthWithBarBuffer() * 0.1) { num = (double)this.dataScalers.WidthWithBarBuffer() * 0.1; } double num2 = num - this._parentPosition; double num3 = (double)this.dataScalers.WidthWithBarBuffer(); if (num3 > 0.0) { double num4 = -1.0 * num2 / num3; this.dataScalers.FutureSplitPercent = (float)((double)this._futureSplitPercent + num4); if (this._futureSplitPercent != this.dataScalers.FutureSplitPercent && DateTime.Compare(this._desiredEndDate, DateTime.MaxValue) != 0) { if (Math.Abs(this._futureSplitPercent - this.dataScalers.FutureSplitPercent) > 0.2) { //this._futureSplitPercent = this._futureSplitPercent; } int num5 = (int)Math.Round((this.dataScalers.FutureSplitPercent - this._futureSplitPercent) * this.dataScalers.NumBars); if (num5 != 0) { int num6 = this.dataScalers.IndexFromDate(this._desiredEndDate); num6 += num5; if (num6 >= 0 && num6 < this.dataScalers.Count()) { this.dataScalers.DesiredEndDate = this.dataScalers.DateValue(num6); } } } this._chart.Refresh(true); } } private void DateMarginSplitter_SizeChanged(object sender, SizeChangedEventArgs e) { this.centerLine.Y2 = (this.lineRowDef.ActualHeight); } } }