Ejemplo n.º 1
0
        /// <summary>
        /// Renders a ledgroup.
        /// </summary>
        /// <param name="ledGroup">The led group to render.</param>
        // ReSharper disable once MemberCanBeMadeStatic.Local - idc
        protected virtual void Render(ILedGroup ledGroup)
        {
            if (ledGroup == null)
            {
                return;
            }

            IList <CorsairLed> leds = ledGroup.GetLeds().ToList();

            IBrush brush = ledGroup.Brush;

            if (brush == null)
            {
                return;
            }

            try
            {
                switch (brush.BrushCalculationMode)
                {
                case BrushCalculationMode.Relative:
                    RectangleF brushRectangle = RectangleHelper.CreateRectangleFromRectangles(leds.Select(x => x.LedRectangle));
                    float      offsetX        = -brushRectangle.X;
                    float      offsetY        = -brushRectangle.Y;
                    brushRectangle.X = 0;
                    brushRectangle.Y = 0;
                    brush.PerformRender(brushRectangle, leds.Select(x => new BrushRenderTarget(x.Id, x.LedRectangle.Move(offsetX, offsetY))));
                    break;

                case BrushCalculationMode.Absolute:
                    brush.PerformRender(DeviceRectangle, leds.Select(x => new BrushRenderTarget(x.Id, x.LedRectangle)));
                    break;

                default:
                    throw new ArgumentException();
                }

                brush.UpdateEffects();
                brush.PerformFinalize();

                foreach (KeyValuePair <BrushRenderTarget, CorsairColor> renders in brush.RenderedTargets)
                {
                    this[renders.Key.LedId].Color = renders.Value;
                }
            }
            // ReSharper disable once CatchAllClause
            catch (Exception ex) { OnException(ex); }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Renders a ledgroup.
        /// </summary>
        /// <param name="ledGroup">The led group to render.</param>
        private void Render(ILedGroup ledGroup)
        {
            IList <Led> leds  = ledGroup.GetLeds().ToList();
            IBrush      brush = ledGroup.Brush;

            if ((brush == null) || !brush.IsEnabled)
            {
                return;
            }

            switch (brush.BrushCalculationMode)
            {
            case BrushCalculationMode.Relative:
                Rectangle brushRectangle = new Rectangle(leds.Select(x => GetDeviceLedLocation(x)));
                Point     offset         = new Point(-brushRectangle.Location.X, -brushRectangle.Location.Y);
                brushRectangle.Location.X = 0;
                brushRectangle.Location.Y = 0;
                brush.PerformRender(brushRectangle,
                                    leds.Select(x => new BrushRenderTarget(x, GetDeviceLedLocation(x, offset))));
                break;

            case BrushCalculationMode.Absolute:
                brush.PerformRender(SurfaceRectangle, leds.Select(x => new BrushRenderTarget(x, GetDeviceLedLocation(x))));
                break;

            default:
                throw new ArgumentException();
            }

            //brush.UpdateEffects();
            brush.PerformFinalize();

            foreach (KeyValuePair <BrushRenderTarget, Color> renders in brush.RenderedTargets)
            {
                renders.Key.Led.Color = renders.Value;
            }
        }