public override void MouseMove(Point point, CustomStrokeCollection strokes, Color selectedColor) { if (!IsDrawing) { return; } string secondId = null; int secondIndex = -1; List <Stroke> hoveredAnchors = strokes.ToList().FindAll(stroke => stroke is AnchorPoint && ((CustomStroke)stroke).HitTest(point)); if (hoveredAnchors.Count > 0) { AnchorPoint anchor = (AnchorPoint)hoveredAnchors.Last(); point = anchor.Parent.getAnchorPointPosition(anchor.AnchorIndex); secondId = anchor.ParentId; secondIndex = anchor.AnchorIndex; } StylusPointCollection pts = new StylusPointCollection { new StylusPoint(MouseLeftDownPoint.X, MouseLeftDownPoint.Y), new StylusPoint(point.X, point.Y) }; if (ActiveStroke != null) { strokes.Remove(ActiveStroke); } if (this.FirstAnchorPointId == null) { if (secondId == null) { ActiveStroke = new BaseLine(pts, strokes); } else { ActiveStroke = new BaseLine(pts, strokes, null, -1, secondId, secondIndex); } } else { if (secondId == null) { ActiveStroke = new BaseLine(pts, strokes, this.FirstAnchorPointId, this.FirstAnchorPointIndex, null, -1); } else { ActiveStroke = new BaseLine(pts, strokes, this.FirstAnchorPointId, this.FirstAnchorPointIndex, secondId, secondIndex); } } ActiveStroke.DrawingAttributes.Color = selectedColor; strokes.Add(ActiveStroke); }
public override void Undo(CustomStrokeCollection strokes) { if (strokes.has(Id)) { CustomStroke old = strokes.get(Id); if (old.isLocked()) { throw new Exception("Stroke is Locked"); } strokes.Remove(strokes.get(Id)); EditionSocket.RemoveStroke(Id); } }
public override void MouseUp(Point point, CustomStrokeCollection strokes) { if (ActiveStroke != null) { strokes.Remove(ActiveStroke); var clone = ActiveStroke.Clone(); strokes.Add(clone); ((CustomStroke)clone).Select(); EditionSocket.AddStroke(((Savable)clone).toJson()); Editeur.instance.Do(new NewStroke(((CustomStroke)clone).Id.ToString(), ((Savable)clone).toJson())); } IsDrawing = false; this.FirstAnchorPointId = null; }
public override void MouseUp(Point point, CustomStrokeCollection strokes) { if (ActiveStroke != null) { strokes.Remove(ActiveStroke); var clone = ActiveStroke.Clone(); if (clone is TextStroke) { ((TextStroke)clone).showBorder = false; } strokes.Add(clone); ((CustomStroke)clone).Select(); EditionSocket.AddStroke(((Savable)clone).toJson()); Editeur.instance.Do(new NewStroke(((CustomStroke)clone).Id.ToString(), ((Savable)clone).toJson())); } IsDrawing = false; }
public override void Undo(CustomStrokeCollection strokes) { if (strokes.has(Id)) { CustomStroke old = strokes.get(Id); if (old.isLocked()) { throw new Exception("Stroke is Locked"); } EditionSocket.EditStroke(SerializedStrokeBefore); CustomStroke updated = SerializationHelper.stringToStroke(JObject.Parse(SerializedStrokeBefore), strokes); bool selected = ((CustomStroke)old).isSelected(); bool editting = ((CustomStroke)old).isEditing(); ((CustomStroke)old).stopEditing(); strokes.Remove(strokes.get(Id)); int newindex = strokes.ToList().FindIndex(stroke => ((CustomStroke)stroke).Index > updated.Index); try { strokes.Insert(newindex, updated); } catch { strokes.Add(updated); } if (selected) { strokes.get(updated.Id.ToString()).Select(); } if (editting) { strokes.get(updated.Id.ToString()).startEditing(); } if (updated is Anchorable) { strokes.ToList().FindAll(stroke => stroke is BaseLine).ForEach(stroke => ((BaseLine)stroke).anchorableMoved((Anchorable)updated)); } } }
public virtual void Refresh() { int index = -1; if (strokes.has(this.Id.ToString())) { if (this is Handleable) { ((Handleable)strokes.get(this.Id.ToString())).deleteDragHandles(); } index = strokes.IndexOf(strokes.get(this.Id.ToString())); if (strokes.has(this.Id.ToString())) { strokes.Remove(strokes.get(this.Id.ToString())); } } strokes.Insert(index, this.Clone()); }
public override void MouseMove(Point point, CustomStrokeCollection strokes, Color selectedColor) { if (!IsDrawing) { return; } StylusPointCollection pts = new StylusPointCollection(); pts.Add(new StylusPoint(MouseLeftDownPoint.X, MouseLeftDownPoint.Y)); pts.Add(new StylusPoint(point.X, point.Y)); if (ActiveStroke != null) { strokes.Remove(ActiveStroke); } ActiveStroke = InstantiateForm(pts, strokes, selectedColor); strokes.Add(ActiveStroke); }