コード例 #1
0
        private void OnPaintCanvas(object sender, SKPaintSurfaceEventArgs e)
        {
            SKImageInfo info    = e.Info;
            SKSurface   surface = e.Surface;
            SKCanvas    canvas  = surface.Canvas;

            int surfaceWidth  = info.Width;
            int surfaceHeight = info.Height;

            SKPoint surfaceSize = new SKPoint(surfaceWidth, surfaceHeight);


            //絵画開始
            //背景色を塗る
            canvas.Clear(PaintColors.OutOfRangeBackground.ToSKColor());

            //アートボードの絵画
            anArtBoard.SizeRecalculation(surfaceSize);

            using (SKPaint paint = new SKPaint())
            {
                paint.Style = SKPaintStyle.Fill;
                paint.Color = PaintColors.ArtBoardBackground.ToSKColor();
                canvas.DrawRect(anArtBoard.AbsoluteRect, paint);
            }


            radius = Math.Min(anArtBoard.Size.X, anArtBoard.Size.Y) / 2.0f * 0.7f;



            anArtBoard.InProgressPath.StrokeColor = PaintColors.Black;
            anArtBoard.InProgressPath.StrokeSize  = 5;
            anArtBoard.InProgressPath.StrokeJoin  = SKStrokeJoin.Round;
            anArtBoard.InProgressPath.StrokeCap   = SKStrokeCap.Round;
            anArtBoard.InProgressPath.Screentone  = PaintPatterns.CheckeredPattern(PaintColors.Blue.ToSKColor());

            anArtBoard.BezierHandleList.Clear();
            anArtBoard.BezierHandleList.Add(
                new BezierHandle(
                    anArtBoard.AbsolutePosition + new SKPoint(anArtBoard.Size.X / 2, anArtBoard.Size.Y / 2 - radius),
                    anArtBoard.AbsolutePosition + new SKPoint(anArtBoard.Size.X / 2 + radius * controlPointCoefficient, anArtBoard.Size.Y / 2 - radius)));
            anArtBoard.BezierHandleList.Add(
                new BezierHandle(
                    anArtBoard.AbsolutePosition + new SKPoint(anArtBoard.Size.X / 2 + radius, anArtBoard.Size.Y / 2),
                    anArtBoard.AbsolutePosition + new SKPoint(anArtBoard.Size.X / 2 + radius, anArtBoard.Size.Y / 2 + radius * controlPointCoefficient)));
            anArtBoard.BezierHandleList.Add(
                new BezierHandle(
                    anArtBoard.AbsolutePosition + new SKPoint(anArtBoard.Size.X / 2, anArtBoard.Size.Y / 2 + radius),
                    anArtBoard.AbsolutePosition + new SKPoint(anArtBoard.Size.X / 2 - radius * controlPointCoefficient, anArtBoard.Size.Y / 2 + radius)));
            anArtBoard.BezierHandleList.Add(
                new BezierHandle(
                    anArtBoard.AbsolutePosition + new SKPoint(anArtBoard.Size.X / 2 - radius, anArtBoard.Size.Y / 2),
                    anArtBoard.AbsolutePosition + new SKPoint(anArtBoard.Size.X / 2 - radius, anArtBoard.Size.Y / 2 - radius * controlPointCoefficient)));


            //絶対座標からアスペクト座標に変換
            foreach (var bezierHandle in anArtBoard.BezierHandleList)
            {
                bezierHandle.AnchorPoint       = anArtBoard.MatrixToAspectCoordinates().MapPoint(bezierHandle.AnchorPoint);
                bezierHandle.MouseControlPoint = anArtBoard.MatrixToAspectCoordinates().MapPoint(bezierHandle.MouseControlPoint);
            }


            //暫定Path絵画
            if (anArtBoard.BezierHandleList.Count >= 2)
            {
                anArtBoard.InProgressPath.Reset();

                //bezierHandleList -> inProgressPath
                anArtBoard.GenerateBezierPath(pathPreview);
                anArtBoard.InProgressPath.Transform(this.anArtBoard.InverseMatrixToAbsoluteCoordinates());
                canvas.DrawPath(anArtBoard.InProgressPath, anArtBoard.InProgressPath.GetFillPaint());
                canvas.DrawPath(anArtBoard.InProgressPath, anArtBoard.InProgressPath.GetStrokePaint());
            }



            //コントロールポイントを絵画
            SKPaint aBezierHandlePaint = new SKPaint()
            {
                IsAntialias = true,
                Style       = SKPaintStyle.Stroke,
                Color       = PaintColors.Lasso.ToSKColor(),
                StrokeWidth = 2,
                StrokeJoin  = SKStrokeJoin.Round,
                StrokeCap   = SKStrokeCap.Round
            };

            SKPaint aBezierHandleAnchorPaint = new SKPaint()
            {
                IsAntialias = true,
                Style       = SKPaintStyle.Fill,
                Color       = PaintColors.Lasso.ToSKColor()
            };



            using (SKPath path = new SKPath())
            {
                foreach (var aBezierHandle in anArtBoard.BezierHandleList)
                {
                    SKPoint anchorPoint          = anArtBoard.InverseMatrixToAbsoluteCoordinates().MapPoint(aBezierHandle.AnchorPoint);
                    SKPoint mouseControlPoint    = anArtBoard.InverseMatrixToAbsoluteCoordinates().MapPoint(aBezierHandle.MouseControlPoint);
                    SKPoint theOtherControlPoint = anArtBoard.InverseMatrixToAbsoluteCoordinates().MapPoint(aBezierHandle.TheOtherControlPoint);


                    path.MoveTo(anchorPoint);
                    path.LineTo(mouseControlPoint);

                    canvas.DrawCircle(anchorPoint, 4, aBezierHandleAnchorPaint);


                    path.MoveTo(anchorPoint);
                    path.LineTo(theOtherControlPoint);
                }

                canvas.DrawPath(path, aBezierHandlePaint);
            }
        }
コード例 #2
0
ファイル: MainPage.xaml.cs プロジェクト: satochibi/MNGDraw
        private void OnPaintCanvas(object sender, SKPaintSurfaceEventArgs e)
        {
            SKImageInfo info    = e.Info;
            SKSurface   surface = e.Surface;
            SKCanvas    canvas  = surface.Canvas;

            int     surfaceWidth  = info.Width;
            int     surfaceHeight = info.Height;
            SKPoint surfaceSize   = new SKPoint(surfaceWidth, surfaceHeight);



            //絵画開始

            //背景色を塗る
            canvas.Clear(PaintColors.OutOfRangeBackground.ToSKColor());

            //アートボードの絵画
            anArtBoard.SizeRecalculation(surfaceSize);

            using (SKPaint paint = new SKPaint())
            {
                paint.Style = SKPaintStyle.Fill;
                paint.Color = anArtBoard.BackgroundColor.ToSKColor();
                canvas.DrawRect(anArtBoard.AbsoluteRect, paint);
            }



            //completedPathList絵画
            //foreach (var aLayer in aManga.PageList[this.currentPageNumber].LayerList)の逆順: (2→1→0)
            for (int index = aManga.PageList[this.currentPageNumber].LayerList.Count - 1; 0 <= index; index--)
            {
                var aLayer = aManga.PageList[this.currentPageNumber].LayerList[index];

                foreach (var aCompletedPath in aLayer.CompletedPathList)
                {
                    if (!aCompletedPath.IsVisibility)
                    {
                        continue;
                    }
                    SKPath aPath = new SKPath(aCompletedPath);//ディープコピー(aCompletedPathが拡大され続けるのを防ぐ)
                    aPath.Transform(this.anArtBoard.InverseMatrixToAbsoluteCoordinates());

                    canvas.DrawPath(aPath, aCompletedPath.GetFillBlendPaint(anArtBoard.BackgroundColor));
                    canvas.DrawPath(aPath, aCompletedPath.GetFillPaint());
                    canvas.DrawPath(aPath, aCompletedPath.GetStrokePaint(this.anArtBoard.ScaleFactor));
                }
            }



            //暫定Path絵画
            if (anArtBoard.BezierHandleList.Count >= 2)
            {
                anArtBoard.InProgressPath.Reset();

                //bezierHandleList -> inProgressPath
                anArtBoard.GenerateBezierPath((PathPreviewAlgorithms)SaveProperties.PathPreviewAlgorithms);
                anArtBoard.InProgressPath.Transform(this.anArtBoard.InverseMatrixToAbsoluteCoordinates());

                canvas.DrawPath(anArtBoard.InProgressPath, anArtBoard.InProgressPath.GetFillBlendPaint(anArtBoard.BackgroundColor));
                canvas.DrawPath(anArtBoard.InProgressPath, anArtBoard.InProgressPath.GetFillPaint());
                canvas.DrawPath(anArtBoard.InProgressPath, anArtBoard.InProgressPath.GetStrokePaint());
            }



            //コントロールポイントを絵画
            SKPaint aBezierHandlePaint = new SKPaint()
            {
                IsAntialias = true,
                Style       = SKPaintStyle.Stroke,
                Color       = PaintColors.Lasso.ToSKColor(),
                StrokeWidth = 2,
                StrokeJoin  = SKStrokeJoin.Round,
                StrokeCap   = SKStrokeCap.Round
            };

            SKPaint aBezierHandleAnchorPaint = new SKPaint()
            {
                IsAntialias = true,
                Style       = SKPaintStyle.Fill,
                Color       = PaintColors.Lasso.ToSKColor()
            };



            using (SKPath path = new SKPath())
            {
                foreach (var aBezierHandle in anArtBoard.BezierHandleList)
                {
                    SKPoint anchorPoint          = anArtBoard.InverseMatrixToAbsoluteCoordinates().MapPoint(aBezierHandle.AnchorPoint);
                    SKPoint mouseControlPoint    = anArtBoard.InverseMatrixToAbsoluteCoordinates().MapPoint(aBezierHandle.MouseControlPoint);
                    SKPoint theOtherControlPoint = anArtBoard.InverseMatrixToAbsoluteCoordinates().MapPoint(aBezierHandle.TheOtherControlPoint);


                    path.MoveTo(anchorPoint);
                    path.LineTo(mouseControlPoint);

                    canvas.DrawCircle(anchorPoint, 4, aBezierHandleAnchorPaint);


                    path.MoveTo(anchorPoint);
                    path.LineTo(theOtherControlPoint);
                }

                canvas.DrawPath(path, aBezierHandlePaint);
            }
        }