84 lines
2.5 KiB
C#
84 lines
2.5 KiB
C#
using MetroGauges.Controls.DrawTools;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Shapes;
|
|
|
|
namespace MetroGauges.Controls
|
|
{
|
|
public class CircleTool : DrawToolBase
|
|
{
|
|
bool isMouseDown = false;
|
|
|
|
Path path = new Path() { Stroke = new SolidColorBrush(Colors.White), StrokeThickness = 1, Cursor = Cursors.Hand };
|
|
EllipseGeometry ellipseGeometry = new EllipseGeometry();
|
|
|
|
public CircleTool(DesignControl canvas) : base(canvas)
|
|
{
|
|
IsStartDraw = true;
|
|
}
|
|
|
|
public override void MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
|
{
|
|
isMouseDown = true;
|
|
if (IsStartDraw)
|
|
{
|
|
this.DrawDesign.DisabledMove = true;
|
|
|
|
Point mousePosition = Mouse.GetPosition(this.DrawDesign.canvasDesign);
|
|
path.Data = ellipseGeometry;
|
|
ellipseGeometry.Center = mousePosition;
|
|
path.DataContext = mousePosition;
|
|
|
|
this.AddShap(path);
|
|
}
|
|
}
|
|
|
|
public override void MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
|
|
{
|
|
isMouseDown = false;
|
|
IsStartDraw = false;
|
|
this.DrawDesign.DisabledMove = false;
|
|
|
|
if (ellipseGeometry.RadiusX == 0)
|
|
{
|
|
this.DrawDesign.canvasDesign.Children.Remove(path);
|
|
}
|
|
|
|
}
|
|
|
|
public override void MouseMove(object sender, MouseEventArgs e)
|
|
{
|
|
if (IsStartDraw && isMouseDown)
|
|
{
|
|
Point mousePosition = Mouse.GetPosition(this.DrawDesign.canvasDesign);
|
|
Point sourePoint = (Point)path.DataContext;
|
|
ellipseGeometry.RadiusX = Math.Abs(mousePosition.X - sourePoint.X);
|
|
ellipseGeometry.RadiusY = Math.Abs(mousePosition.X - sourePoint.X);
|
|
//ellipseGeometry.RadiusY = Math.Abs(mousePosition.Y - sourePoint.Y); //椭圆
|
|
}
|
|
}
|
|
|
|
public override void MouseRightButtonUp(object sender, MouseButtonEventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
public override void m_Root_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
public override void Highlight(FrameworkElement shape)
|
|
{
|
|
this.DrawDesign.CrrentDrawTool = this;
|
|
base.Highlight(shape);
|
|
}
|
|
}
|
|
}
|