Ejemplo n.º 1
0
        /// <summary>
        /// StartLasso
        /// </summary>
        /// <param name="points"></param>
        private void StartLasso(List <Point> points)
        {
            Debug.Assert(!_disableLasso && _lassoHelper == null, "StartLasso is called unexpectedly.");

            if (InkCanvas.ClearSelectionRaiseSelectionChanging()  // If user cancels clearing the selection, we shouldn't initiate Lasso.
                // NTRAID:WINDOWS#1534264-2006/02/28-WAYNEZEN
                // If the active editng mode is no longer as Select, we shouldn't activate LassoSelectionBehavior.
                // Note the order really matters here. This checking has to be done
                // after ClearSelectionRaiseSelectionChanging is invoked.
                && EditingCoordinator.ActiveEditingMode == InkCanvasEditingMode.Select)
            {
                //
                // obtain a dynamic hit-tester for selecting with lasso
                //
                _incrementalLassoHitTester =
                    this.InkCanvas.Strokes.GetIncrementalLassoHitTester(_percentIntersectForInk);
                //
                // add event handler
                //
                _incrementalLassoHitTester.SelectionChanged += new LassoSelectionChangedEventHandler(OnSelectionChanged);

                //
                // start dynamic rendering
                //

                _lassoHelper = new LassoHelper();
                InkCanvas.BeginDynamicSelection(_lassoHelper.Visual);

                Point[] lassoPoints = _lassoHelper.AddPoints(points);
                if (0 != lassoPoints.Length)
                {
                    _incrementalLassoHitTester.AddPoints(lassoPoints);
                }
            }
            else
            {
                // If we fail on clearing the selection or switching to Select mode, we should just disable lasso.
                _disableLasso = true;
            }
        }