Example #1
0
		public MyView (RectangleF frame) : base (frame)
		{
			lineColor = NSColor.Blue;
			path = new NSBezierPath ();
			path.MoveTo (Bounds.Location);
			path.LineTo (new PointF (Bounds.GetMaxX (),Bounds.GetMaxY ()));
		}
Example #2
0
 internal static CGGradient CreateGraidentWithColors(NSColor startingColor, NSColor endingColor)
 {
     var locations = new[] { 0.0f, 1.0f };
     var cgStartingcolor = startingColor.CGColor;
     var cgEndingColor = endingColor.CGColor;
     var colors = new[] { cgStartingcolor, cgEndingColor };
     return new CGGradient(CGColorSpace.CreateDeviceRGB(), colors, locations);
 }
Example #3
0
File: Generator.cs Project: M1C/Eto
 public static Color Convert(NSColor color)
 {
     if (color == null)
         return Color.Black;
     float red, green, blue, alpha;
     color.GetRgba (out red, out green, out blue, out alpha);
     return new Color (red, green, blue, alpha);
 }
Example #4
0
		protected List<double> NSColorToXY (NSColor source)
		{
			var color = ColorService.XyFromColor ((int)(source.RedComponent * 255),
			                                      (int)(source.GreenComponent * 255),
			                                      (int)(source.BlueComponent * 255));

			return new List<double> { color.x, color.y };
		}
Example #5
0
        public static NSAttributedString CreateString(this string text, NSColor color, NSFont font)
        {
            NSObject[] objects = new NSObject[] { color, font };
            NSObject[] keys = new NSObject[] { NSAttributedString.ForegroundColorAttributeName, NSAttributedString.FontAttributeName };
            NSDictionary attributes = NSDictionary.FromObjectsAndKeys (objects, keys);

            return new NSAttributedString (text, attributes);
        }
Example #6
0
		public static NSImage Tint(this NSImage image, NSColor tint)
		{
			var colorGenerator = new CIConstantColorGenerator
			{ 
				Color = CIColor.FromCGColor(tint.CGColor)
			};

			var colorFilter = new CIColorControls
			{
				Image = (CIImage)colorGenerator.ValueForKey(CIFilterOutputKey.Image),
				Saturation = 3f,
				Brightness = 0.35f,
				Contrast = 1f
			};

			var monochromeFilter = new CIColorMonochrome
			{
				Image = CIImage.FromCGImage(image.CGImage),
				Color = CIColor.FromRgb(0.75f, 0.75f, 0.75f),
				Intensity = 1f
			};

			var compositingFilter = new CIMultiplyCompositing
			{
				Image = (CIImage)colorFilter.ValueForKey(CIFilterOutputKey.Image),
				BackgroundImage = (CIImage)monochromeFilter.ValueForKey(CIFilterOutputKey.Image)
			};

			var outputImage = (CIImage)compositingFilter.ValueForKey(CIFilterOutputKey.Image);
			var extent = outputImage.Extent;

			var newsize = Size.Truncate(extent.Size.ToEto());
			if (newsize.IsEmpty)
				return image;

			var tintedImage = new NSImage(newsize.ToNS());
			tintedImage.LockFocus();
			try
			{
				var graphics = NSGraphicsContext.CurrentContext.GraphicsPort;
				var ciContext = CIContext.FromContext(graphics, new CIContextOptions { UseSoftwareRenderer = true });
				ciContext.DrawImage(outputImage, extent, extent);
			}
			finally
			{
				tintedImage.UnlockFocus();
			}

			var newrep = tintedImage.Representations()[0];
			newrep.Size = image.Size;
			tintedImage.Size = image.Size;
			return tintedImage;
		}
		public override void DrawRect (RectangleF dirtyRect)
		{
			RectangleF bounds = Bounds;
			SizeF stripeSize = bounds.Size;
			stripeSize.Width = bounds.Width / 10.0f;
			RectangleF stripe = bounds;
			stripe.Size = stripeSize;
			NSColor[] colors = new NSColor[2] { NSColor.White, NSColor.Blue };
			for (int i = 0; i < 10; i++){
				colors[i % 2].Set();
				NSGraphics.RectFill(stripe);
				PointF origin = stripe.Location;
				origin.X += stripe.Size.Width;
				stripe.Location = origin;
			}
		}
Example #8
0
		public static NSImage Tint(this NSImage image, NSColor tint)
		{
			CIFilter colorGenerator = CIFilter.FromName("CIConstantColorGenerator");
			CIColor color = CIColor.FromCGColor(tint.ToCG());

			colorGenerator.SetValueForKey(color, CIFilterInputKey.Color);
			CIFilter colorFilter = CIFilter.FromName("CIColorControls");

			colorFilter.SetValueForKey(colorGenerator.ValueForKey(CIFilterOutputKey.Image), CIFilterInputKey.Image);
			colorFilter.SetValueForKey(NSNumber.FromFloat(3f), CIFilterInputKey.Saturation);
			colorFilter.SetValueForKey(NSNumber.FromFloat(0.35f), CIFilterInputKey.Brightness);
			colorFilter.SetValueForKey(NSNumber.FromFloat(1f), CIFilterInputKey.Contrast);

			CIFilter monochromeFilter = CIFilter.FromName("CIColorMonochrome");
			CIImage baseImage = CIImage.FromCGImage(image.CGImage);

			monochromeFilter.SetValueForKey(baseImage, CIFilterInputKey.Image);
			monochromeFilter.SetValueForKey(CIColor.FromRgb(0.75f, 0.75f, 0.75f), CIFilterInputKey.Color);
			monochromeFilter.SetValueForKey(NSNumber.FromFloat(1f), CIFilterInputKey.Intensity);

			CIFilter compositingFilter = CIFilter.FromName("CIMultiplyCompositing");

			compositingFilter.SetValueForKey(colorFilter.ValueForKey(CIFilterOutputKey.Image), CIFilterInputKey.Image);
			compositingFilter.SetValueForKey(monochromeFilter.ValueForKey(CIFilterOutputKey.Image), CIFilterInputKey.BackgroundImage);

			CIImage outputImage = (CIImage)compositingFilter.ValueForKey(CIFilterOutputKey.Image);
			var extent = outputImage.Extent;

			var newsize = sd.Size.Truncate(extent.Size);

			var tintedImage = new NSImage(newsize);
			var newrep = new NSBitmapImageRep(IntPtr.Zero, newsize.Width, newsize.Height, 8, 4, true, false, NSColorSpace.DeviceRGB, 4 * newsize.Width, 32);
			tintedImage.AddRepresentation(newrep);

			var graphics = NSGraphicsContext.FromBitmap(newrep);
			NSGraphicsContext.GlobalSaveGraphicsState();
			NSGraphicsContext.CurrentContext = graphics;

			var ciContext = CIContext.FromContext(graphics.GraphicsPort, new CIContextOptions { UseSoftwareRenderer = true });
			ciContext.DrawImage(outputImage, extent, extent);

			NSGraphicsContext.GlobalRestoreGraphicsState();

			newrep.Size = image.Size;
			return tintedImage;
		}
Example #9
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 #10
0
		public NSGradient (NSColor[] colors, float[] locations) : 
			this(colors, locations, NSColorSpace.GenericRGBColorSpace)
		{
		}
Example #11
0
		private void DrawLine(NSColor color, float x1, float y1, float x2, float y2)
		{
			DrawLine(color, new PointF(x1,y1), new PointF(x2,y2));
		}
Example #12
0
        public override void DrawImage(NSImage image, System.Drawing.RectangleF frame, NSView controlView)
        {
            var context = NSGraphicsContext.CurrentContext.GraphicsPort;

            var darkHighlight = NSColor.FromCalibratedRgba (0.931f, 0.931f, 0.931f, 1.0f);
            var innerBoxShadowColor = NSColor.FromCalibratedRgba (0.896f, 0.896f, 0.896f, 1.0f);
            var switchInnerFillEnabledColor1 = NSColor.FromCalibratedRgba (0.215f, 0.447f, 0.668f, 1.0f);
            var switchInnerFillEnabledColor2 = NSColor.FromCalibratedHsba (switchInnerFillEnabledColor1.HueComponent,
                                                                           switchInnerFillEnabledColor1.SaturationComponent, 1,
                                                                           switchInnerFillEnabledColor1.AlphaComponent);

            var switchInnerFillGradient = new NSGradient (NSColor.DarkGray, NSColor.Gray);
            var buttonFillGradientColors = new NSColor[] { innerBoxShadowColor, NSColor.FromCalibratedRgba(0.948f, 0.948f, 0.948f, 1.0f), NSColor.White };
            var buttonFillGradientPositions = new float[] { 0.0f, 0.25f, 0.51f };
            var switchButtonFillGradient = new NSGradient (buttonFillGradientColors, buttonFillGradientPositions);
            var switchInnerFillEnabledGradient = new NSGradient (new NSColor[] { switchInnerFillEnabledColor1, switchInnerFillEnabledColor2 }, new float[] { 0.0f, 1.0f});

            var switchBoxInnerShadow = new NSShadow ();
            switchBoxInnerShadow.ShadowColor = NSColor.Black;
            switchBoxInnerShadow.ShadowOffset = new SizeF (0.1f, 0.1f);
            switchBoxInnerShadow.ShadowBlurRadius = 5;

            var switchButtonShadow = new NSShadow ();
            switchButtonShadow.ShadowColor = NSColor.DarkGray;
            switchButtonShadow.ShadowOffset = new SizeF (0.1f, 0.1f);
            switchButtonShadow.ShadowBlurRadius = 2;

            var switchFrame =  new RectangleF(frame.X, frame.Y, 69, 28);

            var switchBoxPath = NSBezierPath.FromRoundedRect (new RectangleF (switchFrame.X + 12.5f, switchFrame.Y + switchFrame.Height - 23.5f, 49, 20), 9, 9);

            var gradientToUse = IntValue > 0 ? switchInnerFillEnabledGradient : switchInnerFillGradient;
            gradientToUse.DrawInBezierPath (switchBoxPath, -90);

            var switchBoxBorderRect = switchBoxPath.Bounds;
            switchBoxBorderRect.Inflate (switchBoxInnerShadow.ShadowBlurRadius, switchBoxInnerShadow.ShadowBlurRadius);
            switchBoxBorderRect.Offset (-switchBoxInnerShadow.ShadowOffset.Width, -switchBoxInnerShadow.ShadowOffset.Height);
            switchBoxBorderRect = RectangleF.Union (switchBoxBorderRect, switchBoxPath.Bounds);
            switchBoxBorderRect.Inflate (1, 1);

            var switchBoxNegativePath = NSBezierPath.FromRoundedRect (switchBoxBorderRect, 0, 0);
            switchBoxNegativePath.AppendPath (switchBoxPath);
            switchBoxNegativePath.WindingRule = NSWindingRule.EvenOdd;

            context.SaveState ();

            var switchBoxInnerShadowOffset = new SizeF(0.1f, -1.1f);
            var xOffset = switchBoxInnerShadowOffset.Width + (float)Math.Round(switchBoxBorderRect.Width);
            var yOffset = switchBoxInnerShadowOffset.Height;
            NSShadow switchBoxInnerShadowWithOffset = (NSShadow)switchBoxInnerShadow.Copy ();
            switchBoxInnerShadowWithOffset.ShadowOffset = new SizeF (xOffset + (xOffset >= 0 ? 0.1f : -0.1f), yOffset + (yOffset >= 0 ? 0.1f : -0.1f));
            switchBoxInnerShadowWithOffset.Set ();

            NSColor.Gray.SetFill ();
            switchBoxPath.AddClip ();

            var transform = new NSAffineTransform ();
            transform.Translate (-(float)Math.Round (switchBoxBorderRect.Width), 0);
            transform.TransformBezierPath (switchBoxNegativePath).Fill ();

            context.RestoreState ();

            NSColor.WindowFrame.SetStroke ();
            switchBoxPath.LineWidth = 0.5f;
            switchBoxPath.Stroke ();

            // Switch label drawing

            var labelPosition = IntValue > 0 ? 19 : 32;
            var switchLabelRect = new RectangleF (switchFrame.X + labelPosition, switchFrame.Y + switchFrame.Height - 20, 22, 15);
            NSMutableParagraphStyle switchLabelStyle = (NSMutableParagraphStyle)NSMutableParagraphStyle.DefaultParagraphStyle.MutableCopy ();
            switchLabelStyle.Alignment = NSTextAlignment.Center;
            var switchLabelFontAttributes = NSDictionary.FromObjectsAndKeys (
                new NSObject[] { NSFont.FromFontName("Helvetica-Bold", NSFont.SmallSystemFontSize), darkHighlight, switchLabelStyle },
                new NSObject[] { NSAttributedString.FontAttributeName, NSAttributedString.ForegroundColorAttributeName, NSAttributedString.ParagraphStyleAttributeName });

            var labelText = IntValue > 0 ? "On" : "Off";
            new NSString (labelText).DrawString (switchLabelRect, switchLabelFontAttributes);

            // Switch Button
            var position = this.IntValue > 0 ? 43.0f : 10.0f;
            var switchButtonPath = NSBezierPath.FromOvalInRect (new RectangleF (switchFrame.X + position, switchFrame.Y + switchFrame.Height - 24, 21, 21));

            context.SaveState ();
            switchButtonShadow.Set ();
            context.BeginTransparencyLayer (null);
            switchButtonFillGradient.DrawInBezierPath (switchButtonPath, 135.0f);
            context.EndTransparencyLayer ();
            context.RestoreState ();

            context.SaveState ();
            switchButtonShadow.Set ();
            NSColor.DarkGray.SetStroke ();
            switchButtonPath.LineWidth = 0.5f;
            switchButtonPath.Stroke ();
            context.RestoreState ();
        }
Example #13
0
 private void CommonInit()
 {
     BackgroundColor = NSColor.Black;
 }
Example #14
0
		public static CGColor ConvertNSToCG (NSColor color)
		{
			var cs = NSColorSpace.DeviceRGBColorSpace;

			var devColor = color.UsingColorSpace (cs);
			float[] components;
			devColor.GetComponents (out components);
			return new CGColor(cs.ColorSpace, components);
		}
		public CustomCatTextAttachmentCell (NSImage image) : base (image)
		{
			borderColor = NSColor.FromDeviceHsba ((float)random.NextDouble (), 1f, 1f, 1f);
		}
Example #16
0
		private void DrawStringOutline(string text, NSColor color, RectangleF rect, int align)
		{
			NSString nsString = new NSString (text);

			int halign = align % 3;
			int valign = align / 3;


			var objectsText = new object[] { m_font, color };
			var keysText = new object[] { NSAttributedString.FontAttributeName, NSAttributedString.ForegroundColorAttributeName };
			var attributesText = NSDictionary.FromObjectsAndKeys(objectsText, keysText);

			var objectsOutline = new object[] { m_font, NSColor.White };
			var keysOutline = new object[] { NSAttributedString.FontAttributeName, NSAttributedString.ForegroundColorAttributeName };
			var attributesOutline = NSDictionary.FromObjectsAndKeys(objectsOutline, keysOutline);


			SizeF size = nsString.StringSize (attributesText);

			if (halign == 0) {
			} else if (halign == 1) {
				rect.X = (rect.Left + rect.Right) / 2 - size.Width / 2;
			} else if (halign == 2) {
				rect.X = rect.Right - size.Width;
			}
			rect.Width = size.Width;

			if (valign == 0) {
			} else if (valign == 1) {
				rect.Y = (rect.Top + rect.Bottom) / 2 - size.Height / 2;
			} else if (valign == 2) {
				rect.Y = rect.Bottom - size.Height;
			}
			rect.Height = size.Height;

			NSColor.Black.Set ();
			for (int ox = -1; ox <= 1; ox++) {
				for (int oy = -1; oy <= 1; oy++) {
					RectangleF rectString = rect;
					rectString.Offset (new PointF (ox, oy));
					nsString.DrawString (Invert (rectString), attributesOutline);
				}
			}
			nsString.DrawString(Invert(rect), attributesText);
		}
Example #17
0
		public override void AwakeFromNib ()
		{
			base.AwakeFromNib ();

			m_colorBackground = GuiUtils.ConvertColor(Colors.LightChartBackground);
			m_colorGrid = GuiUtils.ConvertColor(Colors.LightChartGrid);
			m_colorAxis = GuiUtils.ConvertColor (Colors.LightChartAxis);
			m_colorMouse = GuiUtils.ConvertColor(Colors.LightChartMouse);
			m_colorDownloadGraph = GuiUtils.ConvertColor(Colors.LightChartLineDownload);
			m_colorDownloadLine = GuiUtils.ConvertColor(Colors.LightChartLineDownload);
			m_colorUploadGraph = GuiUtils.ConvertColor(Colors.LightChartLineUpload);
			m_colorUploadLine = GuiUtils.ConvertColor(Colors.LightChartLineUpload);
			//m_colorLegendText = GuiUtils.ConvertColor(Colors.LightChartLegend);
			m_colorDownloadText = GuiUtils.ConvertColor(Colors.LightChartLineDownload);
			m_colorUploadText = GuiUtils.ConvertColor(Colors.LightChartLineUpload);

			m_font = NSFont.FromFontName ("Menlo", 10);

			m_chart = Engine.Instance.Stats.Charts.ChartsList[m_chartIndex];

			Engine.Instance.Stats.Charts.UpdateEvent += new Core.UI.Charts.UpdateHandler(Charts_UpdateEvent);

		}
		public void AppendLine (NSColor color, string text)
		{
			InvokeOnMainThread (() => DoAppend (color, text + Environment.NewLine));
		}
Example #19
0
 public static void DrawTextInRect(CGContext context, RectangleF rect, string text, string fontName, float fontSize, NSColor fontColor)
 {
     context.SaveState();
     NSString str = new NSString(text);
     var dict = new NSMutableDictionary();
     dict.Add(NSAttributedString.ForegroundColorAttributeName, fontColor);
     dict.Add(NSAttributedString.FontAttributeName, NSFont.FromFontName(fontName, fontSize));
     str.DrawString(rect, dict);
     context.RestoreState();
 }
Example #20
0
		public ColorRect (RectangleF frame, NSColor color) 
		{
			Frame = frame;
			Color = color;
		}
Example #21
0
 public static NSAttributedString CreateString(this string text, NSColor color)
 {
     var defaults = new DefaultSettings ();
     return CreateString (text, color, defaults.Font);
 }
		void DoAppend (NSColor color, string text)
		{
			var pos = Storage.Length;
			Storage.Append (new NSAttributedString (text));
			var range = new NSRange (pos, text.Length);
			Text.SetFont (font, range);
			Text.SetTextColor (color, range);
		}
Example #23
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);
		}
Example #24
0
		private void DrawLine(NSColor color, PointF p1, PointF p2)
		{
			color.Set();
			NSBezierPath.StrokeLine (Invert(p1), Invert(p2));
		}
Example #25
0
 public static void DrawText(RectangleF rect, float x, float y, string text, string fontName, float fontSize, NSColor fontColor)
 {
     NSMutableDictionary dict = new NSMutableDictionary();
     dict.Add(NSAttributedString.FontAttributeName, NSFont.FromFontName(fontName, fontSize));
     dict.Add(NSAttributedString.ForegroundColorAttributeName, fontColor);
     NSString nsstr = new NSString(text);
     RectangleF rectBounds = nsstr.BoundingRectWithSize(new SizeF(rect.Width, rect.Height), NSStringDrawingOptions.UsesFontLeading | NSStringDrawingOptions.UsesLineFragmentOrigin, dict);
     rectBounds.X = rect.X + x;
     rectBounds.Y = rect.Y + y;
     nsstr.DrawString(rectBounds, NSStringDrawingOptions.UsesFontLeading | NSStringDrawingOptions.UsesLineFragmentOrigin, dict);
 }
 private static ColorF ToNexusColor(NSColor c)
 {
     return new ColorF(c.AlphaComponent, c.RedComponent, c.GreenComponent, c.BlueComponent);
 }