/// <summary> /// Initializes a new instance of the <see cref="ImmutableRadialGradientBrush"/> class. /// </summary> /// <param name="source">The brush from which this brush's properties should be copied.</param> public ImmutableRadialGradientBrush(IRadialGradientBrush source) : base(source) { Center = source.Center; GradientOrigin = source.GradientOrigin; Radius = source.Radius; }
protected override void CreateResources() { _sceneBrush = RenderTarget.CreateSolidColorBrush(Color.Black); // Background grid brush var bitmapTarget = RenderTarget.CreateCompatibleRenderTarget(new SizeF(10, 10)); var gridBrush = bitmapTarget.CreateSolidColorBrush(new ColorF(.93f, .94f, .96f)); bitmapTarget.BeginDraw(); bitmapTarget.FillRectangle(RectangleF.FromLTRB(0, 0, 10, 1), gridBrush); bitmapTarget.FillRectangle(RectangleF.FromLTRB(0, 0, 1, 10), gridBrush); bitmapTarget.EndDraw().ThrowIfFailed(); IBitmap bitmap = bitmapTarget.GetBitmap(); _gridPatternBrush = RenderTarget.CreateBitmapBrush(bitmap, new BitmapBrushProperties(ExtendMode.Wrap, ExtendMode.Wrap)); // Gradient brush Span <GradientStop> stops = stackalloc[] { new GradientStop(0.0f, Color.Gold), new GradientStop(0.85f, new ColorF(Color.Orange, 0.8f)), new GradientStop(1.0f, new ColorF(Color.OrangeRed, 0.7f)) }; _radialGradientBrush = RenderTarget.CreateRadialGradientBrush( new RadialGradientBrushProperties(new PointF(330, 330), new PointF(140, 140), 140, 140), RenderTarget.CreateGradienStopCollection(stops)); }
public RadialGradientBrushImpl(IRadialGradientBrush brush, Size destinationSize) { var center = brush.Center.ToPixels(destinationSize); var gradientOrigin = brush.GradientOrigin.ToPixels(destinationSize); var radius = brush.Radius; this.PlatformBrush = new RadialGradient(center.X, center.Y, radius, gradientOrigin.X, gradientOrigin.Y, radius); foreach (var stop in brush.GradientStops) { ((RadialGradient)this.PlatformBrush).AddColorStop(stop.Offset, stop.Color.ToCairo()); } ((RadialGradient)this.PlatformBrush).Extend = Extend.Pad; }
public RadialGradientBrushImpl( IRadialGradientBrush brush, SharpDX.Direct2D1.RenderTarget target, Rect destinationRect) { if (brush.GradientStops.Count == 0) { return; } var gradientStops = brush.GradientStops.Select(s => new SharpDX.Direct2D1.GradientStop { Color = s.Color.ToDirect2D(), Position = (float)s.Offset }).ToArray(); var position = destinationRect.Position; var centerPoint = position + brush.Center.ToPixels(destinationRect.Size); var gradientOrigin = position + brush.GradientOrigin.ToPixels(destinationRect.Size) - centerPoint; // Note: Direct2D supports RadiusX and RadiusY but Cairo backend supports only Radius property var radiusX = brush.Radius * destinationRect.Width; var radiusY = brush.Radius * destinationRect.Height; using (var stops = new SharpDX.Direct2D1.GradientStopCollection( target, gradientStops, brush.SpreadMethod.ToDirect2D())) { PlatformBrush = new SharpDX.Direct2D1.RadialGradientBrush( target, new SharpDX.Direct2D1.RadialGradientBrushProperties { Center = centerPoint.ToSharpDX(), GradientOriginOffset = gradientOrigin.ToSharpDX(), RadiusX = (float)radiusX, RadiusY = (float)radiusY }, new SharpDX.Direct2D1.BrushProperties { Opacity = (float)brush.Opacity, Transform = PrimitiveExtensions.Matrix3x2Identity, }, stops); } }
protected override void CreateResources() { base.CreateResources(); // Gradient brush Span <GradientStop> stops = stackalloc[] { new GradientStop(0.0f, Color.Gold), new GradientStop(0.85f, new ColorF(Color.Orange, 0.8f)), new GradientStop(1.0f, new ColorF(Color.OrangeRed, 0.7f)) }; _radialGradientBrush = RenderTarget.CreateRadialGradientBrush( new RadialGradientBrushProperties(new PointF(330, 330), new PointF(140, 140), 140, 140), RenderTarget.CreateGradienStopCollection(stops)); _textRenderer = new CustomTextRenderer(Direct2dFactory, RenderTarget, _blackBrush, _radialGradientBrush); }
public static IRadialGradientBrush CreateRef(this IRadialGradientBrush objectRef) => ((IRadialGradientBrush)objectRef.CreateRef(typeof(IRadialGradientBrush)));