コード例 #1
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();
            }
        }
コード例 #2
0
 public override void DrawRect(RectangleF dirtyRect)
 {
     backgroundGradient.DrawInRect(Frame, -90);
     if (dirtyRect == Frame)
     {
         strokeColor.SetStroke();
         NSBezierPath.StrokeRect(dirtyRect);
     }
 }
コード例 #3
0
ファイル: ViewRotary.cs プロジェクト: daviddw/Kinsky
        public override void DrawRect(NSRect aRect)
        {
            // draw bars
            if (iMaxValue > 0)
            {
                // draw the current value bar
                NSColor colour = NSColor.ColorWithCalibratedRedGreenBlueAlpha(71.0f / 255.0f, 172.0f / 255.0f, 220.0f / 255.0f, 1.0f);
                colour.SetStroke();

                DrawArc(0, iValue, true);

                // draw the preview bar
                if (iPreviewEnabled)
                {
                    colour = NSColor.ColorWithCalibratedRedGreenBlueAlpha(187.0f / 255.0f, 187.0f / 255.0f, 0.0f / 255.0f, 1.0f);
                    colour.SetStroke();

                    DrawArc(iValue, iPreviewValue, (iPreviewValue > iValue));
                }
            }

            // draw text
            if (iText != null)
            {
                NSMutableParagraphStyle style = new NSMutableParagraphStyle();
                style.SetParagraphStyle(NSParagraphStyle.DefaultParagraphStyle);
                style.SetAlignment(NSTextAlignment.NSCenterTextAlignment);

                NSDictionary dict = NSDictionary.DictionaryWithObjectsAndKeys(FontManager.FontMedium, NSAttributedString.NSFontAttributeName,
                                                                              style, NSAttributedString.NSParagraphStyleAttributeName,
                                                                              NSColor.WhiteColor, NSAttributedString.NSForegroundColorAttributeName,
                                                                              null);
                style.Release();

                NSSize size = iText.SizeWithAttributes(dict);
                NSRect rect = new NSRect((Bounds.Width - size.width) * 0.5f, (Bounds.Height - size.height) * 0.5f, size.width, size.height);

                iText.DrawInRectWithAttributes(rect, dict);
            }
        }
コード例 #4
0
        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());
        }
コード例 #5
0
        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();
        }
コード例 #6
0
 public override void DrawRect(RectangleF dirtyRect)
 {
     lineColor.SetStroke();
     path.Stroke();
 }
コード例 #7
0
ファイル: MyView.cs プロジェクト: spica/mac-samples
 public override void DrawRect(CGRect dirtyRect)
 {
     lineColor.SetStroke();
     path.Stroke();
 }
コード例 #8
0
 public override void DrawRect(CGRect dirtyRect)
 {
     base.DrawRect(dirtyRect);
     lineColor?.SetStroke();
     currentPath.Stroke();
 }