示例#1
0
        public void DrawLayer(CALayer layer, CoreGraphics.CGContext context)
        {
            NSGraphicsContext.GlobalSaveGraphicsState();
            NSGraphicsContext graphicsContext = NSGraphicsContext.FromGraphicsPort(context, true);

            NSGraphicsContext.CurrentContext = graphicsContext;

            NSBezierPath path = new NSBezierPath();
            //ベジェ曲線
            var x1 = this.Frame.Left;
            var y1 = this.Frame.Top;
            var x2 = this.Frame.Right;
            var y2 = this.Frame.Bottom;

            path.MoveTo(new CoreGraphics.CGPoint(x1, y1));
            path.CurveTo(new CoreGraphics.CGPoint(x2, y1),
                         new CoreGraphics.CGPoint(x1, y2),
                         new CoreGraphics.CGPoint(x2, y2));
            //背景は白
            NSColor.White.Set();
            path.Fill();
            //線は青
            NSColor.Blue.Set();
            //線の太さ
            path.LineWidth = 2;
            path.Stroke();

            NSGraphicsContext.GlobalRestoreGraphicsState();
        }
示例#2
0
        public override void DrawRect(CGRect dirtyRect)
        {
            base.DrawRect(dirtyRect);

            // Use Core Graphic routines to draw our UI
            NSBezierPath path = new NSBezierPath();

            foreach (var p in _paths)
            {
                path.MoveTo(p.Item1);
                path.LineTo(p.Item2);
            }

            foreach (var n in _nodes)
            {
                path.AppendPathWithOvalInRect(new CGRect(
                                                  n.X - NodeRadius, n.Y - NodeRadius,
                                                  2 * NodeRadius, 2 * NodeRadius));
            }

            NSColor.Cyan.SetStroke();
            path.Stroke();
            NSColor.Orange.SetFill();
            path.Fill();
        }
示例#3
0
        public override void DrawRect(CGRect dirtyRect)
        {
            if (EffectiveAppearance.AllowsVibrancy)
            {
                // Vibrant drawing codepath.
                NSColor.LabelColor.Set();
                NSBezierPath path = NSBezierPath.FromOvalInRect(Bounds.Inset(5, 5));
                path.LineWidth = 5;
                path.Stroke();

                NSColor.SecondaryLabelColor.Set();
                path = NSBezierPath.FromOvalInRect(Bounds.Inset(10, 10));
                path.Fill();
            }
            else
            {
                NSColor.Red.Set();
                NSBezierPath path = NSBezierPath.FromOvalInRect(Bounds.Inset(5f, 5f));
                path.LineWidth = 5;
                path.Stroke();

                NSColor.Purple.Set();
                path = NSBezierPath.FromOvalInRect(Bounds.Inset(10f, 10f));
                path.Fill();
            }
        }
        private NSImage CreateImageWithColor(string colorValue)
        {
            NSGraphicsContext.GlobalSaveGraphicsState();
            CGSize  size      = new CGSize(12, 12);
            NSImage tintImage = new NSImage(size);

            tintImage.LockFocus();

            float        cornerRadius = 5f;
            CGRect       rect         = new CGRect(0, 0, 10, 10);
            NSBezierPath path         = NSBezierPath.FromRoundedRect(rect, cornerRadius, cornerRadius);

            if (string.IsNullOrEmpty(colorValue))
            {
                NSColor.Grid.Set();
                path.Stroke();
            }
            else
            {
                Utility.ColorWithHexColorValue(colorValue, 1.0f).SetFill();
                path.Fill();
            }

            tintImage.UnlockFocus();
            CGContext context = NSGraphicsContext.CurrentContext.CGContext;

            return(tintImage);
        }
示例#5
0
        public override void DrawRect(CGRect dirtyRect)
        {
            //TODO: uncomment code https://bugzilla.xamarin.com/show_bug.cgi?id=24144
//			if (EffectiveAppearance.AllowsVibrancy) {
//				// Vibrant drawing codepath.
//				NSColor.LabelColor.Set ();
//				NSBezierPath path = NSBezierPath.FromOvalInRect (Bounds.Inset (5, 5));
//				path.LineWidth = 5;
//				path.Stroke ();
//
//				NSColor.SecondaryLabelColor.Set ();
//				path = NSBezierPath.FromOvalInRect (Bounds.Inset (10, 10));
//				path.Fill ();
//			} else {
            NSColor.Red.Set();
            NSBezierPath path = NSBezierPath.FromOvalInRect(Bounds.Inset(5f, 5f));

            path.LineWidth = 5;
            path.Stroke();

            NSColor.Purple.Set();
            path = NSBezierPath.FromOvalInRect(Bounds.Inset(10f, 10f));
            path.Fill();
//			}
        }
示例#6
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);
        }
        public override void DrawRect(CGRect dirtyRect)
        {
            NSBezierPath bezierPath = NSBezierPath.FromRoundedRect(Bounds, kRoundedRadius, kRoundedRadius);

            bezierPath.LineWidth = 1;

            NSColor.White.Set();
            bezierPath.Fill();
        }
        public override void DrawBackground(CGRect dirtyRect)
        {
            base.DrawBackground(dirtyRect);

            NSColor textColor;

            if (IsParent || IsSubSelect)
            {
                textColor = NSColor.White;
            }
            else
            {
                textColor = NSColor.Black;
            }

            var cellView  = (NSTableCellView)Subviews [0];
            var textField = cellView.TextField;
            NSAttributedString attributeTitle = Utility.AttributedTitle(textField.StringValue,
                                                                        textColor, textField.Font.FontName,
                                                                        (float)textField.Font.PointSize,
                                                                        NSTextAlignment.Left);

            textField.AttributedStringValue = attributeTitle;

            var button = (NSButton)cellView.Subviews [2];

            if (button.Tag == 3)
            {
                if (IsSubSelect)
                {
                    button.Cell.Image = Utility.ImageWithFilePath("/Images/TOC/toc-doc-white.png");
                }
                else
                {
                    button.Cell.Image = Utility.ImageWithFilePath("/Images/TOC/toc_doc.png");
                }
            }

            if (IsParent)
            {
                Utility.BlendNSColor(Level, LNRConstants.TOCLEVEL_MAX).Set();
            }
            else if (IsSubSelect)
            {
                Utility.BlendNSColor(Level, LNRConstants.TOCLEVEL_MAX).Set();
            }
            else
            {
                NSColor.White.Set();
            }

            NSBezierPath selectionPath = NSBezierPath.FromRoundedRect(Bounds, 0, 0);

            selectionPath.Fill();
        }
示例#9
0
        private void DrawArrow(NSScrollerPart aScrollPart)
        {
            NSRect rect = RectForPart(aScrollPart);

            // draw background
            NSColor.BlackColor.Set();
            AppKitFramework.NSRectFill(rect);

            // draw button background
            if (aScrollPart == HitPart)
            {
                NSColor.WhiteColor.Set();
            }
            else
            {
                NSColor.ColorWithCalibratedWhiteAlpha(0.1f, 1.0f).Set();
            }

            NSBezierPath path = new NSBezierPath();

            path.AppendBezierPathWithRoundedRectXRadiusYRadius(rect.InsetRect(1.0f, 1.0f), 2.0f, 2.0f);
            path.LineWidth = 2.0f;
            path.Stroke();
            path.Release();

            // draw arrow
            NSColor.WhiteColor.Set();

            float arrowSize = 6.0f;

            NSRect arrowRect = new NSRect(rect.MidX - (arrowSize * 0.5f),
                                          rect.MidY - (arrowSize * 0.5f),
                                          arrowSize,
                                          arrowSize);

            path = new NSBezierPath();
            if (aScrollPart == NSScrollerPart.NSScrollerDecrementLine)
            {
                path.MoveToPoint(new NSPoint(arrowRect.MinX, arrowRect.MaxY));
                path.LineToPoint(new NSPoint(arrowRect.MaxX, arrowRect.MaxY));
                path.LineToPoint(new NSPoint(arrowRect.MidX, arrowRect.MinY));
                path.LineToPoint(new NSPoint(arrowRect.MinX, arrowRect.MaxY));
            }
            else
            {
                path.MoveToPoint(new NSPoint(arrowRect.MinX, arrowRect.MinY));
                path.LineToPoint(new NSPoint(arrowRect.MaxX, arrowRect.MinY));
                path.LineToPoint(new NSPoint(arrowRect.MidX, arrowRect.MaxY));
                path.LineToPoint(new NSPoint(arrowRect.MinX, arrowRect.MinY));
            }
            path.ClosePath();
            path.Fill();
            path.Release();
        }
示例#10
0
        public override void DrawRect(NSRect aRect)
        {
            float left   = Bounds.MinX + iPadding;
            float right  = Bounds.MaxX - iPadding;
            float top    = Bounds.MaxY - iPadding - iAnchorHeight;
            float bottom = Bounds.MinY + iPadding + iAnchorHeight;

            NSBezierPath path = new NSBezierPath();

            // start the path in the bottom left corner, just past the arc of the corner and go clockwise
            path.MoveToPoint(new NSPoint(left, bottom + iCornerRadius));
            path.LineToPoint(new NSPoint(left, top - iCornerRadius));
            path.AppendBezierPathWithArcFromPointToPointRadius(new NSPoint(left, top),
                                                               new NSPoint(left + iCornerRadius, top),
                                                               iCornerRadius);
            if (iAnchorOnTop)
            {
                path.LineToPoint(new NSPoint(iAnchorApex - iAnchorWidth * 0.5f, top));
                path.LineToPoint(new NSPoint(iAnchorApex, top + iAnchorHeight));
                path.LineToPoint(new NSPoint(iAnchorApex + iAnchorWidth * 0.5f, top));
            }
            path.LineToPoint(new NSPoint(right - iCornerRadius, top));
            path.AppendBezierPathWithArcFromPointToPointRadius(new NSPoint(right, top),
                                                               new NSPoint(right, top - iCornerRadius),
                                                               iCornerRadius);
            path.LineToPoint(new NSPoint(right, bottom + iCornerRadius));
            path.AppendBezierPathWithArcFromPointToPointRadius(new NSPoint(right, bottom),
                                                               new NSPoint(right - iCornerRadius, bottom),
                                                               iCornerRadius);
            if (!iAnchorOnTop)
            {
                path.LineToPoint(new NSPoint(iAnchorApex + iAnchorWidth * 0.5f, bottom));
                path.LineToPoint(new NSPoint(iAnchorApex, bottom - iAnchorHeight));
                path.LineToPoint(new NSPoint(iAnchorApex - iAnchorWidth * 0.5f, bottom));
            }
            path.LineToPoint(new NSPoint(left + iCornerRadius, bottom));
            path.AppendBezierPathWithArcFromPointToPointRadius(new NSPoint(left, bottom),
                                                               new NSPoint(left, bottom + iCornerRadius),
                                                               iCornerRadius);
            path.ClosePath();

            NSColor.WhiteColor.SetStroke();
            path.LineWidth = 4.0f;
            path.Stroke();

            NSColor.ColorWithCalibratedWhiteAlpha(0.0f, 0.9f).SetFill();
            path.Fill();

            path.Release();
        }
        public override void DrawRect(CGRect dirtyRect)
        {
            base.DrawRect(dirtyRect);
            if (!Selected)
            {
                return;
            }

            NSBezierPath path = new NSBezierPath();

            path.AppendPathWithRect(new CGRect(Bounds.X, Bounds.Height - 2, Bounds.Width, 2));
            (Selected ? NSColor.Text : NSColor.DisabledControlText).Set();
            path.Fill();
        }
示例#12
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();
            }
        }
示例#13
0
        public override void DrawSelection(RectangleF dirtyRect)
        {
            // Check the selectionHighlightStyle, in case it was set to None

            if (Frame.Top <= LNRConstants.TOCITEMHEIGHT_MIN)
            {
                return;
            }

            if (SelectionHighlightStyle != NSTableViewSelectionHighlightStyle.None)
            {
                Utility.BlendNSColor(Level, LNRConstants.TOCLEVEL_MAX).Set();

                NSBezierPath selectionPath = NSBezierPath.FromRoundedRect(Bounds, 0, 0);
                selectionPath.Fill();
            }
        }
示例#14
0
        public override void DrawRect(RectangleF rect)
        {
            var xamarinBlue = NSColor.FromDeviceRgba(0.071f, 0.463f, 0.725f, 1.000f);

            NSBezierPath xamarinLogoPath = new NSBezierPath();

            xamarinLogoPath.MoveTo(new PointF(230.49f, 92.68f));
            xamarinLogoPath.LineTo(new PointF(200.74f, 92.68f));
            xamarinLogoPath.LineTo(new PointF(159.7f, 167.71f));
            xamarinLogoPath.LineTo(new PointF(200.74f, 242.73f));
            xamarinLogoPath.LineTo(new PointF(230.49f, 242.73f));
            xamarinLogoPath.LineTo(new PointF(191.23f, 167.71f));
            xamarinLogoPath.LineTo(new PointF(230.49f, 92.68f));
            xamarinLogoPath.ClosePath();
            xamarinLogoPath.MoveTo(new PointF(118.66f, 92.68f));
            xamarinLogoPath.LineTo(new PointF(88.92f, 92.68f));
            xamarinLogoPath.LineTo(new PointF(128.18f, 167.71f));
            xamarinLogoPath.LineTo(new PointF(88.92f, 242.73f));
            xamarinLogoPath.LineTo(new PointF(118.66f, 242.73f));
            xamarinLogoPath.LineTo(new PointF(159.7f, 167.71f));
            xamarinLogoPath.LineTo(new PointF(118.66f, 92.68f));
            xamarinLogoPath.ClosePath();
            xamarinLogoPath.MoveTo(new PointF(220.7f, 37.0f));
            xamarinLogoPath.CurveTo(new PointF(232.55f, 41.1f), new PointF(220.7f, 37.0f), new PointF(227.07f, 38.03f));
            xamarinLogoPath.CurveTo(new PointF(242.62f, 49.31f), new PointF(238.03f, 44.18f), new PointF(242.62f, 49.31f));
            xamarinLogoPath.LineTo(new PointF(304.22f, 152.47f));
            xamarinLogoPath.CurveTo(new PointF(308.95f, 170.05f), new PointF(304.22f, 152.47f), new PointF(309.55f, 163.02f));
            xamarinLogoPath.CurveTo(new PointF(304.22f, 183.53f), new PointF(308.36f, 177.09f), new PointF(304.22f, 183.53f));
            xamarinLogoPath.LineTo(new PointF(243.57f, 286.11f));
            xamarinLogoPath.CurveTo(new PointF(234.05f, 294.31f), new PointF(243.57f, 286.11f), new PointF(239.7f, 291.09f));
            xamarinLogoPath.CurveTo(new PointF(220.97f, 299.0f), new PointF(228.4f, 297.53f), new PointF(220.97f, 299.0f));
            xamarinLogoPath.LineTo(new PointF(97.25f, 299.0f));
            xamarinLogoPath.CurveTo(new PointF(84.16f, 294.31f), new PointF(97.25f, 299.0f), new PointF(89.51f, 297.53f));
            xamarinLogoPath.CurveTo(new PointF(75.83f, 286.11f), new PointF(78.81f, 291.09f), new PointF(75.83f, 286.11f));
            xamarinLogoPath.LineTo(new PointF(13.99f, 181.77f));
            xamarinLogoPath.CurveTo(new PointF(11.03f, 170.05f), new PointF(13.99f, 181.77f), new PointF(11.33f, 176.21f));
            xamarinLogoPath.CurveTo(new PointF(12.81f, 157.16f), new PointF(10.73f, 163.9f), new PointF(12.81f, 157.16f));
            xamarinLogoPath.LineTo(new PointF(75.59f, 49.31f));
            xamarinLogoPath.CurveTo(new PointF(85.07f, 41.1f), new PointF(75.59f, 49.31f), new PointF(79.59f, 44.18f));
            xamarinLogoPath.CurveTo(new PointF(97.5f, 37.0f), new PointF(90.54f, 38.03f), new PointF(97.5f, 37.0f));
            xamarinLogoPath.LineTo(new PointF(220.7f, 37.0f));
            xamarinLogoPath.LineTo(new PointF(220.7f, 37.0f));
            xamarinLogoPath.ClosePath();
            xamarinBlue.SetFill();
            xamarinLogoPath.Fill();
        }
示例#15
0
        public override void DrawRect(RectangleF dirtyRect)
        {
            int radius = 5, arrowHeight = 10, arrowWidth = 20;
            var roundedRectangleRect = new RectangleF(0, 0, this.Bounds.Width, this.Bounds.Height - arrowHeight);
            var path = new NSBezierPath();

            path.AppendPathWithRoundedRect(roundedRectangleRect, radius, radius);

            // Draw the triangle
            path.MoveTo(new PointF((this.Bounds.Width / 2) - (arrowWidth / 2), this.Bounds.Height - arrowHeight));
            path.LineTo(new PointF((this.Bounds.Width / 2), this.Bounds.Height));
            path.LineTo(new PointF((this.Bounds.Width / 2) + (arrowWidth / 2), this.Bounds.Height - arrowHeight));
            path.ClosePath();

            NSColor.Control.SetFill();
            path.Fill();
        }
示例#16
0
        public override void DrawRect(CGRect dirtyRect)
        {
            /*
             * Things look good no matter where the view is located; either a vibrant appearance or
             * a non-vibrant appearance. Since the view says YES to allowsVibrancy, everything drawn in
             * drawRect will be vibrant; all colors, images, etc.
             */

            NSColor.FromDeviceWhite(0f, 0.85f).Set();
            NSBezierPath path = NSBezierPath.FromOvalInRect(Bounds.Inset(5f, 5f));

            path.LineWidth = 5;
            path.Stroke();

            NSColor.FromDeviceWhite(0f, 0.48f).Set();
            path = NSBezierPath.FromOvalInRect(Bounds.Inset(10f, 10f));
            path.Fill();
        }
示例#17
0
        public override void DrawBackground(RectangleF dirtyRect)
        {
            if (IsParent)
            {
                Utility.BlendNSColor(Level, LNRConstants.TOCLEVEL_MAX).Set();
            }
            else if (IsSubSelect)
            {
                //IsSubSelect = false;
                Utility.BlendNSColor(Level, LNRConstants.TOCLEVEL_MAX).Set();
            }
            else
            {
                NSColor.White.Set();
            }

            NSBezierPath selectionPath = NSBezierPath.FromRoundedRect(Bounds, 0, 0);

            selectionPath.Fill();
        }
示例#18
0
        public override void DrawKnob(CGRect knobRect)
        {
            // Mimick the dimensions of the original slider
            knobRect.Width  -= 6;
            knobRect.Height -= 6;
            knobRect.Y      += 3;
            knobRect.X      += 3;
            var radius = 7.5f;

            var path = new NSBezierPath();

            path.AppendPathWithRoundedRect(knobRect, radius, radius);
            // Draw inside
            var knobColor = ThumbColor.IsDefault ? NSColor.ControlLightHighlight : ThumbColor.ToNSColor();

            knobColor.SetFill();
            path.Fill();
            // Draw border
            NSColor.ControlShadow.SetStroke();
            path.Stroke();
        }
示例#19
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());
        }
示例#20
0
        public override void DrawKnob(CGRect knobRect)
        {
            // Mimick the dimensions of the original slider
            knobRect.Width  -= 6;
            knobRect.Height -= 6;
            knobRect.Y      += 3;
            knobRect.X      += 3;
            var radius = 7.5f;

            var path = new NSBezierPath();

            path.AppendPathWithRoundedRect(knobRect, radius, radius);
            // Draw inside

            var defaultKnobColor = NSColor.ControlLightHighlight;

            if (Forms.IsMojaveOrNewer)
            {
                defaultKnobColor = NSColor.Highlight;
            }

            var knobColor = ThumbColor.IsDefault ? defaultKnobColor : ThumbColor.ToNSColor();

            knobColor.SetFill();
            path.Fill();

            // Draw border
            if (Forms.IsMojaveOrNewer)
            {
                NSColor.ControlShadow.SetStroke();
            }
            else
            {
                NSColor.SeparatorColor.SetStroke();
            }

            path.Stroke();
        }
        public override void DrawRect(RectangleF dirtyRect)
        {
            var contentRect = new RectangleF(Bounds.X + LineThickness, Bounds.Y + LineThickness, Bounds.Width - (LineThickness * 2), Bounds.Height - (LineThickness * 2));

            // Mac coords are reversed vs. .Net / MonoTouch coords, so we just reverse the top/bottom coords to compensate
            var top    = contentRect.Bottom;
            var bottom = contentRect.Top;

            var left  = contentRect.Left;
            var right = contentRect.Right;
            var path  = new NSBezierPath();

            // Draw the 'arrow' at the top
            path.MoveTo(new PointF(ArrowX, top));
            path.LineTo(new PointF(ArrowX + ArrowWidth / 2, top - ArrowHeight));
            path.LineTo(new PointF(right - CornerRadius, top - ArrowHeight));

            // Right right
            var topRightCorner = new PointF(right, top - ArrowHeight);

            path.CurveTo(new PointF(right, top - ArrowHeight - CornerRadius), topRightCorner, topRightCorner);

            // Right line
            path.LineTo(new PointF(right, bottom + CornerRadius));

            // Bottom right
            var bottomRightCorner = new PointF(right, bottom);

            path.CurveTo(new PointF(right - CornerRadius, bottom), bottomRightCorner, bottomRightCorner);

            // Bottom line
            path.LineTo(new PointF(left + CornerRadius, bottom));

            // Bottom left
            var bottomLeftCorner = new PointF(left, bottom);

            path.CurveTo(new PointF(left, bottom + CornerRadius), bottomLeftCorner, bottomLeftCorner);

            // Left line
            path.LineTo(new PointF(left, top - ArrowHeight - CornerRadius));

            // Top left
            var topLeftCorner = new PointF(left, top - ArrowHeight);

            path.CurveTo(new PointF(left + CornerRadius, top - ArrowHeight), topLeftCorner, topLeftCorner);

            // Line up to start of 'arrow' & finish
            path.LineTo(new PointF(ArrowX - ArrowWidth / 2, top - ArrowHeight));
            path.ClosePath();

            // Fill the path with a semi-transparent white
            NSColor.FromDeviceWhite(1.0f, FillOpacity).SetFill();
            path.Fill();

            NSGraphicsContext.GlobalSaveGraphicsState();

            // Clip all rendering of controls within view to within the path outline we specified earlier
            var clip = NSBezierPath.FromRect(Bounds);

            clip.AppendPath(path);
            clip.AddClip();

            // Draw the border
            path.LineWidth = LineThickness * 2;
            NSColor.White.SetStroke();
            path.Stroke();

            NSGraphicsContext.GlobalRestoreGraphicsState();
        }
示例#22
0
        public override void DrawRect(CGRect dirtyRect)
        {
            if (Gradient != null)
            {
                Gradient.DrawInRect(dirtyRect, GradientAngle);
            }

            // -----------------------------------------
            nfloat textOffset   = 0f;
            nfloat imageXOffset = 0f;
            nfloat imageWidth   = 0f;

            if (Image != null)
            {
                if (Image.Size.Height > dirtyRect.Height)
                {
                    Image.Size = new CGSize(Image.Size.Height, dirtyRect.Height);
                }
                if (Image.Size.Width > dirtyRect.Width)
                {
                    Image.Size = new CGSize(dirtyRect.Width, Image.Size.Width);
                }

                imageWidth = Image.Size.Width;

                nfloat minXOffset = (dirtyRect.Height - Image.Size.Height) / 2f;

                imageXOffset = CornerRadius;
                if (imageXOffset < minXOffset)
                {
                    imageXOffset = minXOffset;
                }

                if (AttributedTitle == null)
                {
                    imageXOffset = dirtyRect.Width / 2f - Image.Size.Width / 2f;
                }
                else if (IconLocation == IconLocationEnum.Right_BeforeCenteredText)
                {
                    imageXOffset = dirtyRect.Width / 2f - AttributedTitle.Size.Width / 2f - Image.Size.Width - minXOffset / 2f;
                }
                else if (IconLocation == IconLocationEnum.Left_AfterCenteredText)
                {
                    imageXOffset = dirtyRect.Width / 2f + AttributedTitle.Size.Width / 2f + minXOffset / 2f;
                }
                else if (IconLocation == IconLocationEnum.Right_AfterCenteredText)
                {
                    imageXOffset = dirtyRect.Width - minXOffset / 2f - Image.Size.Width;
                }
                else if (IconLocation == IconLocationEnum.Right)
                {
                    nfloat space = (dirtyRect.Width - AttributedTitle.Size.Width - Image.Size.Width) / 3;
                    textOffset   = space;
                    imageXOffset = space + AttributedTitle.Size.Width + space;
                }
                else if (IconLocation == IconLocationEnum.Left)
                {
                    nfloat space = (dirtyRect.Width - AttributedTitle.Size.Width - Image.Size.Width) / 3;
                    imageXOffset = space;
                    textOffset   = space + Image.Size.Width + space;
                }

                CGRect imgRect = new CGRect(dirtyRect.X + imageXOffset,
                                            dirtyRect.Y + dirtyRect.Height / 2f - Image.Size.Height / 2f,
                                            Image.Size.Width,
                                            Image.Size.Height);
                Image.Draw(imgRect);
            }

            if (AttributedTitle != null)
            {
                if (IconLocation == IconLocationEnum.Right_BeforeCenteredText || IconLocation == IconLocationEnum.Left_BeforeCenteredText)
                {
                    if ((imageXOffset + imageWidth) > (dirtyRect.Width - AttributedTitle.Size.Width) / 2f)
                    {
                        textOffset = imageXOffset + imageWidth;
                    }
                }

                CGRect titleRect = new CGRect(dirtyRect.X + textOffset,
                                              dirtyRect.Y + dirtyRect.Height / 2f - AttributedTitle.Size.Height / 2f - 1f,
                                              dirtyRect.Width - textOffset,
                                              AttributedTitle.Size.Height);

                this.AttributedTitle.DrawInRect(titleRect);
            }

            if (Highlighted)
            {
                NSColor fillColor = HighlitedColorOverlay;
                if (fillColor == null)
                {
                    fillColor = NSColor.FromRgba(0, 0, 0, 0.1f);
                }
                fillColor.Set();

                NSBezierPath highlitedFill = new NSBezierPath();
                highlitedFill.AppendPathWithRoundedRect(dirtyRect, CornerRadius, CornerRadius);
                highlitedFill.Fill();
            }

            if (!this.Enabled && DoNotChangeColorWhenDisabled != true)
            {
                NSColor fillColor = HighlitedColorOverlay;
                if (fillColor == null)
                {
                    fillColor = NSColor.FromRgba(0, 0, 0, 0.1f);
                }
                fillColor.Set();

                NSBezierPath highlitedFill = new NSBezierPath();
                highlitedFill.AppendPathWithRoundedRect(dirtyRect, CornerRadius, CornerRadius);
                highlitedFill.Fill();
            }
            // -----------------------------------------
            //base.DrawRect (dirtyRect);

            if (!Highlighted && BorderShadow != null)
            {
                BorderShadow.Set();
            }


            NSBezierPath bounds = new NSBezierPath();

            bounds.AppendPathWithRoundedRect(dirtyRect, CornerRadius, CornerRadius);
            bounds.AddClip();

            bounds.LineWidth = BorderLineWidth;

            if (BorderColor != null)
            {
                BorderColor.SetStroke();
            }

            bounds.Stroke();
        }
示例#23
0
        public static SCNNode SCBoxNode(string title, CGRect frame, NSColor color, float cornerRadius, bool centered)
        {
            NSMutableDictionary titleAttributes         = null;
            NSMutableDictionary centeredTitleAttributes = null;

            // create and extrude a bezier path to build the box
            var path = NSBezierPath.FromRoundedRect(frame, cornerRadius, cornerRadius);

            path.Flatness = 0.05f;

            var shape = SCNShape.Create(path, 20);

            shape.ChamferRadius = 0.0f;

            var node = SCNNode.Create();

            node.Geometry = shape;

            // create an image and fill with the color and text
            var textureSize = new CGSize();

            textureSize.Width  = (float)Math.Ceiling((double)frame.Size.Width * 1.5);
            textureSize.Height = (float)Math.Ceiling((double)frame.Size.Height * 1.5);

            var texture = new NSImage(textureSize);

            texture.LockFocus();

            var drawFrame = new CGRect(0, 0, textureSize.Width, textureSize.Height);

            nfloat hue, saturation, brightness, alpha;

            (color.UsingColorSpace(NSColorSpace.DeviceRGBColorSpace)).GetHsba(out hue, out saturation, out brightness, out alpha);
            var lightColor = NSColor.FromDeviceHsba(hue, saturation - 0.2f, brightness + 0.3f, alpha);

            lightColor.Set();

            NSGraphics.RectFill(drawFrame);

            NSBezierPath fillpath = null;

            if (cornerRadius == 0 && centered == false)
            {
                //special case for the "labs" slide
                drawFrame.Offset(0, -2);
                fillpath = NSBezierPath.FromRoundedRect(drawFrame, cornerRadius, cornerRadius);
            }
            else
            {
                drawFrame.Inflate(-3, -3);
                fillpath = NSBezierPath.FromRoundedRect(drawFrame, cornerRadius, cornerRadius);
            }

            color.Set();
            fillpath.Fill();

            // draw the title if any
            if (title != null)
            {
                if (titleAttributes == null)
                {
                    var paraphStyle = new NSMutableParagraphStyle();
                    paraphStyle.LineBreakMode     = NSLineBreakMode.ByWordWrapping;
                    paraphStyle.Alignment         = NSTextAlignment.Center;
                    paraphStyle.MinimumLineHeight = 38;
                    paraphStyle.MaximumLineHeight = 38;

                    var font = NSFont.FromFontName("Myriad Set Semibold", 34) != null?NSFont.FromFontName("Myriad Set Semibold", 34) : NSFont.FromFontName("Avenir Medium", 34);

                    var shadow = new NSShadow();
                    shadow.ShadowOffset     = new CGSize(0, -2);
                    shadow.ShadowBlurRadius = 4;
                    shadow.ShadowColor      = NSColor.FromDeviceWhite(0.0f, 0.5f);

                    titleAttributes = new NSMutableDictionary();
                    titleAttributes.SetValueForKey(font, NSAttributedString.FontAttributeName);
                    titleAttributes.SetValueForKey(NSColor.White, NSAttributedString.ForegroundColorAttributeName);
                    titleAttributes.SetValueForKey(shadow, NSAttributedString.ShadowAttributeName);
                    titleAttributes.SetValueForKey(paraphStyle, NSAttributedString.ParagraphStyleAttributeName);

                    var centeredParaphStyle = (NSMutableParagraphStyle)paraphStyle.MutableCopy();
                    centeredParaphStyle.Alignment = NSTextAlignment.Center;

                    centeredTitleAttributes = new NSMutableDictionary();
                    centeredTitleAttributes.SetValueForKey(font, NSAttributedString.FontAttributeName);
                    centeredTitleAttributes.SetValueForKey(NSColor.White, NSAttributedString.ForegroundColorAttributeName);
                    centeredTitleAttributes.SetValueForKey(shadow, NSAttributedString.ShadowAttributeName);
                    centeredTitleAttributes.SetValueForKey(paraphStyle, NSAttributedString.ParagraphStyleAttributeName);
                }

                var attrString = new NSAttributedString(title, centered ? centeredTitleAttributes : titleAttributes);
                var textSize   = attrString.Size;

                //check if we need two lines to draw the text
                var twoLines = title.Contains("\n");
                if (!twoLines)
                {
                    twoLines = textSize.Width > frame.Size.Width && title.Contains(" ");
                }

                //if so, we need to adjust the size to center vertically
                if (twoLines)
                {
                    textSize.Height += 38;
                }

                if (!centered)
                {
                    drawFrame.Inflate(-15, 0);
                }

                //center vertically
                var dy = (drawFrame.Size.Height - textSize.Height) * 0.5f;
                var drawFrameHeight = drawFrame.Size.Height;
                drawFrame.Size = new CGSize(drawFrame.Size.Width, drawFrame.Size.Height - dy);
                attrString.DrawString(drawFrame);
            }

            texture.UnlockFocus();

            //set the created image as the diffuse texture of our 3D box
            var front = SCNMaterial.Create();

            front.Diffuse.Contents        = texture;
            front.LocksAmbientWithDiffuse = true;

            //use a lighter color for the chamfer and sides
            var sides = SCNMaterial.Create();

            sides.Diffuse.Contents  = lightColor;
            node.Geometry.Materials = new SCNMaterial[] {
                front,
                sides,
                sides,
                sides,
                sides
            };

            return(node);
        }
示例#24
0
        public override void DrawRect(CGRect dirtyRect)
        {
            var path = new NSBezierPath ();

            path.AppendPathWithRect (dirtyRect);
            NSColor.Clear.SetFill ();
            path.Fill ();

            path.AppendPathWithRect (highlightRect);
            NSColor.Red.SetStroke ();
            path.Stroke ();
        }
        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();
        }
示例#26
0
 public virtual void Fill()
 {
     path.Fill();
 }