Files
MetroGauges-Old/MetroGauges/Controls/DrawTools/PolylineTool.cs
2026-02-23 17:02:55 +08:00

117 lines
3.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shapes;
namespace MetroGauges.Controls.DrawTools
{
public class PolylineTool : DrawToolBase
{
Polyline currentline = new Polyline();
PointCollection ps= new PointCollection();
public PolylineTool(DesignControl canvas) : base(canvas)
{
IsStartDraw = true;
}
public override void MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (IsStartDraw)
{
Point mousePosition = Mouse.GetPosition(this.DrawDesign.canvasDesign);
if (ps.Count == 0)
{
ps.Add(mousePosition);
ps.Add(mousePosition);
currentline.Points = ps;
currentline.Stroke = new SolidColorBrush(Colors.White);
currentline.StrokeThickness = 1;
//
currentline.DataContext = new ShapDataContext() { IsClosed =false };
this.AddShap(currentline);
//currentline.Cursor = Cursors.Hand;
//this.CanvasDesign.Children.Add(currentline);
//this.DrawShaps.Add(currentline);
}
else
{
ps.Add(mousePosition);
}
}
}
public override void Highlight(FrameworkElement shape)
{
this.DrawDesign.CrrentDrawTool = this;
Polyline line = shape as Polyline;
(shape.DataContext as ShapDataContext).OringLocation = line.Points;
base.Highlight(shape);
}
public override void MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
if (IsStartDraw)
{
}
}
public override void MouseMove(object sender, MouseEventArgs e)
{
if (IsStartDraw)
{
if (ps.Count > 0)
{
Point mousePosition = Mouse.GetPosition(this.DrawDesign.canvasDesign);
Point lastPoint = ps[ps.Count - 1];
lastPoint.X = mousePosition.X;
lastPoint.Y = mousePosition.Y;
ps[ps.Count - 1] = lastPoint;
currentline.Points = ps;
}
}
}
public override void MouseRightButtonUp(object sender, MouseButtonEventArgs e)
{
if (Keyboard.IsKeyDown(Key.LeftCtrl))
{
}
if (IsStartDraw)
{
IsStartDraw = false;
ps.Remove(ps[ps.Count - 1]);
}
}
public override void m_Root_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
}
}
}