Animatroller.Framework.LogicalDevice.VirtualPixel1D.RaiseMultiPixelChanged C# (CSharp) Method

RaiseMultiPixelChanged() protected method

protected RaiseMultiPixelChanged ( int startPosition, int size ) : void
startPosition int
size int
return void
        protected void RaiseMultiPixelChanged(int startPosition, int size)
        {
            if (suspended)
            {
                if (!suspendedStart.HasValue || startPosition < suspendedStart.Value)
                    suspendedStart = startPosition;

                if (!suspendedEnd.HasValue || (startPosition + size - 1) > suspendedEnd.Value)
                    suspendedEnd = (startPosition + size - 1);

                return;
            }

            var handler = MultiPixelChanged;
            if (handler != null)
            {
                var newValues = new List<ColorBrightness>();
                for (int i = 0; i < size; i++)
                {
                    int position = i + startPosition;
                    newValues.Add(new ColorBrightness(this.color[position], this.brightness[position] * this.globalBrightness.Value));
                }
                handler(this, new MultiPixelChangedEventArgs(startPosition, newValues.ToArray()));
            }

            foreach (var pixelDevice in this.devices)
            {
                int? firstPosition = null;
                var newValues = new List<ColorBrightness>();
                for (int i = 0; i < size; i++)
                {
                    int position = i + startPosition;
                    if (pixelDevice.IsPositionForThisDevice(position))
                    {
                        if (!firstPosition.HasValue)
                            firstPosition = position - pixelDevice.StartPosition;

                        newValues.Add(new ColorBrightness(this.color[position], this.brightness[position] * this.globalBrightness.Value));
                    }
                }

                if (newValues.Any())
                {
                    handler = pixelDevice.MultiPixelChanged;
                    if (handler != null)
                        handler(this, new MultiPixelChangedEventArgs(firstPosition.Value, newValues.ToArray()));
                }
            }
        }