public static NSPopover MakePopover(Xwt.Widget child, Color backgroundColor) { return new NSPopover { Behavior = NSPopoverBehavior.Transient, ContentViewController = new FactoryViewController (child) { BackgroundColor = backgroundColor.ToCGColor () } }; }
static NSImage?GetImageInternal(IList <Point> points, float lineWidth, Color strokeColor, Color backgroundColor) { var minPointX = points.Min(p => p.X); var minPointY = points.Min(p => p.Y); var drawingWidth = points.Max(p => p.X) - minPointX; var drawingHeight = points.Max(p => p.Y) - minPointY; const int minSize = 1; if (drawingWidth < minSize || drawingHeight < minSize) { return(null); } var imageSize = new CGSize(drawingWidth, drawingHeight); using var context = new CGBitmapContext(IntPtr.Zero, (nint)drawingWidth, (nint)drawingHeight, 8, (nint)drawingWidth * 4, NSColorSpace.GenericRGBColorSpace.ColorSpace, CGImageAlphaInfo.PremultipliedFirst); context.SetFillColor(backgroundColor.ToCGColor()); context.FillRect(new CGRect(CGPoint.Empty, imageSize)); context.SetStrokeColor(strokeColor.ToCGColor()); context.SetLineWidth(lineWidth); context.SetLineCap(CGLineCap.Round); context.SetLineJoin(CGLineJoin.Round); context.AddLines(points.Select(p => new CGPoint(p.X - minPointX, p.Y - minPointY)).ToArray()); context.StrokePath(); using var cgImage = context.ToImage(); NSImage image = new(cgImage, imageSize); return(image); }
void UpdateBorder() { // NOTE: borders are not a "supported" style of the contained // button, thus we don't use the themer here. Color borderColor = Element.BorderColor; if (_defaultBorderColor == null) { _defaultBorderColor = Control.Layer.BorderColor; } // if (borderColor.IsDefault) { Control.Layer.BorderColor = _defaultBorderColor; } else { Control.Layer.BorderColor = borderColor.ToCGColor(); } double borderWidth = Element.BorderWidth; if (_defaultBorderWidth == -1) { _defaultBorderWidth = Control.Layer.BorderWidth; } if (borderWidth == (double)Button.BorderWidthProperty.DefaultValue) { Control.Layer.BorderWidth = _defaultBorderWidth; } else { Control.Layer.BorderWidth = (nfloat)borderWidth; } }
public void SetColor (SolidBrush widget, Color color) { widget.ControlObject = color.ToCGColor (); }
void drawBackground(CGContext context, Color color, float width, float height) { context.SetFillColor(color.ToCGColor()); context.FillRect(new RectangleF(HALF_PIXEL_X, HALF_PIXEL_Y, width + HALF_PIXEL_X, height + HALF_PIXEL_Y)); context.FillPath(); }
public void SetColor(SolidBrush widget, Color color) { widget.ControlObject = color.ToCGColor(); }
object ISolidBrush.Create(Color color) { return(color.ToCGColor()); }
void UpdateBackground() { _renderer.ApplyNativeImageAsync(Page.BackgroundImageSourceProperty, bgImage => { if (bgImage != null) { Layer.BackgroundColor = NSColor.FromPatternImage(bgImage).CGColor; } else { Brush background = _renderer.Element.Background; if (!Brush.IsNullOrEmpty(background)) { _renderer.NativeView.UpdateBackground(_renderer.Element.Background); } else { Color bgColor = _renderer.Element.BackgroundColor; Layer.BackgroundColor = bgColor.IsDefault ? ColorExtensions.WindowBackgroundColor.CGColor : bgColor.ToCGColor(); } } }); }
object SolidBrush.IHandler.Create(Color color) { return(color.ToCGColor()); }
public void SetColor (Pen widget, Color color) { ((PenControl)widget.ControlObject).Color = color.ToCGColor (); }
public void SetPixel(int x, int y, Color color) { if (x < 0 || x > NativeCGImage.Width - 1) throw new InvalidEnumArgumentException ("Parameter must be positive and < Width."); if (y < 0 || y > NativeCGImage.Height - 1) throw new InvalidEnumArgumentException ("Parameter must be positive and < Height."); MakeSureWeHaveAnAlphaChannel (); // We are going to cheat here by drawing directly to the cached context that is // associated to the image. This way we do not have to play with pixels and offsets // to change the data. If this proves to be non performant then we will change it later. cachedContext.SaveState (); cachedContext.ConcatCTM (cachedContext.GetCTM ().Invert ()); cachedContext.ConcatCTM (imageTransform); cachedContext.SetFillColor(color.ToCGColor()); cachedContext.FillRect (new RectangleF(x,y, 1,1)); cachedContext.FillPath (); cachedContext.RestoreState(); }
void UpdateBackground() { if (View.Layer == null) { return; } this.ApplyNativeImageAsync(Page.BackgroundImageSourceProperty, image => { if (image != null) { View.Layer.BackgroundColor = NSColor.FromPatternImage(image).CGColor; } else { Color bgColor = Element.BackgroundColor; View.Layer.BackgroundColor = bgColor.IsDefault ? NSColor.White.CGColor : bgColor.ToCGColor(); Brush background = Element.Background; View.UpdateBackground(background); } }); }
public object Create (Color color, float thickness) { return new PenControl { Color = color.ToCGColor (), Thickness = thickness, MiterLimit = 10f, LineCap = PenLineCap.Square.ToCG () }; }
public object Create (Color startColor, Color endColor, PointF startPoint, PointF endPoint) { return new BrushObject { Gradient = new CGGradient(CGColorSpace.CreateDeviceRGB(), new CGColor [] { startColor.ToCGColor (), endColor.ToCGColor () } ), InverseGradient = new CGGradient(CGColorSpace.CreateDeviceRGB(), new CGColor [] { endColor.ToCGColor (), startColor.ToCGColor () } ), StartPoint = startPoint.ToSD (), EndPoint = endPoint.ToSD () }; }
protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if ((e.PropertyName == ExtendedBoxView.CornerRadiusProperty.PropertyName) || (e.PropertyName == ExtendedBoxView.BorderColorProperty.PropertyName) || (e.PropertyName == ExtendedBoxView.BorderThicknessProperty.PropertyName) || (e.PropertyName == BoxView.ColorProperty.PropertyName) || (e.PropertyName == BoxView.IsVisibleProperty.PropertyName) || (e.PropertyName == ExtendedBoxView.ForcedBoxShapeProperty.PropertyName)) { // SetNatuve Control is additive, so remove the current view from the Native Control // Cycle through any sub-views until get to the correct view identified by the Tag // property. This is done to be defensive, rather than assume there is only one sub view // or if there are any sub views foreach (UIView subv1 in NativeView.Subviews) { if (subv1.Tag == 1) { subv1.RemoveFromSuperview(); break; } } if (this.Element.IsVisible) { UIView ebvView = CreateBoxView(this.Element); SetNativeControl(ebvView); } } // Process shadow property changes - this can be done directly on the Native View without re-assigning it if (e.PropertyName == ExtendedBoxView.HasShadowProperty.PropertyName) { ExtendedBoxView ebv = this.Element; if (ebv.HasShadow) { // Adjust shadow colour for any transparency in the box colour Color shadowColour = new Color(ebv.ShadowColor.R, ebv.ShadowColor.G, ebv.ShadowColor.B, ebv.ShadowColor.A * ebv.Color.A); AddShadow(NativeView, shadowColour.ToCGColor(), (float)ebv.ShadowPosition.dX, (float)ebv.ShadowPosition.dY); } else { RemoveShadow(NativeView); } } else if (e.PropertyName == ExtendedBoxView.ShadowPositionProperty.PropertyName) { ExtendedBoxView ebv = this.Element; if (ebv.HasShadow) { NativeView.Layer.ShadowOffset = new CGSize((float)ebv.ShadowPosition.dX, (float)ebv.ShadowPosition.dY); } } else if (e.PropertyName == ExtendedBoxView.ShadowColorProperty.PropertyName) { ExtendedBoxView ebv = this.Element; if (ebv.HasShadow) { // Adjust shadow colour for any transparency in the box colour Color shadowColour = new Color(ebv.ShadowColor.R, ebv.ShadowColor.G, ebv.ShadowColor.B, ebv.ShadowColor.A * ebv.Color.A); NativeView.Layer.ShadowColor = shadowColour.ToCGColor(); } } }
void UpdateBackground() { this.ApplyNativeImageAsync(Page.BackgroundImageSourceProperty, bgImage => { if (bgImage != null) { View.Layer.BackgroundColor = NSColor.FromPatternImage(bgImage).CGColor; } else { Color bgColor = Element.BackgroundColor; View.Layer.BackgroundColor = bgColor.IsDefault ? NSColor.White.CGColor : bgColor.ToCGColor(); } }); }
protected void HatchHorizontal(CGContext context) { var hatchSize = getHatchWidth(hatchStyle); var lineWidth = getLineWidth(hatchStyle); initializeContext(context, hatchSize, false); /* draw background */ drawBackground(context, backColor, hatchSize, hatchSize); /* draw horizontal line in the foreground color */ context.SetStrokeColor(foreColor.ToCGColor()); context.SetLineWidth(lineWidth); context.SetLineCap(CGLineCap.Square); // draw a horizontal line context.MoveTo(0, 0); context.AddLineToPoint(hatchSize, 0); context.StrokePath(); }
public object Create(Color startColor, Color endColor, PointF startPoint, PointF endPoint) { return(new BrushObject { Gradient = new CGGradient(CGColorSpace.CreateDeviceRGB(), new CGColor [] { startColor.ToCGColor(), endColor.ToCGColor() }), InverseGradient = new CGGradient(CGColorSpace.CreateDeviceRGB(), new CGColor [] { endColor.ToCGColor(), startColor.ToCGColor() }), StartPoint = startPoint.ToSD(), EndPoint = endPoint.ToSD() }); }
/** * Percentage patterns were obtained by creating a screen shot from a windows fill * and looking at the patterns at the pixel level. A little tedious to say the least * but they do seem correct and recreate the same pattern from windows to here. */ protected void HatchPercentage(CGContext context) { var hatchWidth = getHatchWidth(hatchStyle); var hatchHeight = getHatchHeight(hatchStyle); var lineWidth = getLineWidth(hatchStyle); initializeContext(context, hatchHeight, false); /* some patterns require us to reverse the colors */ switch (hatchStyle) { case HatchStyle.Percent05: case HatchStyle.Percent10: case HatchStyle.Percent20: case HatchStyle.Percent25: case HatchStyle.Percent30: drawBackground(context, backColor, hatchWidth, hatchWidth); context.SetFillColor(foreColor.ToCGColor()); break; default: drawBackground(context, foreColor, hatchWidth, hatchWidth); context.SetFillColor(backColor.ToCGColor()); break; } // create a work rectangle for setting pixels RectangleF rect = new RectangleF(0, 0, 1, 1); // Only set the pixels for some if (hatchStyle != HatchStyle.Percent50 && hatchStyle != HatchStyle.Percent40 && hatchStyle != HatchStyle.Percent30 && hatchStyle != HatchStyle.Percent60) { rect.X = 0; rect.Y = (int)(hatchHeight / 2.0f); setPixels(context, rect); rect.X = (int)(hatchWidth / 2.0f); rect.Y = 0; setPixels(context, rect); } // 50 and 40 start out the same with a 50 percent if (hatchStyle == HatchStyle.Percent50 || hatchStyle == HatchStyle.Percent40) { int x = 0; int y = 0; for (y = 0; y < hatchHeight; y += 2) { for (x = 1; x < hatchWidth; x += 2) { rect.X = x; rect.Y = y; setPixels(context, rect); } } for (y = 1; y < hatchHeight; y += 2) { for (x = 0; x < hatchWidth; x += 2) { rect.X = x; rect.Y = y; setPixels(context, rect); } } // Percent40 is a 50 with two more dots set of back color // within a set area. This creates an interesting effect // of a double plus sign in opposite corners. if (hatchStyle == HatchStyle.Percent40) { rect.X = 1; rect.Y = 1; setPixels(context, rect); rect.X = 5; rect.Y = 5; setPixels(context, rect); } } // Percent30 and Percent60 are really messed up so we will just set some dots // to present the pattern. Percent60 is a 30 with colors reversed, go figure. if (hatchStyle == HatchStyle.Percent30 || hatchStyle == HatchStyle.Percent60) { rect.X = 0; rect.Y = 0; setPixels(context, rect); rect.X = 2; rect.Y = 0; setPixels(context, rect); rect.X = 0; rect.Y = 2; setPixels(context, rect); rect.X = 2; rect.Y = 2; setPixels(context, rect); rect.X = 1; rect.Y = 3; setPixels(context, rect); rect.X = 3; rect.Y = 1; setPixels(context, rect); } }
public void SetColor(Pen widget, Color color) { ((PenControl)widget.ControlObject).Color = color.ToCGColor(); }
public void DrawText( string text, Rectangle bounds, Color color, TextFormat textFormat) { if (null == textFormat) { throw new ArgumentNullException(nameof(textFormat)); } if (String.IsNullOrEmpty(text)) { return; } var rect = bounds.ToCGRect(); var font = GetCGFontFromTextFormat(textFormat); this._graphicsContext.SetFont(font); this._graphicsContext.SetFontSize(textFormat.FontSize); float originX; if (textFormat.HorizontalAlignment == LayoutAlignment.Start) { originX = 0; } else if (textFormat.HorizontalAlignment == LayoutAlignment.Center) { originX = 0.5f; } else if (textFormat.HorizontalAlignment == LayoutAlignment.End) { originX = 1.0f; } else if (textFormat.HorizontalAlignment == LayoutAlignment.Fill) { originX = 0.5f; } else { throw new NotSupportedException("Unsupported alignment."); } float originY; if (textFormat.VerticalAlignment == LayoutAlignment.Start) { originY = 0; } else if (textFormat.VerticalAlignment == LayoutAlignment.Center) { originY = 0.5f; } else if (textFormat.VerticalAlignment == LayoutAlignment.End) { originY = 1.0f; } else if (textFormat.VerticalAlignment == LayoutAlignment.Fill) { originY = 0.5f; } else { throw new NotSupportedException("Unsupported alignment."); } float x, y; if ((originX == 0) && (originY == 0)) { x = (float)rect.Left; y = (float)rect.Top; } else { // TODO: NSStringDrawing.DrawString(, , new UIStringAttributes() { }) // Measure text this._graphicsContext.SetTextDrawingMode(CGTextDrawingMode.Invisible); var startingPoint = this._graphicsContext.TextPosition; this._graphicsContext.ShowText(text); var endingPoint = this._graphicsContext.TextPosition; this._graphicsContext.SetTextDrawingMode(CGTextDrawingMode.Fill); var textBounds = new CGRect(startingPoint.X, startingPoint.Y, endingPoint.X - startingPoint.X, endingPoint.Y - startingPoint.Y); x = ((float)rect.Width - (float)textBounds.Width * originX) + (float)rect.Left; y = ((float)rect.Height - (float)textBounds.Height * originY) + (float)rect.Top; } this._graphicsContext.SetFillColor(color.ToCGColor()); this._graphicsContext.ShowTextAtPoint(x, y, text); }
public void SetShadowColor(Color color) { _shadowLayer.ShadowColor = color == Color.Default ? _defaultShadowColor : color.ToCGColor(); }
protected virtual void SetBorderColor(Color color) { this.Layer.BorderColor = color.ToCGColor(); }
public override void AudioVisualizerPaint() //object sender, PaintEventArgs e) { InitPaint(); if (_wavePeaks != null) { bool showSpectrogram = IsSpectrogramAvailable && ShowSpectrogram; bool showSpectrogramOnly = showSpectrogram && !ShowWaveform; int waveformHeight = Height - (showSpectrogram ? SpectrogramDisplayHeight : 0); // background DrawBackground(); // grid lines if (ShowGridLines && !showSpectrogramOnly) { DrawGridLines(waveformHeight); } // spectrogram if (showSpectrogram) { DrawSpectrogram(); } // waveform if (ShowWaveform) { var colorNormal = Color.ToCGColor(); var colorSelected = SelectedColor.ToCGColor(); var isSelectedHelper = new IsSelectedHelper(_allSelectedParagraphs, _wavePeaks.SampleRate); int baseHeight = (int)(_wavePeaks.HighestPeak / VerticalZoomFactor); int halfWaveformHeight = waveformHeight / 2; Func <float, float> calculateY = (value) => { float offset = (value / baseHeight) * halfWaveformHeight; if (offset > halfWaveformHeight) { offset = halfWaveformHeight; } if (offset < -halfWaveformHeight) { offset = -halfWaveformHeight; } return(halfWaveformHeight - offset); }; for (int x = 0; x < Width; x++) { float pos = (float)RelativeXPositionToSeconds(x) * _wavePeaks.SampleRate; int pos0 = (int)pos; int pos1 = pos0 + 1; if (pos1 >= _wavePeaks.Peaks.Count) { break; } float pos1Weight = pos - pos0; float pos0Weight = 1F - pos1Weight; var peak0 = _wavePeaks.Peaks[pos0]; var peak1 = _wavePeaks.Peaks[pos1]; float max = peak0.Max * pos0Weight + peak1.Max * pos1Weight; float min = peak0.Min * pos0Weight + peak1.Min * pos1Weight; float yMax = calculateY(max); float yMin = Math.Max(calculateY(min), yMax + 0.1F); var c = isSelectedHelper.IsSelected(pos0) ? colorNormal : colorSelected; _context.SetStrokeColor(c); DrawLine(x, (int)Math.Round(yMax), x, (int)Math.Round(yMin)); } } // time line if (!showSpectrogramOnly) { DrawTimeLine(waveformHeight); } // scene changes // if (_sceneChanges != null) // { // foreach (double time in _sceneChanges) // { // int pos = SecondsToXPosition(time - StartPositionSeconds); // if (pos > 0 && pos < Width) // { // using (var p = new Pen(Color.AntiqueWhite)) // graphics.DrawLine(p, pos, 0, pos, Height); // } // } // } // current video position if (_currentVideoPositionSeconds > 0) { int pos = SecondsToXPosition(_currentVideoPositionSeconds - StartPositionSeconds); if (pos > 0 && pos < Width) { _context.SetStrokeColor(Color.Turquoise.ToCGColor()); DrawLine(pos, 0, pos, Height); // using (var p = new Pen(Color.Turquoise)) // graphics.DrawLine(p, pos, 0, pos, Height); } } // paragraphs foreach (Paragraph p in _displayableParagraphs) { if (p.EndTime.TotalSeconds >= StartPositionSeconds && p.StartTime.TotalSeconds <= EndPositionSeconds) { DrawParagraph(p); } } // current selection // if (NewSelectionParagraph != null) // { // int currentRegionLeft = SecondsToXPosition(NewSelectionParagraph.StartTime.TotalSeconds - StartPositionSeconds); // int currentRegionRight = SecondsToXPosition(NewSelectionParagraph.EndTime.TotalSeconds - StartPositionSeconds); // int currentRegionWidth = currentRegionRight - currentRegionLeft; // if (currentRegionRight >= 0 && currentRegionLeft <= Width) // { // using (var brush = new SolidBrush(Color.FromArgb(128, 255, 255, 255))) // graphics.FillRectangle(brush, currentRegionLeft, 0, currentRegionWidth, graphics.VisibleClipBounds.Height); // // if (currentRegionWidth > 40) // { // using (var brush = new SolidBrush(Color.Turquoise)) // graphics.DrawString(string.Format("{0:0.###} {1}", ((double)currentRegionWidth / _wavePeaks.SampleRate / _zoomFactor), Configuration.Settings.Language.Waveform.Seconds), Font, brush, new PointF(currentRegionLeft + 3, Height - 32)); // } // } // } } else { DrawBackground(); if (ShowGridLines) { DrawGridLines(Height); } // using (var textBrush = new SolidBrush(TextColor)) // using (var textFont = new Font(Font.FontFamily, 8)) // { // if (Width > 90) // { // graphics.DrawString(WaveformNotLoadedText, textFont, textBrush, new PointF(Width / 2 - 65, Height / 2 - 10)); // } // else // { // using (var stringFormat = new StringFormat(StringFormatFlags.DirectionVertical)) // graphics.DrawString(WaveformNotLoadedText, textFont, textBrush, new PointF(1, 10), stringFormat); // } // } } // if (Focused) // { // using (var p = new Pen(SelectedColor)) // graphics.DrawRectangle(p, new Rectangle(0, 0, Width - 1, Height - 1)); // } // _imageView.Image = _bitmap.ToNSImage(); _imageView.Image = new NSImage(_context.ToImage(), new CGSize(Width, Height)); ; // public CGImage ToCGImage() // { // var rawData = new byte[Width * Height * 4]; // var bytesPerPixel = 4; // var bytesPerRow = bytesPerPixel * Width; // var bitsPerComponent = 8; // using (var colorSpace = CGColorSpace.CreateDeviceRGB()) // { // using (var context = new CGBitmapContext(rawData, Width, Height, bitsPerComponent, bytesPerRow, colorSpace, CGBitmapFlags.ByteOrder32Big | CGBitmapFlags.PremultipliedLast)) // { // for (int y = 0; y < Height; y++) // { // for (int x = 0; x < Width; x++) // { // Color c = GetPixel(x, y); // var i = bytesPerRow * y + bytesPerPixel * x; // rawData[i + 0] = c.R; // rawData[i + 1] = c.G; // rawData[i + 2] = c.B; // rawData[i + 3] = c.A; // } // } // //context.Flush(); // // context.SetFillColor(new CGColor(1,0,0, 1)); // context.FillRect(new CGRect(0,0, 20, 20)); // // context.SetTextDrawingMode(CGTextDrawingMode.Clip); // context.SetFillColor(new CGColor(0,0,0, 1)); // context.ShowTextAtPoint(20, 20, "HEJ"); // context.SetTextDrawingMode(CGTextDrawingMode.Fill); // context.ShowTextAtPoint(30, 30, "Yo"); // return context.ToImage(); // } // } // } }
public static void UpdateColor(this UIView nativeControl, Color color, int thickness) { nativeControl.Layer.BackgroundColor = color.ToCGColor(); nativeControl.Layer.BorderColor = color.ToCGColor(); nativeControl.Layer.BorderWidth = thickness; }
private void UpdateLineColor(Color color) { this.control.Layer.BorderColor = color.ToCGColor(); this.control.Layer.CornerRadius = 5f; this.control.Layer.BorderWidth = 1f; }