public override void HandleMouseDown(MouseButtonEventArgs e) { base.HandleMouseDown(e); if (e.ChangedButton != MouseButton.Left) { return; } Canvas.StateInfo.Tip = "Drawing... double click to end"; var point = e.GetPosition(Canvas); point = AlignPointToXY(point); if (prePoint == default || (prePoint != default && point != prePoint)) { points.Add(point); } prePoint = point; if (e.ClickCount == 2) { prePoint = default; points.Clear(); // The user might double click in the same place. if (element != null) { CreationComplete(element); element = null; } Canvas.StateInfo.Tip = StateTip; } }
protected override void CreationComplete(DrawingComponent ele) { if (ele is DrawingLineString) { Canvas.RemoveVisual(ele); } else { var container = Canvas.GetVisuals().OfType <DrawingPolygon>() .FirstOrDefault(v => v.Geometry.FillContains(ele.Geometry)); if (container != null) { var holes = new List <IEnumerable <Point> > { (ele as DrawingPolygon).Shell }; if (container.HasHoles) { holes.AddRange(container.Holes); } container.Update(container.Shell, holes); container.Render(DrawingCanvas.DefaultPen); Canvas.RemoveVisual(ele); } Canvas._version++; } }
public override void HandleKeyDown(KeyEventArgs e) { base.HandleKeyDown(e); if (e.Key == Key.Delete && selectedVisual != null) { if (!(selectedVisual is DrawingPoint)) { Canvas._version++; } Canvas.RemoveVisual(selectedVisual); selectedVisual = null; } }
public static Geometry ToNTSGeometry(this DrawingComponent component) { if (component is DrawingPolygon drawingPolygon) { return(drawingPolygon.ToNTSGeometry()); } if (component is DrawingLineString drawingLineString) { return(drawingLineString.ToNTSGeometry()); } if (component is DrawingPoint drawingPoint) { return(drawingPoint.ToNTSGeometry()); } return(null); }
public override void HandleMouseDown(MouseButtonEventArgs e) { base.HandleMouseDown(e); if (e.ChangedButton != MouseButton.Left) { return; } isDragging = true; var position = e.GetPosition(Canvas); var visual = Canvas.GetVisual(position); if (visual != null && visual.IsReadOnly) { return; } selectedVisual = visual; if (selectedVisual != null) { selectedVisual.Render(DrawingCanvas.HighLightPen); Canvas.CaptureMouse(); } }
protected override void CreationComplete(DrawingComponent com) { Canvas._version++; }
protected virtual void CreationComplete(DrawingComponent com) { }
public void RemoveVisual(DrawingComponent visual) { visuals.Remove(visual); RemoveVisualChild(visual); RemoveLogicalChild(visual); }
public void AddVisual(DrawingComponent visual) { visuals.Add(visual); AddVisualChild(visual); AddLogicalChild(visual); }