//-------------------------------------------------------------------------------
        //
        // Protected Methods
        //
        //-------------------------------------------------------------------------------

        #region Protected Methods

        /// <summary>
        ///     Attaching to the element, we get attached in StylusDown
        /// </summary>
        protected override void OnActivate()
        {
            _actionStarted = false;

            // Capture the mouse.
            InitializeCapture();

            // Hittest for the grab handle
            MouseDevice mouse = Mouse.PrimaryDevice;

            _hitResult = InkCanvas.SelectionAdorner.SelectionHandleHitTest(
                mouse.GetPosition((IInputElement)(InkCanvas.SelectionAdorner)));

            Debug.Assert(_hitResult != InkCanvasSelectionHitResult.None);
            EditingCoordinator.InvalidateBehaviorCursor(this);

            // Get the current selection bounds.
            _selectionRect = InkCanvas.GetSelectionBounds( );

            // Set the initial tracking position and rectangle
            _previousLocation = mouse.GetPosition(InkCanvas.SelectionAdorner);
            _previousRect     = _selectionRect;

            // Start the feedback rubber band.
            InkCanvas.InkCanvasSelection.StartFeedbackAdorner(_selectionRect, _hitResult);

            // Add handlers to the mouse events.
            InkCanvas.SelectionAdorner.AddHandler(Mouse.MouseUpEvent, new MouseButtonEventHandler(OnMouseUp));
            InkCanvas.SelectionAdorner.AddHandler(Mouse.MouseMoveEvent, new MouseEventHandler(OnMouseMove));
            InkCanvas.SelectionAdorner.AddHandler(UIElement.LostMouseCaptureEvent,
                                                  new MouseEventHandler(OnLostMouseCapture));
        }
Ejemplo n.º 2
0
        public void CopyInkCanvasObjects(InkCanvas inkCanvas, InkCanvas clipboardCanvas)
        {
            var selectionBounds = inkCanvas.GetSelectionBounds();

            if (selectionBounds.IsEmpty)
            {
                return;
            }
            Clear(clipboardCanvas);

            var selectedElements = inkCanvas.GetSelectedElements().ToList();
            var selectedStrokes  = new StrokeCollection(inkCanvas.GetSelectedStrokes());

            ClearSelection(inkCanvas);

            var elements = new List <UIElement>();

            WPFHelper.CloneElementsTo(elements, selectedElements.GetEnumerator(), clipboardCanvas);
            WPFHelper.CloneStrokesTo(clipboardCanvas.Strokes, selectedStrokes);
            elements.ForEach(element => clipboardCanvas.Children.Add(element));
            inkCanvas.Select(selectedStrokes, selectedElements);

            var dataObject = new DataObject();

            dataObject.SetData(ClipboardIdFormat, _clipboardStateId = Guid.NewGuid());
            dataObject.SetData(DataFormats.Bitmap, ImageHelper.GetCroppedImageFromInkCanvas(selectionBounds, inkCanvas));
            Clipboard.SetDataObject(dataObject);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Unmagnifies the sketch by a preset amount and notifies listerners.
        /// </summary>
        public void ZoomOut(int pixels)
        {
            StrokeCollection oldSelection = InkCanvas.GetSelectedStrokes();

            SelectAllStrokes();
            System.Windows.Rect oldBounds     = InkCanvas.GetSelectionBounds();
            System.Windows.Rect smallerBounds = new System.Windows.Rect(oldBounds.TopLeft,
                                                                        new System.Windows.Size(oldBounds.Width * SketchPanelConstants.ZoomOutFactor, oldBounds.Height * SketchPanelConstants.ZoomOutFactor));

            CommandList.MoveResizeCmd resize = new CommandList.MoveResizeCmd(ref inkSketch, oldBounds, smallerBounds);
            CM.ExecuteCommand(resize);

            InkCanvas.Select(oldSelection);
            InkChanged(false);
        }