/// <summary>
        /// Gets the brush for the given device.
        /// </summary>
        /// <param name="engineDevice">The device for which to get the brush.</param>
        internal override D2D.Brush GetBrush(EngineDevice engineDevice)
        {
            // Check for disposed state
            if (base.IsDisposed)
            {
                throw new ObjectDisposedException(this.GetType().Name);
            }

            LoadedBrushResources result = m_loadedBrushes[engineDevice.DeviceIndex];

            if (result.Brush == null)
            {
                // Convert gradient stops to structure from SharpDX
                D2D.GradientStop[] d2dGradientStops = new D2D.GradientStop[m_gradientStops.Length];
                for (int loop = 0; loop < d2dGradientStops.Length; loop++)
                {
                    d2dGradientStops[loop] = new D2D.GradientStop()
                    {
                        Color    = m_gradientStops[loop].Color.ToDXColor(),
                        Position = m_gradientStops[loop].Position
                    };
                }

                // Create the brush
                result = new LoadedBrushResources();
                result.GradientStops = new D2D.GradientStopCollection(
                    engineDevice.FakeRenderTarget2D,
                    d2dGradientStops,
                    (D2D.Gamma)m_gamma,
                    (D2D.ExtendMode)m_extendMode);

                unsafe
                {
                    Matrix3x2 identityMatrix = Matrix3x2.Identity;
                    result.Brush = new D2D.LinearGradientBrush(
                        engineDevice.FakeRenderTarget2D,
                        new D2D.LinearGradientBrushProperties()
                    {
                        StartPoint = m_startPoint.ToDXVector(),
                        EndPoint   = m_endPoint.ToDXVector()
                    },
                        new D2D.BrushProperties()
                    {
                        Opacity   = m_opacity,
                        Transform = *(SharpDX.Mathematics.Interop.RawMatrix3x2 *) & identityMatrix
                    },
                        result.GradientStops);
                }

                m_loadedBrushes[engineDevice.DeviceIndex] = result;
            }

            return(result.Brush);
        }
예제 #2
0
        /// <summary>
        /// Unloads all resources loaded on the given device.
        /// </summary>
        /// <param name="engineDevice">The device for which to unload the resource.</param>
        internal override void UnloadResources(EngineDevice engineDevice)
        {
            LoadedBrushResources loadedBrush = m_loadedBrushes[engineDevice.DeviceIndex];

            if (loadedBrush.Brush != null)
            {
                loadedBrush.Brush         = GraphicsHelper.DisposeObject(loadedBrush.Brush);
                loadedBrush.GradientStops = GraphicsHelper.DisposeObject(loadedBrush.GradientStops);

                m_loadedBrushes[engineDevice.DeviceIndex] = loadedBrush;
            }
        }
예제 #3
0
        /// <summary>
        /// Gets the brush for the given device.
        /// </summary>
        /// <param name="engineDevice">The device for which to get the brush.</param>
        internal override D2D.Brush GetBrush(EngineDevice engineDevice)
        {
            // Check for disposed state
            if (base.IsDisposed)
            {
                throw new ObjectDisposedException(this.GetType().Name);
            }

            LoadedBrushResources result = m_loadedBrushes[engineDevice.DeviceIndex];

            if (result.Brush == null)
            {
                // Convert gradient stops to structure from SharpDX
                D2D.GradientStop[] d2dGradientStops = new D2D.GradientStop[m_gradientStops.Length];
                for (int loop = 0; loop < d2dGradientStops.Length; loop++)
                {
                    d2dGradientStops[loop] = new D2D.GradientStop()
                    {
                        Color    = m_gradientStops[loop].Color.ToDXColor(),
                        Position = m_gradientStops[loop].Position
                    };
                }

                // Create the brush
                result = new LoadedBrushResources();
                result.GradientStops = new D2D.GradientStopCollection(
                    engineDevice.FakeRenderTarget2D,
                    d2dGradientStops,
                    (D2D.Gamma)m_gamma,
                    (D2D.ExtendMode)m_extendMode);
                result.Brush = new D2D.RadialGradientBrush(
                    engineDevice.FakeRenderTarget2D,
                    new D2D.RadialGradientBrushProperties()
                {
                    Center = m_center.ToDXVector(),
                    GradientOriginOffset = m_gradientOriginOffset.ToDXVector(),
                    RadiusX = m_radiusX,
                    RadiusY = m_radiusY
                },
                    new D2D.BrushProperties()
                {
                    Opacity   = m_opacity,
                    Transform = Matrix3x2.Identity.ToDXMatrix()
                },
                    result.GradientStops);

                m_loadedBrushes[engineDevice.DeviceIndex] = result;
            }

            return(result.Brush);
        }