Пример #1
0
 public InkCellController(ColoringBookColoring coloring)
 {
     CurrentColoring = coloring;
     CellImage       = new WriteableBitmap(
         (int)CurrentColoring.TemplateImage.Width,
         (int)CurrentColoring.TemplateImage.Height);
 }
Пример #2
0
        // Extracts the points in a list that are on either side of a boundary.
        private static List <BoundaryPoint> GetBoundaryPoints(List <Point> points, ColoringBookColoring coloring)
        {
            if (points == null || points.Count == 0)
            {
                return(null);
            }

            var boundaryPoints       = new List <BoundaryPoint>();
            var previouslyOnBoundary = coloring.TemplateImage.IsOnBoundary(points.First());
            var previousPoint        = points.First();

            foreach (var point in points)
            {
                var currentlyOnBoundary = coloring.TemplateImage.IsOnBoundary(point);

                if (currentlyOnBoundary && !previouslyOnBoundary)
                {
                    boundaryPoints.Add(new BoundaryPoint(false, previousPoint));
                }

                if (!currentlyOnBoundary && previouslyOnBoundary)
                {
                    boundaryPoints.Add(new BoundaryPoint(true, point));
                }

                previousPoint        = point;
                previouslyOnBoundary = currentlyOnBoundary;
            }

            return(boundaryPoints);
        }
Пример #3
0
        public static void LoadHome(Type subPage = null)
        {
            var rootFrame = Window.Current.Content as Frame;

            CurrentProject = null;

            rootFrame?.Navigate(typeof(Home), subPage);
            rootFrame.CacheSize = 0;
        }
Пример #4
0
        public static void LoadColoringPage(ColoringBookColoring coloring)
        {
            if (coloring == null)
            {
                LoadHome();
                return;
            }

            var rootFrame = Window.Current.Content as Frame;

            CurrentProject = coloring;

            rootFrame?.Navigate(typeof(ColoringPage), coloring);
            rootFrame.CacheSize = 0;
        }
Пример #5
0
        public static List <List <InkPoint> > SplitIntoStrokes(IEnumerable <InkPoint> newPoints,
                                                               InkPoint previousPoint, ColoringBookColoring coloring)
        {
            var potentialStrokes = new List <List <InkPoint> >();
            var newStroke        = new List <InkPoint>();

            foreach (var newPoint in newPoints)
            {
                var startPoint = previousPoint;
                var finalPoint = newPoint;

                var lastAddedPoint = new Point(-1, -1);

                var points         = GetPointsBetweenPoints(startPoint.Position, finalPoint.Position);
                var boundaryPoints = GetBoundaryPoints(points, coloring);

                var boundaryLines = GetLinesFromPoints(startPoint.Position, finalPoint.Position, boundaryPoints, coloring);

                if (boundaryLines?.Count > 0)
                {
                    foreach (var line in boundaryLines)
                    {
                        // Self contained stroke.
                        if (line.IsFromBoundary && line.IsToBoundary)
                        {
                            // Save old line.
                            if (newStroke.Count > 0)
                            {
                                potentialStrokes.Add(newStroke);
                                newStroke = new List <InkPoint>();
                            }

                            // Save self contained line.
                            if (line.Start != lastAddedPoint)
                            {
                                var pressure = InterpolatePressure(startPoint, finalPoint, line.Start);
                                newStroke.Add(new InkPoint(line.Start, pressure));
                                lastAddedPoint = line.Start;
                            }

                            if (line.End != lastAddedPoint)
                            {
                                var pressure = InterpolatePressure(startPoint, finalPoint, line.End);
                                newStroke.Add(new InkPoint(line.End, pressure));
                                lastAddedPoint = line.End;
                            }

                            if (newStroke.Count > 0)
                            {
                                potentialStrokes.Add(newStroke);
                            }

                            // Reset list.
                            newStroke = new List <InkPoint>();
                        }
                        else if (line.IsFromBoundary)
                        {
                            // Save old line.
                            if (newStroke.Count > 0)
                            {
                                potentialStrokes.Add(newStroke);
                            }

                            newStroke = new List <InkPoint>();

                            // Begin new one.
                            if (line.Start != lastAddedPoint)
                            {
                                var pressure = InterpolatePressure(startPoint, finalPoint, line.Start);
                                newStroke.Add(new InkPoint(line.Start, pressure));
                                lastAddedPoint = line.Start;
                            }

                            if (line.End != lastAddedPoint)
                            {
                                var pressure = InterpolatePressure(startPoint, finalPoint, line.End);
                                newStroke.Add(new InkPoint(line.End, pressure));
                                lastAddedPoint = line.End;
                            }
                        }
                        else if (line.IsToBoundary)
                        {
                            // Add points - check if previous point is the same as start point.
                            if ((newStroke.Count == 0 || newStroke.Last().Position != line.Start) &&
                                line.Start != lastAddedPoint)
                            {
                                var pressure = InterpolatePressure(startPoint, finalPoint, line.Start);
                                newStroke.Add(new InkPoint(line.Start, pressure));
                                lastAddedPoint = line.Start;
                            }

                            if (line.End != lastAddedPoint)
                            {
                                var pressure = InterpolatePressure(startPoint, finalPoint, line.End);
                                newStroke.Add(new InkPoint(line.End, pressure));
                                lastAddedPoint = line.End;
                            }

                            // End stroke.
                            if (newStroke.Count > 0)
                            {
                                potentialStrokes.Add(newStroke);
                            }

                            // Start new stroke.
                            newStroke = new List <InkPoint>();
                        }
                    }
                }
                else
                {
                    // Normal stroke completely within user cell.
                    if (coloring.IsWithinUserCurrentCell(startPoint.Position) &&
                        coloring.IsWithinUserCurrentCell(finalPoint.Position))
                    {
                        if ((newStroke.Count == 0 || newStroke.Last() != startPoint) &&
                            startPoint.Position != lastAddedPoint)
                        {
                            newStroke.Add(startPoint);
                            lastAddedPoint = startPoint.Position;
                        }

                        if (finalPoint.Position != lastAddedPoint)
                        {
                            newStroke.Add(finalPoint);
                            lastAddedPoint = finalPoint.Position;
                        }
                    }

                    // Start, end or both of stroke is not within boundary and didn't trigger previous conditions.
                    else
                    {
                        // Save old stroke.
                        if (newStroke.Count > 0)
                        {
                            potentialStrokes.Add(newStroke);
                            newStroke = new List <InkPoint>();
                        }

                        if (startPoint.Position != lastAddedPoint &&
                            coloring.IsWithinUserCurrentCell(startPoint.Position))
                        {
                            newStroke.Add(startPoint);
                            lastAddedPoint = startPoint.Position;
                        }

                        if (lastAddedPoint != finalPoint.Position &&
                            coloring.IsWithinUserCurrentCell(finalPoint.Position))
                        {
                            newStroke.Add(finalPoint);
                            lastAddedPoint = finalPoint.Position;
                        }
                    }
                }

                previousPoint = newPoint;
            }

            if (newStroke.Count > 0)
            {
                potentialStrokes.Add(newStroke);
            }

            return(potentialStrokes);
        }
Пример #6
0
        private static List <MyInkLine> GetLinesFromPoints(Point start, Point end,
                                                           List <BoundaryPoint> boundaryPoints, ColoringBookColoring coloring)
        {
            var lines = new List <MyInkLine>();

            if (boundaryPoints == null || boundaryPoints.Count == 0)
            {
                return(null);
            }

            var didStartReachable  = coloring.IsWithinUserCurrentCell(start);
            var didFinishReachable = coloring.IsWithinUserCurrentCell(end);

            // Set start to be the previous point. If the point is within the cell, equate to being "after" a boundary.
            // We create a line if consecutive after -> before && (after || before) is within users cell (both should be).
            var startBPoint   = new BoundaryPoint(didStartReachable, start);
            var previousPoint = startBPoint;

            // Set end point as reverse and we would want a line *to* there to *from* there as with start.
            var endBPoint = new BoundaryPoint(!didFinishReachable, end);

            boundaryPoints.Add(endBPoint);

            foreach (var currentPoint in boundaryPoints)
            {
                // if after -> before
                if (previousPoint.IsAfterBoundary && !currentPoint.IsAfterBoundary &&
                    coloring.IsWithinUserCurrentCell(currentPoint.Point))
                {
                    if (previousPoint.Equals(startBPoint))
                    {
                        lines.Add(new MyInkLine(previousPoint.Point, currentPoint.Point, false, true));
                    }
                    else if (currentPoint.Equals(endBPoint))
                    {
                        // Boundary to end.
                        lines.Add(new MyInkLine(previousPoint.Point, currentPoint.Point, true, false));
                    }
                    else
                    {
                        // It must be boundary to boundary.
                        lines.Add(new MyInkLine(previousPoint.Point, currentPoint.Point, true, true));
                    }
                }

                previousPoint = currentPoint;
            }

            return(lines);
        }