private void ControlLineEndThumb_DragDelta(object sender, DragDeltaEventArgs e) { var thumb = sender as Thumb; Canvas canvas = ControlLine.ControlLineCanvas.canvas; Point endPos = ControlLine.End.GetPos(e.HorizontalChange, e.VerticalChange); Point startPos = ControlLine.Start.GetPos(); if (endPos.X < 0) { endPos.X = 0; } else if (endPos.X > canvas.ActualWidth - ControlLine.End.ActualWidth) { endPos.X = canvas.ActualWidth - ControlLine.End.ActualWidth; } if (endPos.Y < 0) { endPos.Y = 0; } else if (endPos.Y > canvas.ActualHeight - ControlLine.End.ActualHeight) { endPos.Y = canvas.ActualHeight - ControlLine.End.ActualHeight; } Vector v = Point.Subtract(endPos, startPos); ControlLine.End.SetPos(endPos); ControlLine.Mid.SetPos(new Point(startPos.X + v.X / 2, startPos.Y + v.Y / 2)); ControlLine.UpdateLine(); thumb.UpdateLayout(); e.Handled = true; }
private void AddLine(ControlLineCanvas canvas1, ControlLineCanvas canvas2) { if (canvas1.IsDrawing) { canvas1.IsDrawing = false; var cl1 = canvas1.ControlLines[canvas1.ControlLines.Count - 1]; var cl2 = new ControlLine(canvas2, cl1); canvas2.ControlLines.Add(cl2); cl1.Mid.PreviewMouseRightButtonDown += DeleteLine; cl2.Mid.PreviewMouseRightButtonDown += DeleteLine; } }
public ControlLineMidThumb(ControlLine controlLine, double x, double y) : base(controlLine, x, y) { ControlTemplate template = controlLine.ControlLineCanvas.FindResource("midTemplate") as ControlTemplate; Template = template; ApplyTemplate(); DragDelta += ControlLineMidThumb_DragDelta; controlLine.ControlLineCanvas.Add(this); Canvas.SetLeft(this, x); Canvas.SetTop(this, y); Panel.SetZIndex(this, 1); UpdateLayout(); }
private void canvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (!CanDraw) { return; } Point mousePos = e.GetPosition(canvas); var controlLine = new ControlLine(this, mousePos.X, mousePos.Y); IsDrawing = true; ControlLines.Add(controlLine); controlLine.End.CaptureMouse(); controlLine.End.RaiseEvent(e); }
public ControlLine(ControlLineCanvas controlLineCanvas, ControlLine controlLine) { ControlLineCanvas = controlLineCanvas; Point startPos = controlLine.Start.GetPos(); Point endPos = controlLine.End.GetPos(); Start = new ControlLineStartThumb(this, startPos.X, startPos.Y); End = new ControlLineEndThumb(this, endPos.X, endPos.Y); Vector v = Point.Subtract(startPos, endPos); Mid = new ControlLineMidThumb(this, endPos.X + v.X / 2, endPos.Y + v.Y / 2); Canvas.SetZIndex(End, 2); Line = new LineGeometry(); Path = new Path(); Path.Stroke = Brushes.LimeGreen; Path.StrokeThickness = 1; Path.Data = Line; ControlLineCanvas.canvas.Children.Add(Path); UpdateLine(); }
private void ControlLineMidThumb_DragDelta(object sender, DragDeltaEventArgs e) { var thumb = sender as Thumb; Canvas canvas = ControlLine.ControlLineCanvas.canvas; Point startPos = ControlLine.Start.GetPos(e.HorizontalChange, e.VerticalChange); Point midPos = ControlLine.Mid.GetPos(e.HorizontalChange, e.VerticalChange); Point endPos = ControlLine.End.GetPos(e.HorizontalChange, e.VerticalChange); double canvasWidth = canvas.ActualWidth; double canvasHeight = canvas.ActualHeight; double startWidth = ControlLine.Start.ActualWidth; double startHeight = ControlLine.Start.ActualHeight; double endWidth = ControlLine.End.ActualWidth; double endHeight = ControlLine.End.ActualHeight; if (startPos.X < 0) { double diff = 0 - startPos.X; startPos.X += diff; midPos.X += diff; endPos.X += diff; } else if (startPos.X > canvasWidth - startWidth) { double diff = startPos.X - canvasWidth + startWidth; startPos.X -= diff; midPos.X -= diff; endPos.X -= diff; } if (startPos.Y < 0) { double diff = 0 - startPos.Y; startPos.Y += diff; midPos.Y += diff; endPos.Y += diff; } else if (startPos.Y > canvasHeight - startHeight) { double diff = startPos.Y - canvasHeight + startHeight; startPos.Y -= diff; midPos.Y -= diff; endPos.Y -= diff; } if (endPos.X < 0) { double diff = 0 - endPos.X; startPos.X += diff; midPos.X += diff; endPos.X += diff; } else if (endPos.X > canvasWidth - endWidth) { double diff = endPos.X - canvasWidth + endWidth; startPos.X -= diff; midPos.X -= diff; endPos.X -= diff; } if (endPos.Y < 0) { double diff = 0 - endPos.Y; startPos.Y += diff; midPos.Y += diff; endPos.Y += diff; } else if (endPos.Y > canvasHeight - endHeight) { double diff = endPos.Y - canvasHeight + endHeight; startPos.Y -= diff; midPos.Y -= diff; endPos.Y -= diff; } ControlLine.Start.SetPos(startPos); ControlLine.Mid.SetPos(midPos); ControlLine.End.SetPos(endPos); ControlLine.UpdateLine(); thumb.UpdateLayout(); e.Handled = true; }
public ControlLineThumb(ControlLine controlLine, double x, double y) { MouseEnter += ControlLineThumb_MouseEnter; MouseLeave += ControlLineThumb_MouseLeave; ControlLine = controlLine; }