internal override void Create()
        {
            if (NativeBrush != null)
            {
                NativeBrush.Dispose();
            }

            var stops = new GradientStop[m_gradientStops.Length];

            for (int s = 0; s < m_gradientStops.Length; s++)
            {
                stops[s].Color    = m_gradientStops[s].Color.ToColor4();
                stops[s].Position = m_gradientStops[s].Position;
            }

            var props = new RadialGradientBrushProperties
            {
                Center = m_center.ToSharpDX(),
                GradientOriginOffset = m_gradientOriginOffset.ToSharpDX(),
                RadiusX = m_radiusX,
                RadiusY = m_radiusY
            };

            using (var stopcol = new GradientStopCollection(Owner.D2dRenderTarget, stops, Gamma.StandardRgb, ExtendMode.Clamp))
            {
                NativeBrush = new RadialGradientBrush(Owner.D2dRenderTarget, props, stopcol);
            }
        }
        internal RadialGradientBrush(Direct2DRenderTarget renderTargetOwner, 
                                     GradientStop[] gradientStops, 
                                     ExtendMode extendMode, 
                                     PointF centerPoint, 
                                     PointF gradientOriginOffset,
                                     SizeF radius)
        {
            m_renderTargetOwner = renderTargetOwner;
            m_extendMode = extendMode;
            m_radius = radius;
            m_gradientOriginOffset = gradientOriginOffset;
            m_centerPoint = centerPoint;

            var gradientStopList = new List<SlimDX.Direct2D.GradientStop>(gradientStops.Length);

            for (int i = 0; i < gradientStops.Length; i++)
            {
                gradientStopList.Add(gradientStops[i].InternalGradientStop);
            }

            var props = new RadialGradientBrushProperties();
            props.CenterPoint = centerPoint.InternalPointF;
            props.GradientOriginOffset = gradientOriginOffset.InternalPointF;
            props.HorizontalRadius = radius.Width;
            props.VerticalRadius = radius.Height;

            m_internalGradientStopCollection = new GradientStopCollection(m_renderTargetOwner.InternalRenderTarget,
                                                                          gradientStopList.ToArray(),
                                                                          Gamma.Linear,
                                                                          (SlimDX.Direct2D.ExtendMode)extendMode);

            m_internalRadialGradientBrush = new SlimDX.Direct2D.RadialGradientBrush(m_renderTargetOwner.InternalRenderTarget,
                                                                                    m_internalGradientStopCollection, props);
        }
        private RadialGradientBrush(Vector2 pCenter, Vector2 pDirection, IGraphicsAdapter pAdapter, params GradientColor[] pColor)
        {
            if (pAdapter.Method == RenderMethods.DirectX)
            {
                var dx   = (DirectXAdapter)pAdapter;
                var prop = new RadialGradientBrushProperties()
                {
                    Center  = pCenter,
                    RadiusX = pDirection.X,
                    RadiusY = pDirection.Y
                };

                GradientStop[] stops = new GradientStop[pColor.Length];
                for (int i = 0; i < pColor.Length; i++)
                {
                    stops[i].Color    = pColor[i].Color;
                    stops[i].Position = pColor[i].Position;
                }

                var grad = new GradientStopCollection(dx.Context, stops);
                _brush         = new SharpDX.Direct2D1.RadialGradientBrush(dx.Context, ref prop, grad);
                _brush.Opacity = 1f;
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Beispiel #4
0
        void FillIn2(D2DGraphics g, Color boxColor)
        {
            RawRectangleF rect = new RawRectangleF(0, 0, Width, Height);
            RadialGradientBrushProperties props2 = new RadialGradientBrushProperties()
            {
                Center = new RawVector2((rect.Left + rect.Right) / 2, (rect.Top + rect.Bottom) / 2),
                GradientOriginOffset = new RawVector2(0, 0),
                RadiusX = Width / 2,
                RadiusY = Height / 2
            };

            GradientStop[] gradientStops2 = new GradientStop[2];

            gradientStops2[0].Color    = GDIDataD2DUtils.TransToRawColor4(Color.FromArgb(55, boxColor.R, boxColor.G, boxColor.B));
            gradientStops2[0].Position = 0f;


            //gradientStops2[1].Color = GDIDataD2DUtils.TransToRawColor4(Color.FromArgb(40, 0,0,255));
            //gradientStops2[1].Position = 0.5f;

            gradientStops2[1].Color    = GDIDataD2DUtils.TransToRawColor4(Color.FromArgb(55, boxColor.R, boxColor.G, boxColor.B));
            gradientStops2[1].Position = 1f;

            //
            GradientStopCollection gradientStopCollection2 = new GradientStopCollection(g.RenderTarget, gradientStops2, Gamma.StandardRgb, ExtendMode.Clamp);
            RadialGradientBrush    radialGradientBrush     = new RadialGradientBrush(g.RenderTarget, props2, gradientStopCollection2);

            g.RenderTarget.FillRectangle(rect, radialGradientBrush);

            gradientStopCollection2.Dispose();
            radialGradientBrush.Dispose();
        }
        public D2DRadialGradientBrush(RenderContext context, Point center, Point originOffset, float radiusX, float radiusY, params Color[] gradientColors)
        {
            if (gradientColors.Length < 2)
            {
                throw new ArgumentException("Radial gradient brush requires at least 2 colors.", nameof(gradientColors));
            }
            var properties = new RadialGradientBrushProperties {
                Center = center.ToD2DVector(),
                GradientOriginOffset = originOffset.ToD2DVector(),
                RadiusX = radiusX,
                RadiusY = radiusY
            };
            var colorCount    = gradientColors.Length;
            var gradientStops = new GradientStop[colorCount];

            for (var i = 0; i < colorCount; ++i)
            {
                gradientStops[i] = new GradientStop {
                    Color    = gradientColors[i].ToRC4(),
                    Position = (float)i / (colorCount - 1)
                };
            }
            var collection = new GradientStopCollection(context.RenderTarget.DeviceContext2D, gradientStops);

            NativeBrush = new RadialGradientBrush(context.RenderTarget.DeviceContext2D, properties, collection);
            _collection = collection;
        }
Beispiel #6
0
        /// <summary>
        /// Creates new brushes in order to perform animations on the individual gradient based squares.
        /// </summary>
        /// <param name="direct2DWindowTarget">The object we use to draw! Our device! Our soul!</param>
        private static void AnimateBrushGradient(RenderTarget direct2DWindowTarget)
        {
            // Animate the gradientstops.
            for (int x = 0; x < _gradientStops.Length; x++)
            {
                float currentPosition = _gradientStops[x].Position;

                if (currentPosition >= 1F)
                {
                    currentPosition = 0F;
                }
                else
                {
                    currentPosition += 0.01F;
                }

                _gradientStops[x].Position = currentPosition;
            }

            // Conditionally dispose.
            _squareGradientBrush?.Factory?.Dispose();
            _squareGradientBrush?.GradientStopCollection?.Dispose();
            _squareGradientBrush?.Dispose();
            _squareRadialGradientBrush?.Factory?.Dispose();
            _squareRadialGradientBrush?.GradientStopCollection?.Dispose();
            _squareRadialGradientBrush?.Dispose();

            // Fix memory leak with GradientStopCollection
            // Thanks, anonymous StackOverflow user! https://stackoverflow.com/questions/47876001/mysterious-direct2d-memory-leak-with-gradients
            using (var gradientStopCollection = new GradientStopCollection(direct2DWindowTarget, _gradientStops))
            {
                /* How about a brush with a gradient? */
                LinearGradientBrushProperties linearGradientBrushProperties = new LinearGradientBrushProperties()
                {
                    StartPoint = new RawVector2(_gradientRectangle.Top - 50, _gradientRectangle.Left - 50),      // Note: Physical location of the start point, in this case top left corner.
                    EndPoint   = new RawVector2(_gradientRectangle.Bottom + 50, _gradientRectangle.Right + 50)   // Note: Physical location of the start point, in this case bottom right corner.
                };
                _squareGradientBrush = new LinearGradientBrush(direct2DWindowTarget, linearGradientBrushProperties, gradientStopCollection);

                /* A radial brush? */
                RadialGradientBrushProperties radialGradientBrushProperties = new RadialGradientBrushProperties()
                {
                    Center = new RawVector2(_radialRectangle.Left + 50, _radialRectangle.Top + 50),    // Note: Physical location of the start point, in this case the actual center.
                    GradientOriginOffset = new RawVector2(0, 0),
                    RadiusX = 100,
                    RadiusY = 100
                };
                _squareRadialGradientBrush = new RadialGradientBrush(direct2DWindowTarget, radialGradientBrushProperties, gradientStopCollection);
            }
        }
        private void RadialGradientBrushAddClicked(object sender, EventArgs e)
        {
            ExtendMode ex = radialExtendCombo.SelectedIndex > 0 ? (ExtendMode)radialExtendCombo.SelectedIndex : ExtendMode.Clamp;
            Gamma      gamma;

            switch (gammaComboBox.SelectedIndex)
            {
            case 0:
                gamma = Gamma.Linear;
                break;

            case 1:
                gamma = Gamma.StandardRgb;
                break;

            default:
                throw new InvalidOperationException("Unknown gamma selected");
            }

            GradientStop[] stops =
            {
                new GradientStop(0,    color1),
                new GradientStop(1.0f, color2),
            };

            GradientStopCollection stopCollection = renderTarget.CreateGradientStopCollection(
                stops, gamma, ex);

            RadialGradientBrushProperties properties;

            if (ex == ExtendMode.Clamp)
            {
                properties = new RadialGradientBrushProperties(
                    new Point2F(50, 50), new Point2F(600, 400), 600, 600);
            }
            else
            {
                properties = new RadialGradientBrushProperties(
                    new Point2F(50, 50), new Point2F(0, 0), 50, 50);
            }

            RadialGradientBrush brush = renderTarget.CreateRadialGradientBrush(
                properties, stopCollection);

            parent.brushes.Add(brush);
            parent.currentBrushIndex = parent.brushes.Count - 1;
            FillBrushesListBox();
        }
Beispiel #8
0
        /// <summary>
        /// This method creates the render target and all associated D2D and DWrite resources
        /// </summary>
        void CreateDeviceResources()
        {
            // Only calls if resources have not been initialize before
            if (renderTarget == null)
            {
                // The text format
                textFormat = dwriteFactory.CreateTextFormat("Bodoni MT", 24, DWrite.FontWeight.Normal, DWrite.FontStyle.Italic, DWrite.FontStretch.Normal);

                // Create the render target
                SizeU size = new SizeU((uint)host.ActualWidth, (uint)host.ActualHeight);
                RenderTargetProperties     props     = new RenderTargetProperties();
                HwndRenderTargetProperties hwndProps = new HwndRenderTargetProperties(host.Handle, size, PresentOptions.None);
                renderTarget = d2dFactory.CreateHwndRenderTarget(props, hwndProps);

                // A black brush to be used for drawing text
                ColorF cf = new ColorF(0, 0, 0, 1);
                blackBrush = renderTarget.CreateSolidColorBrush(cf);

                // Create a linear gradient.
                GradientStop[] stops =
                {
                    new GradientStop(1, new ColorF(1f, 0f, 0f, 0.25f)),
                    new GradientStop(0, new ColorF(0f, 0f, 1f, 1f))
                };

                GradientStopCollection        pGradientStops = renderTarget.CreateGradientStopCollection(stops, Gamma.Linear, ExtendMode.Wrap);
                LinearGradientBrushProperties gradBrushProps = new LinearGradientBrushProperties(new Point2F(50, 25), new Point2F(25, 50));

                linearGradientBrush = renderTarget.CreateLinearGradientBrush(gradBrushProps, pGradientStops);

                gridPatternBitmapBrush = CreateGridPatternBrush(renderTarget);

                solidBrush1 = renderTarget.CreateSolidColorBrush(new ColorF(0.3F, 0.5F, 0.65F, 0.25F));
                solidBrush2 = renderTarget.CreateSolidColorBrush(new ColorF(0.0F, 0.0F, 0.65F, 0.5F));
                solidBrush3 = renderTarget.CreateSolidColorBrush(new ColorF(0.9F, 0.5F, 0.3F, 0.75F));

                // Create a linear gradient.
                stops[0] = new GradientStop(1, new ColorF(0f, 0f, 0f, 0.25f));
                stops[1] = new GradientStop(0, new ColorF(1f, 1f, 0.2f, 1f));
                GradientStopCollection radiantGradientStops = renderTarget.CreateGradientStopCollection(stops, Gamma.Linear, ExtendMode.Wrap);

                RadialGradientBrushProperties radialBrushProps = new RadialGradientBrushProperties(new Point2F(25, 25), new Point2F(0, 0), 10, 10);
                radialGradientBrush = renderTarget.CreateRadialGradientBrush(radialBrushProps, radiantGradientStops);
            }
        }
Beispiel #9
0
        private Brush CreateEllipseBrush(Ellipse ellipse)
        {
            RectF bounds = ellipse.Bounds;

            RadialGradientBrushProperties properties = new RadialGradientBrushProperties(bounds.Center,
                                                                                         new PointF(),
                                                                                         ellipse.RadiusX,
                                                                                         ellipse.RadiusY);

            using (GradientStopCollection collection = _renderTarget.CreateGradientStopCollection(new GradientStop[] {
                new GradientStop(0, Color.FromKnown(Colors.Blue, 1)),
                new GradientStop(0.5f, Color.FromKnown(Colors.Green, 1)),
                new GradientStop(1, Color.FromKnown(Colors.Blue, 1))
            }))
            {
                Brush brush = _renderTarget.CreateRadialGradientBrush(properties, BrushProperties.Default, collection);
                brush.Transform = Matrix3x2.Rotation(_angle, bounds.Center);
                return(brush);
            }
        }
Beispiel #10
0
 public static RadialGradientBrush New(string name, Direct2DDevice device, RadialGradient radialGradient)
 {
     using (var d2dGradientStopCollection = new SharpDX.Direct2D1.GradientStopCollection(device,
                                                                                         radialGradient.GradientStops.Select(gs => (SharpDX.Direct2D1.GradientStop)gs).ToArray(),
                                                                                         (SharpDX.Direct2D1.ExtendMode)radialGradient.GradientStops.ExtendMode))
     {
         var rgbProperties = new RadialGradientBrushProperties
         {
             Center = radialGradient.Center,
             GradientOriginOffset = radialGradient.OriginOffset,
             RadiusX = radialGradient.RadiusX,
             RadiusY = radialGradient.RadiusY
         };
         var brushProperties = new BrushProperties()
         {
             Opacity = radialGradient.Opacity
         };
         var brush = new SharpDX.Direct2D1.RadialGradientBrush(device, rgbProperties, brushProperties, d2dGradientStopCollection);
         return(new RadialGradientBrush(name, device, radialGradient, brush));
     }
 }
Beispiel #11
0
        public Microsoft.WindowsAPICodePack.DirectX.Direct2D1.Brush GetDirectXBrush(System.Windows.Media.Brush mediaBrush)
        {
            if (mediaBrush is System.Windows.Media.SolidColorBrush)
            {
                return(GetDirectXBrush(((System.Windows.Media.SolidColorBrush)mediaBrush).Color));
            }
            else if (mediaBrush is System.Windows.Media.RadialGradientBrush)
            {
                System.Windows.Media.RadialGradientBrush mediaRadialBrush = (mediaBrush as System.Windows.Media.RadialGradientBrush);
                RadialGradientBrushProperties            properties       = new RadialGradientBrushProperties(mediaRadialBrush.Center.AsDirectX2DPoint(), mediaRadialBrush.GradientOrigin.AsDirectX2DPoint(), (float)mediaRadialBrush.RadiusX, (float)mediaRadialBrush.RadiusY);
                List <Microsoft.WindowsAPICodePack.DirectX.Direct2D1.GradientStop> stopCollection = new List <Microsoft.WindowsAPICodePack.DirectX.Direct2D1.GradientStop>();
                foreach (var stop in mediaRadialBrush.GradientStops)
                {
                    stopCollection.Add(new Microsoft.WindowsAPICodePack.DirectX.Direct2D1.GradientStop((float)stop.Offset, new ColorF((float)stop.Color.R, ((float)stop.Color.G / 255), ((float)stop.Color.B / 255), ((float)stop.Color.A / 255))));
                }
                Microsoft.WindowsAPICodePack.DirectX.Direct2D1.GradientStopCollection stops = this.RenderTarget.CreateGradientStopCollection(stopCollection, Gamma.StandardRgb, ExtendMode.Wrap);

                Microsoft.WindowsAPICodePack.DirectX.Direct2D1.RadialGradientBrush radialBrush = this.RenderTarget.CreateRadialGradientBrush(properties, stops);
                return(radialBrush);
            }
            return(null);
        }
Beispiel #12
0
        public override Brush GetBrush(RenderTarget renderTarget, byte alpha)
        {
            if (_canvasRadialGradientBrush == null || _canvasRadialGradientBrush.IsDisposed)
            {
                var center = new Vector2(_x0, _y0);
                center = LocalMatrix.Transform(center);

                var properties = new RadialGradientBrushProperties
                {
                    RadiusX = _r,
                    RadiusY = _r,
                    Center  = center
                };

                var collection = new GradientStopCollection(renderTarget, _canvasGradientStopCollection, Gamma.Linear, ExtendMode.Clamp);
                //TODO: OID: property missed, Same for Linear
                _canvasRadialGradientBrush = new RadialGradientBrush(renderTarget, properties, collection);
            }

            _canvasRadialGradientBrush.Opacity = alpha / 255f;

            return(_canvasRadialGradientBrush);
        }
Beispiel #13
0
 public D2DSpriteRadialGradientBrush CreateRadialGradientBrush(D2DSpriteGradientStopCollection collection,
                                                               RadialGradientBrushProperties r)
 {
     return(new D2DSpriteRadialGradientBrush(this, collection.GradientStopCollection, r));
 }
        public Microsoft.WindowsAPICodePack.DirectX.Direct2D1.Brush GetDirectXBrush(System.Windows.Media.Brush mediaBrush)
        {
            if (mediaBrush is System.Windows.Media.SolidColorBrush)
                return GetDirectXBrush(((System.Windows.Media.SolidColorBrush)mediaBrush).Color);
            else if (mediaBrush is System.Windows.Media.RadialGradientBrush)
            {
                System.Windows.Media.RadialGradientBrush mediaRadialBrush = (mediaBrush as System.Windows.Media.RadialGradientBrush);
                RadialGradientBrushProperties properties = new RadialGradientBrushProperties(mediaRadialBrush.Center.AsDirectX2DPoint(), mediaRadialBrush.GradientOrigin.AsDirectX2DPoint(), (float)mediaRadialBrush.RadiusX, (float)mediaRadialBrush.RadiusY);
                List<Microsoft.WindowsAPICodePack.DirectX.Direct2D1.GradientStop> stopCollection = new List<Microsoft.WindowsAPICodePack.DirectX.Direct2D1.GradientStop>();
                foreach (var stop in mediaRadialBrush.GradientStops)
                {
                    stopCollection.Add(new Microsoft.WindowsAPICodePack.DirectX.Direct2D1.GradientStop((float)stop.Offset, new ColorF((float)stop.Color.R, ((float)stop.Color.G / 255), ((float)stop.Color.B / 255), ((float)stop.Color.A / 255))));
                }
                Microsoft.WindowsAPICodePack.DirectX.Direct2D1.GradientStopCollection stops = this.RenderTarget.CreateGradientStopCollection(stopCollection, Gamma.StandardRgb, ExtendMode.Wrap);

                Microsoft.WindowsAPICodePack.DirectX.Direct2D1.RadialGradientBrush radialBrush = this.RenderTarget.CreateRadialGradientBrush(properties, stops);
                return radialBrush;
            }
            return null;
        }
Beispiel #15
0
 public IRadialGradientBrush CreateRadialGradientBrush(RadialGradientBrushProperties radialGradientBrushProperties, BrushProperties?brushProperties, IGradientStopCollection gradientStopCollection) =>
 base.innerRefT.CreateRadialGradientBrush(radialGradientBrushProperties, brushProperties, gradientStopCollection);
Beispiel #16
0
 private static void ConfigureRadialGradient(out RadialGradientBrushProperties description)
 {
     description = new RadialGradientBrushProperties();
 }
Beispiel #17
0
        private Brush CreateEllipseBrush(Ellipse ellipse)
        {
            RectF bounds = ellipse.Bounds;

            RadialGradientBrushProperties properties = new RadialGradientBrushProperties(bounds.Center,
                new PointF(),
                ellipse.RadiusX,
                ellipse.RadiusY);
            using (GradientStopCollection collection = _renderTarget.CreateGradientStopCollection(new GradientStop[] {
                        new GradientStop(0, Color.FromARGB(Colors.Blue,1)),
                        new GradientStop(0.5f, Color.FromARGB(Colors.Green,1)),
                        new GradientStop(1, Color.FromARGB(Colors.Blue,1))
                    }))
            {
                Brush brush = _renderTarget.CreateRadialGradientBrush(properties, BrushProperties.Default, collection);
                brush.Transform = Matrix3x2.Rotation(_angle, bounds.Center);
                return brush;
            }
        }
        internal override void Create()
        {
            if (NativeBrush != null)
                NativeBrush.Dispose();

            var stops = new GradientStop[m_gradientStops.Length];
            for (int s = 0; s < m_gradientStops.Length; s++)
            {
                stops[s].Color = m_gradientStops[s].Color.ToColor4();
                stops[s].Position = m_gradientStops[s].Position;
            }

            var props = new RadialGradientBrushProperties
            {
                Center = m_center.ToSharpDX(), 
                GradientOriginOffset = m_gradientOriginOffset.ToSharpDX(), 
                RadiusX = m_radiusX, 
                RadiusY = m_radiusY
            };

            using (var stopcol = new GradientStopCollection(Owner.D2dRenderTarget, stops, Gamma.StandardRgb, ExtendMode.Clamp))
            {
                NativeBrush = new RadialGradientBrush(Owner.D2dRenderTarget, props, stopcol);
            }
        }
 public ID2D1RadialGradientBrush CreateRadialGradientBrush(RadialGradientBrushProperties radialGradientBrushProperties, BrushProperties brushProperties, ID2D1GradientStopCollection gradientStopCollection)
 {
     return(CreateRadialGradientBrush(ref radialGradientBrushProperties, brushProperties, gradientStopCollection));
 }
Beispiel #20
0
        /// <summary>
        /// This method creates the render target and all associated D2D and DWrite resources
        /// </summary>
        void CreateDeviceResources()
        {
            // Only calls if resources have not been initialize before
            if (renderTarget == null)
            {
                // The text format
                textFormat = dwriteFactory.CreateTextFormat("Bodoni MT", 24, DWrite.FontWeight.Normal, DWrite.FontStyle.Italic, DWrite.FontStretch.Normal);

                // Create the render target
                SizeU size = new SizeU((uint)host.ActualWidth, (uint)host.ActualHeight);
                RenderTargetProperties props = new RenderTargetProperties();
                HwndRenderTargetProperties hwndProps = new HwndRenderTargetProperties(host.Handle, size, PresentOptions.None);
                renderTarget = d2dFactory.CreateHwndRenderTarget(props, hwndProps);

                // A black brush to be used for drawing text
                ColorF cf = new ColorF(0, 0, 0, 1);
                blackBrush = renderTarget.CreateSolidColorBrush(cf);

                // Create a linear gradient.
                GradientStop[] stops = 
                { 
                    new GradientStop(1, new ColorF(1f, 0f, 0f, 0.25f)),
                    new GradientStop(0, new ColorF(0f, 0f, 1f, 1f))
                };

                GradientStopCollection pGradientStops = renderTarget.CreateGradientStopCollection(stops, Gamma.Linear, ExtendMode.Wrap);
                LinearGradientBrushProperties gradBrushProps = new LinearGradientBrushProperties(new Point2F(50, 25), new Point2F(25, 50));

                linearGradientBrush = renderTarget.CreateLinearGradientBrush(gradBrushProps, pGradientStops);

                gridPatternBitmapBrush = CreateGridPatternBrush(renderTarget);

                solidBrush1 = renderTarget.CreateSolidColorBrush(new ColorF(0.3F, 0.5F, 0.65F, 0.25F));
                solidBrush2 = renderTarget.CreateSolidColorBrush(new ColorF(0.0F, 0.0F, 0.65F, 0.5F));
                solidBrush3 = renderTarget.CreateSolidColorBrush(new ColorF(0.9F, 0.5F, 0.3F, 0.75F));

                // Create a linear gradient.
                stops[0] = new GradientStop(1, new ColorF(0f, 0f, 0f, 0.25f));
                stops[1] = new GradientStop(0, new ColorF(1f, 1f, 0.2f, 1f));
                GradientStopCollection radiantGradientStops = renderTarget.CreateGradientStopCollection(stops, Gamma.Linear, ExtendMode.Wrap);

                RadialGradientBrushProperties radialBrushProps = new RadialGradientBrushProperties(new Point2F(25, 25), new Point2F(0, 0), 10, 10);
                radialGradientBrush = renderTarget.CreateRadialGradientBrush(radialBrushProps, radiantGradientStops);
            }
        }
Beispiel #21
0
        private void RadialGradientBrushAddClicked(object sender, EventArgs e)
        {
            ExtendMode ex = radialExtendCombo.SelectedIndex > 0 ? (ExtendMode)radialExtendCombo.SelectedIndex : ExtendMode.Clamp;
            Gamma gamma = radialGammaCombo.SelectedIndex > 0 ? (Gamma)radialGammaCombo.SelectedIndex : Gamma.Gamma_10;

            GradientStop[] stops = 
            {
                new GradientStop(0, color1),
                new GradientStop(1.0f, color2),
            };

            GradientStopCollection stopCollection = renderTarget.CreateGradientStopCollection(
                stops, gamma, ex);

            RadialGradientBrushProperties properties;

            if (ex == ExtendMode.Clamp)
            {
                properties = new RadialGradientBrushProperties(
                    new Point2F(50, 50), new Point2F(600, 400), 600, 600);
            }
            else
            {
                properties = new RadialGradientBrushProperties(
                    new Point2F(50, 50), new Point2F(0, 0), 50, 50);
            }
            
            RadialGradientBrush brush = renderTarget.CreateRadialGradientBrush(
                properties, stopCollection);

            parent.brushes.Add(brush);
            parent.currentBrushIndex = parent.brushes.Count - 1;
            FillBrushesListBox();
        }
Beispiel #22
0
        private void RadialGradientBrushAddClicked(object sender, EventArgs e)
        {
            ExtendMode ex = radialExtendCombo.SelectedIndex > 0 ? (ExtendMode)radialExtendCombo.SelectedIndex : ExtendMode.Clamp;
            Gamma gamma;

            switch (gammaComboBox.SelectedIndex)
            {
                case 0:
                    gamma = Gamma.Linear;
                    break;
                case 1:
                    gamma = Gamma.StandardRgb;
                    break;
                default:
                    throw new InvalidOperationException("Unknown gamma selected");
            }

            GradientStop[] stops = 
            {
                new GradientStop(0, color1),
                new GradientStop(1.0f, color2),
            };

            GradientStopCollection stopCollection = renderTarget.CreateGradientStopCollection(
                stops, gamma, ex);

            RadialGradientBrushProperties properties;

            if (ex == ExtendMode.Clamp)
            {
                properties = new RadialGradientBrushProperties(
                    new Point2F(50, 50), new Point2F(600, 400), 600, 600);
            }
            else
            {
                properties = new RadialGradientBrushProperties(
                    new Point2F(50, 50), new Point2F(0, 0), 50, 50);
            }
            
            RadialGradientBrush brush = renderTarget.CreateRadialGradientBrush(
                properties, stopCollection);

            parent.brushes.Add(brush);
            parent.currentBrushIndex = parent.brushes.Count - 1;
            FillBrushesListBox();
        }
 public D2DSpriteRadialGradientBrush(D2DSpriteBatch batch, GradientStopCollection collection, RadialGradientBrushProperties rgbp)
 {
     this.Brush = new RadialGradientBrush(batch.DWRenderTarget, collection, rgbp);
 }