// Draw the view public override void DrawRect(CoreGraphics.CGRect dirtyRect) { CGRect bounds = this.Bounds; // Using the system focus ring instead. Achieved by overriding DrawFocusRingMask and FocusRingMaskBounds // // Am I the window's first responder? // if (this.Window.FirstResponder == this) { // NSColor.KeyboardFocusIndicator.Set(); // NSBezierPath.DefaultLineWidth = 4.0f; // NSBezierPath.StrokeRect(bounds); // } if (Highlighted) { NSGradient gr = new NSGradient(NSColor.White, mBgColor); gr.DrawInRect(bounds, new CGPoint(0.0f, 0.0f)); } else { mBgColor.Set(); NSBezierPath.FillRect(bounds); } DrawStringCenteredInRectangle(mLetter, bounds); }
public ExpanderWidget() { disclosure = new NSButton { BezelStyle = NSBezelStyle.Disclosure, AutoresizingMask = NSViewResizingMask.MaxYMargin, ImagePosition = NSCellImagePosition.ImageOnly, Frame = new RectangleF(5, 4, 13, 13), State = NSCellStateValue.Off }; disclosure.SetButtonType(NSButtonType.OnOff); disclosure.Activated += delegate { if (DisclosureToggled != null) { DisclosureToggled(this, EventArgs.Empty); } }; label = new NSButton { Bordered = false, AutoresizingMask = NSViewResizingMask.MaxYMargin | NSViewResizingMask.WidthSizable, Alignment = NSTextAlignment.Left, Frame = new RectangleF(17, 3, 60, 13), Target = disclosure, Action = new Selector("performClick:") }; label.SetButtonType(NSButtonType.MomentaryChange); AutoresizesSubviews = true; backgroundGradient = new NSGradient(NSColor.FromCalibratedRgba(0.93f, 0.93f, 0.97f, 1.0f), NSColor.FromCalibratedRgba(0.74f, 0.76f, 0.83f, 1.0f)); strokeColor = NSColor.FromCalibratedRgba(0.60f, 0.60f, 0.60f, 1.0f); AddSubview(label); AddSubview(disclosure); }
public ExpanderWidget() { label = new NSTextView() { AutoresizingMask = NSViewResizingMask.MaxYMargin | NSViewResizingMask.WidthSizable, Alignment = NSTextAlignment.Left, Editable = false, Selectable = false, DrawsBackground = false, Frame = new RectangleF(17, 3, 60, 13) }; disclosure = new NSButton() { BezelStyle = NSBezelStyle.Disclosure, AutoresizingMask = NSViewResizingMask.MaxYMargin, ImagePosition = NSCellImagePosition.ImageOnly, Frame = new RectangleF(5, 4, 13, 13), State = NSCellStateValue.On }; disclosure.SetButtonType(NSButtonType.OnOff); disclosure.AddObserver(this, new NSString("cell.state"), NSKeyValueObservingOptions.New, IntPtr.Zero); AutoresizesSubviews = true; backgroundGradient = new NSGradient(NSColor.FromCalibratedRgba(0.93f, 0.93f, 0.97f, 1.0f), NSColor.FromCalibratedRgba(0.74f, 0.76f, 0.83f, 1.0f)); strokeColor = NSColor.FromCalibratedRgba(0.60f, 0.60f, 0.60f, 1.0f); AddSubview(label); AddSubview(disclosure); }
private PaletteView(IntPtr instance) : base(instance) { m_gradient = NSGradient.Create(NSColor.blackColor(), NSColor.blackColor()).Retain(); NSNotificationCenter.defaultCenter().addObserver_selector_name_object( // note that the controller doesn't go away so we don't bother removing ourself this, "docStateChanged:", Document.StateChanged, null); }
public void Fill(object backend) { ContextInfo ctx = (ContextInfo)backend; if (ctx.Pattern is Gradient) { GradientInfo gr = (GradientInfo)WidgetRegistry.GetBackend(ctx.Pattern); NSGradient g = new NSGradient(gr.Colors.ToArray(), gr.Stops.ToArray()); g.DrawInBezierPath(ctx.Path, 0f); } else { ctx.Path.Fill(); } ctx.Pattern = null; ctx.Path.Dispose(); ctx.Path = new NSBezierPath(); }
private void Initialize() { // initialize default values CornerRadius = 4; GradientAngle = 90; ImagePosition = NSCellImagePosition.ImageLeft; TitleText = "Button"; TitleForegroundColor = NSColor.FromRgb(255, 255, 255); TitleFont = UIUtils.GetSystemFontOfSize(16f, NSFontWeight.Semibold); Gradient = new NSGradient(NSColor.FromRgb(58, 156, 217), NSColor.FromRgb(20, 130, 222)); BorderColor = NSColor.FromRgb(48, 147, 209); BorderLineWidth = 0.5f; IconLocation = IconLocationEnum.Right_BeforeCenteredText; }
public void NSGradientConstructorTests() { NSColorSpace colorSpace = NSColorSpace.GenericRGBColorSpace; NSGradient g = new NSGradient(new[] { NSColor.Black, NSColor.White, NSColor.Black }, new[] { 0f, .5f, 1.0f }, colorSpace); Assert.IsNotNull(g); Assert.AreEqual(colorSpace, g.ColorSpace); Assert.AreEqual(3, g.ColorStopsCount); // Since we are asking for colors on a gradient, there will be some color blending, even with just black and white. const float closeEnough = .05f; NSColor black = NSColor.Black.UsingColorSpace(NSColorSpace.CalibratedRGB); NSColor white = NSColor.White.UsingColorSpace(NSColorSpace.CalibratedRGB); NSColor color; nfloat location; g.GetColor(out color, out location, 0); color = color.UsingColorSpace(NSColorSpace.CalibratedRGB); Assert.IsTrue(black.RedComponent - color.RedComponent < closeEnough); Assert.IsTrue(black.BlueComponent - color.BlueComponent < closeEnough); Assert.IsTrue(black.GreenComponent - color.GreenComponent < closeEnough); Assert.AreEqual(0.0f, (float)location); g.GetColor(out color, out location, 1); color = color.UsingColorSpace(NSColorSpace.CalibratedRGB); Assert.IsTrue(white.RedComponent - color.RedComponent < closeEnough); Assert.IsTrue(white.BlueComponent - color.BlueComponent < closeEnough); Assert.IsTrue(white.GreenComponent - color.GreenComponent < closeEnough); Assert.AreEqual(0.5f, (float)location); g.GetColor(out color, out location, 2); color = color.UsingColorSpace(NSColorSpace.CalibratedRGB); Assert.IsTrue(black.RedComponent - color.RedComponent < closeEnough); Assert.IsTrue(black.BlueComponent - color.BlueComponent < closeEnough); Assert.IsTrue(black.GreenComponent - color.GreenComponent < closeEnough); Assert.AreEqual(1.0f, (float)location); }
public void Fill(object backend) { var ctx = GetContext(backend); if (ctx.Pattern is GradientInfo) { GradientInfo gr = (GradientInfo)ctx.Pattern; NSGradient g = new NSGradient(gr.Colors.ToArray(), gr.Stops.ToArray()); g.DrawInBezierPath(ctx.Path, 0f); } else if (ctx.Pattern is NSColor) { NSColor col = (NSColor)ctx.Pattern; col.Set(); col.SetFill(); } else { ctx.Path.Fill(); } ctx.Pattern = null; ctx.Path.Dispose(); ctx.Path = new NSBezierPath(); }
public void docStateChanged(NSNotification notification) { DocChange change = notification.object_().To<DocChange>(); NSGradient gradient = null; if (!NSObject.IsNullOrNil(change.Document)) { if ((change.Type & ChangeType.Palette) == ChangeType.Palette) { float[] locations = new float[change.Document.Palette.Length]; NSMutableArray colors = NSMutableArray.arrayWithCapacity((uint) change.Document.Palette.Length); for (int i = 0; i < change.Document.Palette.Length; ++i) { locations[i] = change.Document.Palette[i].Location; colors.addObject((NSColor) change.Document.Palette[i].Color); } gradient = NSGradient.Create(colors, locations).Retain(); } } else { gradient = NSGradient.Create(NSColor.blackColor(), NSColor.blackColor()).Retain(); } if (gradient != null) { if (m_gradient != null) m_gradient.release(); m_gradient = gradient; setNeedsDisplay(true); } }