Пример #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);
        }
Пример #2
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);
			}
		}