Example #1
0
        /// <summary>
        /// Get the cached bounding boxes to be updated.
        /// </summary>
        private Rect GetStrokesBounds()
        {
            // Update the strokes bounds if they are changed.
            if (_areStrokesChanged)
            {
                _cachedStrokesBounds = SelectedStrokes.Count != 0 ?
                                       SelectedStrokes.GetBounds( ) : Rect.Empty;
                _areStrokesChanged = false;
            }

            return(_cachedStrokesBounds);
        }
Example #2
0
        /// <summary>
        /// Our own internal listener for strokes changed.
        /// This is used so that if someone deletes or modifies a stroke
        /// we are currently displaying for selection, we can update our size
        /// </summary>
        private void OnStrokeCollectionChanged(object target, StrokeCollectionChangedEventArgs e)
        {
            // If the strokes only get added to the InkCanvas, we don't have to update our internal selected strokes.
            if (e.Added.Count != 0 && e.Removed.Count == 0)
            {
                return;
            }

            foreach (Stroke s in e.Removed)
            {
                if (SelectedStrokes.Contains(s))
                {
                    s.Invalidated -= new EventHandler(this.OnStrokeInvalidated);
                    s.IsSelected   = false;

                    // Now remove the stroke from our private collection.
                    SelectedStrokes.Remove(s);
                }
            }

            // Mark the strokes change
            _areStrokesChanged = true;
            UpdateSelectionAdorner();
        }
Example #3
0
        public void HandlePreviewMouseDown(Point mousePos)
        {
            this.isDragging = true;
            Rect selectionZone = this.Canvas.GetSelectionBounds();

            if (selectionZone.Size != Size.Empty)
            {
                selectionZone.Inflate(new Size(15, 15)); //To cover the resizing bounds
            }
            //if (this.OutilSelectionne == "lasso" && this.StrokeBeingDragged == null)
            if (this.OutilSelectionne == "lasso" && this.StrokeBeingRotated == null && this.StrokeBeingDragged == null)
            {
                foreach (Stroke s in SelectedStrokes.Where(x => (x as Form).Type != "Arrow"))
                {
                    Point pts = (s as Form).RotatePoint;
                    if (Math.Abs(Point.Subtract(pts, mousePos).Length) < 10 && this.StrokeBeingRotated == null)
                    {
                        this.Canvas.MoveEnabled = false;
                        this.StrokeBeingRotated = s;
                        this.isDragging         = false;
                        //this.Canvas.EditingMode = InkCanvasEditingMode.None;
                    }
                }
            }
            if (this.OutilSelectionne == "lasso" && this.StrokeBeingDragged == null && this.StrokeBeingRotated == null)
            {
                foreach (Stroke s in SelectedStrokes.Where(x => (x as Form).Type == "Arrow"))
                {
                    for (int i = 0; i < s.StylusPoints.Count; i++)
                    {
                        Point pts = s.StylusPoints[i].ToPoint();
                        if (Math.Abs(Point.Subtract(pts, mousePos).Length) < 10 && this.IndexBeingDragged == -1)
                        {
                            this.StrokeBeingDragged = s;
                            this.IndexBeingDragged  = i;
                            this.isDragging         = false;
                            editeur.ShowEncrage     = true;
                            //this.Canvas.EditingMode = InkCanvasEditingMode.None;
                        }
                    }
                }
            }
            if (this.OutilSelectionne == "lasso" && !selectionZone.Contains(mousePos) && this.StrokeBeingDragged == null && this.StrokeBeingRotated == null)
            {
                StrokeCollection selection = new StrokeCollection();
                for (int i = Traits.Count - 1; i >= 0; i--)
                {
                    if (Traits[i].GetBounds().Contains(mousePos) && selection.Count == 0) //&& (Traits[i] as Form).Type != "Arrow")
                    {
                        if ((Traits[i] as Form).Type == "Arrow")
                        {
                            if (Traits[i].HitTest(mousePos))
                            {
                                selection.Add(Traits[i]);
                            }
                        }
                        else
                        {
                            selection.Add(Traits[i]);
                        }
                    }
                }
                editeur.HandleChangeSelection(selection);
            }
            else
            {
                this.isDragging = false;
                editeur.HandleMouseDown(mousePos);
            }
        }