Пример #1
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;
     }
 }
Пример #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);
        }
Пример #3
0
 private void SettingsCombo_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     gradientMesh = null;
     canvasControl.Invalidate();
 }
Пример #4
0
 private void Clear_Clicked(object sender, RoutedEventArgs e)
 {
     patchPoints.Clear();
     gradientMesh = null;
     canvasControl.Invalidate();
 }        
Пример #5
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();
        }
Пример #6
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();
        }
Пример #7
0
		private void CanvasAnimatedControl_OnCreateResources(CanvasAnimatedControl sender, CanvasCreateResourcesEventArgs args)
		{
			//guides
			_center = new Vector2((float)(sender.Size.Width / 2.0), (float)(sender.Size.Height / 2.0f));
			_size = (float) Math.Min(sender.Size.Height, sender.Size.Width);
			_half = _size / 2.0f;
			_ringCount = Convert.ToInt32(Math.Floor((_half - (StartOffset + EndOffset))/(RingPadding + RingStrokeWidth)));
			var nudge = _size * 0.174f;

			//mask
			var crt = new CanvasRenderTarget(sender, _size, _size, sender.Dpi);
			using (var session = crt.CreateDrawingSession())
			{
				session.Clear(new Vector4(0, 0, 0, 0));
				var pa = new CanvasGradientMeshPatch[4];
				pa[0] = CanvasGradientMesh.CreateCoonsPatch(
					new[]
					{
						new Vector2(_half, 0.0f), //center top
						new Vector2(_half, 0.0f), //center top
						new Vector2(_size, 0.0f), //right top
						new Vector2(_size, _half), //right middle
						new Vector2(_half-nudge, _half), //center middle (nudged left)
						new Vector2(_half-nudge, _half), //center middle (nudged left)
						new Vector2(_size, _half), //right middle
						new Vector2(_size, _size), //right bottom
						new Vector2(_half, _size), //center bottom
						new Vector2(_half, _size), //center bottom
						new Vector2(-nudge, _size), //left bottom (nudged left)
						new Vector2(-nudge, 0.0f), //left top (nudged left)
					},
					new[]
					{
						new Vector4(1, 1, 1, 1), new Vector4(1, 1, 1, 1),
						new Vector4(0, 0, 0, 0), new Vector4(0, 0, 0, 0),
					},
					new[]
					{
						CanvasGradientMeshPatchEdge.Antialiased, CanvasGradientMeshPatchEdge.Antialiased,
						CanvasGradientMeshPatchEdge.Antialiased, CanvasGradientMeshPatchEdge.Antialiased
					});

				var gm = new CanvasGradientMesh(session, pa);
				session.DrawGradientMesh(gm);
			}
			var ib = new CanvasImageBrush(sender, crt);
			_brush = ib;

			//animation pattern
			_pattern = new List<double>();
			for (int i = 0; i < 3; i++)
			{
				for (int j = 0; j < _ringCount; j++)
				{
					_pattern.Add(0.0);
				}
			}
			for (int i = 0; i < _ringCount; i++)
			{
				_pattern.Add((1.0/_ringCount)*(i + 1));
			}
			for (int i = _ringCount - 1; i > 0; i--)
			{
				_pattern.Add((1.0 / _ringCount) * (i));
			}
			for (int j = 0; j < _ringCount; j++)
			{
				_pattern.Add(0.0);
			}
		}