Inheritance: INativeObject, IDisposable
Exemplo n.º 1
0
 public static void FillEllipsis(CGContext context, RectangleF rect, CGColor color, float lineWidth)
 {
     context.SaveState();
     context.SetFillColor(color);
     context.AddEllipseInRect(rect);
     context.FillPath();
     context.RestoreState();
 }
Exemplo n.º 2
0
 public static void FillRect(CGContext context, RectangleF rect, CGColor color)
 {
     context.SaveState();
     context.AddRect(rect);
     context.Clip();
     context.SetFillColor(color);
     context.FillRect(rect);
     context.RestoreState();
 }
Exemplo n.º 3
0
 public static void DrawEllipsis(CGContext context, RectangleF rect, CGColor color, float lineWidth)
 {
     context.SaveState();
     context.SetStrokeColor(color);
     context.SetLineWidth(lineWidth);
     context.AddEllipseInRect(rect);
     context.StrokePath();
     context.RestoreState();
 }
Exemplo n.º 4
0
 public static void DrawRect(CGContext context, RectangleF rect, CGColor color, float lineWidth)
 {
     context.SaveState();
     context.AddRect(rect);
     context.Clip();
     context.SetLineWidth(lineWidth);
     context.SetStrokeColor(color);
     context.StrokeRect(rect);
     context.RestoreState();
 }
Exemplo n.º 5
0
        private void Initialize()
        {
            TextColor = GlobalTheme.TableHeaderTextColor;
            BackgroundColor = GlobalTheme.TableHeaderBackgroundColor;
            BackgroundMouseDownColor = GlobalTheme.TableHeaderBackgroundMouseDownColor;
            BackgroundMouseOverColor = GlobalTheme.TableHeaderBackgroundMouseOverColor;
            BorderColor = GlobalTheme.TableHeaderBorderColor;

            // This allows MouseEntered and MouseExit to work
            AddTrackingRect(Bounds, this, IntPtr.Zero, false);
        }
Exemplo n.º 6
0
        public override bool Equals(object o)
        {
            CGColor other = o as CGColor;

            if (other == null)
            {
                return(false);
            }

            return(CGColorEqualToColor(this.handle, other.handle));
        }
Exemplo n.º 7
0
        private void Initialize()
        {
            RoundedRadius = 6;
            TextColor = GlobalTheme.ButtonTextColor;
            BackgroundColor = GlobalTheme.ButtonToolbarBackgroundColor;
            DisabledBackgroundColor = GlobalTheme.ButtonToolbarBackgroundColor;
            BackgroundMouseDownColor = GlobalTheme.ButtonToolbarBackgroundMouseDownColor;
            BackgroundMouseOverColor = GlobalTheme.ButtonToolbarBackgroundMouseOverColor;
            BorderColor = GlobalTheme.ButtonToolbarBorderColor;

            // This allows MouseEntered and MouseExit to work
            AddTrackingRect(Bounds, this, IntPtr.Zero, false);
        }
Exemplo n.º 8
0
        public CGColor(CGColor source, float alpha)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (source.handle == IntPtr.Zero)
            {
                throw new ObjectDisposedException("source");
            }

            handle = CGColorCreateCopyWithAlpha(source.handle, alpha);
        }
Exemplo n.º 9
0
		CALayer SetupBackgroundLayer() 
		{
			backgroundLayer = new CAGradientLayer ();
			
			CGColor gradColor1 = new CGColor (13.0f / 255.0f, 116.0f / 255.0f, 1.0f,1.0f);
			CGColor gradColor2 = new CGColor (0.0f, 53.0f / 255.0f, 126.0f / 255.0f,1.0f);
			
			((CAGradientLayer)backgroundLayer).Colors = new CGColor[2] { gradColor1, gradColor2 };
			backgroundLayer.CornerRadius = 12.0f;
			CAConstraintLayoutManager layout = CAConstraintLayoutManager.LayoutManager;
			backgroundLayer.LayoutManager = layout;
			
			return backgroundLayer;
		}
Exemplo n.º 10
0
 public static void DrawLine(CGContext context, PointF[] points, float lineWidth, CGColor color)
 {
     context.SaveState();
     var path = new CGPath();
     path.AddLines(points);
     context.AddPath(path);
     context.SetLineWidth(lineWidth);
     context.SetStrokeColor(color);
     context.StrokePath();
     context.RestoreState();
 }
Exemplo n.º 11
0
		public static Color Convert (CGColor color)
		{
			return new Color (color.Components [0], color.Components [1], color.Components [2], color.Alpha);
		}
Exemplo n.º 12
0
 public void SetShadowWithColor(SizeF offset, float blur, CGColor color)
 {
     CGContextSetShadowWithColor(handle, offset, blur, color.handle);
 }
Exemplo n.º 13
0
 public static void FillGradient(CGContext context, RectangleF rect, CGColor color1, CGColor color2, bool isHorizontal)
 {
     CGGradient gradientBackground;
     CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB();
     
     float[] locationListBackground = new float[] { 1.0f, 0.0f };
     List<float> colorListBackground = new List<float>();
     colorListBackground.AddRange(color1.Components);
     colorListBackground.AddRange(color2.Components);
     gradientBackground = new CGGradient(colorSpace, colorListBackground.ToArray(), locationListBackground);
     
     context.SaveState();
     context.AddRect(rect);
     context.Clip();
     //context.ScaleCTM(1, -1);
     if(isHorizontal)
         context.DrawLinearGradient(gradientBackground, new PointF(rect.X, rect.Y), new PointF(rect.X + rect.Width, rect.Y + rect.Height), CGGradientDrawingOptions.DrawsBeforeStartLocation);
     else
         context.DrawLinearGradient(gradientBackground, new PointF(0, 0), new PointF(0, rect.Height), CGGradientDrawingOptions.DrawsBeforeStartLocation);
     context.RestoreState();
 }       
Exemplo n.º 14
0
		public CGGradient (CGColorSpace colorspace, CGColor [] colors)
		{
			if (colors == null)
				throw new ArgumentNullException ("colors");
			
			IntPtr csh = colorspace == null ? IntPtr.Zero : colorspace.handle;
			using (var array = CFArray.FromNativeObjects (colors))
				handle = CGGradientCreateWithColors (csh, array.Handle, null);
		}
Exemplo n.º 15
0
		public void SetFillColorWithColor (CGColor color)
		{
			CGContextSetFillColorWithColor (handle, color.handle);
		}
		public override void AwakeFromNib ()
		{
			// Create the root layer
			rootLayer = new CALayer ();

			// Set the root layer;s background color to black
			rootLayer.BackgroundColor = new CGColor (0,0,0);

			// Create the fire emitter layer
			fireEmitter = new CAEmitterLayer ();
			fireEmitter.Position = new System.Drawing.PointF (225,50);
			fireEmitter.Mode = CAEmitterLayer.ModeOutline;
			fireEmitter.Shape = CAEmitterLayer.ShapeLine;
			fireEmitter.RenderMode = CAEmitterLayer.RenderAdditive;
			fireEmitter.Size = new SizeF (0,0);

			// Create the smoke emitter layer
			smokeEmitter = new CAEmitterLayer ();
			smokeEmitter.Position = new PointF (225,50);
			smokeEmitter.Mode = CAEmitterLayer.ModePoints;

			// Create the fire emitter cell
			CAEmitterCell fire = CAEmitterCell.EmitterCell ();
			fire.EmissionLongitude = (float)Math.PI;
			fire.BirthRate = 0;
			fire.Velocity = 80;
			fire.VelocityRange = 30;
			fire.EmissionRange = 1.1f;
			fire.AccelerationY = 200;
			fire.ScaleSpeed = 0.3f;

			RectangleF rect = RectangleF.Empty;
			CGColor color = new CGColor (0.8f,0.4f,0.2f,0.10f);
			fire.Color = color;
			fire.Contents = NSImage.ImageNamed ("fire.png").AsCGImage (ref rect, null, null);

			// Name the cell so that it can be animated later using keypaths
			fire.Name = "fire";

			// Add the fire emitter cell to the fire emitter layer
			fireEmitter.Cells = new CAEmitterCell[] { fire };

			//Create the smoke emitter cell
			CAEmitterCell smoke = CAEmitterCell.EmitterCell ();
			smoke.BirthRate = 11;
			smoke.EmissionLongitude = (float)Math.PI / 2;
			smoke.LifeTime = 0;
			smoke.Velocity = 40;
			smoke.VelocityRange = 20;
			smoke.EmissionRange = (float)Math.PI / 4;
			smoke.Spin = 1;
			smoke.SpinRange = 6;
			smoke.AccelerationY = 160;
			smoke.Scale = 0.1f;
			smoke.AlphaSpeed = -0.12f;
			smoke.ScaleSpeed = 0.7f;
			smoke.Contents = NSImage.ImageNamed ("smoke.png").AsCGImage (ref rect, null, null);
			//Name the cell so that it can be animated later using keypaths
			smoke.Name = "smoke";

			// Add the smoke emitter cell to the smoke emitter layer
			smokeEmitter.Cells = new CAEmitterCell[] { smoke };

			// Add the two emitter layers to the root layer
			rootLayer.AddSublayer (smokeEmitter);
			rootLayer.AddSublayer (fireEmitter);

			// Set the view's layer to the base layer
			view.Layer = rootLayer;
			view.WantsLayer = true;

			// Set the fire simulation to reflect the intial slider postion
			slidersChanged (this);

			// Force the view to update
			view.NeedsDisplay = true;

		}
		partial void slidersChanged (NSObject sender)
		{
			// Query the gasSlider's value
			float gas = gasSlider.IntValue / 100.0f;

			// Update the fire properties
			fireEmitter.SetValueForKeyPath ((NSNumber)(gas * 1000), (NSString)"emitterCells.fire.birthRate");
			fireEmitter.SetValueForKeyPath ((NSNumber)gas, (NSString)"emitterCells.fire.lifetime");
			fireEmitter.SetValueForKeyPath ((NSNumber)(gas * 0.35), (NSString)"emitterCells.fire.lifetimeRange");
			fireEmitter.Size = new SizeF (50 * gas, 0);
			
			// Update the smoke properties
			smokeEmitter.SetValueForKeyPath ((NSNumber)(gas * 4), (NSString)"emitterCells.smoke.lifetime");
			CGColor color = new CGColor (1,1,1,gas * 0.3f);
			smokeEmitter.SetValueForKeyPath(color.Handle, (NSString)"emitterCells.smoke.color");
		}
Exemplo n.º 18
0
		public static NSColor NSColorFromCGColor(CGColor cgColor)
		{
			return Messaging.GetNSObject<NSColor>(Messaging.IntPtr_objc_msgSend_IntPtr(NSColorClassPtr, selColorWithCGColor, cgColor.Handle));
		}
Exemplo n.º 19
0
 public static void StrokePath(CGContext context, CGPath path, float pathWidth, CGColor color)
 {
     context.SaveState();
     context.SetLineWidth(pathWidth);
     context.SetStrokeColor(color);
     context.AddPath(path);
     context.StrokePath();
     context.RestoreState();
 }
Exemplo n.º 20
0
		public static NSColor NSColorFromCGColor(CGColor cgColor)
		{
			NSApplication.EnsureUIThread();
			return Messaging.GetNSObject<NSColor>(Messaging.IntPtr_objc_msgSend_IntPtr(NSColorClassPtr, selColorWithCGColor, cgColor.Handle));
		}
Exemplo n.º 21
0
 public static void EOFillPath(CGContext context, CGPath path, CGColor color)
 {
     context.SaveState();
     context.SetFillColor(color);
     context.AddPath(path);
     context.EOFillPath();
     context.RestoreState();
 }
        private NSMutableAttributedString buildAttributedString(string text, Font font, StringFormat format = null, 
			Color? fontColor=null)
        {
            // Create a new attributed string definition
            var ctAttributes = new CTStringAttributes ();

            // Font attribute
            ctAttributes.Font = font.nativeFont;
            // -- end font

            if (format != null && (format.FormatFlags & StringFormatFlags.DirectionVertical) == StringFormatFlags.DirectionVertical)
            {
                //ctAttributes.VerticalForms = true;

            }

            if (fontColor.HasValue) {

                // Font color
                var fc = fontColor.Value;
                var cgColor = new CGColor(fc.R / 255f,
                    fc.G / 255f,
                    fc.B / 255f,
                    fc.A / 255f);

                ctAttributes.ForegroundColor = cgColor;
                ctAttributes.ForegroundColorFromContext = false;
                // -- end font Color
            }

            if (font.Underline) {
                // Underline
            #if MONOMAC
                int single = (int)MonoMac.AppKit.NSUnderlineStyle.Single;
                int solid = (int)MonoMac.AppKit.NSUnderlinePattern.Solid;
                var attss = single | solid;
                ctAttributes.UnderlineStyleValue = attss;
            #else
                ctAttributes.UnderlineStyleValue = 1;
            #endif
                // --- end underline
            }

            if (font.Strikeout) {
                // StrikeThrough
            #if MONOMAC
                int single = (int)MonoMac.AppKit.NSUnderlineStyle.Single;
                int solid = (int)MonoMac.AppKit.NSUnderlinePattern.Solid;
                var attss = single | solid;
                ctAttributes.UnderlineStyleValue = attss;
            #else
                ctAttributes.UnderlineStyleValue = 1;
            #endif

                // --- end StrikeThrough
            }

            var alignment = CTTextAlignment.Left;
            var alignmentSettings = new CTParagraphStyleSettings();
            alignmentSettings.Alignment = alignment;
            var paragraphStyle = new CTParagraphStyle(alignmentSettings);

            ctAttributes.ParagraphStyle = paragraphStyle;
            // end text alignment

            NSMutableAttributedString atts =
                new NSMutableAttributedString(text,ctAttributes.Dictionary);

            return atts;
        }
Exemplo n.º 23
0
		public void SetStrokeColorWithColor (CGColor color)
		{
			CGContextSetStrokeColorWithColor (handle, color.handle);
		}
Exemplo n.º 24
0
        public CGColor(CGColor source, float alpha)
        {
            if (source == null)
                throw new ArgumentNullException ("source");
            if (source.handle == IntPtr.Zero)
                throw new ObjectDisposedException ("source");

            handle = CGColorCreateCopyWithAlpha (source.handle, alpha);
        }
Exemplo n.º 25
0
		public void SetShadowWithColor (SizeF offset, float blur, CGColor color)
		{
			CGContextSetShadowWithColor (handle, offset, blur, color.handle);
		}
Exemplo n.º 26
0
 public void SetFillColorWithColor(CGColor color)
 {
     CGContextSetFillColorWithColor(handle, color.handle);
 }
Exemplo n.º 27
0
        public static void DrawLine(CGContext context, List<PointF> points, CGColor color, float lineWidth, bool closePath, bool dashed)
        {
            if (points == null)
                throw new NullReferenceException();

            if (points.Count == 0)
                throw new ArgumentException("The line must have at least one point.");

            context.SaveState();
            context.SetStrokeColor(color);
            context.SetLineWidth(lineWidth);
            context.MoveTo(points[0].X, points[0].Y);
            for(int a = 1; a < points.Count; a++)
                context.AddLineToPoint(points[a].X, points[a].Y);
            if (dashed)
                context.SetLineDash(0, new float[2] { 1, 2 }, 2);
            if (closePath)
                context.ClosePath();
            context.StrokePath();
            context.RestoreState();
        }
Exemplo n.º 28
0
 public void SetStrokeColorWithColor(CGColor color)
 {
     CGContextSetStrokeColorWithColor(handle, color.handle);
 }
        private static NSMutableAttributedString buildAttributedString(string text, Font font, 
		                                                        Color? fontColor=null)
        {
            // Create a new attributed string definition
            var ctAttributes = new CTStringAttributes ();

            // Font attribute
            ctAttributes.Font = font.nativeFont;
            // -- end font

            if (fontColor.HasValue) {

                // Font color
                var fc = fontColor.Value;
                var cgColor = new CGColor(fc.R / 255f,
                                          fc.G / 255f,
                                          fc.B / 255f,
                                          fc.A / 255f);

                ctAttributes.ForegroundColor = cgColor;
                ctAttributes.ForegroundColorFromContext = false;
                // -- end font Color
            }

            if (font.Underline) {
                // Underline
            #if MONOMAC
                int single = (int)MonoMac.AppKit.NSUnderlineStyle.Single;
                int solid = (int)MonoMac.AppKit.NSUnderlinePattern.Solid;
                var attss = single | solid;
                ctAttributes.UnderlineStyleValue = attss;
            #else
                ctAttributes.UnderlineStyleValue = 1;
            #endif
                // --- end underline
            }

            if (font.Strikeout) {
                // StrikeThrough
                //				NSColor bcolor = NSColor.Blue;
                //				NSObject bcolorObject = new NSObject(bcolor.Handle);
                //				attsDic.Add(NSAttributedString.StrikethroughColorAttributeName, bcolorObject);
                //				#if MACOS
                //				int stsingle = (int)MonoMac.AppKit.NSUnderlineStyle.Single;
                //				int stsolid = (int)MonoMac.AppKit.NSUnderlinePattern.Solid;
                //				var stattss = stsingle | stsolid;
                //				var stunderlineObject = NSNumber.FromInt32(stattss);
                //				#else
                //				var stunderlineObject = NSNumber.FromInt32 (1);
                //				#endif
                //
                //				attsDic.Add(StrikethroughStyleAttributeName, stunderlineObject);
                // --- end underline
            }

            // Text alignment
            var alignment = CTTextAlignment.Left;
            var alignmentSettings = new CTParagraphStyleSettings();
            alignmentSettings.Alignment = alignment;
            var paragraphStyle = new CTParagraphStyle(alignmentSettings);

            ctAttributes.ParagraphStyle = paragraphStyle;
            // end text alignment

            NSMutableAttributedString atts =
                new NSMutableAttributedString(text,ctAttributes.Dictionary);

            return atts;
        }
Exemplo n.º 30
0
        public override void DrawRect(RectangleF dirtyRect)
        {
            float padding = 4;
            CGContext context = NSGraphicsContext.CurrentContext.GraphicsPort;

            if (RoundedRadius == 0)
            {
                if (!Enabled)
                    CoreGraphicsHelper.FillRect(context, Bounds, DisabledBackgroundColor);
                else if (_isMouseDown)
                    CoreGraphicsHelper.FillRect(context, Bounds, BackgroundMouseDownColor);
                else if (_isMouseOver)
                    CoreGraphicsHelper.FillRect(context, Bounds, BackgroundMouseOverColor);
                else
                    CoreGraphicsHelper.FillRect(context, Bounds, BackgroundColor);

                CoreGraphicsHelper.DrawRect(context, Bounds, BorderColor, 2);
            } 
            else
            {
                var roundedPath = NSBezierPath.FromRoundedRect(Bounds, RoundedRadius, RoundedRadius);
                NSColor nsColor = null;
                if(!Enabled)
                    nsColor = NSColor.FromCIColor(CIColor.FromCGColor(DisabledBackgroundColor));
                else if (_isMouseDown)
                    nsColor = NSColor.FromCIColor(CIColor.FromCGColor(BackgroundMouseDownColor));
                else if (_isMouseOver)
                    nsColor = NSColor.FromCIColor(CIColor.FromCGColor(BackgroundMouseOverColor));
                else
                    nsColor = NSColor.FromCIColor(CIColor.FromCGColor(BackgroundColor));
                nsColor.SetFill();
                roundedPath.Fill();
            }

            //CoreGraphicsHelper.DrawRect(context, Bounds, BorderColor, 2);
            RectangleF rectTextSize = CoreGraphicsHelper.MeasureString(Bounds.Size, Title, "Roboto", 11);
            RectangleF rectText;
            if (Image != null)
            {
                float xImage = ((Bounds.Width - rectTextSize.Width - (padding * 2) - Image.Size.Width) / 2);
                RectangleF rectImage = new RectangleF(xImage, (Bounds.Height - Image.Size.Height) / 2, Image.Size.Width, Image.Size.Height);
                Image.DrawInRect(rectImage, new RectangleF(0, 0, Image.Size.Width, Image.Size.Height), NSCompositingOperation.SourceOver, 1.0f);

                float xText = xImage + padding + Image.Size.Width + padding;
                rectText = new RectangleF(xText, (Bounds.Height - rectTextSize.Height) / 2, rectTextSize.Width, rectTextSize.Height);
            } 
            else
            {
                rectText = new RectangleF(padding * 2, ((Bounds.Height - rectTextSize.Height) / 2) - 2, rectTextSize.Width, rectTextSize.Height);
            }

            CoreGraphicsHelper.DrawText(rectText, 0, 0, Title, "Roboto", 11, NSColor.White);

            var triangleColor = new CGColor(0.8f, 0.8f, 0.8f);
            float trianglePadding = 8;
            float triangleWidth = 8;
            var path = new CGPath();
            path.MoveToPoint(new PointF(Bounds.Width - trianglePadding, trianglePadding));
            path.AddLineToPoint(new PointF(Bounds.Width - trianglePadding - (triangleWidth / 2), Bounds.Height - trianglePadding));
            path.AddLineToPoint(new PointF(Bounds.Width - trianglePadding - triangleWidth, trianglePadding));
            path.AddLineToPoint(new PointF(Bounds.Width - trianglePadding, trianglePadding));

            CoreGraphicsHelper.StrokePath(context, path, 1, triangleColor);
            if(_isMouseOver)
                CoreGraphicsHelper.FillPath(context, path, triangleColor);
        }