コード例 #1
0
        void IWindow.ShowColorSelector(Color[] options)
        {
            if (changeColorNSEvent == null)
            {
                return;
            }
            var menu = new NSMenu();

            foreach (var opt in options)
            {
                var item    = new NSMenuItem();
                var imgSize = new CoreGraphics.CGSize(50, 12);
                var img     = new NSImage(imgSize);
                img.LockFocus();
                using (var path = NSBezierPath.FromRect(
                           new CoreGraphics.CGRect(0, 0, imgSize.Width, imgSize.Height)))
                    using (var cl = opt.ToNSColor()) {
                        cl.SetFill();
                        path.Fill();
                    }
                img.UnlockFocus();
                item.Image  = img;
                item.Title  = "";
                item.Action = new Selector("OnColorMenuItemClicked:");
                item.Target = this;
                item.Tag    = unchecked ((int)opt.ToUnsignedArgb());
                menu.AddItem(item);
            }
            NSMenu.PopUpContextMenu(menu, changeColorNSEvent, changeColorLinkLabel);
        }
コード例 #2
0
ファイル: TableViewBackend.cs プロジェクト: zhangwenquan/xwt
 public override void DrawBackground(CGRect dirtyRect)
 {
     if (Selected && EffectiveAppearance.Name == NSAppearance.NameVibrantDark &&
         SelectionHighlightStyle != NSTableViewSelectionHighlightStyle.None)
     {
         (Selected ? NSColor.AlternateSelectedControl : BackgroundColor).SetFill();
         var path = NSBezierPath.FromRect(dirtyRect);
         path.Fill();
     }
     else
     {
         base.DrawBackground(dirtyRect);
     }
 }
コード例 #3
0
        public override void DrawRect(CGRect dirtyRect)
        {
            var window            = ((AppStoreWindow)Window);
            var drawsAsMainWindow = window.DrawsAsMainWindow();

            // Start by filling the title bar area with black in fullscreen mode to match native apps
            // Custom title bar drawing blocks can simply override this by not applying the clipping path
            if (window.IsFullScreen())
            {
                NSColor.Black.SetFill();
                NSBezierPath.FromRect(Bounds).Fill();
            }

            CGPath clippingPath;
            var    drawingRect = Bounds;

            if (window.TitleBarDrawingCallbackAction != null)
            {
                clippingPath = DrawingHelper.CreateClippingPath(drawingRect, CORNER_CLIP_RADIUS);
                window.TitleBarDrawingCallbackAction(drawsAsMainWindow, drawingRect, clippingPath);
            }
            else
            {
                // There's a thin whitish line between the darker gray window border line
                // and the gray noise textured gradient; preserve that when drawing a native title bar
                var clippingRect = drawingRect;
                clippingRect.Height -= 1;
                clippingPath         = DrawingHelper.CreateClippingPath(clippingRect, CORNER_CLIP_RADIUS);

                DrawWindowBackgroundGradient(drawingRect, clippingPath);
            }

            if (window.ShowsTitle && ((window.StyleMask & NSWindowStyle.FullScreenWindow) == 0 || window.ShowsTitleInFullscreen))
            {
                NSDictionary dictionary;
                var          titleTextRect = GetTitleFrame(out dictionary, window);

                if (window.VerticallyCenterTitle)
                {
                    titleTextRect.Y = (float)Math.Floor(drawingRect.GetMidY() - titleTextRect.Height / 2f + 1);
                }

                var title = new NSAttributedString(window.Title, dictionary);
                title.DrawString(titleTextRect);
            }
        }
コード例 #4
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();
            }
        }
コード例 #5
0
        void DrawTitleRect()
        {
            Utility.ColorWithHexColorValue(BookInfo.ColorSecondary, 1.0f).Set();
            NSGraphics.RectFill(titleBorderFrame);

            var oPath = NSBezierPath.FromRect(wideBorderLineFrame);

            Utility.ColorWithHexColorValue(BookInfo.FontColor, 1.0f).Set();
            oPath.LineWidth = 3;
            oPath.Stroke();

            var iPath = NSBezierPath.FromRect(thinBorderLineFrame);

            Utility.ColorWithHexColorValue(BookInfo.ColorSecondary, 1.0f).Set();
            iPath.LineWidth = 1;
            iPath.Stroke();
        }
コード例 #6
0
        public override void DrawRect(CoreGraphics.CGRect dirtyRect)
        {
            NSBezierPath path = NSBezierPath.FromRect(new CoreGraphics.CGRect(-200, -200, 200, 200));

            var rotation = new NSAffineTransform();

            rotation.RotateByDegrees((System.nfloat) 30);

            var transtation = new NSAffineTransform();

            transtation.Translate(250, 300);
            rotation.AppendTransform(transtation);

            path.TransformUsingAffineTransform(rotation);

            DrawPath(path);
        }
コード例 #7
0
ファイル: StyleBar.cs プロジェクト: Dynalon/tomboy.osx
        public override void DrawRect(System.Drawing.RectangleF dirtyRect)
        {
            var bounds = Bounds;

            if (dirtyRect.Height < bounds.Height)
            {
                return;
            }
            var bottomBorder = new RectangleF(dirtyRect.X,
                                              dirtyRect.Y,
                                              dirtyRect.Width,
                                              dirtyRect.Y + .2f);

            NSColor.Black.Set();
            var path = NSBezierPath.FromRect(bottomBorder);

            path.Fill();
        }
コード例 #8
0
        protected void DrawPath(NSBezierPath path)
        {
            NSColor.Black.SetStroke();
            path.LineWidth = 3;
            path.Stroke();

            NSColor.Red.SetStroke();
            var boundsPath = NSBezierPath.FromRect(path.Bounds);

            boundsPath.LineWidth = 4;
            boundsPath.Stroke();

            NSColor.Green.SetStroke();
            var controlPointBoundsPath = NSBezierPath.FromRect(path.ControlPointBounds);

            controlPointBoundsPath.LineWidth = 2;
            controlPointBoundsPath.Stroke();
        }
コード例 #9
0
        private void DrawBaselineSeparator(CGRect separatorFrame)
        {
            var window            = (AppStoreWindow)Window;
            var drawsAsMainWindow = window.DrawsAsMainWindow();
            var bottomColor       = drawsAsMainWindow ? window.BaselineSeparatorColor : window.InactiveBaselineSeparatorColor;

            if (bottomColor == default(NSColor))
            {
                bottomColor = AppStoreWindow.DefaultBaselineSeparatorColor(drawsAsMainWindow);
            }

            bottomColor.Set();

            NSGraphics.RectFill(separatorFrame);
            separatorFrame.Y     += separatorFrame.Height;
            separatorFrame.Height = 1.0f;
            NSColor.FromDeviceWhite(1.0f, 0.12f).SetFill();
            NSBezierPath.FromRect(separatorFrame).Fill();
        }
コード例 #10
0
        public static CAShapeLayer ToShape(this RectanglePath element)
        {
            var shape = new CAShapeLayer();

            var bezierPath = NSBezierPath.FromRect(new CGRect(0, 0, element.Width, element.Height));

            shape.Path = bezierPath.ToCGPath();

            if (!string.IsNullOrEmpty(element.Stroke))
            {
                shape.StrokeColor = XExtensions.ConvertToNSColor(element.Stroke).CGColor;
            }

            if (!string.IsNullOrEmpty(element.Fill))
            {
                shape.FillColor = XExtensions.ConvertToNSColor(element.Fill).CGColor;
            }

            shape.LineWidth = element.StrokeWidth * 2;
            shape.Bounds    = new CGRect(0, 0, element.Width, element.Height);
            return(shape);
        }
コード例 #11
0
ファイル: ScanView.cs プロジェクト: msioen/MenuBarCodeReader
        public override void DrawRect(CGRect dirtyRect)
        {
            if (_selecting)
            {
                var bgPath = NSBezierPath.FromRect(Bounds);

                if (ScanMode == EScanMode.Select && _startLocation.HasValue && _endLocation.HasValue)
                {
                    var path = NSBezierPath.FromRect(BuildRect(_startLocation.Value, _endLocation.Value));
                    path = path.BezierPathByReversingPath();
                    bgPath.AppendPath(path);

                    NSColor.Black.SetStroke();
                    path.LineWidth = 1;
                    path.Stroke();
                }

                NSColor.Gray.ColorWithAlphaComponent(0.2f).SetFill();
                bgPath.Fill();
            }

            base.DrawRect(dirtyRect);
        }
コード例 #12
0
        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();
        }
コード例 #13
0
ファイル: TerminalView.cs プロジェクト: nosami/VtNetCore.UWP
        public override void DrawRect(CGRect dirtyRect)
        {
            base.DrawRect(dirtyRect);

            var attributes = new NSStringAttributes
            {
                ForegroundColor = NSColor.Blue,
                Font            = NSFont.FromFontName("Andale Mono", 14)
            };

            ProcessTextFormat(attributes);

            NSColor.Black.SetFill();
            NSBezierPath.FillRect(dirtyRect);

            lock (Terminal)
            {
                int   row            = ViewTop;
                float verticalOffset = -row * (float)CharacterHeight;

                var lines = Terminal.ViewPort.GetLines(ViewTop, Rows);

                foreach (var line in lines)
                {
                    if (line == null)
                    {
                        row++;
                        continue;
                    }

                    int column = 0;

                    var xform = new NSAffineTransform();
                    xform.Scale((nfloat)(line.DoubleWidth ? 2.0 : 1.0), (nfloat)((line.DoubleHeightTop || line.DoubleHeightBottom) ? 2.0 : 1.0));
                    xform.Concat();

                    var spanStart = 0;
                    while (column < line.Count)
                    {
                        bool selected        = TextSelection == null ? false : TextSelection.Within(column, row);
                        var  backgroundColor = GetBackgroundColor(line[column].Attributes, selected);

                        if (column < (line.Count - 1) && GetBackgroundColor(line[column + 1].Attributes, TextSelection == null ? false : TextSelection.Within(column + 1, row)) == backgroundColor)
                        {
                            column++;
                            continue;
                        }

                        var rect = new CGRect(
                            spanStart * CharacterWidth,
                            ((row - (line.DoubleHeightBottom ? 1 : 0)) * CharacterHeight + verticalOffset) * (line.DoubleHeightBottom | line.DoubleHeightTop ? 0.5 : 1.0),
                            ((column - spanStart + 1) * CharacterWidth) + 0.9,
                            CharacterHeight + 0.9
                            );

                        backgroundColor.SetFill();
                        NSBezierPath.FillRect(rect);

                        column++;
                        spanStart = column;
                    }
                    xform.Invert();
                    xform.Concat();

                    row++;
                }

                row = ViewTop;
                foreach (var line in lines)
                {
                    if (line == null)
                    {
                        row++;
                        continue;
                    }

                    int column = 0;

                    var xform = new NSAffineTransform();
                    xform.Scale((nfloat)(line.DoubleWidth ? 2.0 : 1.0), (nfloat)((line.DoubleHeightTop || line.DoubleHeightBottom) ? 2.0 : 1.0));
                    xform.Concat();

                    var    spanStart = 0;
                    string toDisplay = string.Empty;
                    while (column < line.Count)
                    {
                        bool selected        = TextSelection == null ? false : TextSelection.Within(column, row);
                        var  foregroundColor = GetForegroundColor(line[column].Attributes, selected);

                        toDisplay += line[column].Char.ToString() + line[column].CombiningCharacters;
                        if (
                            column < (line.Count - 1) &&
                            GetForegroundColor(line[column + 1].Attributes, TextSelection == null ? false : TextSelection.Within(column + 1, row)) == foregroundColor &&
                            line[column + 1].Attributes.Underscore == line[column].Attributes.Underscore &&
                            line[column + 1].Attributes.Reverse == line[column].Attributes.Reverse &&
                            line[column + 1].Attributes.Bright == line[column].Attributes.Bright
                            )
                        {
                            column++;
                            continue;
                        }

                        var textPosition = new CGPoint(
                            spanStart * CharacterWidth,
                            ((row - (line.DoubleHeightBottom ? 1 : 0)) * CharacterHeight + verticalOffset + attributes.Font.Descender) * (line.DoubleHeightBottom | line.DoubleHeightTop ? 0.5 : 1.0)
                            );

                        attributes.ForegroundColor = foregroundColor;
                        attributes.UnderlineStyle  = line[column].Attributes.Underscore ? 1 : 0;
                        var nsStr = new NSString(toDisplay);

                        nsStr.DrawAtPoint(textPosition, attributes.Dictionary);


                        column++;
                        spanStart = column;
                        toDisplay = "";
                    }
                    xform.Invert();
                    xform.Concat();


                    row++;
                }

                if (Terminal.CursorState.ShowCursor)
                {
                    var cursorY    = Terminal.ViewPort.TopRow - ViewTop + Terminal.CursorState.CurrentRow;
                    var cursorRect = new CGRect(
                        Terminal.CursorState.CurrentColumn * CharacterWidth,
                        cursorY * CharacterHeight,
                        CharacterWidth + 0.9,
                        CharacterHeight + 0.9
                        );

                    var path = NSBezierPath.FromRect(cursorRect);
                    GetForegroundColor(Terminal.CursorState.Attributes, false).Set();
                    path.Stroke();
                }
            }
        }
コード例 #14
0
ファイル: UIBezierPath.cs プロジェクト: zfs990/mac-samples
 public static UIBezierPath FromRect(CGRect rect)
 {
     return(new UIBezierPath(NSBezierPath.FromRect(rect)));
 }
コード例 #15
0
        public static NSImage ToCropped(NSImage source, double zoomFactor, double xOffset, double yOffset, double cropWidthRatio, double cropHeightRatio)
        {
            double sourceWidth  = source.CGImage.Width;
            double sourceHeight = source.CGImage.Height;

            double desiredWidth  = sourceWidth;
            double desiredHeight = sourceHeight;

            double desiredRatio = cropWidthRatio / cropHeightRatio;
            double currentRatio = sourceWidth / sourceHeight;

            if (currentRatio > desiredRatio)
            {
                desiredWidth = (cropWidthRatio * sourceHeight / cropHeightRatio);
            }
            else if (currentRatio < desiredRatio)
            {
                desiredHeight = (cropHeightRatio * sourceWidth / cropWidthRatio);
            }

            xOffset = xOffset * desiredWidth;
            yOffset = yOffset * desiredHeight;

            desiredWidth  = desiredWidth / zoomFactor;
            desiredHeight = desiredHeight / zoomFactor;

            float cropX = (float)(((sourceWidth - desiredWidth) / 2) + xOffset);
            float cropY = (float)(((sourceHeight - desiredHeight) / 2) + yOffset);

            if (cropX < 0)
            {
                cropX = 0;
            }

            if (cropY < 0)
            {
                cropY = 0;
            }

            if (cropX + desiredWidth > sourceWidth)
            {
                cropX = (float)(sourceWidth - desiredWidth);
            }

            if (cropY + desiredHeight > sourceHeight)
            {
                cropY = (float)(sourceHeight - desiredHeight);
            }


            var       colorSpace       = CGColorSpace.CreateDeviceRGB();
            const int bytesPerPixel    = 4;
            int       width            = (int)desiredWidth;
            int       height           = (int)desiredHeight;
            var       bytes            = new byte[width * height * bytesPerPixel];
            int       bytesPerRow      = bytesPerPixel * width;
            const int bitsPerComponent = 8;

            using (var context = new CGBitmapContext(bytes, width, height, bitsPerComponent, bytesPerRow, colorSpace, CGBitmapFlags.PremultipliedLast | CGBitmapFlags.ByteOrder32Big))
            {
                var clippedRect = new CGRect(0, 0, desiredWidth, desiredHeight);
                context.BeginPath();

                using (var path = NSBezierPath.FromRect(clippedRect))
                {
                    context.AddPath(path.ToCGPath());
                    context.Clip();
                }

                var drawRect = new CGRect(-cropX, -cropY, sourceWidth, sourceHeight);
                context.DrawImage(drawRect, source.CGImage);

                using (var output = context.ToImage())
                {
                    return(new NSImage(output, CGSize.Empty));
                }
            }
        }