コード例 #1
0
 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();
     }
 }
コード例 #2
0
        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);
        }
コード例 #3
0
 public override void MouseUp(Point point, CustomStrokeCollection strokes)
 {
     strokes.ToList().FindAll(stroke => stroke is Anchorable).ForEach(stroke => {
         ((Anchorable)stroke).hideAnchorPoints();
     });
     if (this.editing != null)
     {
         this.editing.DoneMoving();
     }
     this.editing = null;
 }
コード例 #4
0
        public static void LoadShape(string strignifiedStroke, CustomStrokeCollection strokes)
        {
            dynamic shape = JObject.Parse(strignifiedStroke);

            if (shape["ShapeType"] != StrokeType.LINE.ToString())
            {
                LoadForm(shape, strokes);
            }
            else
            {
                LoadLine(shape, strokes);
            }
        }
コード例 #5
0
        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);
            }
        }
コード例 #6
0
 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;
 }
コード例 #7
0
        public override void MouseDown(Point point, CustomStrokeCollection strokes)
        {
            IsDrawing          = true;
            MouseLeftDownPoint = point;

            List <Stroke> hoveredAnchors = strokes.ToList().FindAll(stroke => stroke is AnchorPoint && ((CustomStroke)stroke).HitTest(point));

            if (hoveredAnchors.Count > 0)
            {
                AnchorPoint anchor = (AnchorPoint)hoveredAnchors.Last();
                this.FirstAnchorPointId    = anchor.ParentId;
                this.FirstAnchorPointIndex = anchor.AnchorIndex;
                MouseLeftDownPoint         = anchor.Parent.getAnchorPointPosition(this.FirstAnchorPointIndex);
            }
        }
コード例 #8
0
        public override void MouseDown(Point point, CustomStrokeCollection strokes)
        {
            if (editing != null)
            {
                return;
            }

            List <Stroke> clicked         = strokes.ToList().FindAll(stroke => ((CustomStroke)stroke).HitTest(point) && (stroke is Movable || stroke is BaseLine));
            List <Stroke> clickedHandles  = clicked.FindAll(stroke => stroke is DragHandle);
            List <Stroke> clickedSelected = clicked.FindAll(stroke => ((CustomStroke)stroke).isSelected());

            if (clickedHandles.Count > 0)
            {
                this.initialCursorPosition = point;
                this.initialObjectPoints   = clicked.Last().StylusPoints;
                this.editing = (Movable)clickedHandles.Last();

                if (strokes.get(((DragHandle)this.editing).ParentId) is BaseLine)
                {
                    strokes.ToList().FindAll(stroke => stroke is Anchorable).ForEach(stroke => {
                        ((Anchorable)stroke).showAnchorPoints();
                    });
                }

                return;
            }

            if (clickedSelected.Count > 0)
            {
                if (clicked.Last() is BaseLine)
                {
                    if (!((CustomStroke)clicked.Last()).isEditing())
                    {
                        return;
                    }

                    ((BaseLine)clicked.Last()).newPoint(point);
                    this.MouseDown(point, strokes);
                    return;
                }

                this.initialCursorPosition = point;
                this.initialObjectPoints   = clicked.Last().StylusPoints;
                this.editing = (Movable)clickedSelected.Last();
            }
        }
コード例 #9
0
ファイル: FormTool.cs プロジェクト: ChagnonSebastien/LOG3900
        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;
        }
コード例 #10
0
        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));
                }
            }
        }
コード例 #11
0
ファイル: FormTool.cs プロジェクト: ChagnonSebastien/LOG3900
        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);
        }
コード例 #12
0
        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);
        }
コード例 #13
0
        public override void MouseMove(Point point, CustomStrokeCollection strokes, Color selectedColor)
        {
            if (editing == null)
            {
                return;
            }

            Vector displacement             = new Vector(point.X - initialCursorPosition.X, point.Y - initialCursorPosition.Y);
            StylusPointCollection newPoints = new StylusPointCollection();

            this.initialObjectPoints.ToList().ForEach(originalPoint =>
            {
                if (editing is ShapeStroke)
                {
                    newPoints.Add(new StylusPoint(originalPoint.X + displacement.X, originalPoint.Y + displacement.Y));
                }
                else
                {
                    newPoints.Add(new StylusPoint(point.X, point.Y));
                }
            });

            this.editing.Move(newPoints);
        }
コード例 #14
0
 public CustomStroke(StylusPointCollection pts, CustomStrokeCollection strokes) : base(pts)
 {
     this.strokes = strokes;
     Id           = Guid.NewGuid();
     this.Index   = strokes.Count > 0 ? ((CustomStroke)strokes.Last()).Index + 1 : 1;
 }
コード例 #15
0
ファイル: FormTool.cs プロジェクト: ChagnonSebastien/LOG3900
 public override void MouseDown(Point point, CustomStrokeCollection strokes)
 {
     IsDrawing          = true;
     MouseLeftDownPoint = point;
 }
コード例 #16
0
 public override Stroke InstantiateForm(StylusPointCollection pts, CustomStrokeCollection strokes, Color color)
 {
     return(new TextStroke(pts, strokes, true));
 }
コード例 #17
0
 public override void MouseUp(Point point, CustomStrokeCollection strokes)
 {
     // Is a base canvas fonctionnality and is treated by the canvas
 }
コード例 #18
0
 public override void MouseMove(Point point, CustomStrokeCollection strokes, Color selectedColor)
 {
     // Is a base canvas fonctionnality and is treated by the canvas
 }
コード例 #19
0
        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);
        }
コード例 #20
0
 public abstract void Redo(CustomStrokeCollection strokes);
コード例 #21
0
ファイル: Elipse.cs プロジェクト: ChagnonSebastien/LOG3900
 public override Stroke InstantiateForm(StylusPointCollection pts, CustomStrokeCollection strokes, Color color)
 {
     return(new BaseElipseStroke(pts, strokes, color));
 }
コード例 #22
0
 public CustomStroke(string id, int index, StylusPointCollection pts, CustomStrokeCollection strokes) : base(pts)
 {
     this.strokes = strokes;
     Id           = new Guid(id);
     this.Index   = index;
 }
コード例 #23
0
ファイル: FormTool.cs プロジェクト: ChagnonSebastien/LOG3900
 public abstract Stroke InstantiateForm(StylusPointCollection pts, CustomStrokeCollection strokes, Color color);
コード例 #24
0
 public CustomStroke(int index, StylusPointCollection pts, CustomStrokeCollection strokes) : base(pts)
 {
     this.strokes = strokes;
     Id           = Guid.NewGuid();
     this.Index   = index;
 }