コード例 #1
0
ファイル: InkCanvasBinding.cs プロジェクト: tmyt/InfiniteNote
        private void OnStrokeCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
        {
            var list = _inkSynchronizer.BeginDry();

            StrokeCollected?.Invoke(this, list);
            _inkSynchronizer.EndDry();
        }
コード例 #2
0
        private void canvasControl_Draw(CanvasControl sender, CanvasDrawEventArgs args)
        {
            if (needToCreateSizeDepdendentResources)
            {
                CreateSizeDependentResources();
            }

            if (needsClear || needsInkSurfaceValidation)
            {
                ClearInkSurface();
            }
            if (needsInkSurfaceValidation)
            {
                DrawStrokeCollectionToInkSurface(strokeList);
            }
            needToCreateSizeDepdendentResources = false;
            needsClear = false;
            needsInkSurfaceValidation = false;

            DrawBackgroundText(args.DrawingSession);

            var strokes = inkSynchronizer.BeginDry();

            DrawStrokeCollectionToInkSurface(strokes); // Incremental draw only.

            inkSynchronizer.EndDry();

            args.DrawingSession.DrawImage(renderTarget);

            DrawForegroundText(args.DrawingSession);

            DrawSelectionBoundingRect(args.DrawingSession);

            DrawSelectionLasso(sender, args.DrawingSession);
        }
コード例 #3
0
        private void InkPresenter_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
        {
            var strokes = _synch.BeginDry();

            RenderStrokes(strokes);

            _synch.EndDry();
        }
コード例 #4
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;
            };
        }
コード例 #5
0
ファイル: InkExample.xaml.cs プロジェクト: mjeanrichard/Win2D
        private void InkPresenter_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
        {
            foreach (var s in args.Strokes)
            {
                inkManager.AddStroke(s);
            }

            Debug.Assert(pendingDry == null);

            pendingDry = inkSynchronizer.BeginDry();

            canvasControl.Invalidate();
        }
コード例 #6
0
        private void InkPresenter_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
        {
            pendingDry = inkSynchronizer.BeginDry();

            var container = new InkStrokeContainer();

            foreach (var stroke in pendingDry)
            {
                container.AddStroke(stroke.Clone());
            }

            strokes.Add(container);

            drawingCanvas.Invalidate();
        }
コード例 #7
0
        private void InkPresenter_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
        {
            var strokes   = _inkSynchronizer.BeginDry();
            var container = new InkStrokeContainer();

            container.AddStrokes(from item in strokes
                                 select item.Clone());

            _inkStrokes.Add(container);
            history.Push(_inkStrokes);

            _inkSynchronizer.EndDry();

            DrawingCanvas.Invalidate();
        }
コード例 #8
0
        private void InkPresenter_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
        {
            // Custom drying
            var strokes = _inkSynchronizer.BeginDry();

            var container     = new InkStrokeContainer();
            var clonedStrokes = from item in strokes select item.Clone();

            container.AddStrokes(clonedStrokes);
            viewModel.AddStroke(container);

            _inkSynchronizer.EndDry();
            drawingCanvas.Invalidate();

            if (inkToShapeButton.IsChecked.Value) // Store a copy of the strokes for recognition if button is checked
            {
                viewModel.RecognizeStrokes(clonedStrokes);
            }
            else
            {
                viewModel.StopRecognizingStrokes();
            }
        }
コード例 #9
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;
            };
        }