public NSGradient(NSColor[] colors, float[] locations, NSColorSpace colorSpace) : base(NSObjectFlag.Empty)
        {
            if (colors == null)
            {
                throw new ArgumentNullException("colors");
            }
            if (locations == null)
            {
                throw new ArgumentNullException("locations");
            }
            if (colorSpace == null)
            {
                throw new ArgumentNullException("colorSpace");
            }

            var nsa_colorArray = NSArray.FromNSObjects(colors);

            int    size = Marshal.SizeOf(locations[0]) * locations.Length;
            IntPtr pNativeFloatArray = Marshal.AllocHGlobal(size);

            Marshal.Copy(locations, 0, pNativeFloatArray, locations.Length);

            if (IsDirectBinding)
            {
                Handle = MonoMac.ObjCRuntime.Messaging.IntPtr_objc_msgSend_IntPtr_IntPtr_IntPtr(this.Handle, selInitWithColorsAtLocationsColorSpace, nsa_colorArray.Handle, pNativeFloatArray, colorSpace.Handle);
            }
            else
            {
                Handle = MonoMac.ObjCRuntime.Messaging.IntPtr_objc_msgSendSuper_IntPtr_IntPtr_IntPtr(this.SuperHandle, selInitWithColorsAtLocationsColorSpace, nsa_colorArray.Handle, pNativeFloatArray, colorSpace.Handle);
            }
            nsa_colorArray.Dispose();
            Marshal.FreeHGlobal(pNativeFloatArray);
        }
Example #2
0
        unsafe void Initialize(NSColor[] colors, void *locationPtr, NSColorSpace colorSpace)
        {
            if (colors == null)
            {
                throw new ArgumentNullException("colors");
            }
            if (locationPtr == null)
            {
                throw new ArgumentNullException("locationPtr");
            }
            if (colorSpace == null)
            {
                throw new ArgumentNullException("colorSpace");
            }

            var nsa_colorArray = NSArray.FromNSObjects(colors);

            IntPtr locations = new IntPtr(locationPtr);

            if (IsDirectBinding)
            {
                Handle = ObjCRuntime.Messaging.IntPtr_objc_msgSend_IntPtr_IntPtr_IntPtr(this.Handle, selInitWithColorsAtLocationsColorSpace, nsa_colorArray.Handle, locations, colorSpace.Handle);
            }
            else
            {
                Handle = ObjCRuntime.Messaging.IntPtr_objc_msgSendSuper_IntPtr_IntPtr_IntPtr(this.SuperHandle, selInitWithColorsAtLocationsColorSpace, nsa_colorArray.Handle, locations, colorSpace.Handle);
            }
            nsa_colorArray.Dispose();
        }
Example #3
0
 public NSGradient(NSColor[] colors, double[] locations, NSColorSpace colorSpace) : base(NSObjectFlag.Empty)
 {
     unsafe
     {
         fixed(void *locationPtr = locations)
         {
             Initialize(colors, locationPtr, colorSpace);
         }
     }
 }
Example #4
0
 public NSGradient(NSColor[] colors, float[] locations, NSColorSpace colorSpace)
 {
     unsafe {
         double[] converted = Array.ConvertAll <float, double> (locations, new Converter <float, double> (a => (double)a));
         fixed(void *locationPtr = converted)
         {
             Initialize(colors, locationPtr, colorSpace);
         }
     }
 }
Example #5
0
        public static NSColor FromColorSpace(NSColorSpace space, nfloat [] components)
        {
            if (components == null)
            {
                throw new ArgumentNullException("components");
            }

            unsafe
            {
                fixed(nfloat *componentsptr = &components[0])
                {
                    return(_FromColorSpace(space, (IntPtr)componentsptr, components.Length));
                }
            }
        }
Example #6
0
		public static NSColor FromColorSpace (NSColorSpace space, float[] components)
		{
			if (components == null)
				throw new ArgumentNullException ("components");

			int size = Marshal.SizeOf(components[0]) * components.Length;
			IntPtr pNativeFloatArray = Marshal.AllocHGlobal(size);
			Marshal.Copy(components, 0, pNativeFloatArray, components.Length);

			NSColor color = _FromColorSpace (space, pNativeFloatArray, components.Length);

			Marshal.FreeHGlobal(pNativeFloatArray);

			return color;
		}
Example #7
0
 public NSGradient(NSColor[] colors, float[] locations, NSColorSpace colorSpace)
 {
     unsafe {
     #if ARCH_32
         fixed (void * locationPtr = locations) {
             Initialize (colors, locationPtr, colorSpace);
         }
     #else
         double[] converted = Array.ConvertAll<float, double> (locations, new Converter<float, double> (a => (double)a));
         fixed (void * locationPtr = converted) {
             Initialize (colors, locationPtr, colorSpace);
         }
     #endif
     }
 }
Example #8
0
 public NSGradient(NSColor[] colors, double[] locations, NSColorSpace colorSpace)
     : base(NSObjectFlag.Empty)
 {
     unsafe {
     #if ARCH_64
         fixed (void * locationPtr = locations) {
             Initialize (colors, locationPtr, colorSpace);
         }
     #else
         float[] converted = Array.ConvertAll<double, float> (locations, new Converter<double, float> (a => (float)a));
         fixed (void * locationPtr = converted) {
             Initialize (colors, locationPtr, colorSpace);
         }
     #endif
     }
 }
Example #9
0
        public static NSColor FromColorSpace(NSColorSpace space, nfloat [] components)
        {
            if (components == null)
            {
                throw new ArgumentNullException("components");
            }

            var pNativeFloatArray = IntPtr.Zero;

            try {
                pNativeFloatArray = Marshal.AllocHGlobal(components.Length * IntPtr.Size);
                nfloat.CopyArray(components, 0, pNativeFloatArray, components.Length);
                return(_FromColorSpace(space, pNativeFloatArray, components.Length));
            } finally {
                Marshal.FreeHGlobal(pNativeFloatArray);
            }
        }
Example #10
0
        public NSGradient(NSColor[] colors, double[] locations, NSColorSpace colorSpace) : base(NSObjectFlag.Empty)
        {
            unsafe {
#if ARCH_64
                fixed(void *locationPtr = locations)
                {
                    Initialize(colors, locationPtr, colorSpace);
                }
#else
                float[] converted = Array.ConvertAll <double, float> (locations, new Converter <double, float> (a => (float)a));
                fixed(void *locationPtr = converted)
                {
                    Initialize(colors, locationPtr, colorSpace);
                }
#endif
            }
        }
        public static NSColor FromColorSpace(NSColorSpace space, float[] components)
        {
            if (components == null)
            {
                throw new ArgumentNullException("components");
            }

            int    size = Marshal.SizeOf(components[0]) * components.Length;
            IntPtr pNativeFloatArray = Marshal.AllocHGlobal(size);

            Marshal.Copy(components, 0, pNativeFloatArray, components.Length);

            NSColor color = _FromColorSpace(space, pNativeFloatArray, components.Length);

            Marshal.FreeHGlobal(pNativeFloatArray);

            return(color);
        }
Example #12
0
        public static NSColor FromColorSpace(NSColorSpace space, nfloat [] components)
        {
            if (components == null)
                throw new ArgumentNullException ("components");

            var pNativeFloatArray = IntPtr.Zero;

            try {
                pNativeFloatArray = Marshal.AllocHGlobal (components.Length * IntPtr.Size);
            #if XAMCORE_2_0
                nfloat.CopyArray (components, 0, pNativeFloatArray, components.Length);
            #else
                Marshal.Copy (components, 0, pNativeFloatArray, components.Length);
            #endif
                return _FromColorSpace (space, pNativeFloatArray, components.Length);
            } finally {
                Marshal.FreeHGlobal (pNativeFloatArray);
            }
        }
Example #13
0
        public void ColorSpaceNoMainThread()
        {
            if (NSScreen.MainScreen == null)
            {
                Assert.Inconclusive("Could not find main screen.");
            }

            var          called     = new AutoResetEvent(false);
            NSColorSpace colorSpace = null;

            var backgroundThread = new Thread(() => {
                colorSpace = NSScreen.MainScreen.ColorSpace;
                called.Set();
            });

            backgroundThread.Start();
            Assert.IsTrue(called.WaitOne(1000), "called");
            Assert.IsNotNull(colorSpace, "colorSpace");
        }
        public void NSGradientConstructorTests()
        {
            NSColorSpace colorSpace = NSColorSpace.GenericRGBColorSpace;
            NSGradient   g          = new NSGradient(new[] { NSColor.Black, NSColor.White, NSColor.Black }, new[] { 0f, .5f, 1.0f }, colorSpace);

            Assert.IsNotNull(g);
            Assert.AreEqual(colorSpace, g.ColorSpace);
            Assert.AreEqual(3, g.ColorStopsCount);

            // Since we are asking for colors on a gradient, there will be some color blending, even with just black and white.
            const float closeEnough = .05f;
            NSColor     black       = NSColor.Black.UsingColorSpace(NSColorSpace.CalibratedRGB);
            NSColor     white       = NSColor.White.UsingColorSpace(NSColorSpace.CalibratedRGB);

            NSColor color;
            nfloat  location;

            g.GetColor(out color, out location, 0);
            color = color.UsingColorSpace(NSColorSpace.CalibratedRGB);
            Assert.IsTrue(black.RedComponent - color.RedComponent < closeEnough);
            Assert.IsTrue(black.BlueComponent - color.BlueComponent < closeEnough);
            Assert.IsTrue(black.GreenComponent - color.GreenComponent < closeEnough);
            Assert.AreEqual(0.0f, (float)location);

            g.GetColor(out color, out location, 1);
            color = color.UsingColorSpace(NSColorSpace.CalibratedRGB);
            Assert.IsTrue(white.RedComponent - color.RedComponent < closeEnough);
            Assert.IsTrue(white.BlueComponent - color.BlueComponent < closeEnough);
            Assert.IsTrue(white.GreenComponent - color.GreenComponent < closeEnough);
            Assert.AreEqual(0.5f, (float)location);

            g.GetColor(out color, out location, 2);
            color = color.UsingColorSpace(NSColorSpace.CalibratedRGB);
            Assert.IsTrue(black.RedComponent - color.RedComponent < closeEnough);
            Assert.IsTrue(black.BlueComponent - color.BlueComponent < closeEnough);
            Assert.IsTrue(black.GreenComponent - color.GreenComponent < closeEnough);
            Assert.AreEqual(1.0f, (float)location);
        }
Example #15
0
		public NSGradient (NSColor[] colors, float[] locations, NSColorSpace colorSpace) : base (NSObjectFlag.Empty)
		{
			if (colors == null)
				throw new ArgumentNullException ("colors");
			if (locations == null)
				throw new ArgumentNullException ("locations");
			if (colorSpace == null)
				throw new ArgumentNullException ("colorSpace");

			var nsa_colorArray = NSArray.FromNSObjects (colors);

        	int size = Marshal.SizeOf(locations[0]) * locations.Length;
        	IntPtr pNativeFloatArray = Marshal.AllocHGlobal(size);
			Marshal.Copy(locations,0, pNativeFloatArray, locations.Length);
			
			if (IsDirectBinding) {
				Handle = MonoMac.ObjCRuntime.Messaging.IntPtr_objc_msgSend_IntPtr_IntPtr_IntPtr (this.Handle, selInitWithColorsAtLocationsColorSpace, nsa_colorArray.Handle, pNativeFloatArray, colorSpace.Handle);
			} else {
				Handle = MonoMac.ObjCRuntime.Messaging.IntPtr_objc_msgSendSuper_IntPtr_IntPtr_IntPtr (this.SuperHandle, selInitWithColorsAtLocationsColorSpace, nsa_colorArray.Handle, pNativeFloatArray, colorSpace.Handle);
			}
			nsa_colorArray.Dispose ();
			Marshal.FreeHGlobal(pNativeFloatArray);
		}
Example #16
0
        unsafe void Initialize(NSColor[] colors, void * locationPtr, NSColorSpace colorSpace)
        {
            if (colors == null)
                throw new ArgumentNullException ("colors");
            if (locationPtr == null)
                throw new ArgumentNullException ("locationPtr");
            if (colorSpace == null)
                throw new ArgumentNullException ("colorSpace");

            var nsa_colorArray = NSArray.FromNSObjects (colors);

            IntPtr locations = new IntPtr (locationPtr);
            if (IsDirectBinding) {
                Handle = XamCore.ObjCRuntime.Messaging.IntPtr_objc_msgSend_IntPtr_IntPtr_IntPtr (this.Handle, selInitWithColorsAtLocationsColorSpace, nsa_colorArray.Handle, locations, colorSpace.Handle);
            } else {
                Handle = XamCore.ObjCRuntime.Messaging.IntPtr_objc_msgSendSuper_IntPtr_IntPtr_IntPtr (this.SuperHandle, selInitWithColorsAtLocationsColorSpace, nsa_colorArray.Handle, locations, colorSpace.Handle);
            }
            nsa_colorArray.Dispose ();
        }
Example #17
0
        public static Color ToColor(this UIColor color, NSColorSpace colorSpace)
        {
            var convertedColor = color.UsingColorSpace(colorSpace);

            return(convertedColor.ToColor());
        }