Ejemplo n.º 1
0
 public void Fill(object backend)
 {
     var ctx = GetContext (backend);
     if (ctx.Pattern is GradientInfo) {
         GradientInfo gr = (GradientInfo) ctx.Pattern;
         NSGradient g = new NSGradient (gr.Colors.ToArray (), gr.Stops.ToArray ());
         g.DrawInBezierPath (ctx.Path, 0f);
     }
     else if (ctx.Pattern is NSColor) {
         NSColor col = (NSColor) ctx.Pattern;
         col.Set ();
         col.SetFill ();
     }
     else {
         ctx.Path.Fill ();
     }
     ctx.Pattern = null;
     ctx.Path.Dispose ();
     ctx.Path = new NSBezierPath ();
 }
Ejemplo n.º 2
0
        public override void DrawRect(RectangleF dirtyRect)
        {
            var context = NSGraphicsContext.CurrentContext.GraphicsPort;

            var innerBoxShadowColor = NSColor.FromCalibratedRgba (0.896f, 0.896f, 0.896f, 1.0f);
            var darkHighlight = NSColor.FromCalibratedRgba (0.931f, 0.931f, 0.931f, 1.0f);
            var boxBackgroundColor = NSColor.FromCalibratedRgba (1.0f, 1.0f, 1.0f, 0.5f);

            var headingGradient = new NSGradient (
                new NSColor[] { NSColor.White, darkHighlight },
                new float[] { 0.50f, 1.0f });

            var shadow = new NSShadow ();
            shadow.ShadowColor = innerBoxShadowColor;
            shadow.ShadowOffset = new SizeF (0.1f, 0.1f);
            shadow.ShadowBlurRadius = 8.0f;

            var headerShadow = new NSShadow ();
            headerShadow.ShadowColor = innerBoxShadowColor;
            headerShadow.ShadowOffset = new SizeF(1.1f, -1.1f);
            headerShadow.ShadowBlurRadius = 5.0f;

            var drawFrame = Bounds;

            // Main Box Drawing
            var mainBoxRect = new RectangleF(drawFrame.X + 4.5f, (float)(drawFrame.Y + Math.Floor((drawFrame.Height - 36.0f) * 0.02976f) + 0.5f),
                                         	 drawFrame.Width - 9.0f, (float)(drawFrame.Height - 36.5f - Math.Floor((drawFrame.Height - 36) * 0.02976f)));

            var mainBoxCornerRadius = 4.0f;
            var mainBoxInnerRect = new RectangleF(mainBoxRect.X, mainBoxRect.Y, mainBoxRect.Width, mainBoxRect.Height);
            mainBoxInnerRect.Offset (mainBoxCornerRadius, mainBoxCornerRadius);

            var mainBoxPath = new NSBezierPath ();
            mainBoxPath.AppendPathWithArc (new PointF (mainBoxInnerRect.X, mainBoxInnerRect.Y), mainBoxCornerRadius, 180.0f, 270.0f);
            mainBoxPath.AppendPathWithArc (new PointF (mainBoxInnerRect.Width, mainBoxInnerRect.Y), mainBoxCornerRadius, 270.0f, 360.0f);
            mainBoxPath.LineTo (new PointF (mainBoxRect.Right, mainBoxRect.Bottom));
            mainBoxPath.LineTo (new PointF (mainBoxRect.X, mainBoxRect.Bottom));
            mainBoxPath.ClosePath ();

            boxBackgroundColor.SetFill ();
            mainBoxPath.Fill ();

            // Main Box Inner Shadow
            var mainBoxBorderRect = mainBoxPath.Bounds;
            mainBoxBorderRect.Inflate(shadow.ShadowBlurRadius, shadow.ShadowBlurRadius);
            mainBoxBorderRect.Offset(-shadow.ShadowOffset.Width, -shadow.ShadowOffset.Height);
            mainBoxBorderRect = RectangleF.Union(mainBoxBorderRect, mainBoxPath.Bounds);
            mainBoxBorderRect.Inflate(1, 1);

            var mainBoxNegativePath = NSBezierPath.FromRect (mainBoxBorderRect);
            mainBoxNegativePath.AppendPath (mainBoxPath);
            mainBoxNegativePath.WindingRule = NSWindingRule.EvenOdd;

            context.SaveState ();
            NSShadow shadowWithOffset = (NSShadow)shadow.Copy ();
            var xOffset = shadowWithOffset.ShadowOffset.Width + Math.Round (mainBoxBorderRect.Size.Width);
            var yOffset = shadowWithOffset.ShadowOffset.Height;
            shadowWithOffset.ShadowOffset = new SizeF ((float)(xOffset + (xOffset >= 0 ? 0.1f : -0.1f)), (float)(yOffset + (yOffset >= 0 ? 0.1f : -0.1f)));
            shadowWithOffset.Set ();

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

            var transform = new NSAffineTransform ();
            transform.Translate (-(float)Math.Round (mainBoxBorderRect.Size.Width), 0);
            transform.TransformBezierPath (mainBoxNegativePath).Fill ();
            context.RestoreState ();

            NSColor.Gray.SetStroke ();
            mainBoxPath.LineWidth = 0.5f;
            mainBoxPath.Stroke ();

            // Box Head Drawing
            var headingBoxCornerRadius = 4.0f;
            var headingBoxRect = new RectangleF (drawFrame.X + 4.5f, drawFrame.Y + drawFrame.Height - 36.0f, drawFrame.Width - 9.0f, 25.0f);
            var headingBoxInnerRect = new RectangleF (headingBoxRect.X, headingBoxRect.Y, headingBoxRect.Width, headingBoxRect.Height);
            headingBoxInnerRect.Offset (headingBoxCornerRadius, headingBoxCornerRadius);

            var headingBoxPath = new NSBezierPath ();
            headingBoxPath.MoveTo (new PointF (headingBoxRect.X, headingBoxRect.Y));
            headingBoxPath.LineTo (new PointF (headingBoxRect.Right, headingBoxRect.Y));
            headingBoxPath.AppendPathWithArc (new PointF (headingBoxInnerRect.Width, headingBoxInnerRect.Bottom), headingBoxCornerRadius, 0.0f, 90.0f);
            headingBoxPath.AppendPathWithArc (new PointF (headingBoxInnerRect.X, headingBoxInnerRect.Bottom), headingBoxCornerRadius, 90.0f, 180.0f);
            headingBoxPath.ClosePath ();

            context.SaveState ();
            headerShadow.Set ();
            context.BeginTransparencyLayer (null);
            headingGradient.DrawInBezierPath (headingBoxPath, -90);
            context.EndTransparencyLayer ();
            context.RestoreState ();

            NSColor.Gray.SetStroke ();
            headingBoxPath.LineWidth = 0.5f;
            headingBoxPath.Stroke ();
        }
Ejemplo n.º 3
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 ();
        }
Ejemplo n.º 4
0
 public void Fill(object backend)
 {
     ContextInfo ctx = (ContextInfo) backend;
     if (ctx.Pattern is Gradient) {
         GradientInfo gr = (GradientInfo) WidgetRegistry.GetBackend (ctx.Pattern);
         NSGradient g = new NSGradient (gr.Colors.ToArray (), gr.Stops.ToArray ());
         g.DrawInBezierPath (ctx.Path, 0f);
     }
     else {
         ctx.Path.Fill ();
     }
     ctx.Pattern = null;
     ctx.Path.Dispose ();
     ctx.Path = new NSBezierPath ();
 }