Пример #1
0
        public override void DrawRect(CGRect dirtyRect)
        {
            NSColorList colors = NSColorList.ColorListNamed("System");
            CGRect      rect   = Bounds;

            rect.Height = 12;
            var style = (NSMutableParagraphStyle)NSParagraphStyle.DefaultParagraphStyle.MutableCopy();

            style.Alignment = NSTextAlignment.Right;
            var attrs = new NSStringAttributes {
                Font            = NSFont.SystemFontOfSize(8),
                ForegroundColor = NSColor.LabelColor,
                ParagraphStyle  = style
            };

            foreach (NSString key in colors.AllKeys())
            {
                if (DrawColors)
                {
                    NSColor color = colors.ColorWithKey(key);
                    color.Set();
                    NSGraphics.RectFill(rect);
                }

                if (DrawTitles)
                {
                    key.DrawString(rect, attrs.Dictionary);
                }

                rect.Y += 12;
            }
        }
        public override NSTouchBarItem MakeItem(NSTouchBar touchBar, string identifier)
        {
            switch (Array.IndexOf(DefaultIdentifiers, identifier))
            {
            case 0:
            {
                var item = NSColorPickerTouchBarItem.CreateColorPicker(identifier, NSImage.ImageNamed(NSImageName.TouchBarColorPickerFill));
                item.ColorList  = NSColorList.ColorListNamed("Apple");
                item.ShowsAlpha = false;
                item.Activated += (_, __) =>
                {
                    var color = item.Color.UsingColorSpace(NSColorSpace.CalibratedRGB);
                    this.ColorSelected.Invoke(item, color);
                };
                return(item);
            }

            case 1:
            {
                var item = new NSCustomTouchBarItem(identifier);
                item.View = NSButton.CreateButton(NSImage.ImageNamed(NSImageName.TouchBarRecordStopTemplate), () => this.TurnOffRequested.Invoke(this, null));
                return(item);
            }

            default:
                return(null);
            }
        }
Пример #3
0
        void Initialize()
        {
//			foreach (NSColorList cl in NSColorList.AvailableColorLists) {
//				Console.WriteLine("Color List: {0}", cl.Name);
//			}
            // Possible color list names - "Apple", "Crayons", "System" (causes crash), and "Web Safe Colors" (named by hex values);
            colorList = NSColorList.ColorListNamed("Crayons");
//			foreach (string c in colorList.AllKeys()) {
//				Console.WriteLine("Color: {0}", c);
//			}
        }
Пример #4
0
        public static NSColorPickerTouchBarItem CreateColorPicker(string identifier, string listName)
        {
            NSColorPickerTouchBarItem item;

            switch (listName)
            {
            case "Text":
                item = NSColorPickerTouchBarItem.CreateTextColorPicker(identifier);
                break;

            case "Stroke":
                item = NSColorPickerTouchBarItem.CreateStrokeColorPicker(identifier);
                break;

            default:
                item            = NSColorPickerTouchBarItem.CreateColorPicker(identifier, NSImage.ImageNamed(NSImageName.TouchBarColorPickerFill));
                item.ColorList  = NSColorList.ColorListNamed(listName);
                item.ShowsAlpha = true;
                break;
            }
            item.Activated += (sender, e) => OnColorChange(item.CustomizationLabel, item.Color);
            return(item);
        }