Example #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); }
        }