Example #1
0
        public void SetColor(object backend, Xwt.Drawing.Color color)
        {
            NSColor col = NSColor.FromDeviceRgba((float)color.Red, (float)color.Green, (float)color.Blue, (float)color.Alpha);

            col.Set();
            col.SetFill();
        }
Example #2
0
        public override void DrawRect(CGRect dirtyRect)
        {
            if (_brushToRenderer != null)
            {
                _brushToRenderer.SetFill();
            }
            else
            {
                _colorToRenderer.SetFill();
            }

            var innerRect = NSBezierPath.FromRoundedRect(Bounds, 0, 0);

            NSBezierPath bezierPath = new NSBezierPath();

            bezierPath.MoveTo(new CGPoint(innerRect.Bounds.X, innerRect.Bounds.Y + _bottomLeft));

            // Bottom left (origin):
            bezierPath.AppendPathWithArc(new CGPoint(innerRect.Bounds.X + _bottomLeft, innerRect.Bounds.Y + _bottomLeft), _bottomLeft, (float)180.0, (float)270.0);

            // Bottom right:
            bezierPath.AppendPathWithArc(new CGPoint(innerRect.Bounds.X + innerRect.Bounds.Width - _bottomRight, innerRect.Bounds.Y + _bottomRight), _bottomRight, (float)270.0, (float)360.0);

            // Top right:
            bezierPath.AppendPathWithArc(new CGPoint(innerRect.Bounds.X + innerRect.Bounds.Width - _topRight, innerRect.Bounds.Y + innerRect.Bounds.Height - _topRight), _topRight, (float)0.0, (float)90.0);

            // Top left:
            bezierPath.AppendPathWithArc(new CGPoint(innerRect.Bounds.X + _topLeft, innerRect.Bounds.Y + innerRect.Bounds.Height - _topLeft), _topLeft, (float)90.0, (float)180.0);

            // Implicitly creates left edge.
            bezierPath.Fill();

            base.DrawRect(dirtyRect);
        }
Example #3
0
        public override void DrawWithFrame(RectangleF cellFrame, NSView inView)
        {
            borderColor.SetFill();

            NSGraphics.RectFill(
                new RectangleF(
                    cellFrame.X + padding / 2,
                    cellFrame.Y + padding / 2,
                    cellFrame.Width - padding,
                    cellFrame.Height - padding
                    )
                );

            base.DrawWithFrame(cellFrame, inView);
        }
 public override void DrawRect(CGRect dirtyRect)
 {
     if (BackgroundColor != null)
     {
         BackgroundColor.SetFill();
         NSBezierPath.FillRect(dirtyRect);
     }
     else
     {
         base.DrawRect(dirtyRect);
     }
     if (OnPaint != null)
     {
         OnPaint(dirtyRect.ToRectangleF());
     }
 }
Example #5
0
        /// <summary>
        /// We are using separate layer for higliting elements on a main view
        /// This method is highliting GUI element depends on current introduction step
        /// </summary>
        public void DrawLayer(NSView view, CGRect dirtyRect)
        {
            var     bg        = Colors.WindowBackground;
            NSColor fillColor = NSColor.FromRgba(bg.RedComponent, bg.GreenComponent, bg.BlueComponent, 0.4f);

            NSColor strokeColor = NSColor.FromRgb(50, 158, 230);
            nfloat  strokeWidth = 2;

            if (__InotroductionStage != IntroductionStageEnum.Finished)
            {
                NSBezierPath fillRect = NSBezierPath.FromRect(dirtyRect);
                fillColor.SetFill();
                fillRect.Fill();
            }

            if (__InotroductionStage == IntroductionStageEnum.Firewall)
            {
                CGRect fwRect = __MainViewController.GetFirewallControlViewRect();

                NSBezierPath firewallPath = NSBezierPath.FromRoundedRect(fwRect, fwRect.Height / 2, fwRect.Height / 2);
                firewallPath.LineWidth = strokeWidth;
                strokeColor.SetStroke();
                firewallPath.Stroke();
            }

            if (__InotroductionStage == IntroductionStageEnum.ConnectBtn)
            {
                // CONNECT BUTTON
                CGRect       circleRect    = __MainViewController.GetConnectButtonViewRect();
                NSBezierPath connectBthPth = NSBezierPath.FromRoundedRect(circleRect, circleRect.Width / 2, circleRect.Height / 2);
                connectBthPth.LineWidth = strokeWidth;
                strokeColor.SetStroke();
                connectBthPth.Stroke();
            }

            if (__InotroductionStage == IntroductionStageEnum.Servers)
            {
                // SERVERS SELECTION
                CGRect serversRect = __MainViewController.GetServerSelectionViewRect();
                serversRect = new CGRect(serversRect.X + 3, serversRect.Y + 3, serversRect.Width - 6, serversRect.Height - 6);
                NSBezierPath serversViewPath = NSBezierPath.FromRoundedRect(serversRect, 4, 4);
                serversViewPath.LineWidth = strokeWidth;
                strokeColor.SetStroke();
                serversViewPath.Stroke();
            }
        }
        public static XIR.Image RemoteRepresentation(this NSBezierPath nsbezierpath)
        {
            nfloat width  = 1f;
            nfloat height = 1f;

            // We check here for the element count.  If it is zero an error is being thrown if you access ControlPointBounds.
            if (nsbezierpath.ElementCount > 0)
            {
                // let's make sure we leave a little room for the line width drawing as well by adding the LineWidth of the
                // bezier path.
                width  = nsbezierpath.ControlPointBounds.Width + nsbezierpath.LineWidth * 2;
                height = nsbezierpath.ControlPointBounds.Height + nsbezierpath.LineWidth * 2;
            }
            else
            {
                return(new NSImage(new CGSize(width, height)).RemoteRepresentation());
            }

            var nsimage = new NSImage(new CGSize(width, height));

            nsimage.LockFocus();
            var transform = new NSAffineTransform();

            // We need to offset the image a little, specifically by the line width, so it will not be cut off
            var offsetXZero = -nsbezierpath.ControlPointBounds.X;
            var offsetYZero = -nsbezierpath.ControlPointBounds.Y;

            transform.Translate(offsetXZero + nsbezierpath.LineWidth / 2, offsetYZero + nsbezierpath.LineWidth / 2);
            nsbezierpath.TransformUsingAffineTransform(transform);

            brush.SetFill();
            nsbezierpath.Fill();

            pen.SetStroke();
            nsbezierpath.Stroke();

            nsimage.UnlockFocus();

            return(nsimage.RemoteRepresentation());
        }
Example #7
0
        public override void DrawRect(CGRect dirtyRect)
        {
            if (BackgroundColor != null)
            {
                BackgroundColor.SetFill();
                NSBezierPath.FillRect(dirtyRect);
            }
            else
            {
                base.DrawRect(dirtyRect);
            }

            if (RespectInteriorBackgroundStyle &&
                (Superview as NSTableRowView)?.InteriorBackgroundStyle == NSBackgroundStyle.Dark)
            {
                DarkBgAttributedStringWithLinks.DrawString(Bounds);
            }
            else
            {
                AttributedStringWithLinks.DrawString(Bounds);
            }

                        #if NSLINKLABEL_DEBUG
            int i = 0;
            foreach (var r in GetLinksRectsInternal())
            {
                if (((++i) % 2) == 0)
                {
                    NSColor.Yellow.SetFill();
                }
                else
                {
                    NSColor.Green.SetFill();
                }
                NSBezierPath.FillRect(r.Value);
            }
        }
Example #8
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();
        }
        public static void DrawUISwitch(CGRect dirtyRect, bool isEnabled, bool isSwitchOn,
                                        int BorderWidth,
                                        NSColor SwitchOnBackgroundColor,
                                        NSColor SwitchOffBackgroundColor,
                                        NSColor SwitchOffBorderColor,
                                        NSColor InternalSwitcherColor,
                                        NSColor InternalSwitcherShadowColor
                                        )
        {
            NSGraphicsContext context = NSGraphicsContext.CurrentContext;

            context.CGContext.SaveState();


            NSColor switchOnBackgroundColor     = SwitchOnBackgroundColor;
            NSColor switchOffBackgroundColor    = SwitchOffBackgroundColor;
            NSColor switchOffBorderColor        = SwitchOffBorderColor;
            NSColor internalSwitcherColor       = InternalSwitcherColor;
            NSColor internalSwitcherShadowColor = InternalSwitcherShadowColor;

            if (isEnabled == false)
            {
                // if disabled - set background color darker
                switchOnBackgroundColor     = SetColorDarker(switchOnBackgroundColor);
                switchOffBackgroundColor    = SetColorDarker(switchOffBackgroundColor);
                switchOffBorderColor        = SetColorDarker(switchOffBorderColor);
                internalSwitcherColor       = SetColorDarker(internalSwitcherColor);
                internalSwitcherShadowColor = SetColorDarker(internalSwitcherShadowColor);
            }

            nfloat offset = dirtyRect.Height * 0.1f;

            dirtyRect = new CGRect(dirtyRect.X + offset,
                                   dirtyRect.Y + offset,
                                   dirtyRect.Width - offset * 2,
                                   dirtyRect.Height - offset * 2);

            // set backgrund color
            NSColor bodyColor = (isSwitchOn)? switchOnBackgroundColor : switchOffBackgroundColor;

            bodyColor.SetFill();

            // draw background
            NSBezierPath bodyPath = NSBezierPath.FromRoundedRect(dirtyRect, dirtyRect.Height / 2, dirtyRect.Height / 2);

            bodyPath.Fill();

            // draw border
            if (!isSwitchOn)
            {
                bodyPath.AddClip();
                bodyPath.LineWidth = BorderWidth;

                if (switchOffBorderColor != null)
                {
                    switchOffBorderColor.SetStroke();
                }
                bodyPath.Stroke();
            }

            //restore \ save context status
            context.CGContext.RestoreState();
            context.CGContext.SaveState();

            // DRAW CIRCLE
            CGRect circleRect;

            if (!isSwitchOn)
            {
                circleRect = new CGRect(dirtyRect.X,
                                        dirtyRect.Y,
                                        dirtyRect.Height,
                                        dirtyRect.Height);
            }
            else
            {
                circleRect = new CGRect((dirtyRect.Width - dirtyRect.Height + dirtyRect.X),
                                        dirtyRect.Y,
                                        dirtyRect.Height,
                                        dirtyRect.Height);
            }

            // draw circle with shadow (no shadow for dark mode)
            if (!Colors.IsDarkMode)
            {
                CGRect circleShadowRect = new CGRect(circleRect.X + offset / 3, circleRect.Y + offset / 3, circleRect.Height - 2 * offset / 3, circleRect.Height - 2 * offset / 3);

                NSBezierPath circleShadowPath = NSBezierPath.FromRoundedRect(circleShadowRect, circleShadowRect.Height / 2, circleShadowRect.Height / 2);
                context.CGContext.SetShadow(new CGSize(offset / 3, -offset),
                                            offset * 1f,
                                            new CGColor(internalSwitcherShadowColor.RedComponent,
                                                        internalSwitcherShadowColor.GreenComponent,
                                                        internalSwitcherShadowColor.BlueComponent));
                circleShadowPath.Fill();
            }

            // restore context state
            context.CGContext.RestoreState();

            // set circle color
            NSColor circleColor = internalSwitcherColor;

            circleColor.SetFill();

            // draw circle without shadow to fill internal area filled by shadow
            NSBezierPath circlePath = NSBezierPath.FromRoundedRect(circleRect, circleRect.Height / 2, circleRect.Height / 2);

            circlePath.Fill();

            // circle border
            circlePath.AddClip();
            circlePath.LineWidth = 1;

            if (Colors.IsDarkMode)
            {
                // no border for Dark mode
                internalSwitcherColor.SetStroke();
            }
            else
            {
                if (switchOffBorderColor != null)
                {
                    switchOffBorderColor.SetStroke();
                }
            }
            circlePath.Stroke();
        }
Example #10
0
 public override void DrawSelection(CGRect dirtyRect)
 {
     selectedBkColor.SetFill();
     NSBezierPath.FillRect(dirtyRect);
     DrawFocusedMessage();
 }
Example #11
0
 public override void DrawRect(CoreGraphics.CGRect dirtyRect)
 {
     color.SetFill();
     NSGraphics.RectFill(this.Bounds);
 }