예제 #1
0
        private void InkToolbar_Loading(FrameworkElement sender, object args)
        {
            // Clear all built-in buttons from the InkToolbar.
            inkToolbar.InitialControls = InkToolbarInitialControls.None;

            InkToolbarEraserButton       eraser    = new InkToolbarEraserButton();
            InkToolbarBallpointPenButton ballpoint = new InkToolbarBallpointPenButton();
            InkToolbarPencilButton       pencil    = new InkToolbarPencilButton();
            InkToolbarStencilButton      ruler     = new InkToolbarStencilButton();

            inkToolbar.Children.Add(eraser);
            inkToolbar.Children.Add(ballpoint);
            inkToolbar.Children.Add(pencil);
            inkToolbar.Children.Add(ruler);
        }
예제 #2
0
        // </SnippetInkToolbarLoadedCB>

        // <SnippetInkToolbarLoadingCB>
        /// <summary>
        /// Handles the Loading event of the InkToolbar.
        /// Here, we identify the buttons to include on the InkToolbar.
        /// </summary>
        /// <param name="sender">The InkToolbar</param>
        /// <param name="args">The InkToolbar event data.
        /// If there is no event data, this parameter is null</param>
        private void inkToolbar_Loading(FrameworkElement sender, object args)
        {
            // Clear all built-in buttons from the InkToolbar.
            inkToolbar.InitialControls = InkToolbarInitialControls.None;

            // Add only the ballpoint pen, pencil, and eraser.
            // Note that the buttons are added to the toolbar in the order
            // defined by the framework, not the order we specify here.
            InkToolbarBallpointPenButton ballpoint = new InkToolbarBallpointPenButton();
            InkToolbarPencilButton       pencil    = new InkToolbarPencilButton();
            InkToolbarEraserButton       eraser    = new InkToolbarEraserButton();

            inkToolbar.Children.Add(eraser);
            inkToolbar.Children.Add(ballpoint);
            inkToolbar.Children.Add(pencil);
        }
        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            var display = DisplayInformation.GetForCurrentView();

            display.DpiChanged += Display_DpiChanged;

            Display_DpiChanged(display, null);

            var maxSize = Math.Max(CanvasContainer.Width, CanvasContainer.Height);

            ScrollViewer.MaxZoomFactor = MaxImageSize / System.Convert.ToSingle(maxSize);


            #region multi stylus support
            // Set supported inking device types.
            InkCanvas.InkPresenter.InputDeviceTypes = Windows.UI.Core.CoreInputDeviceTypes.Pen | Windows.UI.Core.CoreInputDeviceTypes.Mouse;

            // Phase 1: we need to discover the three user clicks with pen on the toolbar, we store only the unique stylus id (into Dictionary<int, InkDrawingAttributes> _stylusAttributes) and no InkDrawingAttributes because at this time user has still
            // not choosen the tool and color. So in that phase we do have an entry on the _stylusAttributes with a key but with a null value

            // get reference to inktoolbar buttons
            InkToolbarBallpointPenButton penButton         = InkToolbar.GetToolButton(InkToolbarTool.BallpointPen) as InkToolbarBallpointPenButton;
            InkToolbarHighlighterButton  highlighterButton = InkToolbar.GetToolButton(InkToolbarTool.Highlighter) as InkToolbarHighlighterButton;
            InkToolbarPencilButton       pencilButton      = InkToolbar.GetToolButton(InkToolbarTool.Pencil) as InkToolbarPencilButton;

            // subscribing to inktoolbar button events
            // TODO: unsubscribe to all those events
            if (penButton != null)
            {
                penButton.PointerEntered += this.OnConfigButtonPointerEntered;
                penButton.Click          += this.OnPenButtonClicked;
            }

            // TODO: unsubscribe to all those events
            if (highlighterButton != null)
            {
                highlighterButton.PointerEntered += this.OnConfigButtonPointerEntered;
                highlighterButton.Click          += this.OnPenButtonClicked;
            }

            // TODO: unsubscribe to all those events
            if (pencilButton != null)
            {
                pencilButton.PointerEntered += this.OnConfigButtonPointerEntered;
                pencilButton.Click          += this.OnPenButtonClicked;
            }

            this.InkToolbar.ActiveToolChanged           += this.OnActiveToolbarToolChanged;
            this.InkToolbar.InkDrawingAttributesChanged += this.OnToolbarAttributesChanged;

            // Phase 1 (ConfigControl_PointerExited): Every time user select (or not) a new property we sotre it for its own unique stylus id
            // Phase 2 (unprocessedInput.PointerHovered): when the user starts inking just a moment before the ink starts we get the unique stylus id from the PointerHovered
            // we look into _stylusAttributes for the InkDrawingAttributes of that stylus and we apply to the InkCanvas.InkPresenter.UpdateDefaultDrawingAttributes
            #endregion


            // 1. Activate custom drawing
            this.inkSynchronizer = InkCanvas.InkPresenter.ActivateCustomDrying();

            InkCanvas.InkPresenter.SetPredefinedConfiguration(InkPresenterPredefinedConfiguration.SimpleMultiplePointer);


            // 2. add use custom drawing when strokes are collected
            InkCanvas.InkPresenter.StrokesCollected += InkPresenter_StrokesCollected;


            // 3. Get the eraser button to handle custom dry ink and replace the erase all button with new logic
            var eraser = InkToolbar.GetToolButton(InkToolbarTool.Eraser) as InkToolbarEraserButton;

            if (eraser != null)
            {
                eraser.Checked   += Eraser_Checked;
                eraser.Unchecked += Eraser_Unchecked;
            }

            InkCanvas.InkPresenter.InputProcessingConfiguration.RightDragAction = InkInputRightDragAction.LeaveUnprocessed;

            var unprocessedInput = InkCanvas.InkPresenter.UnprocessedInput;
            unprocessedInput.PointerPressed  += UnprocessedInput_PointerPressed;
            unprocessedInput.PointerMoved    += UnprocessedInput_PointerMoved;
            unprocessedInput.PointerReleased += UnprocessedInput_PointerReleased;
            unprocessedInput.PointerExited   += UnprocessedInput_PointerExited;
            unprocessedInput.PointerLost     += UnprocessedInput_PointerLost;
            unprocessedInput.PointerHovered  += UnprocessedInput_PointerHovered;

            this.eraseAllFlyout = FlyoutBase.GetAttachedFlyout(eraser) as Flyout;

            if (this.eraseAllFlyout != null)
            {
                var button = this.eraseAllFlyout.Content as Button;

                if (button != null)
                {
                    var newButton = new Button();
                    newButton.Style   = button.Style;
                    newButton.Content = button.Content;

                    newButton.Click            += EraseAllInk;
                    this.eraseAllFlyout.Content = newButton;
                }
            }

            this.InkCanvas.Holding += this.OnHolding;
        }