public static NSColor ToNS(this CGColor color) { #if XAMMAC return(NSColor.FromCGColor(color)); #else return(MacExtensions.NSColorFromCGColor(color)); #endif }
public static NSColor ToNSUI(this Color color) { if (color.ControlObject is NSColor nscolor) { return(nscolor); } if (color.ControlObject is CGColor cgcolor && MacVersion.IsAtLeast(10, 8)) { return(NSColor.FromCGColor(cgcolor)); } return(NSColor.FromDeviceRgba(color.R, color.G, color.B, color.A)); }
public static NSColor GetBGColor(this NSView view) { var colorRef = view.Layer?.BackgroundColor; if (colorRef != null) { return(NSColor.FromCGColor(colorRef)); } else { return(null); } }
public static Color GetBackgroundColor(this NSControl self) { if (self == null) { return(Color.Transparent); } if (self.WantsLayer) { NSColor.FromCGColor(self.Layer.BackgroundColor).ToColor(); } return(Color.Transparent); }
public static NSColor ToNS(this CGColor color) { if (color == null) { return(null); } if (MacVersion.IsAtLeast(10, 8)) { return(NSColor.FromCGColor(color)); } return(NSColor.FromColorSpace(new NSColorSpace(color.ColorSpace), color.Components)); }
protected void SetNativeControl(TNativeView uiview) { if (uiview.WantsLayer) { this.defaultColor = NSColor.FromCGColor(uiview.Layer.BackgroundColor); } this.Control = uiview; if (this.Element.BackgroundColor != Color.Default) { this.SetBackgroundColor(this.Element.BackgroundColor); } this.UpdateIsEnabled(); this.AddSubview((NSView)uiview); }
public override void AwakeFromNib() { base.AwakeFromNib(); //set window background color this.View.WantsLayer = true; this.View.Layer.BackgroundColor = new CoreGraphics.CGColor(1, 1, (float)1, (float)1); ExpiringCertificatesLabel.StringValue = serverNode.NoOfExpiringCert60days + " Certificates Expiring in 60 days"; if (serverNode.NoOfExpiringCert60days > 0) { ExpiringCertificatesLabel.TextColor = NSColor.FromCGColor(new CoreGraphics.CGColor((float)0.4, (float)0.3, (float)1, (float)1)); } ActiveCertificatesLabel.StringValue = serverNode.NoOfActiveCerts + " Certificates Active"; ExpiredCertificatesLabel.StringValue = serverNode.NoOfExpiredCerts + " Certificates Expired"; RevokedCertificatesLabel.StringValue = serverNode.NoOfRevokedCerts + " Certificates Revoked"; }
public void Draw(CGContext ctx, CGColor foregroundColor, double x, double y) { bool tempForegroundSet = false; // if no color attribute is set for the whole string, // NSLayoutManager will use the default control foreground color. // To override the default color we need to apply the current CGContext stroke color // before all other attributes are set, otherwise it will remove all other foreground colors. if (foregroundColor != null && !Attributes.Any(a => a is ColorTextAttribute && a.StartIndex == 0 && a.Count == Text.Length)) { // FIXME: we need to find a better way to accomplish this without the need to reset all attributes. ResetAttributes(NSColor.FromCGColor(foregroundColor)); tempForegroundSet = true; } ctx.SaveState(); NSGraphicsContext.GlobalSaveGraphicsState(); var nsContext = NSGraphicsContext.FromCGContext(ctx, true); NSGraphicsContext.CurrentContext = nsContext; using (var TextLayout = new NSLayoutManager()) { TextLayout.AddTextContainer(TextContainer); TextStorage.AddLayoutManager(TextLayout); TextLayout.DrawBackgroundForGlyphRange(new NSRange(0, Text.Length), new CGPoint(x, y)); TextLayout.DrawGlyphsForGlyphRange(new NSRange(0, Text.Length), new CGPoint(x, y)); TextStorage.RemoveLayoutManager(TextLayout); TextLayout.RemoveTextContainer(0); } // reset foreground color change if (tempForegroundSet) { ResetAttributes(); } NSGraphicsContext.GlobalRestoreGraphicsState(); ctx.RestoreState(); }
protected override void UpdateContents() { if (Node == null) { return; } foreach (var constraint in constraints) { constraint.Active = false; constraint.Dispose(); } constraints.Clear(); OptimalWidth = MarginSize; bool selected = Superview is NSTableRowView rowView && rowView.Selected; var iconName = ObjectValueTreeViewController.GetIcon(Node.Flags); ImageView.Image = GetImage(iconName, Gtk.IconSize.Menu, selected); constraints.Add(ImageView.CenterYAnchor.ConstraintEqualToAnchor(CenterYAnchor)); constraints.Add(ImageView.LeadingAnchor.ConstraintEqualToAnchor(LeadingAnchor, MarginSize)); constraints.Add(ImageView.WidthAnchor.ConstraintEqualToConstant(ImageSize)); constraints.Add(ImageView.HeightAnchor.ConstraintEqualToConstant(ImageSize)); OptimalWidth += ImageView.Image.Size.Width; OptimalWidth += RowCellSpacing; var editable = TreeView.AllowWatchExpressions && Node.Parent is RootObjectValueNode; var textColor = NSColor.ControlText; var placeholder = string.Empty; var name = Node.Name; if (Node.IsUnknown) { if (TreeView.DebuggerService.Frame != null) { textColor = NSColor.FromCGColor(GetCGColor(Styles.ObjectValueTreeValueDisabledText)); } } else if (Node.IsError || Node.IsNotSupported) { } else if (Node.IsImplicitNotSupported) { } else if (Node.IsEvaluating) { if (Node.GetIsEvaluatingGroup()) { textColor = NSColor.FromCGColor(GetCGColor(Styles.ObjectValueTreeValueDisabledText)); } } else if (Node.IsEnumerable) { } else if (Node is AddNewExpressionObjectValueNode) { placeholder = GettextCatalog.GetString("Add new expression"); name = string.Empty; editable = true; } else if (TreeView.Controller.GetNodeHasChangedSinceLastCheckpoint(Node)) { textColor = NSColor.FromCGColor(GetCGColor(Styles.ObjectValueTreeValueModifiedText)); } TextField.PlaceholderAttributedString = GetAttributedPlaceholderString(placeholder); TextField.AttributedStringValue = GetAttributedString(name); TextField.TextColor = textColor; TextField.Editable = editable; UpdateFont(TextField); TextField.SizeToFit(); OptimalWidth += TextField.Frame.Width; constraints.Add(TextField.CenterYAnchor.ConstraintEqualToAnchor(CenterYAnchor)); constraints.Add(TextField.LeadingAnchor.ConstraintEqualToAnchor(ImageView.TrailingAnchor, RowCellSpacing)); if (MacObjectValueTreeView.ValidObjectForPreviewIcon(Node)) { SetPreviewButtonIcon(PreviewButtonIcon.Hidden); if (!previewIconVisible) { AddSubview(PreviewButton); previewIconVisible = true; } constraints.Add(TextField.WidthAnchor.ConstraintGreaterThanOrEqualToConstant(TextField.Frame.Width)); constraints.Add(PreviewButton.CenterYAnchor.ConstraintEqualToAnchor(CenterYAnchor)); constraints.Add(PreviewButton.LeadingAnchor.ConstraintEqualToAnchor(TextField.TrailingAnchor, RowCellSpacing)); constraints.Add(PreviewButton.WidthAnchor.ConstraintEqualToConstant(ImageSize)); constraints.Add(PreviewButton.HeightAnchor.ConstraintEqualToConstant(ImageSize)); OptimalWidth += RowCellSpacing; OptimalWidth += PreviewButton.Frame.Width; } else { if (previewIconVisible) { PreviewButton.RemoveFromSuperview(); previewIconVisible = false; } constraints.Add(TextField.TrailingAnchor.ConstraintEqualToAnchor(TrailingAnchor, -MarginSize)); } foreach (var constraint in constraints) { constraint.Active = true; } OptimalWidth += MarginSize; }
protected override void UpdateContents() { if (Node == null) { return; } foreach (var constraint in constraints) { constraint.Active = false; constraint.Dispose(); } constraints.Clear(); OptimalWidth = MarginSize; var editable = TreeView.AllowWatchExpressions && Node.Parent is RootObjectValueNode; var selected = Superview is NSTableRowView rowView && rowView.Selected; var iconName = ObjectValueTreeViewController.GetIcon(Node.Flags); var wrapper = (MacObjectValueNode)ObjectValue; var textColor = NSColor.ControlText; var showAddNewExpression = false; var placeholder = string.Empty; var name = Node.Name; if (Node.IsUnknown) { if (!selected && TreeView.DebuggerService.Frame != null) { textColor = NSColor.FromCGColor(GetCGColor(Styles.ObjectValueTreeValueDisabledText)); } } else if (Node.IsError || Node.IsNotSupported) { } else if (Node.IsImplicitNotSupported) { } else if (Node.IsEvaluating) { if (!selected && Node.GetIsEvaluatingGroup()) { textColor = NSColor.FromCGColor(GetCGColor(Styles.ObjectValueTreeValueDisabledText)); } } else if (Node.IsEnumerable) { } else if (Node is AddNewExpressionObjectValueNode) { placeholder = GettextCatalog.GetString("Add item to watch"); showAddNewExpression = true; name = string.Empty; editable = true; } else if (!selected && TreeView.Controller.GetNodeHasChangedSinceLastCheckpoint(Node)) { textColor = NSColor.FromCGColor(GetCGColor(Styles.ObjectValueTreeValueModifiedText)); } NSView firstView; if (showAddNewExpression) { AddNewExpressionButton.Image = GetImage("gtk-add", Gtk.IconSize.Menu, selected); firstView = AddNewExpressionButton; if (!addNewExpressionVisible) { ImageView.RemoveFromSuperview(); AddSubview(AddNewExpressionButton); addNewExpressionVisible = true; } } else { ImageView.Image = GetImage(iconName, Gtk.IconSize.Menu, selected); firstView = ImageView; if (addNewExpressionVisible) { AddNewExpressionButton.RemoveFromSuperview(); addNewExpressionVisible = false; AddSubview(ImageView); } } constraints.Add(firstView.CenterYAnchor.ConstraintEqualToAnchor(CenterYAnchor)); constraints.Add(firstView.LeadingAnchor.ConstraintEqualToAnchor(LeadingAnchor, MarginSize)); constraints.Add(firstView.WidthAnchor.ConstraintEqualToConstant(ImageSize)); constraints.Add(firstView.HeightAnchor.ConstraintEqualToConstant(ImageSize)); OptimalWidth += ImageSize; OptimalWidth += RowCellSpacing; TextField.PlaceholderAttributedString = GetAttributedPlaceholderString(placeholder); TextField.StringValue = name; TextField.TextColor = textColor; TextField.Editable = editable; UpdateFont(TextField); TextField.SizeToFit(); ImageView.AccessibilityTitle = ObjectValueTreeViewController.GetAccessibilityTitleForIcon( Node.Flags, GettextCatalog.GetString("Object Name")); var value = editable && string.IsNullOrEmpty(name) ? placeholder : name; var textWidth = GetWidthForString(TextField.Font, value); OptimalWidth += textWidth; NSView textView; if (editing) { textView = editorTextView; var span = editor.TextBuffer.CurrentSnapshot.GetEntireSpan(); editor.TextBuffer.Replace(span, name); if (!editorTextViewVisible) { TextField.RemoveFromSuperview(); editorTextViewVisible = true; AddSubview(textView); } constraints.Add(textView.TopAnchor.ConstraintEqualToAnchor(TopAnchor, (nfloat)editor.FormattedLineSource.BaseIndentation)); constraints.Add(textView.BottomAnchor.ConstraintEqualToAnchor(BottomAnchor, (nfloat)editor.FormattedLineSource.BaseIndentation)); } else { textView = TextField; if (editorTextViewVisible) { editorTextView.RemoveFromSuperview(); editorTextViewVisible = false; AddSubview(TextField); } constraints.Add(TextField.CenterYAnchor.ConstraintEqualToAnchor(CenterYAnchor)); } constraints.Add(textView.LeadingAnchor.ConstraintEqualToAnchor(firstView.TrailingAnchor, RowCellSpacing)); if (!editing && MacObjectValueTreeView.ValidObjectForPreviewIcon(Node)) { SetPreviewButtonIcon(PreviewButtonIcon.Hidden); if (!previewIconVisible) { AddSubview(PreviewButton); previewIconVisible = true; } constraints.Add(TextField.WidthAnchor.ConstraintGreaterThanOrEqualToConstant(textWidth)); constraints.Add(PreviewButton.CenterYAnchor.ConstraintEqualToAnchor(CenterYAnchor)); constraints.Add(PreviewButton.LeadingAnchor.ConstraintEqualToAnchor(TextField.TrailingAnchor, RowCellSpacing)); constraints.Add(PreviewButton.WidthAnchor.ConstraintEqualToConstant(ImageSize)); constraints.Add(PreviewButton.HeightAnchor.ConstraintEqualToConstant(ImageSize)); OptimalWidth += RowCellSpacing; OptimalWidth += ImageSize; } else { if (previewIconVisible) { PreviewButton.RemoveFromSuperview(); previewIconVisible = false; } constraints.Add(textView.TrailingAnchor.ConstraintEqualToAnchor(TrailingAnchor, -MarginSize)); } foreach (var constraint in constraints) { constraint.Active = true; } OptimalWidth += MarginSize; wrapper.OptimalNameFont = TreeView.CustomFont; wrapper.OptimalNameWidth = OptimalWidth; wrapper.OptimalXOffset = Frame.X; }
private void DrawStringOutline(CGContext context, string text, CGColor color, CGRect rect, int align) { NSString nsString = new NSString(text); int halign = align % 3; int valign = align / 3; /* * var attributesText = new NSAttributedString("Outline", * new CoreText.CTStringAttributes() * { * ForegroundColor = color, * Font = m_font * }); * var attributesOutline = new NSAttributedString("Outline", * new CoreText.CTStringAttributes() * { * ForegroundColor = m_colorWhite, * Font = m_font * }); */ var objectsText = new object[] { m_font, NSColor.FromCGColor(color) }; var keysText = new object[] { "NSFont", "NSColor" }; var attributesText = NSDictionary.FromObjectsAndKeys(objectsText, keysText); var objectsOutline = new object[] { m_font, NSColor.White }; var keysOutline = new object[] { "NSFont", "NSColor" }; var attributesOutline = NSDictionary.FromObjectsAndKeys(objectsOutline, keysOutline); CGSize size = nsString.StringSize(attributesText); if (halign == 0) { } else if (halign == 1) { rect.X = (rect.Left + rect.Right) / 2 - size.Width / 2; } else if (halign == 2) { rect.X = rect.Right - size.Width; } rect.Width = size.Width; if (valign == 0) { } else if (valign == 1) { rect.Y = (rect.Top + rect.Bottom) / 2 - size.Height / 2; } else if (valign == 2) { rect.Y = rect.Bottom - size.Height; } rect.Height = size.Height; NSColor.Black.Set(); for (int ox = -1; ox <= 1; ox++) { for (int oy = -1; oy <= 1; oy++) { CGRect rectString = rect; rectString.Offset(new CGPoint(ox, oy)); nsString.DrawString(Invert(rectString), attributesOutline); } } nsString.DrawString(Invert(rect), attributesText); //nsString.DrawString(Invert(rect), null); /* * using (var textLine = new CoreText.CTLine(attributesText)) * { * textLine.Draw(context); * } */ }
protected override void UpdateContents() { if (Node == null) { return; } foreach (var constraint in constraints) { constraint.Active = false; constraint.Dispose(); } constraints.Clear(); bool selected = Superview is NSTableRowView rowView && rowView.Selected; var wrapper = (MacObjectValueNode)ObjectValue; var editable = TreeView.GetCanEditNode(Node); var textColor = NSColor.ControlText; string evaluateStatusIcon = null; string valueButtonText = null; var showViewerButton = false; Color? previewColor = null; bool showSpinner = false; string strval; if (Node.IsUnknown) { if (TreeView.DebuggerService.Frame != null) { strval = GettextCatalog.GetString("The name '{0}' does not exist in the current context.", Node.Name); } else { strval = string.Empty; } evaluateStatusIcon = Ide.Gui.Stock.Warning; } else if (Node.IsError || Node.IsNotSupported) { evaluateStatusIcon = Ide.Gui.Stock.Warning; strval = Node.Value ?? string.Empty; int i = strval.IndexOf('\n'); if (i != -1) { strval = strval.Substring(0, i); } if (!selected) { textColor = NSColor.FromCGColor(GetCGColor(Styles.ObjectValueTreeValueErrorText)); } } else if (Node.IsImplicitNotSupported) { strval = string.Empty; if (!selected) { textColor = NSColor.FromCGColor(GetCGColor(Styles.ObjectValueTreeValueDisabledText)); } if (Node.CanRefresh) { valueButtonText = GettextCatalog.GetString("Show Value"); } } else if (Node.IsEvaluating) { strval = GettextCatalog.GetString("Evaluating\u2026"); showSpinner = true; if (!selected) { textColor = NSColor.FromCGColor(GetCGColor(Styles.ObjectValueTreeValueDisabledText)); } } else if (Node.IsEnumerable) { if (Node is ShowMoreValuesObjectValueNode) { valueButtonText = GettextCatalog.GetString("Show More"); } else { valueButtonText = GettextCatalog.GetString("Show Values"); } strval = string.Empty; } else if (Node is AddNewExpressionObjectValueNode) { strval = string.Empty; editable = false; } else { strval = TreeView.Controller.GetDisplayValueWithVisualisers(Node, out showViewerButton); if (!selected && TreeView.Controller.GetNodeHasChangedSinceLastCheckpoint(Node)) { textColor = NSColor.FromCGColor(GetCGColor(Styles.ObjectValueTreeValueModifiedText)); } var val = Node.GetDebuggerObjectValue(); if (val != null && !val.IsNull && DebuggingService.HasGetConverter <Color> (val)) { try { previewColor = DebuggingService.GetGetConverter <Color> (val).GetValue(val); } catch { previewColor = null; } } } strval = strval.Replace("\r\n", " ").Replace("\n", " "); var views = new List <NSView> (); OptimalWidth = MarginSize; // First item: Status Icon -or- Spinner if (evaluateStatusIcon != null) { statusIcon.Image = GetImage(evaluateStatusIcon, Gtk.IconSize.Menu, selected); statusIcon.AccessibilityTitle = ObjectValueTreeViewController.GetAccessibilityTitleForIcon( evaluateStatusIcon, GettextCatalog.GetString("Object Value")); if (!statusIconVisible) { AddSubview(statusIcon); statusIconVisible = true; } constraints.Add(statusIcon.CenterYAnchor.ConstraintEqualToAnchor(CenterYAnchor)); constraints.Add(statusIcon.WidthAnchor.ConstraintEqualToConstant(ImageSize)); constraints.Add(statusIcon.HeightAnchor.ConstraintEqualToConstant(ImageSize)); views.Add(statusIcon); OptimalWidth += ImageSize; OptimalWidth += RowCellSpacing; } else if (statusIconVisible) { statusIcon.RemoveFromSuperview(); statusIconVisible = false; } if (showSpinner) { if (!spinnerVisible) { AddSubview(spinner); spinner.StartAnimation(this); spinnerVisible = true; } constraints.Add(spinner.CenterYAnchor.ConstraintEqualToAnchor(CenterYAnchor)); constraints.Add(spinner.WidthAnchor.ConstraintEqualToConstant(ImageSize)); constraints.Add(spinner.HeightAnchor.ConstraintEqualToConstant(ImageSize)); views.Add(spinner); OptimalWidth += ImageSize; OptimalWidth += RowCellSpacing; } else if (spinnerVisible) { spinner.RemoveFromSuperview(); spinner.StopAnimation(this); spinnerVisible = false; } // Second Item: Color Preview if (previewColor.HasValue) { colorPreview.Layer.BackgroundColor = GetCGColor(previewColor.Value); if (!colorPreviewVisible) { AddSubview(colorPreview); colorPreviewVisible = true; } constraints.Add(colorPreview.CenterYAnchor.ConstraintEqualToAnchor(CenterYAnchor)); constraints.Add(colorPreview.WidthAnchor.ConstraintEqualToConstant(ImageSize)); constraints.Add(colorPreview.HeightAnchor.ConstraintEqualToConstant(ImageSize)); views.Add(colorPreview); OptimalWidth += ImageSize; OptimalWidth += RowCellSpacing; } else if (colorPreviewVisible) { colorPreview.RemoveFromSuperview(); colorPreviewVisible = false; } // Third Item: Value Button if (valueButtonText != null && !((MacObjectValueNode)ObjectValue).HideValueButton) { valueButton.Title = valueButtonText; UpdateFont(valueButton, -3); valueButton.SizeToFit(); if (!valueButtonVisible) { AddSubview(valueButton); valueButtonVisible = true; } constraints.Add(valueButton.CenterYAnchor.ConstraintEqualToAnchor(CenterYAnchor)); views.Add(valueButton); OptimalWidth += valueButton.Frame.Width; OptimalWidth += RowCellSpacing; } else if (valueButtonVisible) { valueButton.RemoveFromSuperview(); valueButtonVisible = false; } // Fourth Item: Viewer Button if (showViewerButton) { if (!viewerButtonVisible) { AddSubview(viewerButton); viewerButtonVisible = true; } constraints.Add(viewerButton.CenterYAnchor.ConstraintEqualToAnchor(CenterYAnchor)); constraints.Add(viewerButton.WidthAnchor.ConstraintEqualToConstant(viewerButton.Image.Size.Width)); constraints.Add(viewerButton.HeightAnchor.ConstraintEqualToConstant(viewerButton.Image.Size.Height)); views.Add(viewerButton); OptimalWidth += viewerButton.Frame.Width; OptimalWidth += RowCellSpacing; } else if (viewerButtonVisible) { viewerButton.RemoveFromSuperview(); viewerButtonVisible = false; } // Fifth Item: Text Value TextField.StringValue = strval; TextField.TextColor = textColor; TextField.Editable = editable; UpdateFont(TextField); TextField.SizeToFit(); OptimalWidth += GetWidthForString(TextField.Font, strval); constraints.Add(TextField.CenterYAnchor.ConstraintEqualToAnchor(CenterYAnchor)); views.Add(TextField); // lay out our views... var leadingAnchor = LeadingAnchor; for (int i = 0; i < views.Count; i++) { var view = views[i]; constraints.Add(view.LeadingAnchor.ConstraintEqualToAnchor(leadingAnchor, i == 0 ? MarginSize : RowCellSpacing)); leadingAnchor = view.TrailingAnchor; } constraints.Add(TextField.TrailingAnchor.ConstraintEqualToAnchor(TrailingAnchor, -MarginSize)); foreach (var constraint in constraints) { constraint.Active = true; } OptimalWidth += MarginSize; wrapper.OptimalValueFont = TreeView.CustomFont; wrapper.OptimalValueWidth = OptimalWidth; }
public static NSColor GetBackgroundColor(this NSView view) => NSColor.FromCGColor(view.Layer.BackgroundColor);