Beispiel #1
0
        void AddSamplePatch()
        {
            float sizeDim = Math.Min((float)canvasControl.Size.Width, (float)canvasControl.Size.Height);
            float scale   = 722 / sizeDim;

            // Move everything upwards slightly so it looks better in the thumbnail.
            float yAdjust = -50.0f;

            Vector2[] points = new Vector2[12];
            points[0] = new Vector2(245.9669f * scale, (358.0068f + yAdjust) * scale);
            points[1] = new Vector2(157.9796f * scale, (127.9815f + yAdjust) * scale);
            points[2] = new Vector2(216.6f * scale, (72.2f + yAdjust) * scale);
            points[3] = new Vector2(288.8f * scale, (72.2f + yAdjust) * scale);

            points[11] = new Vector2(84.99683f * scale, (443.9924f + yAdjust) * scale);
            points[4]  = new Vector2(288.8f * scale, (144.4f + yAdjust) * scale);
            points[10] = new Vector2(72.2f * scale, (216.6f + yAdjust) * scale);
            points[5]  = new Vector2(288.8f * scale, (216.6f + yAdjust) * scale);

            points[9] = new Vector2(72.2f * scale, (288.8f + yAdjust) * scale);
            points[8] = new Vector2(144.4f * scale, (288.8f + yAdjust) * scale);
            points[7] = new Vector2(216.6f * scale, (288.8f + yAdjust) * scale);
            points[6] = new Vector2(292.9843f * scale, (289.9744f + yAdjust) * scale);

            patchPoints.Add(points);
            gradientMesh = null;
            canvasControl.Invalidate();
        }
Beispiel #2
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);
        }
Beispiel #3
0
 private void canvasControl_PointerMoved(object sender, PointerRoutedEventArgs e)
 {
     if (pickedUp.PatchIndex >= 0)
     {
         foreach (var point in e.GetIntermediatePoints(canvasControl))
         {
             if (point.IsInContact)
             {
                 patchPoints[pickedUp.PatchIndex][pickedUp.PointIndex] = point.Position.ToVector2();
                 gradientMesh = null;
                 break;
             }
         }
         canvasControl.Invalidate();
         e.Handled = true;
     }
 }
Beispiel #4
0
        void AddDefaultPatch(bool tensor)
        {
            float sizeDim = Math.Min((float)canvasControl.Size.Width, (float)canvasControl.Size.Height);

            Vector2[] pointArray = new Vector2[tensor ? 16 : 12];

            int[] coonsIndices = { 0, 1, 2, 3, 11, 4, 10, 5, 9, 8, 7, 6 };

            float topLeftMargin = (sizeDim / 10) + ((sizeDim / 10) * patchPoints.Count);

            topLeftMargin = topLeftMargin % sizeDim;

            float spacing = sizeDim / 10.0f;
            int   count   = 0;

            for (int y = 0; y < 4; y++)
            {
                for (int x = 0; x < 4; x++)
                {
                    int index = 0;
                    if (tensor)
                    {
                        index = count;
                    }
                    else
                    {
                        int coordIndex = (y * 4 + x);
                        if (coordIndex == 5 || coordIndex == 6 || coordIndex == 9 || coordIndex == 10)
                        {
                            continue;
                        }

                        index = coonsIndices[count];
                    }
                    pointArray[index] = new Vector2(topLeftMargin + (x * spacing), topLeftMargin + (y * spacing));

                    count++;
                }
            }

            patchPoints.Add(pointArray);
            gradientMesh = null;
            canvasControl.Invalidate();
        }
Beispiel #5
0
 private void SettingsCombo_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     gradientMesh = null;
     canvasControl.Invalidate();
 }
Beispiel #6
0
 private void Clear_Clicked(object sender, RoutedEventArgs e)
 {
     patchPoints.Clear();
     gradientMesh = null;
     canvasControl.Invalidate();
 }