예제 #1
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();
            }
        }
예제 #2
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));
                }
            }
        }
예제 #3
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);
        }
예제 #4
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;
 }
예제 #5
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);
            }
        }