Exemple #1
0
        unsafe static void EvaluateCallback(IntPtr info, nfloat *input, nfloat *output)
        {
            GCHandle lgc       = GCHandle.FromIntPtr(info);
            var      container = lgc.Target as CGFunction;

            container?.evaluate?.Invoke(input, output);
        }
        unsafe static void EvaluateCallback(IntPtr info, nfloat *input, nfloat *output)
        {
            GCHandle   lgc       = GCHandle.FromIntPtr(info);
            CGFunction container = (CGFunction)lgc.Target;

            container.evaluate(input, output);
        }
 private static unsafe void SetColor(UGColor inColor, nfloat *outColor)
 {
     outColor[0] = (nfloat)inColor.R / 255;
     outColor[1] = (nfloat)inColor.G / 255;
     outColor[2] = (nfloat)inColor.B / 255;
     outColor[3] = (nfloat)inColor.A / 255;
 }
			public unsafe void Shading (nfloat* data, nfloat* outData)
			{
				var p = data[0];
				outData[0] = 0.0f;
				outData[1] = (1.0f-Slope(p, 2.0f)) * 0.5f;
				Shaded ();
			}
Exemple #5
0
        public static CGSize GetCGSize(IntPtr handle, string symbol)
        {
            var indirect = dlsym(handle, symbol);

            if (indirect == IntPtr.Zero)
            {
                return(CGSize.Empty);
            }
            unsafe {
                nfloat *ptr = (nfloat *)indirect;
                return(new CGSize(ptr [0], ptr [1]));
            }
        }
        public static CGRect GetRect(string symbol)
        {
            var indirect = Dlfcn.dlsym(Handle, symbol);

            if (indirect == IntPtr.Zero)
            {
                return(CGRect.Empty);
            }
            unsafe {
                nfloat *ptr = (nfloat *)indirect;
                return(new CGRect(ptr [0], ptr [1], ptr [2], ptr [3]));
            }
        }
Exemple #7
0
        public static void SetCGSize(IntPtr handle, string symbol, CGSize value)
        {
            var indirect = dlsym(handle, symbol);

            if (indirect == IntPtr.Zero)
            {
                return;
            }
            unsafe {
                nfloat *ptr = (nfloat *)indirect;
                ptr [0] = value.Width;
                ptr [1] = value.Height;
            }
        }
Exemple #8
0
        public static void SetNFloat(IntPtr handle, string symbol, nfloat value)
        {
            var indirect = dlsym(handle, symbol);

            if (indirect == IntPtr.Zero)
            {
                return;
            }

            unsafe {
                nfloat *ptr = (nfloat *)indirect;
                *       ptr = value;
            }
        }
        private static void CGFunctionBase(UGGradientStop[] stops, nfloat pos, nfloat *outData)
        {
            var first = stops.First();

            if (pos <= first.Offset + EPSILON)
            {
                SetColor(first.Color, outData);
                return;
            }

            var last = stops.Last();

            if (pos >= last.Offset - EPSILON)
            {
                SetColor(last.Color, outData);
                return;
            }

            var e = stops.GetEnumerator();

            e.MoveNext();
            var from = (UGGradientStop)e.Current;

            while (e.MoveNext())
            {
                var to = (UGGradientStop)e.Current;
                if (pos > from.Offset && pos <= to.Offset + EPSILON)
                {
                    var ratio = (pos - from.Offset) / (to.Offset - from.Offset);
                    SetMixedColor(ratio, from.Color, to.Color, outData);
                    return;
                }

                from = to;
            }
            //throw new InvalidOperationException();
        }
Exemple #10
0
        unsafe public void GradientLerp(nfloat *data, nfloat *outData)
        {
            nfloat lerpDist = *(nfloat *)data;

            int i = 0;

            int numPositions = positions.Length;

            // Make sure we put the linear distance value back into the 0.0 .. 1.0 range
            // depending on the wrap mode
            if (wrapMode == WrapMode.Tile || wrapMode == WrapMode.TileFlipY)
            {
                // Repeat
                lerpDist = lerpDist - (nfloat)NMath.Floor(lerpDist);
            }
            else
            {
                // Reflect
                lerpDist = (nfloat)NMath.Abs(lerpDist) % 2.0f;
                if (lerpDist > 1.0f)
                {
                    lerpDist = 2.0f - lerpDist;
                }
            }

            for (i = 0; i < numPositions; i++)
            {
                if (positions[i] > lerpDist)
                {
                    break;
                }
            }

            nfloat prevPosition = 0;
            nfloat dist         = 0;
            nfloat normalized   = 0;

            if (i == 0 || i == numPositions)
            {
                if (i == numPositions)
                {
                    --i;
                }

                // When we have multiple positions we need to interpolate the colors
                // between the two positions.
                // normalized will be the normalized [0,1] amount
                // of the gradiant area between the two positions.
                //
                // The shading colors have already
                // been setup with the color factors taken into account.

                // Get the distance between current position and last position
                dist = factors[i] - prevPosition;
                // normalized value between the two shading colors
                normalized = (nfloat)((lerpDist - prevPosition) / dist);
//				Console.WriteLine("prev {0} dist {1} normal {2} i {3} t {4}",
//				                  prevPosition, dist, normalized, i, t);
                for (ushort ctr = 0; ctr < 4; ctr++)
                {
                    outData[ctr] = GeomUtilities.Lerp(shadingColors[0, ctr],
                                                      shadingColors[1, ctr],
                                                      normalized);
                }
            }
            else
            {
                // When we have multiple positions we need to interpolate the colors
                // between the two positions.
                // normalized will be the normalized [0,1] amount
                // of the gradiant area between the two positions.
                //
                // The shading colors have already
                // been setup with the color factors taken into account.
                prevPosition = positions[i - 1];
                // Get the distance between current position and last position
                dist = positions[i] - prevPosition;
                // normalized value between the two shading colors
                normalized = (nfloat)((lerpDist - prevPosition) / dist);

                for (ushort ctr = 0; ctr < 4; ctr++)
                {
                    outData[ctr] = GeomUtilities.Lerp(shadingColors[i - 1, ctr],
                                                      shadingColors[i, ctr],
                                                      normalized);
                }
            }


            if (gammaCorrection)
            {
                // * NOTE * Here I am only computing the gamma correction for RGB values not alpha
                // I am really not sure if this is correct or not but from my reading on this topic
                // it is really never mentioned that alpha is included.
                for (ushort ctr = 0; ctr < 3; ctr++)
                {
                    outData[ctr] = (nfloat)Math.Pow(outData[ctr], gamma);
                }
            }

//			Console.WriteLine("R: {0}, G: {1}, B: {2}, A: {3}",
//			                  outData[0],
//			                  outData[1],
//			                  outData[2],
//			                  outData[3]);
        }
Exemple #11
0
 unsafe extern static CGRect DrawTiledRects(CGRect aRect, CGRect clipRect, NSRectEdge *sides, nfloat *grays, nint count);
 private static unsafe void SetMixedColor(nfloat ratio, UGColor inFromColor, UGColor inToColor, nfloat *outColor)
 {
     outColor[0] = (inFromColor.R + ratio * (inToColor.R - inFromColor.R)) / 255;
     outColor[1] = (inFromColor.G + ratio * (inToColor.G - inFromColor.G)) / 255;
     outColor[2] = (inFromColor.B + ratio * (inToColor.B - inFromColor.B)) / 255;
     outColor[3] = (inFromColor.A + ratio * (inToColor.A - inFromColor.A)) / 255;
 }
        private static void CGMirrorFunction(UGGradientStop[] stops, nfloat *data, nfloat *outData)
        {
            var pos = NMath.Abs(NMath.IEEERemainder(*data, 2));

            CGFunctionBase(stops, pos, outData);
        }
        private static void CGWrapFunction(UGGradientStop[] stops, nfloat *data, nfloat *outData)
        {
            var pos = *data % 1;

            CGFunctionBase(stops, pos, outData);
        }