Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
0
        private void DrawWindowBackgroundGradient(CGRect drawingRect, CGPath clippingPath)
        {
            var window = (AppStoreWindow)Window;

            clippingPath.ApplyClippingPathInCurrentContext();
            if (window.IsTextured())
            {
                // If this is a textured window, we can draw the real background gradient and noise pattern
                var contentBorderThickness = window.TitleBarHeight;
                if (window.IsFullScreen())
                {
                    contentBorderThickness -= window.MinimumTitleBarHeight();
                }
                window.SetAutorecalculatesContentBorderThickness(false, NSRectEdge.MaxYEdge);
                window.SetContentBorderThickness(contentBorderThickness, NSRectEdge.MaxYEdge);
                NSGraphicsExtensions.DrawWindowBackground(drawingRect);
            }
            else
            {
                // Not textured, we have to fake the background gradient and noise pattern
                var drawsAsMainWindow = window.DrawsAsMainWindow();
                var startColor        = drawsAsMainWindow ? window.TitleBarStartColor : window.InactiveTitleBarStartColor;
                var endColor          = drawsAsMainWindow ? window.TitleBarEndColor : window.InactiveTitleBarEndColor;

                if (startColor == default(NSColor))
                {
                    startColor = AppStoreWindow.DefaultTitleBarStartColor(drawsAsMainWindow);
                }
                if (endColor == default(NSColor))
                {
                    endColor = AppStoreWindow.DefaultTitleBarEndColor(drawsAsMainWindow);
                }

                var context  = NSGraphicsContext.CurrentContext.GraphicsPort;
                var gradient = DrawingHelper.CreateGraidentWithColors(startColor, endColor);
                context.DrawLinearGradient(gradient, new CGPoint(drawingRect.GetMidX(), drawingRect.GetMinY()), new CGPoint(drawingRect.GetMidX(), drawingRect.GetMaxY()), 0);

                if (drawsAsMainWindow)
                {
                    var noiseRect = new CGRect(1.0f, 1.0f, drawingRect.Width, drawingRect.Height);

                    if (window.ShowBaselineSeparator)
                    {
                        var separatorHeight = BaselineSeparatorFrame.Height;
                        noiseRect.Y      -= separatorHeight;
                        noiseRect.Height += separatorHeight;
                    }

                    NSGraphicsContext.CurrentContext.SaveGraphicsState();
                    var noiseClippingPath = DrawingHelper.CreateClippingPath(noiseRect, CORNER_CLIP_RADIUS);
                    context.AddPath(noiseClippingPath);
                    context.Clip();
                    DrawNoise(0.1f);
                    NSGraphicsContext.CurrentContext.RestoreGraphicsState();
                }
            }
            if (window.ShowBaselineSeparator)
            {
                DrawBaselineSeparator(BaselineSeparatorFrame);
            }
        }