Exemplo n.º 1
0
        void EnsureMesh(ICanvasResourceCreator resourceCreator)
        {
            if (gradientMesh != null)
            {
                return;
            }

            CanvasGradientMeshPatch[] patchArray = new CanvasGradientMeshPatch[patchPoints.Count];

            for (int i = 0; i < patchPoints.Count; ++i)
            {
                CanvasGradientMeshPatch patch;

                var points = patchPoints[i];
                var colors = new Vector4[] { Color00.Color, Color03.Color, Color30.Color, Color33.Color };
                var edges  = new CanvasGradientMeshPatchEdge[] { Edge00To03, Edge03To33, Edge33To30, Edge30To00 };

                if (patchPoints[i].Length == 12)
                {
                    patch = CanvasGradientMesh.CreateCoonsPatch(points, colors, edges);
                }
                else
                {
                    Debug.Assert(patchPoints[i].Length == 16);

                    patch = CanvasGradientMesh.CreateTensorPatch(points, colors, edges);
                }

                patchArray[i] = patch;
            }

            // Gradient meshes are allowed to be zero-sized, so there is no need to
            // account for zero here.
            gradientMesh = new CanvasGradientMesh(resourceCreator, patchArray);
        }
Exemplo n.º 2
0
        void DrawControlLines(CanvasDrawingSession drawingSession)
        {
            CanvasGradientMeshPatch[] patches = gradientMesh.Patches;

            for (int i = 0; i < patchPoints.Count; ++i)
            {
                var pointArray = patchPoints[i];
                foreach (Vector2 point in pointArray)
                {
                    drawingSession.FillCircle(point, 7, Colors.White);
                }

                CanvasGradientMeshPatch patch = patches[i];
                bool showInterior             = patchPoints[i].Length == 16;

                DrawBezier(drawingSession, patch.Point00, patch.Point01, patch.Point02, patch.Point03);
                DrawBezier(drawingSession, patch.Point03, patch.Point13, patch.Point23, patch.Point33);
                DrawBezier(drawingSession, patch.Point00, patch.Point10, patch.Point20, patch.Point30);
                DrawBezier(drawingSession, patch.Point30, patch.Point31, patch.Point32, patch.Point33);

                if (showInterior)
                {
                    DrawBezier(drawingSession, patch.Point10, patch.Point11, patch.Point12, patch.Point13);
                    DrawBezier(drawingSession, patch.Point20, patch.Point21, patch.Point22, patch.Point23);

                    DrawBezier(drawingSession, patch.Point01, patch.Point11, patch.Point21, patch.Point31);
                    DrawBezier(drawingSession, patch.Point02, patch.Point12, patch.Point22, patch.Point32);
                }

                drawingSession.DrawLine(patch.Point00, patch.Point01, Colors.White);
                drawingSession.DrawLine(patch.Point02, patch.Point03, Colors.White);

                drawingSession.DrawLine(patch.Point03, patch.Point13, Colors.White);
                drawingSession.DrawLine(patch.Point23, patch.Point33, Colors.White);

                drawingSession.DrawLine(patch.Point33, patch.Point32, Colors.White);
                drawingSession.DrawLine(patch.Point31, patch.Point30, Colors.White);

                drawingSession.DrawLine(patch.Point30, patch.Point20, Colors.White);
                drawingSession.DrawLine(patch.Point10, patch.Point00, Colors.White);

                if (showInterior)
                {
                    drawingSession.DrawLine(patch.Point01, patch.Point11, Colors.White);
                    drawingSession.DrawLine(patch.Point21, patch.Point31, Colors.White);

                    drawingSession.DrawLine(patch.Point02, patch.Point12, Colors.White);
                    drawingSession.DrawLine(patch.Point22, patch.Point32, Colors.White);

                    drawingSession.DrawLine(patch.Point10, patch.Point11, Colors.White);
                    drawingSession.DrawLine(patch.Point12, patch.Point13, Colors.White);

                    drawingSession.DrawLine(patch.Point20, patch.Point21, Colors.White);
                    drawingSession.DrawLine(patch.Point22, patch.Point23, Colors.White);
                }
            }
        }