| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- 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
- {
- /// <summary>
- /// DrawingPointGrab.xaml 的交互逻辑
- /// </summary>
- public partial class DrawingPointGrab : UserControl
- {
- #region Fields
- private Chart _chart;
- private IDrawingTool _drawingTool;
- private bool _flag;
- private bool _isMouseEnter;
- private int _pointIndex;
- #endregion Fields
- #region Constructors
- //private bool DrawingPointGrab_846;
- public DrawingPointGrab()
- {
- base.MouseEnter -= (new MouseEventHandler(this.theBorder_MouseEnter));
- base.MouseEnter += (new MouseEventHandler(this.theBorder_MouseEnter));
- base.LostMouseCapture -= (new MouseEventHandler(this.DrawingPointGrab_LostMouseCapture));
- base.LostMouseCapture += (new MouseEventHandler(this.DrawingPointGrab_LostMouseCapture));
- base.MouseLeave -= (new MouseEventHandler(this.theBorder_MouseLeave));
- base.MouseLeave += (new MouseEventHandler(this.theBorder_MouseLeave));
- 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));
- base.MouseMove -= (new MouseEventHandler(this.theBorder_MouseMove));
- base.MouseMove += (new MouseEventHandler(this.theBorder_MouseMove));
- this._isMouseEnter = false;
- this._flag = false;
- this.InitializeComponent();
- }
- #endregion Constructors
- #region Methods
- #region Public Methods
- public void Setup(IDrawingTool tool, int pointIndex, Chart chart)
- {
- this.Cursor = Cursors.Hand;
- this._drawingTool = tool;
- this._pointIndex = pointIndex;
- this._chart = chart;
- this.Arrows.Visibility = Visibility.Collapsed;
- this.LayoutRoot.BorderBrush = (new SolidColorBrush(Colors.Transparent));
- bool isDarkBackground = this._chart.IsDarkBackground;
- if (isDarkBackground)
- {
- this.dot.Stroke = (new SolidColorBrush(Color.FromArgb(150, 255, 255, 255)));
- }
- else
- {
- this.dot.Stroke = (new SolidColorBrush(Color.FromArgb(150, 0, 0, 0)));
- }
- }
- #endregion Public Methods
- #region Internal Methods
- internal void ShowPointGrab()
- {
- Point point = this._drawingTool[this._pointIndex];
- this.ShowPointGrab(point.X, point.Y);
- }
- #endregion Internal Methods
- #region Private Methods
- private void UpdateStroke()
- {
- if (this._isMouseEnter || this._flag)
- {
- this.Arrows.Visibility = Visibility.Visible;
- if (this._chart.IsDarkBackground)
- {
- this.dot.Stroke = (new SolidColorBrush(Color.FromArgb(255, 255, 255, 255)));
- this.L1.Stroke = (new SolidColorBrush(Colors.Yellow));
- }
- else
- {
- this.dot.Stroke = (new SolidColorBrush(Color.FromArgb(255, 0, 0, 0)));
- this.L1.Stroke = (new SolidColorBrush(Colors.Blue));
- }
- this.L2.Stroke = this.L1.Stroke;
- this.L3.Stroke = this.L1.Stroke;
- this.L4.Stroke = this.L1.Stroke;
- }
- else
- {
- this.dot.Stroke = this._chart.IsDarkBackground ? new SolidColorBrush(Color.FromArgb(150, 255, 255, 255)) :
- new SolidColorBrush(Color.FromArgb(150, 0, 0, 0));
- this.Arrows.Visibility = Visibility.Collapsed;
- }
- }
- private FrameworkElement GetPaintAreaCanvas()
- {
- var parent = this.Parent as FrameworkElement;
- if (parent == null) return null;
- var grandparent = parent.Parent as FrameworkElement;
- if (grandparent == null) return null;
- var paintArea = grandparent.Parent as FrameworkElement;
- return paintArea;
- }
- private void UpdatePosition(MouseEventArgs e)
- {
- var paintArea = GetPaintAreaCanvas();
- if (paintArea == null) return;
- var position = e.GetPosition(paintArea);
- var x = (float)paintArea.ActualWidth;
- x = x < 0 ? 0 : x;
- var y = (paintArea.ActualHeight - 6.0);
- y = y < 0 ? 0 : y;
- position.X = position.X < 0 ? 0 : position.X;
- position.Y = position.Y < 0 ? 0 : position.Y;
- position.X = position.X > x ? x : position.X;
- position.Y = position.Y > y ? y : position.Y;
- this.ShowPointGrab(position.X, position.Y);
- this._drawingTool[this._pointIndex] = position;
- //bool flag = this.GetPaintAreaCanvas() != null && this.GetPaintAreaCanvas() is FrameworkElement;
- //if (flag)
- //{
- // Point position = e.GetPosition((UIElement)this.GetPaintAreaCanvas());
- // FrameworkElement frameworkElement = (FrameworkElement)this.GetPaintAreaCanvas();
- // float num = (float)(frameworkElement.ActualHeight - 6.0);
- // flag = (num < 0f);
- // if (flag)
- // {
- // num = 0f;
- // }
- // float 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.ShowPointGrab(position.X, position.Y);
- // this._drawingTool[this._pointIndex] = position;
- //}
- }
- private void DrawingPointGrab_LostMouseCapture(object sender, MouseEventArgs e)
- {
- if (this._flag)
- {
- this._flag = false;
- this._chart.LockPainting = false;
- this._chart.Refresh();
- this.UpdateStroke();
- }
- }
- private void theBorder_MouseEnter(object sender, MouseEventArgs e)
- {
- bool flag = this._chart.PointerType == PointerType.Drawing;
- if (!flag)
- {
- this._isMouseEnter = true;
- this.UpdateStroke();
- }
- }
- private void theBorder_MouseLeave(object sender, MouseEventArgs e)
- {
- this._isMouseEnter = false;
- this.UpdateStroke();
- }
- private void theBorder_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- if (this._chart.PointerType != PointerType.Drawing)
- {
- if (this._chart.PointerType == PointerType.Erase)
- {
- this._drawingTool.Delete();
- }
- else
- {
- this._chart.LockPainting = true;
- this.CaptureMouse();
- this.UpdatePosition(e);
- this._flag = true;
- this.UpdateStroke();
- }
- }
- }
- private void theBorder_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
- {
- bool flag = this._flag;
- if (flag)
- {
- this.ReleaseMouseCapture();
- this.UpdatePosition(e);
- flag = (this._drawingTool.OwnerSpec != null);
- if (flag)
- {
- this._drawingTool.OwnerSpec.ToolChanged(this._drawingTool);
- }
- this._flag = false;
- this._chart.LockPainting = false;
- this._chart.Refresh();
- this.UpdateStroke();
- }
- }
- private void theBorder_MouseMove(object sender, MouseEventArgs e)
- {
- bool flag = this._chart != null && this._chart.PointerType == PointerType.Erase;
- if (flag)
- {
- this._chart.SetCursorImagePos(true, e);
- }
- flag = this._flag;
- if (flag)
- {
- this.UpdatePosition(e);
- }
- }
- private void ShowPointGrab(double aX, double aY)
- {
- this.SetValue(Canvas.LeftProperty, aX - 7.0);
- this.SetValue(Canvas.TopProperty, aY - 7.0);
- var paintArea = GetPaintAreaCanvas();
- if (paintArea == null) return;
- if (((aX - 10) > paintArea.ActualWidth) || ((aX + 10) < 0) ||
- ((aY - 10) > paintArea.ActualHeight) || ((aY + 10) < 0))
- {
- this.Visibility = Visibility.Collapsed;
- return;
- }
- this.Visibility = Visibility.Visible;
- }
- #endregion Private Methods
- #endregion Methods
- }
- }
|