Пример #1
0
        public InkExample()
        {
            this.InitializeComponent();

            inkCanvas.InkPresenter.InputDeviceTypes = Windows.UI.Core.CoreInputDeviceTypes.Mouse | Windows.UI.Core.CoreInputDeviceTypes.Pen | Windows.UI.Core.CoreInputDeviceTypes.Touch;

            // By default, pen barrel button or right mouse button is processed for inking
            // Set the configuration to instead allow processing these input on the UI thread
            inkCanvas.InkPresenter.InputProcessingConfiguration.RightDragAction = InkInputRightDragAction.LeaveUnprocessed;

            inkCanvas.InkPresenter.UnprocessedInput.PointerPressed += UnprocessedInput_PointerPressed;
            inkCanvas.InkPresenter.UnprocessedInput.PointerMoved += UnprocessedInput_PointerMoved;
            inkCanvas.InkPresenter.UnprocessedInput.PointerReleased += UnprocessedInput_PointerReleased;

            inkCanvas.InkPresenter.StrokeInput.StrokeStarted += StrokeInput_StrokeStarted;

            inkCanvas.InkPresenter.StrokesCollected += InkPresenter_StrokesCollected;
            inkCanvas.InkPresenter.StrokesErased += InkPresenter_StrokesErased;

            inkSynchronizer = inkCanvas.InkPresenter.ActivateCustomDrying();

            textFormat = new CanvasTextFormat();

            // Set defaults
            SelectedDryInkRenderingType = DryInkRenderingType.BuiltIn;
            SelectColor(color0);
            showTextLabels = true;

            needToCreateSizeDependentResources = true;
        }
Пример #2
0
        protected override void OnApplyTemplate()
        {
            _canvasOne = (InfiniteCanvasOne)GetTemplateChild("canvasOne");

            _inkCanvas = (InkCanvas)GetTemplateChild("inkCanvas");
            var enableButton = (Button)GetTemplateChild("EnableDisableButton");

            enableButton.Click += EnableButton_Click;

            _inkSynchronizer = _inkCanvas.InkPresenter.ActivateCustomDrying();

            _inkCanvas.InkPresenter.InputDeviceTypes =
                CoreInputDeviceTypes.Mouse |
                CoreInputDeviceTypes.Pen | CoreInputDeviceTypes.Touch;

            // Set initial ink stroke attributes.
            InkDrawingAttributes drawingAttributes = new InkDrawingAttributes();

            drawingAttributes.Color          = Colors.Black;
            drawingAttributes.IgnorePressure = false;
            drawingAttributes.FitToCurve     = true;
            _inkCanvas.InkPresenter.UpdateDefaultDrawingAttributes(drawingAttributes);

            _inkCanvas.InkPresenter.StrokesCollected += InkPresenter_StrokesCollected;

            base.OnApplyTemplate();
        }
Пример #3
0
        public InkExample()
        {
            this.InitializeComponent();

            inkCanvas.InkPresenter.InputDeviceTypes = Windows.UI.Core.CoreInputDeviceTypes.Mouse | Windows.UI.Core.CoreInputDeviceTypes.Pen | Windows.UI.Core.CoreInputDeviceTypes.Touch;

            // By default, pen barrel button or right mouse button is processed for inking
            // Set the configuration to instead allow processing these input on the UI thread
            inkCanvas.InkPresenter.InputProcessingConfiguration.RightDragAction = InkInputRightDragAction.LeaveUnprocessed;

            inkCanvas.InkPresenter.UnprocessedInput.PointerPressed  += UnprocessedInput_PointerPressed;
            inkCanvas.InkPresenter.UnprocessedInput.PointerMoved    += UnprocessedInput_PointerMoved;
            inkCanvas.InkPresenter.UnprocessedInput.PointerReleased += UnprocessedInput_PointerReleased;

            inkCanvas.InkPresenter.StrokeInput.StrokeStarted += StrokeInput_StrokeStarted;

            inkCanvas.InkPresenter.StrokesCollected += InkPresenter_StrokesCollected;
            inkCanvas.InkPresenter.StrokesErased    += InkPresenter_StrokesErased;

            inkSynchronizer = inkCanvas.InkPresenter.ActivateCustomDrying();

            textFormat = new CanvasTextFormat();

            // Set defaults
            SelectedDryInkRenderingType = DryInkRenderingType.BuiltIn;
            SelectColor(color0);
            showTextLabels = true;

            needToCreateSizeDepdendentResources = true;
        }
Пример #4
0
        public CustomInkCanvas()
        {
            CurrentPen = new PenModel()
            {
                IsFreehand = true,
                Color      = Colors.Blue,
                LineStyle  = PenModel.LineType.Solid,
                Size       = 10
            };

            this.InitializeComponent();

            _inkCanvas      = this.InkCanvas;
            _canvas         = this.LineCanvas;
            _actorCanvas    = this.ActorCanvas;
            _savePoint      = new Dictionary <object, int>();
            _currentContent = new Dictionary <object, int>();
            _redo           = new Dictionary <object, int>();

            _synch = _inkCanvas.InkPresenter.ActivateCustomDrying();
            _inkCanvas.InkPresenter.InputDeviceTypes  = Windows.UI.Core.CoreInputDeviceTypes.Mouse | Windows.UI.Core.CoreInputDeviceTypes.Pen;
            _inkCanvas.InkPresenter.StrokesCollected += InkPresenter_StrokesCollected;

            //QuickPens = StorageIO.QuickPens;

            CreateSavePointCmd = new Command()
            {
                CanExecuteFunc = obj => true, ExecuteFunc = CreateSavePoint
            };
            ClearQuickPensCmd = StorageIO.ClearQuickPensCmd;
            AddQuickPenCmd    = StorageIO.AddQuickPenCmd;
            LoadQuickPenCmd   = new Command <PenModel>()
            {
                CanExecuteFunc = obj => true, ExecuteFunc = LoadQuickPen
            };
            ClearLinesCmd = new Command()
            {
                CanExecuteFunc = obj => true, ExecuteFunc = Clear
            };
            SetLineStyleCmd = new Command <string>()
            {
                CanExecuteFunc = obj => true, ExecuteFunc = SetLineStyle
            };
            UndoCmd = new Command()
            {
                CanExecuteFunc = obj => true, ExecuteFunc = Undo
            };
            RedoCmd = new Command()
            {
                CanExecuteFunc = obj => true, ExecuteFunc = Redo
            };
            this.DataContext            = this;
            CurrentPen.PropertyChanged += CurrentPen_PropertyChanged;

            SmoothingFactor = 16;
        }
Пример #5
0
        public MainPage()
        {
            this.InitializeComponent();

            _inkTimer.Tick += async(s, e) => {
                _inkTimer.Stop();
                var boundingBox = GetBoundingBox(_sessionStrokes);
                try
                {
                    var result = await _dataContextViewModel.ProcessInkAsync(_sessionStrokes);

                    if (result != null && result.Keys.Count > 0)
                    {
                        var top = (from r in result select r).First();
                        await PlaceIconAsync(top.Key, top.Value, boundingBox);
                    }
                }
                catch (Exception ex)
                {
                }
                finally
                {
                    _sessionStrokes.Clear();
                    win2dCanvas.Invalidate();
                }
            };

            inkCanvas.InkPresenter.StrokeInput.StrokeStarted += (s, e) =>
            {
                _inkTimer.Stop();
            };

            inkCanvas.InkPresenter.StrokesCollected += (s, e) => {
                _inkTimer.Stop();

                _pendingDry = _inkSync.BeginDry();
                foreach (var stroke in _pendingDry)
                {
                    _sessionStrokes.Add(stroke);
                }

                win2dCanvas.Invalidate();

                _inkTimer.Start();
            };

            _inkSync = inkCanvas.InkPresenter.ActivateCustomDrying();

            _dataContextViewModel = this.DataContext as MainViewModel;

            this.Unloaded += (s, e) => {
                win2dCanvas.RemoveFromVisualTree();
                win2dCanvas = null;
            };
        }
Пример #6
0
        public void Attach(DependencyObject associatedObject)
        {
            var canvas = (InkCanvas)(AssociatedObject = associatedObject);

            _inkSynchronizer = canvas.InkPresenter.ActivateCustomDrying();
            canvas.InkPresenter.StrokesCollected += OnStrokeCollected;;
            canvas.InkPresenter.UnprocessedInput.PointerMoved += OnPointerMoved;
            canvas.InkPresenter.StrokeInput.StrokeStarted     += OnStrokeStarted;
            canvas.InkPresenter.StrokeInput.StrokeEnded       += OnStrokeEnded;
            canvas.InkPresenter.StrokeInput.StrokeCanceled    += OnStrokeCanceled;
        }
Пример #7
0
 public MainPage()
 {
     this.InitializeComponent();
     _inkSynchronizer = InkCanvas.InkPresenter.ActivateCustomDrying();
     InkCanvas.InkPresenter.SetPredefinedConfiguration(InkPresenterPredefinedConfiguration
                                                       .SimpleMultiplePointer);
     InkCanvas.InkPresenter.InputDeviceTypes =
         CoreInputDeviceTypes.Touch | CoreInputDeviceTypes.Pen | CoreInputDeviceTypes.Mouse;
     InkCanvas.InkPresenter.UnprocessedInput.PointerMoved               += UnprocessedInput_PointerMoved;
     InkCanvas.InkPresenter.InputProcessingConfiguration.Mode            = InkInputProcessingMode.None;
     InkCanvas.InkPresenter.InputProcessingConfiguration.RightDragAction =
         InkInputRightDragAction.LeaveUnprocessed;
 }
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            ApplicationView.GetForCurrentView().TryResizeView(new Size(500, 355)); // for larger view size image recognition accuracy may drop

            imageProcessor = new ImageProcessor();
            perceptron     = new Perceptron();

            inkPresenter = inkCanvas.InkPresenter;

            inkSynchronizer = inkPresenter.ActivateCustomDrying();
            inkPresenter.InputDeviceTypes = Windows.UI.Core.CoreInputDeviceTypes.Mouse | Windows.UI.Core.CoreInputDeviceTypes.Pen | Windows.UI.Core.CoreInputDeviceTypes.Touch;

            inkPresenter.StrokesCollected += InkPresenter_StrokesCollected;
        }
Пример #9
0
        public InkExample()
        {
            this.InitializeComponent();

            inkCanvas.InkPresenter.InputDeviceTypes = Windows.UI.Core.CoreInputDeviceTypes.Mouse | Windows.UI.Core.CoreInputDeviceTypes.Pen | Windows.UI.Core.CoreInputDeviceTypes.Touch;

            // By default, pen barrel button or right mouse button is processed for inking
            // Set the configuration to instead allow processing these input on the UI thread
            inkCanvas.InkPresenter.InputProcessingConfiguration.RightDragAction = InkInputRightDragAction.LeaveUnprocessed;

            inkCanvas.InkPresenter.UnprocessedInput.PointerPressed  += UnprocessedInput_PointerPressed;
            inkCanvas.InkPresenter.UnprocessedInput.PointerMoved    += UnprocessedInput_PointerMoved;
            inkCanvas.InkPresenter.UnprocessedInput.PointerReleased += UnprocessedInput_PointerReleased;

            inkCanvas.InkPresenter.StrokeInput.StrokeStarted += StrokeInput_StrokeStarted;

            inkCanvas.InkPresenter.StrokesCollected += InkPresenter_StrokesCollected;

            inkSynchronizer = inkCanvas.InkPresenter.ActivateCustomDrying();

            inkAttributes      = inkCanvas.InkPresenter.CopyDefaultDrawingAttributes();
            inkAttributes.Size = new Size(10, inkAttributes.Size.Height);

            if (isPencilSupported)
            {
                pencilAttributes      = InkDrawingAttributes.CreateForPencil();
                pencilAttributes.Size = new Size(10, pencilAttributes.Size.Height);
                pencilAttributes.PencilProperties.Opacity = 2;
            }
            else
            {
                usePencilCheckbox.Visibility = Visibility.Collapsed;
            }

            textFormat = new CanvasTextFormat();

            // Set defaults
            SelectedDryInkRenderingType = DryInkRenderingType.BuiltIn;
            SelectColor(color0);
            showTextLabels = true;

            needToCreateSizeDependentResources = true;
        }
Пример #10
0
        private void MainCanvas_Loaded(object sender, RoutedEventArgs e)
        {
            var inkPresenter = inkCanvas.InkPresenter;

            // Add Touch to input types
            inkPresenter.InputDeviceTypes = CoreInputDeviceTypes.Pen;

            // Turn on multi pointer input
            inkPresenter.ActivateCustomDrying();
            inkPresenter.SetPredefinedConfiguration(InkPresenterPredefinedConfiguration.SimpleMultiplePointer);

            _inkSynchronizer = inkPresenter.ActivateCustomDrying();
            inkPresenter.StrokesCollected += InkPresenter_StrokesCollected;

            // Handle whether input is pen eraser
            inkPresenter.UnprocessedInput.PointerPressed += UnprocessedInput_PointerPressed;

            SetUpEraseAll();
        }
Пример #11
0
        private void ConfigureControls()
        {
            _inkCanvas.InkPresenter.InputDeviceTypes = CoreInputDeviceTypes.Pen;
            _inkSync = _inkCanvas.InkPresenter.ActivateCustomDrying();
            _inkCanvas.InkPresenter.StrokesCollected += OnStrokesCollected;

            _inkCanvas.InkPresenter.UnprocessedInput.PointerMoved -= UnprocessedInput_PointerMoved;
            _inkCanvas.InkPresenter.UnprocessedInput.PointerMoved += UnprocessedInput_PointerMoved;

            SetZoomFactor();

            _infiniteCanvasScrollViewer.ViewChanged -= InkScrollViewer_ViewChanged;
            _infiniteCanvasScrollViewer.SizeChanged -= InkScrollViewer_SizeChanged;
            _infiniteCanvasScrollViewer.ViewChanged += InkScrollViewer_ViewChanged;
            _infiniteCanvasScrollViewer.SizeChanged += InkScrollViewer_SizeChanged;

            SetCanvasWidthHeight();

            _canvasTextBox.UpdateFontSize(TextFontSize);
        }
Пример #12
0
        public FunctionGraph()
        {
            InitializeComponent();
            _backgroundColor  = Background.SolidColor();
            _foregroundColor  = Foreground.SolidColor();
            Canvas.ClearColor = _backgroundColor;

            ManipulationMode =
                ManipulationModes.Scale
                | ManipulationModes.TranslateX
                | ManipulationModes.TranslateY
                | ManipulationModes.TranslateInertia
                | ManipulationModes.ScaleInertia;

            _dispatcher     = Window.Current.Dispatcher;
            _currentStrokes = _rootStrokes;

            InkPresenter inkPresenter = InkInput.InkPresenter;

            inkPresenter.UpdateDefaultDrawingAttributes(new InkDrawingAttributes()
            {
                Size  = new Size(4, 4),
                Color = _foregroundColor
            });

            CoreInkIndependentInputSource coreInputSource = CoreInkIndependentInputSource.Create(inkPresenter);

            coreInputSource.PointerMoving   += CoreInputSource_PointerMoving;
            coreInputSource.PointerPressing += CoreInputSource_PointerPressing;

            _inkInputProcessing            = inkPresenter.InputProcessingConfiguration;
            inkPresenter.StrokesCollected += InkPresenter_StrokesCollected;
            _inkSynchronizer = inkPresenter.ActivateCustomDrying();

            SizeChanged += (s, e) => ReduceFunctionDetail();
            RegisterPropertyChangedCallback(BackgroundProperty, OnBackgroundChanged);
            RegisterPropertyChangedCallback(ForegroundProperty, OnForegroundChanged);
        }
        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;
        }
Пример #14
0
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            var inkPresenter = InkCanvas.InkPresenter;

            inkPresenter.InputDeviceTypes = CoreInputDeviceTypes.Mouse | CoreInputDeviceTypes.Pen;

            btnOpen.Click   += BtnOpen_Click;
            btnSave.Click   += BtnSave_Click;
            btnUndo.Click   += BtnUndo_Click;
            btnExport.Click += BtnExport_Click;
            _inkSynchronizer = inkPresenter.ActivateCustomDrying();

            inkPresenter.StrokesCollected += InkPresenter_StrokesCollected;


            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;

            //flyout = FlyoutBase.GetAttachedFlyout(eraser) as Flyout;
            _eraseAllFlyout = FlyoutBase.GetAttachedFlyout(eraser) as Flyout;

            if (_eraseAllFlyout != null)
            {
                var panel = _eraseAllFlyout.Content as StackPanel;

                var button = panel.Children[3] as InkToolbarFlyoutItem;
                panel.Children.RemoveAt(3);
                //panel.Children.OfType<InkToolbarFlyoutItem>().FirstOrDefault();
                if (button != null)
                {
                    var newButton = new InkToolbarFlyoutItem();
                    newButton.Style   = button.Style;
                    newButton.Content = new TextBlock()
                    {
                        Text = "Erase all ink"
                    };
                    //   newButton.Content = button.Content;
                    newButton.Name   = button.Name;
                    newButton.Click += EraseAllInk;
                    try {
                        //  panel.Children.Remove(button);
                        //  panel.Children.Add(newButton);
                        panel.Children.Add(newButton);
                    }
                    catch (Exception ex) {
                        System.Diagnostics.Debug.Write(ex);
                    }
                }
            }
        }
Пример #15
0
        public InkExample()
        {
            this.InitializeComponent();

            inkCanvas.InkPresenter.InputDeviceTypes = Windows.UI.Core.CoreInputDeviceTypes.Mouse | Windows.UI.Core.CoreInputDeviceTypes.Pen | Windows.UI.Core.CoreInputDeviceTypes.Touch;

            // By default, pen barrel button or right mouse button is processed for inking
            // Set the configuration to instead allow processing these input on the UI thread
            inkCanvas.InkPresenter.InputProcessingConfiguration.RightDragAction = InkInputRightDragAction.LeaveUnprocessed;

            inkCanvas.InkPresenter.UnprocessedInput.PointerPressed += UnprocessedInput_PointerPressed;
            inkCanvas.InkPresenter.UnprocessedInput.PointerMoved += UnprocessedInput_PointerMoved;
            inkCanvas.InkPresenter.UnprocessedInput.PointerReleased += UnprocessedInput_PointerReleased;

            inkCanvas.InkPresenter.StrokeInput.StrokeStarted += StrokeInput_StrokeStarted;

            inkCanvas.InkPresenter.StrokesCollected += InkPresenter_StrokesCollected;

            inkSynchronizer = inkCanvas.InkPresenter.ActivateCustomDrying();

            inkAttributes = inkCanvas.InkPresenter.CopyDefaultDrawingAttributes();
            inkAttributes.Size = new Size(10, inkAttributes.Size.Height);

            if (isPencilSupported)
            {
                pencilAttributes = InkDrawingAttributes.CreateForPencil();
                pencilAttributes.Size = new Size(10, pencilAttributes.Size.Height);
                pencilAttributes.PencilProperties.Opacity = 2;
            }
            else
            {
                usePencilCheckbox.Visibility = Visibility.Collapsed;
            }

            textFormat = new CanvasTextFormat();

            // Set defaults
            SelectedDryInkRenderingType = DryInkRenderingType.BuiltIn;
            SelectColor(color0);
            showTextLabels = true;

            needToCreateSizeDependentResources = true;
        }
Пример #16
0
        public MainPage()
        {
            this.InitializeComponent();
            _dataContextViewModel = this.DataContext as MainViewModel;
            _inkTimer             = new DispatcherTimer()
            {
                Interval = TimeSpan.FromMilliseconds(_dataContextViewModel.InkProcessingDelay)
            };
            _dataContextViewModel.InkProcessingDelayChanged += (s, e) => {
                Debug.WriteLine($"InkDelayChanged");
                _inkTimer.Stop();
                _inkTimer.Interval = TimeSpan.FromMilliseconds(_dataContextViewModel.InkProcessingDelay);
                ClearCanvas();
            };
            _inactiveTimer.Tick += (s, e) => { ShowWelcome(); };
            _inkTimer.Tick      += async(s, e) => {
                _inkTimer.Stop();
                var boundingBox = GetBoundingBox(_sessionStrokes);
                try
                {
                    var result = await _dataContextViewModel.ProcessInkAsync(_sessionStrokes);

                    if (result != null && result.Keys.Count > 0)
                    {
                        var top = (from r in result select r).First();
                        UpdateAIStats(result);
                        await PlaceIconAsync(top.Key, top.Value, boundingBox);
                    }
                }
                catch (Exception ex)
                {
                }
                finally
                {
                    UpdateInkStats(_sessionStrokes);
                    _sessionStrokes.Clear();
                    win2dCanvas.Invalidate();
                }
            };

            inkCanvas.InkPresenter.StrokeInput.StrokeStarted += (s, e) =>
            {
                _inkTimer.Stop();
                _inactiveTimer.Stop();
            };

            inkCanvas.InkPresenter.StrokesCollected += (s, e) => {
                _inkTimer.Stop();
                _inactiveTimer.Stop();

                _pendingDry = _inkSync.BeginDry();
                foreach (var stroke in _pendingDry)
                {
                    _sessionStrokes.Add(stroke);
                }

                win2dCanvas.Invalidate();

                _inkTimer.Start();
                _inactiveTimer.Start();
            };

            _inkSync = inkCanvas.InkPresenter.ActivateCustomDrying();

            this.Unloaded += (s, e) => {
                win2dCanvas.RemoveFromVisualTree();
                win2dCanvas = null;
            };
        }