Beispiel #1
0
        public static Color ToColor(this NSColor color)
        {
            nfloat red, green, blue, alpha;

            color.GetRgba(out red, out green, out blue, out alpha);
            return(new Color((double)red, (double)green, (double)blue, (double)alpha));
        }
Beispiel #2
0
        public static CGColor ToCGColor(this NSColor nsColor)
        {
            float r, g, b, a;

            nsColor.GetRgba(out r, out g, out b, out a);
            return(new CGColor(r, g, b, a));
        }
Beispiel #3
0
        public static Color ConvertColor(NSColor color)
        {
            nfloat r, g, b, a;

            color.GetRgba(out r, out g, out b, out a);
            return(new Color((float)r, (float)g, (float)b, (float)a));
        }
Beispiel #4
0
        public static Color GetColor(this NSColor c)
        {
            nfloat r, g, b, a;

            c.GetRgba(out r, out g, out b, out a);
            return(new Color((int)(r * 255 + 0.5f), (int)(g * 255 + 0.5f), (int)(b * 255 + 0.5f), (int)(a * 255 + 0.5f)));
        }
Beispiel #5
0
        public static Color ToEto(this NSColor color)
        {
            if (color == null)
            {
                return(Colors.Black);
            }
            float red, green, blue, alpha;

            color.GetRgba(out red, out green, out blue, out alpha);
            return(new Color(red, green, blue, alpha));
        }
Beispiel #6
0
        public static Color ToEto(this NSColor color)
        {
            if (color == null)
            {
                return(Colors.Black);
            }
            //if (color.ColorSpace.ColorSpaceModel != NSColorSpaceModel.RGB)
            color = color.UsingColorSpace(NSColorSpace.CalibratedRGB);
            nfloat red, green, blue, alpha;

            color.GetRgba(out red, out green, out blue, out alpha);
            return(new Color((float)red, (float)green, (float)blue, (float)alpha));
        }
        /// <summary>
        /// Converts from a UIColor to a DSColor object
        /// </summary>
        /// <returns>The DS color.</returns>
        /// <param name="aColor">A color.</param>
        public static DSColor ToDSColor(this NSColor aColor)
        {
            nfloat red   = 0.0f;
            nfloat blue  = 0.0f;
            nfloat green = 0.0f;
            nfloat alpha = 0.0f;

            aColor.GetRgba(out red, out green, out blue, out alpha);

            var aNewColor = new DSColor((float)red, (float)green, (float)blue, (float)alpha);

            return(aNewColor);
        }
Beispiel #8
0
        static Cairo.Color ConvertColor(NSColor color)
        {
            float r, g, b, a;

            if (color.ColorSpaceName == NSColorSpace.DeviceWhite)
            {
                a = 1.0f;
                r = g = b = color.WhiteComponent;
            }
            else
            {
                color.GetRgba(out r, out g, out b, out a);
            }
            return(new Cairo.Color(r, g, b, a));
        }
Beispiel #9
0
        static string ConvertColorToHex(NSColor color)
        {
            nfloat r, g, b, a;

            if (color.ColorSpaceName == NSColorSpace.DeviceWhite)
            {
                a = 1.0f;
                r = g = b = color.WhiteComponent;
            }
            else
            {
                color.GetRgba(out r, out g, out b, out a);
            }

            return(String.Format("#{0}{1}{2}",
                                 ((int)(r * 255)).ToString("x2"),
                                 ((int)(g * 255)).ToString("x2"),
                                 ((int)(b * 255)).ToString("x2")
                                 ));
        }
Beispiel #10
0
        // Gets the string for the text field from the object passed in.
        public override string StringFor(NSObject value)
        {
            // Not a color?
            if (value.GetType() != typeof(NSColor))
            {
                return(null);
            }

            // Convert to an RGB color space
            NSColor color = ((NSColor)value).UsingColorSpace(NSColorSpace.CalibratedRGB);

            // Get components as floats between 0 and 1
            nfloat red, green, blue, alpha;

            color.GetRgba(out red, out green, out blue, out alpha);

            // Initialize the distance to something large
            double minDistance = 3.0f;
            string closestKey  = "";

            // Find the closest color
            foreach (string key in colorList.AllKeys())
            {
                NSColor c = colorList.ColorWithKey(key);
                nfloat  r, g, b, a;
                c.GetRgba(out r, out g, out b, out a);

                // How far apart are color and c?
                double distance = (Math.Pow(red - r, 2) + Math.Pow(green - g, 2) + Math.Pow(blue - b, 2));
                // Is this the closest yet?
                if (distance < minDistance)
                {
                    minDistance = distance;
                    closestKey  = key;
                }
            }
            return(closestKey);
        }
Beispiel #11
0
        /// <summary>
        /// Converts the given color into a web style hex string in the form #RRBBGG or optionally #RRBBGGAA.
        /// </summary>
        /// <returns>The web hex string representing the given color.</returns>
        /// <param name="color">The <c>NSColor</c> to convert.</param>
        /// <param name="withAlpha">If set to <c>true</c> with the alpha (transparency) of the color will be
        /// included.</param>
        public string NSColorToHexString(NSColor color, bool withAlpha)
        {
            //Break color into pieces
            nfloat red = 0, green = 0, blue = 0, alpha = 0;

            color.GetRgba(out red, out green, out blue, out alpha);

            // Adjust to byte
            alpha *= 255;
            red   *= 255;
            green *= 255;
            blue  *= 255;

            //With the alpha value?
            if (withAlpha)
            {
                return(String.Format("#{0:X2}{1:X2}{2:X2}{3:X2}", (int)alpha, (int)red, (int)green, (int)blue));
            }
            else
            {
                return(String.Format("#{0:X2}{1:X2}{2:X2}", (int)red, (int)green, (int)blue));
            }
        }
Beispiel #12
0
        // NSColor

        public static SKColor ToSKColor(this NSColor color)
        {
            System.nfloat r, g, b, a;
            color.GetRgba(out r, out g, out b, out a);
            return(new SKColor((byte)(r * 255), (byte)(g * 255), (byte)(b * 255), (byte)(a * 255)));
        }
Beispiel #13
0
		static string ConvertColorToHex (NSColor color)
		{
			nfloat r, g, b, a;

			if (color.ColorSpaceName == NSColorSpace.DeviceWhite) {
				a = 1.0f;
				r = g = b = color.WhiteComponent;
			} else {
				color.GetRgba (out r, out g, out b, out a);
			}

			return String.Format ("#{0}{1}{2}",
				((int)(r * 255)).ToString ("x2"),
				((int)(g * 255)).ToString ("x2"),
				((int)(b * 255)).ToString ("x2")
			);
		}
Beispiel #14
0
		static Cairo.Color ConvertColor (NSColor color)
		{
			nfloat r, g, b, a;
			if (color.ColorSpaceName == NSColorSpace.DeviceWhite) {
				a = 1.0f;
				r = g = b = color.WhiteComponent;
			} else {
				color.GetRgba (out r, out g, out b, out a);
			}
			return new Cairo.Color (r, g, b, a);
		}
Beispiel #15
0
 public static SKColorF ToSKColorF(this NSColor color)
 {
     System.nfloat r, g, b, a;
     color.GetRgba(out r, out g, out b, out a);
     return(new SKColorF((float)r, (float)g, (float)b, (float)a));
 }
Beispiel #16
0
		/// <summary>
		/// Converts the given color into a web style hex string in the form #RRBBGG or optionally #RRBBGGAA.
		/// </summary>
		/// <returns>The web hex string representing the given color.</returns>
		/// <param name="color">The <c>NSColor</c> to convert.</param>
		/// <param name="withAlpha">If set to <c>true</c> with the alpha (transparency) of the color will be
		/// included.</param>
		public string NSColorToHexString(NSColor color, bool withAlpha) {
			//Break color into pieces
			nfloat red=0, green=0, blue=0, alpha=0;
			color.GetRgba (out red, out green, out blue, out alpha);

			// Adjust to byte
			alpha *= 255;
			red *= 255;
			green *= 255;
			blue *= 255;

			//With the alpha value?
			if (withAlpha) {
				return String.Format ("#{0:X2}{1:X2}{2:X2}{3:X2}", (int)alpha, (int)red, (int)green, (int)blue);
			} else {
				return String.Format ("#{0:X2}{1:X2}{2:X2}", (int)red, (int)green, (int)blue);
			}
		}