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(); }
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); } }
private CGRect GetTitleFrame(out NSDictionary titleTextStyles, AppStoreWindow window) { var drawsAsMainWindow = window.DrawsAsMainWindow(); var titleTextShadow = drawsAsMainWindow ? window.TitleTextShadow : window.InactiveTitleTextShadow; if (titleTextShadow == null) { titleTextShadow = new NSShadow { ShadowBlurRadius = 0f, ShadowOffset = new CGSize(0f, -1.0f), ShadowColor = NSColor.FromDeviceWhite(1.0f, 0.5f), }; } var titleTextColor = drawsAsMainWindow ? window.TitleTextColor : window.InactiveTitleTextColor; if (titleTextColor == default(NSColor)) { titleTextColor = AppStoreWindow.DefaultTitleTextColor(drawsAsMainWindow); } var titleFont = window.TitleFont ?? NSFont.TitleBarFontOfSize(NSFont.SystemFontSizeForControlSize(NSControlSize.Regular)); var titleParagraphStyle = (NSParagraphStyle)NSParagraphStyle.DefaultParagraphStyle.MutableCopy();//new NSParagraphStyle { LineBreakMode = NSLineBreakMode.TruncatingTail }; titleParagraphStyle.LineBreakMode = NSLineBreakMode.TruncatingTail; titleTextStyles = NSDictionary.FromObjectsAndKeys( new object[] { titleFont, titleTextColor, titleTextShadow, titleParagraphStyle }, new object[] { NSStringAttributeKey.Font, NSStringAttributeKey.ForegroundColor, NSStringAttributeKey.Shadow, NSStringAttributeKey.ParagraphStyle }); var titleSize = new NSAttributedString(window.Title, titleTextStyles).Size; var titleTextRect = new CGRect(0, 0, titleSize.Width, titleSize.Height); var docIconButton = window.StandardWindowButton(NSWindowButton.DocumentIconButton); var versionButton = window.StandardWindowButton(NSWindowButton.DocumentVersionsButton); var closeButton = window.ButtonToLayout(NSWindowButton.CloseButton); var minimizeButton = window.ButtonToLayout(NSWindowButton.MiniaturizeButton); var zoomButton = window.ButtonToLayout(NSWindowButton.ZoomButton); if (docIconButton != null) { var docIconButtonFrame = ConvertRectFromView(docIconButton.Frame, docIconButton.Superview); titleTextRect.X = docIconButtonFrame.GetMaxX() + TITLE_DOCUMENT_BUTTON_OFFSET.Width; titleTextRect.Y = docIconButtonFrame.GetMidY() - titleSize.Height / 2f + TITLE_DOCUMENT_BUTTON_OFFSET.Height; } else if (versionButton != null) { var versionsButtonFrame = ConvertRectFromView(versionButton.Frame, versionButton.Superview); titleTextRect.X = versionsButtonFrame.GetMinX() - titleSize.Width + TITLE_VERSIONS_BUTTON_OFFSET; var document = ((NSWindowController)window.WindowController).Document; if (document.HasUnautosavedChanges || document.IsDocumentEdited) { titleTextRect.X += TITLE_DOCUMENT_STATUS_X_OFFSET; } } else if (closeButton != null || minimizeButton != null || zoomButton != null) { var closeMaxX = closeButton == null ? 0f : closeButton.Frame.GetMaxX(); var minimizeMaxX = minimizeButton == null ? 0f : minimizeButton.Frame.GetMaxX(); var zoomMaxX = zoomButton == null ? 0f : zoomButton.Frame.GetMaxX(); var adjustedX = NMath.Max(NMath.Max(closeMaxX, minimizeMaxX), zoomMaxX) + TITLE_MARGINS.Width; var proposedX = Bounds.GetMidX() - titleSize.Width / 2f; titleTextRect.X = NMath.Max(proposedX, adjustedX); } else { titleTextRect.X = Bounds.GetMidX() - titleSize.Width / 2f; } var fullScreenButton = window.ButtonToLayout(NSWindowButton.FullScreenButton); if (fullScreenButton != null) { var fullScreenX = fullScreenButton.Frame.X; var maxTitleX = titleTextRect.GetMaxX(); if ((fullScreenX - TITLE_MARGINS.Width) < titleTextRect.GetMaxX()) { titleTextRect.Width = titleTextRect.Size.Width - (maxTitleX - fullScreenX) - TITLE_MARGINS.Width; } } titleTextRect.Y = Bounds.GetMaxY() - titleSize.Height - TITLE_MARGINS.Height; return(titleTextRect); }
private RectangleF GetTitleFrame(out NSDictionary titleTextStyles, AppStoreWindow window) { var drawsAsMainWindow = window.DrawsAsMainWindow(); var titleTextShadow = drawsAsMainWindow ? window.TitleTextShadow : window.InactiveTitleTextShadow; if (titleTextShadow == null) { titleTextShadow = new NSShadow { ShadowBlurRadius = 0f, ShadowOffset = new SizeF(0f, -1.0f), ShadowColor = NSColor.FromDeviceWhite(1.0f, 0.5f), }; } var titleTextColor = drawsAsMainWindow ? window.TitleTextColor : window.InactiveTitleTextColor; if (titleTextColor == default(NSColor)) { titleTextColor = AppStoreWindow.DefaultTitleTextColor(drawsAsMainWindow); } var titleFont = window.TitleFont ?? NSFont.TitleBarFontOfSize(NSFont.SystemFontSizeForControlSize(NSControlSize.Regular)); var titleParagraphStyle = (NSParagraphStyle)NSParagraphStyle.DefaultParagraphStyle.MutableCopy();//new NSParagraphStyle { LineBreakMode = NSLineBreakMode.TruncatingTail }; titleParagraphStyle.LineBreakMode = NSLineBreakMode.TruncatingTail; titleTextStyles = NSDictionary.FromObjectsAndKeys( new object[] { titleFont, titleTextColor, titleTextShadow, titleParagraphStyle }, new object[] { NSAttributedString.FontAttributeName, NSAttributedString.ForegroundColorAttributeName, NSAttributedString.ShadowAttributeName, NSAttributedString.ParagraphStyleAttributeName }); var titleSize = new NSAttributedString(window.Title, titleTextStyles).Size; var titleTextRect = new RectangleF(0, 0, titleSize.Width, titleSize.Height); var docIconButton = window.StandardWindowButton(NSWindowButton.DocumentIconButton); var versionButton = window.StandardWindowButton(NSWindowButton.DocumentVersionsButton); var closeButton = window.ButtonToLayout(NSWindowButton.CloseButton); var minimizeButton = window.ButtonToLayout(NSWindowButton.MiniaturizeButton); var zoomButton = window.ButtonToLayout(NSWindowButton.ZoomButton); if (docIconButton != null) { var docIconButtonFrame = ConvertRectFromView(docIconButton.Frame, docIconButton.Superview); titleTextRect.X = docIconButtonFrame.GetMaxX() + TITLE_DOCUMENT_BUTTON_OFFSET.Width; titleTextRect.Y = docIconButtonFrame.GetMidY() - titleSize.Height / 2f + TITLE_DOCUMENT_BUTTON_OFFSET.Height; } else if (versionButton != null) { var versionsButtonFrame = ConvertRectFromView(versionButton.Frame, versionButton.Superview); titleTextRect.X = versionsButtonFrame.GetMinX() - titleSize.Width + TITLE_VERSIONS_BUTTON_OFFSET; var document = ((NSWindowController)window.WindowController).Document; if (document.HasUnautosavedChanges || document.IsDocumentEdited) { titleTextRect.X += TITLE_DOCUMENT_STATUS_X_OFFSET; } } else if (closeButton != null || minimizeButton != null || zoomButton != null) { var closeMaxX = closeButton == null ? 0f : closeButton.Frame.GetMaxX(); var minimizeMaxX = minimizeButton == null ? 0f : minimizeButton.Frame.GetMaxX(); var zoomMaxX = zoomButton == null ? 0f : zoomButton.Frame.GetMaxX(); var adjustedX = Math.Max(Math.Max(closeMaxX, minimizeMaxX), zoomMaxX) + TITLE_MARGINS.Width; var proposedX = Bounds.GetMidX() - titleSize.Width / 2f; titleTextRect.X = Math.Max(proposedX, adjustedX); } else { titleTextRect.X = Bounds.GetMidX() - titleSize.Width / 2f; } var fullScreenButton = window.ButtonToLayout(NSWindowButton.FullScreenButton); if (fullScreenButton != null) { var fullScreenX = fullScreenButton.Frame.X; var maxTitleX = titleTextRect.GetMaxX(); if ((fullScreenX - TITLE_MARGINS.Width) < titleTextRect.GetMaxX()) { titleTextRect.Width = titleTextRect.Size.Width - (maxTitleX - fullScreenX) - TITLE_MARGINS.Width; } } titleTextRect.Y = Bounds.GetMaxY() - titleSize.Height - TITLE_MARGINS.Height; return titleTextRect; }