private void OnStrokeCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
        {
            var list = _inkSynchronizer.BeginDry();

            StrokeCollected?.Invoke(this, list);
            _inkSynchronizer.EndDry();
        }
        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);
        }
        private void canvasControl_Draw(CanvasControl sender, CanvasDrawEventArgs args)
        {
            if (needToCreateSizeDependentResources)
            {
                CreateSizeDependentResources();
            }

            if (needToRedrawInkSurface)
            {
                ClearInkSurface();
                DrawStrokeCollectionToInkSurface(inkManager.GetStrokes());

                needToRedrawInkSurface = false;
            }

            DrawBackgroundText(args.DrawingSession);

            if (pendingDry != null && deferredDryDelay == 0)
            {
                // Incremental draw only.
                DrawStrokeCollectionToInkSurface(pendingDry);

                // We want to transition from displaying wet ink to our newly drawn dry ink with minimum possible risk of flicker.
                // If the ink is opaque, the safest approach is to delay calling EndDry for a couple of frames, deferring it via
                // the CompositionTarget.Rendering event. This will usually briefly overlap the wet and dry ink, which looks fine
                // for regular pen strokes but not for pencil or highlighter rendering. When using such non-opaque drawing modes,
                // we must call EndDry immediately to minimize risk of any overlap.
                if (usePencil)
                {
                    inkSynchronizer.EndDry();
                    pendingDry = null;
                }
                else
                {
                    // Register to call EndDry on the next-but-one draw,
                    // by which time our dry ink will be visible.
                    deferredDryDelay             = 1;
                    CompositionTarget.Rendering += DeferredEndDry;
                }
            }

            args.DrawingSession.DrawImage(renderTarget);

            DrawForegroundText(args.DrawingSession);
            DrawSelectionBoundingRect(args.DrawingSession);
            DrawSelectionLasso(sender, args.DrawingSession);
        }
Exemple #4
0
        private void InkPresenter_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
        {
            var strokes = _synch.BeginDry();

            RenderStrokes(strokes);

            _synch.EndDry();
        }
Exemple #5
0
 private void ProcessPendingInk()
 {
     if (_pendingDry != null)
     {
         _inkSync.EndDry();
         _pendingDry = null;
     }
 }
        private void CompositionTarget_Rendering(object sender, object e)
        {
            if (deferredDryDelay > 0)
            {
                deferredDryDelay--;
            }
            else
            {
                CompositionTarget.Rendering -= CompositionTarget_Rendering;
                pendingDry = null;

                inkSynchronizer.EndDry();
            }
        }
        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();
        }
        private void DeferredEndDry(object sender, object e)
        {
            Debug.Assert(pendingDry != null);

            if (deferredDryDelay > 0)
            {
                deferredDryDelay--;
            }
            else
            {
                CompositionTarget.Rendering -= DeferredEndDry;

                pendingDry = null;

                inkSynchronizer.EndDry();
            }
        }
Exemple #9
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();
            }
        }