public override void Redo(CustomStrokeCollection strokes) { if (!strokes.has(Id)) { strokes.Add(SerializationHelper.stringToStroke(JObject.Parse(SerializedStroke), strokes)); EditionSocket.AddStroke(SerializedStroke); strokes.get(Id).Select(); } }
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 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 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); }
private static void LoadLine(dynamic shape, CustomStrokeCollection strokes) { StylusPointCollection points = new StylusPointCollection(); for (int j = 0; j < shape["ShapeInfo"]["Points"].Count; j++) { points.Add(new StylusPoint((double)shape["ShapeInfo"]["Points"][j]["X"], (double)shape["ShapeInfo"]["Points"][j]["Y"])); } BaseLine loadedLine = new BaseLine(points, strokes) { Id = shape["Id"], FirstAnchorId = shape["ShapeInfo"]["FirstAnchorId"], FirstAnchorIndex = shape["ShapeInfo"]["FirstAnchorIndex"], SecondAncorId = shape["ShapeInfo"]["SecondAnchorId"], SecondAncorIndex = shape["ShapeInfo"]["SecondAnchorIndex"], FirstText = shape["ShapeInfo"]["FirstEndLabel"], FirstRelation = shape["ShapeInfo"]["FirstEndRelation"], SecondText = shape["ShapeInfo"]["SecondEndLabel"], SecondRelation = shape["ShapeInfo"]["SecondEndRelation"] }; strokes.Add(loadedLine); }
private static void LoadForm(dynamic shape, CustomStrokeCollection strokes) { StylusPoint topLeft = new StylusPoint((double)(shape["ShapeInfo"]["Center"]["X"] - shape["ShapeInfo"]["Width"] / 2), (double)(shape["ShapeInfo"]["Center"]["Y"] - shape["ShapeInfo"]["Height"] / 2)); StylusPoint bottomRight = new StylusPoint((double)(shape["ShapeInfo"]["Center"]["X"] + shape["ShapeInfo"]["Width"] / 2), (double)(shape["ShapeInfo"]["Center"]["Y"] + shape["ShapeInfo"]["Height"] / 2)); ShapeStroke loadedShape; if (shape["ShapeType"] == StrokeType.RECTANGLE.ToString()) { loadedShape = new BaseRectangleStroke(new StylusPointCollection() { topLeft, bottomRight }, strokes); } else if (shape["ShapeType"] == StrokeType.ELLIPSE.ToString()) { loadedShape = new BaseElipseStroke(new StylusPointCollection() { topLeft, bottomRight }, strokes); } else if (shape["ShapeType"] == StrokeType.TRIANGLE.ToString()) { loadedShape = new BaseTrangleStroke(new StylusPointCollection() { topLeft, bottomRight }, strokes); } else if (shape["ShapeType"] == StrokeType.ACTOR.ToString()) { loadedShape = new PersonStroke(new StylusPointCollection() { topLeft, bottomRight }, strokes); ((PersonStroke)loadedShape).Name = ""; for (int j = 0; j < shape["ShapeInfo"]["Content"].Count; j++) { ((PersonStroke)loadedShape).Name += shape["ShapeInfo"]["Content"][j] + " "; } } else if (shape["ShapeType"] == StrokeType.CLASS.ToString()) { loadedShape = new ClassStroke(new StylusPointCollection() { topLeft, bottomRight }, strokes); ((ClassStroke)loadedShape).textContent = new List <string>(); for (int j = 0; j < shape["ShapeInfo"]["Content"].Count; j++) { ((ClassStroke)loadedShape).textContent.Add((string)shape["ShapeInfo"]["Content"][j]); } } else { loadedShape = new UseCaseStroke(new StylusPointCollection() { topLeft, bottomRight }, strokes); ((UseCaseStroke)loadedShape).textContent = new List <string>(); for (int j = 0; j < shape["ShapeInfo"]["Content"].Count; j++) { ((UseCaseStroke)loadedShape).textContent.Add((string)shape["ShapeInfo"]["Content"][j]); } } loadedShape.Id = shape["Id"]; loadedShape.DrawingAttributes.Color = (Color)ColorConverter.ConvertFromString((string)shape["ShapeInfo"]["Color"]); strokes.Add(loadedShape); }