Ejemplo n.º 1
0
        public UGRadialGradientBrush(IUGContext context, Vector2 center, float radius, IEnumerable <UGGradientStop> gradientStops, UGEdgeBehavior edgeBehavior)
        {
            Center       = center;
            Radius       = radius;
            EdgeBehavior = edgeBehavior;
            Stops        = gradientStops.ToArray();

            if (Stops.Length < 2)
            {
                throw new ArgumentException(nameof(gradientStops));
            }

            unsafe
            {
                var baseFunction = CGFunctionsHelper.GetCGFunction(EdgeBehavior);
                CGFunction.CGFunctionEvaluate function = (data, outData) => baseFunction(Stops, data, outData);
                var domain = new nfloat[] { 0, edgeBehavior != UGEdgeBehavior.Clamp ? 1.5F : 1 };
                _function = new CGFunction(domain, new nfloat[] { 0, 1, 0, 1, 0, 1, 0, 1 }, function);
            }

            var cgCenter = Center.ToCGPoint();
            var cgRadius = EdgeBehavior != UGEdgeBehavior.Clamp ? 1.5F * Radius : Radius;

            using (var colorSpace = CGColorSpace.CreateSrgb())
            {
                _native = CGShading.CreateRadial(colorSpace, cgCenter, 0F, cgCenter, cgRadius, _function, true, true);
            }
        }