using MuchInfo.Chart.Data.EnumTypes; using MuchInfo.Chart.WPF.Primitives.Interfaces; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; namespace MuchInfo.Chart.WPF.Controls.Drawing { /// /// DrawingChannelGrab.xaml 的交互逻辑 /// public partial class DrawingChannelGrab : UserControl { private IChannelDrawing _channelDrawing; private Chart _chart; private bool _isMouseEnter; private bool _isMouseDown; //private bool DrawingChannelGrab_833; public DrawingChannelGrab() { base.MouseMove -= (new MouseEventHandler(this.theBorder_MouseMove)); base.MouseMove += (new MouseEventHandler(this.theBorder_MouseMove)); base.MouseEnter -= (new MouseEventHandler(this.theBorder_MouseEnter)); base.MouseEnter += (new MouseEventHandler(this.theBorder_MouseEnter)); base.MouseLeave -= (new MouseEventHandler(this.theBorder_MouseLeave)); base.MouseLeave += (new MouseEventHandler(this.theBorder_MouseLeave)); base.LostMouseCapture -= (new MouseEventHandler(this.DrawingPointGrab_LostMouseCapture)); base.LostMouseCapture += (new MouseEventHandler(this.DrawingPointGrab_LostMouseCapture)); base.MouseLeftButtonDown -= (new MouseButtonEventHandler(this.theBorder_MouseLeftButtonDown)); base.MouseLeftButtonDown += (new MouseButtonEventHandler(this.theBorder_MouseLeftButtonDown)); base.MouseLeftButtonUp -= (new MouseButtonEventHandler(this.theBorder_MouseLeftButtonUp)); base.MouseLeftButtonUp += (new MouseButtonEventHandler(this.theBorder_MouseLeftButtonUp)); this._isMouseEnter = false; this._isMouseDown = false; this.InitializeComponent(); } public void Setup(IChannelDrawing channelDrawing, Chart chart) { this.InitializeComponent(); this.Cursor = Cursors.Hand; this._channelDrawing = channelDrawing; this._chart = chart; this.arrowPath.Visibility = Visibility.Collapsed; this.dot.Visibility = Visibility.Visible; this.LayoutRoot.BorderBrush = new SolidColorBrush(Colors.Transparent); this.LayoutRoot.Background = new SolidColorBrush(Color.FromArgb(50, 120, 120, 120)); this.dot.Stroke = this._chart.IsDarkBackground ? new SolidColorBrush(Color.FromArgb(150, 255, 255, 255)) : new SolidColorBrush(Color.FromArgb(150, 0, 0, 0)); } internal void DrawingChannelGrab_2829(bool isTop) { if (isTop) { this.ShowChannelGrab((double)this._channelDrawing.ChanX(), (double)this._channelDrawing.TopY()); } else { this.ShowChannelGrab((double)this._channelDrawing.ChanX(), (double)this._channelDrawing.BotY()); } } private DependencyObject GetGreatGrandparent() { var parent = this.Parent as FrameworkElement; if (parent == null) return null; var grandparent = parent.Parent as FrameworkElement; return grandparent == null ? null : grandparent.Parent; } private void ShowChannelGrab(double aX, double aY) { this.SetValue(Canvas.LeftProperty, aX - 7.0); this.SetValue(Canvas.TopProperty, aY - 7.0); bool flag = this.GetGreatGrandparent() != null && this.GetGreatGrandparent() is FrameworkElement; if (flag) { var frameworkElement = (FrameworkElement)this.GetGreatGrandparent(); bool flag2 = true; flag = (aY - 10.0 > frameworkElement.ActualHeight); if (flag) { flag2 = false; } else { flag = (aY + 10.0 < 0.0); if (flag) { flag2 = false; } else { flag = (aX - 10.0 > frameworkElement.ActualWidth); if (flag) { flag2 = false; } else { flag = (aX + 10.0 < 0.0); if (flag) { flag2 = false; } } } } flag = flag2; this.Visibility = flag ? Visibility.Visible : Visibility.Collapsed; } } private void DrawingPointGrab_LostMouseCapture(object sender, MouseEventArgs e) { if (this._isMouseDown) { this._isMouseDown = false; this._chart.LockPainting = false; this._chart.Refresh(); this.DrawingChannelGrab_2835(); } } private void theBorder_MouseEnter(object sender, MouseEventArgs e) { this._isMouseEnter = true; this.DrawingChannelGrab_2835(); } private void theBorder_MouseLeave(object sender, MouseEventArgs e) { this._isMouseEnter = false; this.DrawingChannelGrab_2835(); } private void DrawingChannelGrab_2835() { bool flag = this._isMouseEnter || this._isMouseDown; if (flag) { this.arrowPath.Visibility = Visibility.Visible; this.dot.Visibility = Visibility.Collapsed; flag = this._chart.IsDarkBackground; this.arrowPath.Stroke = flag ? new SolidColorBrush(Colors.Yellow) : new SolidColorBrush(Colors.Blue); } else { this.arrowPath.Visibility = Visibility.Collapsed; flag = this._chart.IsDarkBackground; this.dot.Stroke = flag ? new SolidColorBrush(Color.FromArgb(150, 255, 255, 255)) : new SolidColorBrush(Color.FromArgb(150, 0, 0, 0)); this.dot.Visibility = Visibility.Visible; } } private void theBorder_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (this._chart != null && this._chart.PointerType == PointerType.Erase) { this._channelDrawing.Delete(); } else { this._chart.LockPainting = true; this.CaptureMouse(); this.BuildChannelGrab(e); this._isMouseDown = true; this.DrawingChannelGrab_2835(); } } private void theBorder_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { bool flag = this._isMouseDown; if (flag) { this.ReleaseMouseCapture(); this.BuildChannelGrab(e); flag = (this._channelDrawing.OwnerSpec != null); if (flag) { this._channelDrawing.OwnerSpec.ToolChanged(this._channelDrawing); } this._isMouseDown = false; this._chart.LockPainting = false; this._chart.Refresh(); this.DrawingChannelGrab_2835(); } } private void theBorder_MouseMove(object sender, MouseEventArgs e) { if (this._chart != null && this._chart.PointerType == PointerType.Erase) { this._chart.SetCursorImagePos(true, e); } if (this._isMouseDown) { this.BuildChannelGrab(e); } } private void BuildChannelGrab(MouseEventArgs e) { bool flag = this.GetGreatGrandparent() != null && this.GetGreatGrandparent() is FrameworkElement; if (flag) { Point position = e.GetPosition((UIElement)this.GetGreatGrandparent()); var frameworkElement = (FrameworkElement)this.GetGreatGrandparent(); var num = (float)(frameworkElement.ActualHeight - 6.0); flag = (num < 0f); if (flag) { num = 0f; } var num2 = (float)frameworkElement.ActualWidth; flag = (num2 < 0f); if (flag) { num2 = 0f; } flag = (position.X < 0.0); if (flag) { position.X = (0.0); } flag = (position.Y < 0.0); if (flag) { position.Y = (0.0); } flag = (position.X > (double)num2); if (flag) { position.X = ((double)num2); } flag = (position.Y > (double)num); if (flag) { position.Y = ((double)num); } this.ShowChannelGrab(position.X, position.Y); this._channelDrawing.ChangeWidth((float)position.Y); } } } }