public InkStrokeConverterArgs(GraphicsRectSizeBase graphics, InkCanvas canvas, InkStrokeBuilder strokeBuilder)
 {
     Graphics      = graphics;
     Canvas        = canvas;
     StrokeBuilder = strokeBuilder;
     PenAttribute  = new InkDrawingAttributes();
 }
Пример #2
0
        public static Sketch ScaleSquare(Sketch sketch, double size)
        {
            //
            double minX = double.MaxValue;
            double minY = double.MaxValue;
            double maxX = double.MinValue;
            double maxY = double.MinValue;

            foreach (InkStroke stroke in sketch.Strokes)
            {
                foreach (InkPoint point in stroke.GetInkPoints())
                {
                    double x = point.Position.X;
                    double y = point.Position.Y;

                    if (x < minX)
                    {
                        minX = x;
                    }
                    if (y < minY)
                    {
                        minY = y;
                    }
                    if (x > maxX)
                    {
                        maxX = x;
                    }
                    if (y > maxY)
                    {
                        maxY = y;
                    }
                }
            }
            Rect B = new Rect(new Point(minX, minY), new Point(maxX, maxY));

            //
            List <InkStroke> newStrokes = new List <InkStroke>();
            InkStrokeBuilder builder    = new InkStrokeBuilder();

            foreach (InkStroke stroke in sketch.Strokes)
            {
                List <Point> newPoints = new List <Point>();
                foreach (InkPoint point in stroke.GetInkPoints())
                {
                    double qx = point.Position.X * size / B.Width;
                    double qy = point.Position.Y * size / B.Height;
                    Point  q  = new Point(qx, qy);
                    newPoints.Add(q);
                }

                //
                InkStroke newStroke = builder.CreateStroke(newPoints);
                newStrokes.Add(newStroke);
            }

            //
            Sketch newSketch = new Sketch(newStrokes, sketch.Times);

            return(newSketch);
        }
        private static Sketch Translate(Sketch sketch, Point k, Point c)
        {
            //
            List <InkStroke> newStrokes = new List <InkStroke>();
            InkStrokeBuilder builder    = new InkStrokeBuilder();

            foreach (InkStroke stroke in sketch.Strokes)
            {
                List <Point> newPoints = new List <Point>();
                foreach (InkPoint point in stroke.GetInkPoints())
                {
                    double qx = point.Position.X + k.X - c.X;
                    double qy = point.Position.Y + k.Y - c.Y;
                    Point  q  = new Point(qx, qy);
                    newPoints.Add(q);
                }

                //
                InkStroke newStroke = builder.CreateStroke(newPoints);
                newStroke.DrawingAttributes = stroke.DrawingAttributes;
                newStrokes.Add(newStroke);
            }

            //
            double frameMinX = sketch.FrameMinX + k.X - c.X;
            double frameMinY = sketch.FrameMinY + k.Y - c.Y;
            double frameMaxX = sketch.FrameMaxX + k.X - c.X;
            double frameMaxY = sketch.FrameMaxY + k.Y - c.Y;
            Sketch newSketch = new Sketch(sketch.Label, newStrokes, sketch.Times, frameMinX, frameMinY, frameMaxX, frameMaxY);

            return(newSketch);
        }
Пример #4
0
        public StrokeSynchronization(InkCanvas canvas, InkToolbar inkToolbar, StrokeChangeBroker strokeChangeBroker)
        {
            this.canvas             = canvas;
            this.inkToolbar         = inkToolbar;
            this.strokeChangeBroker = strokeChangeBroker;

            strokeBuilder = new InkStrokeBuilder();

            idToStrokeMapping = new Dictionary <Guid, InkStroke>();

            strokeChangeBroker.StrokeCollected           += StrokeChangeBrokerOnStrokeCollected;
            strokeChangeBroker.StrokeErased              += StrokeChangeBrokerOnStrokeErased;
            strokeChangeBroker.AllStrokeErased           += StrokeChangeBrokerOnAllStrokeErased;
            strokeChangeBroker.ResendAllStrokesRequested += StrokeChangeBrokerOnResendAllStrokesRequested;

            inkToolbar.EraseAllClicked += InkToolbarOnEraseAllClicked;

            canvas.InkPresenter.StrokesCollected            += InkPresenterOnStrokesCollected;
            canvas.InkPresenter.StrokesErased               += InkPresenterOnStrokesErased;
            canvas.InkPresenter.StrokeInput.StrokeContinued += StrokeInput_StrokeContinued;
            canvas.InkPresenter.StrokeInput.StrokeStarted   += StrokeInput_StrokeStarted;
            canvas.InkPresenter.StrokeInput.StrokeEnded     += StrokeInput_StrokeEnded;
            canvas.InkPresenter.StrokesCollected            += InkPresenter_StrokesCollected;

            points = new List <Point>();
        }
Пример #5
0
        public static Sketch CreateStroke(string label, List <InkStroke> strokeCollection, List <List <long> > timeCollection, double minX, double minY, double maxX, double maxY)
        {
            //
            InkStrokeBuilder    builder             = new InkStrokeBuilder();
            List <InkStroke>    newStrokeCollection = new List <InkStroke>();
            List <List <long> > newTimeCollection   = new List <List <long> >();

            for (int i = 0; i < strokeCollection.Count; ++i)
            {
                IReadOnlyList <InkPoint> points = strokeCollection[i].GetInkPoints();
                List <long> times = timeCollection[i];
                int         count = times.Count < points.Count ? times.Count : points.Count;

                List <Point> newPoints = new List <Point>();
                List <long>  newTimes  = new List <long>();
                for (int j = 0; j < count; ++j)
                {
                    InkPoint point = points[j];
                    long     time  = times[j];

                    newPoints.Add(new Point(point.Position.X, point.Position.Y));
                    newTimes.Add(time);
                }

                newStrokeCollection.Add(builder.CreateStroke(newPoints));
                newTimeCollection.Add(newTimes);
            }

            //
            Sketch sketch = new Sketch(label, newStrokeCollection, newTimeCollection, minX, minY, maxX, maxY);

            return(sketch);
        }
Пример #6
0
        private List <InkStroke> CloneStrokes(List <InkStroke> originals)
        {
            List <InkStroke> strokes = new List <InkStroke>();

            InkStroke        stroke;
            InkStrokeBuilder builder = new InkStrokeBuilder();
            Point            point;
            List <Point>     points;

            foreach (InkStroke original in originals)
            {
                points = new List <Point>();
                foreach (InkPoint inkPoint in original.GetInkPoints())
                {
                    point = new Point(inkPoint.Position.X, inkPoint.Position.Y);
                    points.Add(point);
                }

                stroke = builder.CreateStroke(points);
                stroke.DrawingAttributes = StrokeVisuals;
                strokes.Add(original);
            }

            return(strokes);
        }
        private static IList <InkStroke> ScaleAndTransformStrokes(IList <InkStroke> strokeList, float scale, float rotation = 0)
        {
            var builder = new InkStrokeBuilder();
            IList <InkStroke> rotatedStrokes;
            IList <InkStroke> translatedStrokes = new List <InkStroke>();
            var rotationMatrix = Matrix3x2.CreateRotation(ConvertDegreesToRadians(rotation));
            var scaleMatrix    = Matrix3x2.CreateScale(scale);

            if (rotation != 0)
            {
                rotatedStrokes = new List <InkStroke>();
                foreach (var stroke in strokeList)
                {
                    var newStroke = builder.CreateStrokeFromInkPoints(stroke.GetInkPoints(), rotationMatrix);
                    rotatedStrokes.Add(newStroke);
                }
            }
            else
            {
                rotatedStrokes = strokeList;
            }

            var boundingBox     = (rotation != 0) ? rotatedStrokes.GetBoundingBox() : strokeList.GetBoundingBox();;
            var translateMatrix = Matrix3x2.CreateTranslation((float)-boundingBox.X, (float)-boundingBox.Y);

            foreach (var stroke in rotatedStrokes)
            {
                var newStroke = builder.CreateStrokeFromInkPoints(stroke.GetInkPoints(), rotationMatrix * translateMatrix * scaleMatrix);
                translatedStrokes.Add(newStroke);
            }

            return(translatedStrokes);
        }
Пример #8
0
        private static Sketch Translate(Sketch sketch, Point k, Point c)
        {
            //
            List <InkStroke> newStrokes = new List <InkStroke>();
            InkStrokeBuilder builder    = new InkStrokeBuilder();

            foreach (InkStroke stroke in sketch.Strokes)
            {
                List <Point> newPoints = new List <Point>();
                foreach (InkPoint point in stroke.GetInkPoints())
                {
                    double qx = point.Position.X + k.X - c.X;
                    double qy = point.Position.Y + k.Y - c.Y;
                    Point  q  = new Point(qx, qy);
                    newPoints.Add(q);
                }

                //
                InkStroke newStroke = builder.CreateStroke(newPoints);
                newStrokes.Add(newStroke);
            }

            //
            Sketch newSketch = new Sketch(newStrokes, sketch.Times);

            return(newSketch);
        }
Пример #9
0
        private List <InkStroke> Gridify()
        {
            List <InkStroke> gridlines = new List <InkStroke>();
            InkStrokeBuilder builder   = new InkStrokeBuilder();

            double maxX = MyInkCanvas.ActualWidth;
            double maxY = MyInkCanvas.ActualHeight;

            for (int x = 0; x < maxX; x += 50)
            {
                Point     left  = new Point(x, 0);
                Point     right = new Point(x, maxY);
                InkStroke line  = builder.CreateStroke(new List <Point> {
                    left, right
                });
                line.DrawingAttributes = LINE_VISUALS;
                gridlines.Add(line);
            }

            for (int y = 0; y < maxY; y += 50)
            {
                Point     top    = new Point(0, y);
                Point     bottom = new Point(maxX, y);
                InkStroke line   = builder.CreateStroke(new List <Point> {
                    top, bottom
                });
                line.DrawingAttributes = LINE_VISUALS;
                gridlines.Add(line);
            }

            return(gridlines);
        }
Пример #10
0
        public static Sketch Clone(Sketch mySketch)
        {
            //
            List <InkStroke> newStrokesCollection = new List <InkStroke>();
            InkStrokeBuilder builder = new InkStrokeBuilder();

            foreach (InkStroke stroke in mySketch.Strokes)
            {
                List <Point> newPoints = new List <Point>();
                foreach (InkPoint point in stroke.GetInkPoints())
                {
                    Point newPoint = new Point(point.Position.X, point.Position.Y);
                    newPoints.Add(newPoint);
                }
                newStrokesCollection.Add(builder.CreateStroke(newPoints));
            }

            //
            List <List <long> > newTimesCollection = new List <List <long> >();

            foreach (List <long> times in mySketch.Times)
            {
                List <long> newTimes = new List <long>();
                foreach (long time in times)
                {
                    newTimes.Add(time);
                }
                newTimesCollection.Add(newTimes);
            }

            return(new Sketch(newStrokesCollection, newTimesCollection));
        }
        private static List <InkStroke> FrameStrokes(double minX, double minY, double maxX, double maxY)
        {
            Point topLeft     = new Point(minX, minY);
            Point topRight    = new Point(maxX, minY);
            Point bottomLeft  = new Point(minX, maxY);
            Point bottomRight = new Point(maxX, maxY);

            InkStrokeBuilder builder   = new InkStrokeBuilder();
            InkStroke        topStroke = builder.CreateStroke(new List <Point>()
            {
                topLeft, topRight
            });
            InkStroke leftStroke = builder.CreateStroke(new List <Point>()
            {
                topLeft, bottomLeft
            });
            InkStroke rightStroke = builder.CreateStroke(new List <Point>()
            {
                topRight, bottomRight
            });
            InkStroke bottomStroke = builder.CreateStroke(new List <Point>()
            {
                bottomLeft, bottomRight
            });

            List <InkStroke> strokes = new List <InkStroke>();

            strokes.Add(topStroke);
            strokes.Add(leftStroke);
            strokes.Add(rightStroke);
            strokes.Add(bottomStroke);

            return(strokes);
        }
Пример #12
0
        private List <InkStroke> Dotify(List <InkStroke> strokes)
        {
            List <InkPoint> points = new List <InkPoint>();

            foreach (InkStroke stroke in strokes)
            {
                foreach (InkPoint point in stroke.GetInkPoints())
                {
                    points.Add(point);
                }
            }

            List <InkStroke> dotStrokes = new List <InkStroke>();
            InkStrokeBuilder builder    = new InkStrokeBuilder();

            for (int i = 0; i < points.Count; ++i)
            {
                if (i % 20 != 0)
                {
                    continue;
                }

                InkPoint     point    = points[i];
                List <Point> dotPoint = new List <Point> {
                    new Point(point.Position.X, point.Position.Y)
                };
                InkStroke dotStroke = builder.CreateStroke(dotPoint);
                dotStroke.DrawingAttributes = DOT_VISUALS;
                dotStrokes.Add(dotStroke);
            }

            return(dotStrokes);
        }
Пример #13
0
        private void OnReplay(object sender, RoutedEventArgs e)
        {
            if (strokeBuilder == null)
            {
                strokeBuilder           = new InkStrokeBuilder();
                inkReplayTimer          = new DispatcherTimer();
                inkReplayTimer.Interval = new TimeSpan(TimeSpan.TicksPerSecond / FPS);
                inkReplayTimer.Tick    += InkReplayTimer_Tick;
            }

            strokesToReplay = inkCanvas.InkPresenter.StrokeContainer.GetStrokes();

            ReplayButton.IsEnabled = false;
            inkCanvas.InkPresenter.IsInputEnabled = false;
            ClearCanvasStrokeCache();

            // Calculate the beginning of the earliest stroke and the end of the latest stroke.
            // This establishes the time period during which the strokes were collected.
            beginTimeOfRecordedSession = DateTimeOffset.MaxValue;
            endTimeOfRecordedSession   = DateTimeOffset.MinValue;
            foreach (InkStroke stroke in strokesToReplay)
            {
                DateTimeOffset?startTime = stroke.StrokeStartedTime;
                TimeSpan?      duration  = stroke.StrokeDuration;
                if (startTime.HasValue && duration.HasValue)
                {
                    if (beginTimeOfRecordedSession > startTime.Value)
                    {
                        beginTimeOfRecordedSession = startTime.Value;
                    }
                    if (endTimeOfRecordedSession < startTime.Value + duration.Value)
                    {
                        endTimeOfRecordedSession = startTime.Value + duration.Value;
                    }
                }
            }

            // If we found at least one stroke with a timestamp, then we can replay.
            if (beginTimeOfRecordedSession != DateTimeOffset.MaxValue)
            {
                durationOfRecordedSession = endTimeOfRecordedSession - beginTimeOfRecordedSession;

                ReplayProgress.Maximum    = durationOfRecordedSession.TotalMilliseconds;
                ReplayProgress.Value      = 0.0;
                ReplayProgress.Visibility = Visibility.Visible;

                beginTimeOfReplay = DateTime.Now;
                inkReplayTimer.Start();

                rootPage.NotifyUser("Replay started.", NotifyType.StatusMessage);
            }
            else
            {
                // There was nothing to replay. Either there were no strokes at all,
                // or none of the strokes had timestamps.
                StopReplay();
            }
        }
Пример #14
0
        public static InkStroke CloneInkStroke(InkStroke stroke)
        {
            var inkBuilder = new InkStrokeBuilder();
            var newStroke  = inkBuilder.CreateStrokeFromInkPoints(stroke.GetInkPoints(), stroke.PointTransform);

            newStroke.DrawingAttributes = stroke.DrawingAttributes;

            return(newStroke);
        }
Пример #15
0
        public static async Task <Sketch> XmlToSketch(StorageFile file, InkDrawingAttributes attributes)
        {
            // create a new XML document
            // get the text from the XML file
            // load the file's text into an XML document
            string text = await FileIO.ReadTextAsync(file);

            XDocument document = XDocument.Parse(text);

            //
            string label     = document.Root.Attribute("label").Value;
            double frameMinX = Double.Parse(document.Root.Attribute("frameMinX").Value);
            double frameMinY = Double.Parse(document.Root.Attribute("frameMinY").Value);
            double frameMaxX = Double.Parse(document.Root.Attribute("frameMaxX").Value);
            double frameMaxY = Double.Parse(document.Root.Attribute("frameMaxY").Value);

            // itereate through each stroke element
            InkStrokeBuilder    builder = new InkStrokeBuilder();
            InkStroke           stroke;
            List <InkStroke>    strokesCollection = new List <InkStroke>();
            List <List <long> > timesCollection   = new List <List <long> >();

            foreach (XElement element in document.Root.Elements())
            {
                // initialize the point and time lists
                List <Point> points = new List <Point>();
                List <long>  times  = new List <long>();

                // iterate through each point element
                double x, y;
                Point  point;
                long   time;
                foreach (XElement pointElement in element.Elements())
                {
                    x     = Double.Parse(pointElement.Attribute("x").Value);
                    y     = Double.Parse(pointElement.Attribute("y").Value);
                    point = new Point(x, y);
                    time  = Int64.Parse(pointElement.Attribute("time").Value);

                    points.Add(point);
                    times.Add(time);
                }

                //
                stroke = builder.CreateStroke(points);
                stroke.DrawingAttributes = attributes;

                //
                strokesCollection.Add(stroke);
                timesCollection.Add(times);
            }

            Sketch sketch = new Sketch(label, strokesCollection, timesCollection, frameMinX, frameMinY, frameMaxX, frameMaxY);

            return(sketch);
        }
Пример #16
0
        private async Task <List <InkStroke> > ReadMotionXml(StorageFile file)
        {
            // create a new XML document
            // get the text from the XML file
            // load the file's text into an XML document
            string text = await FileIO.ReadTextAsync(file);

            XDocument document = XDocument.Parse(text);

            // itereate through each stroke element
            InkStrokeBuilder builder     = new InkStrokeBuilder();
            List <InkStroke> strokes     = new List <InkStroke>();
            List <Point>     leftPoints  = new List <Point>();
            List <Point>     rightPoints = new List <Point>();

            List <XElement> rootElements  = document.Root.Elements().ToList();
            XElement        framesElement = rootElements[1];

            foreach (XElement frameElement in framesElement.Elements())
            {
                XElement jointsElement = frameElement.Elements().ToList()[0];

                foreach (XElement jointElement in jointsElement.Elements())
                {
                    XElement jointTypeElement = jointElement.Elements().ToList()[0];

                    if (jointTypeElement.Value.Equals("HandLeft"))
                    {
                        XElement        positionElement = jointElement.Elements().ToList()[1];
                        List <XElement> xyzElements     = positionElement.Elements().ToList();
                        double          x = Double.Parse(xyzElements[0].Value);
                        double          y = Double.Parse(xyzElements[1].Value);

                        leftPoints.Add(new Point(x, y));
                    }

                    if (jointTypeElement.Value.Equals("HandRight"))
                    {
                        XElement        positionElement = jointElement.Elements().ToList()[1];
                        List <XElement> xyzElements     = positionElement.Elements().ToList();
                        double          x = Double.Parse(xyzElements[0].Value);
                        double          y = Double.Parse(xyzElements[1].Value);

                        rightPoints.Add(new Point(x, y));
                    }
                }
            }

            InkStroke leftStroke  = builder.CreateStroke(leftPoints);
            InkStroke rightStroke = builder.CreateStroke(rightPoints);

            strokes.Add(leftStroke);
            strokes.Add(rightStroke);

            return(strokes);
        }
Пример #17
0
        public static InkStroke Translate(this InkStroke inkStroke, double left, double top)
        {
            var builder = new InkStrokeBuilder();
            var points  = inkStroke.GetInkPoints()
                          .Select(x => new InkPoint(x.Position.Translate(left, top), x.Pressure, x.TiltX, x.TiltY, x.Timestamp))
                          .ToList();
            var newStroke = builder.CreateStrokeFromInkPoints(points, inkStroke.PointTransform, inkStroke.StrokeStartedTime, inkStroke.StrokeDuration);

            newStroke.DrawingAttributes = inkStroke.DrawingAttributes;
            return(newStroke);
        }
Пример #18
0
 private void OnRedoClicked(object sender, RoutedEventArgs e)
 {
     if (STROKE_STACK.TryPop(out InkStroke stroke))
     {
         InkStrokeBuilder strokeBuilder = new InkStrokeBuilder();
         strokeBuilder.SetDefaultDrawingAttributes(stroke.DrawingAttributes);
         Matrix3x2 matr = stroke.PointTransform;
         IReadOnlyList <InkPoint> inkPoints = stroke.GetInkPoints();
         inkCanvas.InkPresenter.StrokeContainer.AddStroke(strokeBuilder.CreateStrokeFromInkPoints(inkPoints, matr));
     }
 }
Пример #19
0
        public AddStrokeOperation(InkStroke inkStroke)
        {
            var strokeBuilder = new InkStrokeBuilder();

            strokeBuilder.SetDefaultDrawingAttributes(inkStroke.DrawingAttributes);
            System.Numerics.Matrix3x2 matr      = inkStroke.PointTransform;
            IReadOnlyList <InkPoint>  inkPoints = inkStroke.GetInkPoints();

            AddedStroke = strokeBuilder.CreateStrokeFromInkPoints(inkPoints, matr);
            AddedStroke.StrokeStartedTime = inkStroke.StrokeStartedTime;
        }
Пример #20
0
        public void Undo(InkCanvas inkCanvas)
        {
            foreach (InkStroke isk in DeletedStrokes)
            {
                var strokeBuilder = new InkStrokeBuilder();
                strokeBuilder.SetDefaultDrawingAttributes(isk.DrawingAttributes);
                System.Numerics.Matrix3x2 matr      = isk.PointTransform;
                IReadOnlyList <InkPoint>  inkPoints = isk.GetInkPoints();

                inkCanvas.InkPresenter.StrokeContainer.AddStroke(strokeBuilder.CreateStrokeFromInkPoints(inkPoints, matr, isk.StrokeStartedTime, isk.StrokeDuration));
            }
        }
Пример #21
0
        public void Redo(InkCanvas inkCanvas)
        {
            inkCanvas.InkPresenter.StrokeContainer.Clear();
            foreach (InkStroke isk in StrokesAfter)
            {
                var strokeBuilder = new InkStrokeBuilder();
                strokeBuilder.SetDefaultDrawingAttributes(isk.DrawingAttributes);
                System.Numerics.Matrix3x2 matr      = isk.PointTransform;
                IReadOnlyList <InkPoint>  inkPoints = isk.GetInkPoints();
                InkStroke inkStroke = strokeBuilder.CreateStrokeFromInkPoints(inkPoints, matr);
                inkStroke.StrokeStartedTime = isk.StrokeStartedTime;

                inkCanvas.InkPresenter.StrokeContainer.AddStroke(inkStroke);
            }
        }
Пример #22
0
        private void RestoreValue(BaseOperation operation)
        {
            if (operation is Operation <InkStroke> currentOperation)
            {
                InkStroke        stroke        = currentOperation.Instance;
                InkStrokeBuilder strokeBuilder = new InkStrokeBuilder();
                strokeBuilder.SetDefaultDrawingAttributes(stroke.DrawingAttributes);
                System.Numerics.Matrix3x2 matr      = stroke.PointTransform;
                IReadOnlyList <InkPoint>  inkPoints = stroke.GetInkPoints();
                InkStroke stk = strokeBuilder.CreateStrokeFromInkPoints(inkPoints, matr);

                presenter.StrokeContainer.AddStroke(stk);
                currentOperation.Instance = stk;
            }
        }
Пример #23
0
        private async Task <List <InkStroke> > ReadXml(StorageFile file)
        {
            // create a new XML document
            // get the text from the XML file
            // load the file's text into an XML document
            string text = await FileIO.ReadTextAsync(file);

            XDocument document = XDocument.Parse(text);

            //
            string label = document.Root.Attribute("label").Value;

            // itereate through each stroke element
            InkStrokeBuilder builder = new InkStrokeBuilder();
            InkStroke        stroke;
            List <InkStroke> strokes = new List <InkStroke>();

            foreach (XElement element in document.Root.Elements())
            {
                // initialize the point and time lists
                List <Point> points = new List <Point>();
                List <long>  times  = new List <long>();

                // iterate through each point element
                double x, y;
                Point  point;
                long   time;
                foreach (XElement pointElement in element.Elements())
                {
                    x     = Double.Parse(pointElement.Attribute("x").Value);
                    y     = Double.Parse(pointElement.Attribute("y").Value);
                    point = new Point(x, y);
                    time  = Int64.Parse(pointElement.Attribute("time").Value);

                    points.Add(point);
                    times.Add(time);
                }

                //
                stroke = builder.CreateStroke(points);
                stroke.DrawingAttributes = StrokeVisuals;

                //
                strokes.Add(stroke);
            }

            return(strokes);
        }
Пример #24
0
        private void Redo_Click(object sender, RoutedEventArgs e)
        {
            redo.IsChecked = false;

            if (UndoStrokes.Count > 0)
            {
                var stroke = UndoStrokes.Pop();

                var strokeBuilder = new InkStrokeBuilder();
                strokeBuilder.SetDefaultDrawingAttributes(stroke.DrawingAttributes);
                System.Numerics.Matrix3x2 matr      = stroke.PointTransform;
                IReadOnlyList <InkPoint>  inkPoints = stroke.GetInkPoints();
                InkStroke stk = strokeBuilder.CreateStrokeFromInkPoints(inkPoints, matr);
                canvas.InkPresenter.StrokeContainer.AddStroke(stk);
            }
        }
Пример #25
0
 private void InkPresenter_StrokesErased(InkPresenter sender, InkStrokesErasedEventArgs args)
 {
     foreach (var item in args.Strokes)
     {
         var strokeBuilder = new InkStrokeBuilder();
         strokeBuilder.SetDefaultDrawingAttributes(item.DrawingAttributes);
         var stroke = strokeBuilder.CreateStrokeFromInkPoints(item.GetInkPoints(), item.PointTransform);
         _undoList.Add(stroke);
         if (_redoList.Contains(item))
         {
             _redoList.Remove(item);
         }
     }
     _undoCommand?.RaiseCanExecuteChanged();
     _redoCommand?.RaiseCanExecuteChanged();
 }
Пример #26
0
        public void CreatePreviewInkStroke()
        {
            var strokePreviewInkPoints = new List <InkPoint>();

            for (var i = 0; i < Commons.Constants.PreviewStrokeCoordinates.Length; i += 2)
            {
                var newPoint = new Point(Commons.Constants.PreviewStrokeCoordinates[i], Commons.Constants.PreviewStrokeCoordinates[i + 1] + 10);
                var inkPoint = new InkPoint(newPoint, 1f);
                strokePreviewInkPoints.Add(inkPoint);
            }

            var inkStrokeBuilder = new InkStrokeBuilder();
            var newStroke        = inkStrokeBuilder.CreateStrokeFromInkPoints(strokePreviewInkPoints, Matrix3x2.Identity);

            PreviewInkStroke = newStroke;
        }
Пример #27
0
 public InkCanvasLayer()
 {
     TopCanvas     = new InkCanvas();
     StrokeBuilder = new InkStrokeBuilder();
     TopCanvas.InkPresenter.InputDeviceTypes = CoreInputDeviceTypes.Mouse | CoreInputDeviceTypes.Pen | CoreInputDeviceTypes.Touch;
     ChangeCanvasModel(true);
     TopCanvas.InkPresenter.UpdateDefaultDrawingAttributes(new InkDrawingAttributes()
     {
         Color = Colors.Black
     });
     TopCanvas.InkPresenter.UnprocessedInput.PointerPressed  += UnprocessedInput_PointerPressed;
     TopCanvas.InkPresenter.UnprocessedInput.PointerMoved    += UnprocessedInput_PointerMoved;
     TopCanvas.InkPresenter.UnprocessedInput.PointerReleased += UnprocessedInput_PointerReleased;
     TopCanvas.InkPresenter.UnprocessedInput.PointerHovered  += UnprocessedInput_PointerHovered;
     TopCanvas.InkPresenter.UnprocessedInput.PointerLost     += UnprocessedInput_PointerLost;
     TopCanvas.KeyDown += TopCanvas_KeyDown;
 }
Пример #28
0
        private void ApplyInkFromPoints(List <Point> points)
        {
            var builder = new InkStrokeBuilder();

            builder.SetDefaultDrawingAttributes(CurrentDrawingAttributes);
            for (int i = 0; i < points.Count; i++)
            {
                var strk = builder.CreateStroke(i
                                                + 1 < points.Count ?
                                                new[] { points[i], points[i + 1] } :
                                                new[] { points[i], points[0] });

                CurrentInkCanvas.InkPresenter.StrokeContainer.AddStroke(strk);
            }
            //var stroke = builder.CreateStroke(points);
            //CurrentInkCanvas.InkPresenter.StrokeContainer.AddStroke(stroke);
        }
Пример #29
0
        public void RedoLastStorke()
        {
            if (UndoStrokes.Count > 0)
            {
                var stroke = UndoStrokes.Pop();

                // This will blow up sky high:
                // InkCanvas.InkPresenter.StrokeContainer.AddStroke(stroke);

                var strokeBuilder = new InkStrokeBuilder();
                strokeBuilder.SetDefaultDrawingAttributes(stroke.DrawingAttributes);
                System.Numerics.Matrix3x2 matr      = stroke.PointTransform;
                IReadOnlyList <InkPoint>  inkPoints = stroke.GetInkPoints();
                InkStroke stk = strokeBuilder.CreateStrokeFromInkPoints(inkPoints, matr);
                InkCanvas.InkPresenter.StrokeContainer.AddStroke(stk);
            }
        }
        private void CreatePencilPreviewStroke()
        {
            var strokePreviewInkPoints = new List <InkPoint>();

            for (var i = 0; i < PreviewStrokeCoordinates.Length; i += 2)
            {
                var newPoint = new Point(PreviewStrokeCoordinates[i],
                                         PreviewStrokeCoordinates[i + 1] + 10);
                var inkPoint = new InkPoint(newPoint, 1f);
                strokePreviewInkPoints.Add(inkPoint);
            }

            var inkStrokeBuilder = new InkStrokeBuilder();
            var newStroke        = inkStrokeBuilder.CreateStrokeFromInkPoints(
                strokePreviewInkPoints, Matrix3x2.Identity);

            PencilPreviewInkStroke = newStroke;
        }