Beispiel #1
0
        /// <summary>
        /// Sets the percentage according to the defined steps in the percentage profile
        /// </summary>
        protected async Task ApplyPercentageEffect(float percentage)
        {
            var numberOfActiveSteps = _amountOfSteps; //Default the percentage is deemed 100

            if (!float.IsNaN(percentage))
            {
                Math.Max(0, (int)Math.Floor(percentage / _percentagePerStep));
            }

            var activeSteps   = _percentageProfile.Steps.Take(numberOfActiveSteps);
            var inactiveSteps = _percentageProfile.Steps.Except(activeSteps);

            foreach (var step in activeSteps)
            {
                foreach (var panel in step.PanelIds)
                {
                    await _externalControlEndpoint.SetPanelColorAsync(panel, _redColor.Color.R, _redColor.Color.G, _redColor.Color.B);
                }
            }

            foreach (var step in inactiveSteps)
            {
                foreach (var panel in step.PanelIds)
                {
                    await _externalControlEndpoint.SetPanelColorAsync(panel, _whiteColor.Color.R, _whiteColor.Color.G, _whiteColor.Color.B);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Applies the screen mirror effect to the ligts.
        /// Screen mirror takes the average color of each triangle and applies it to that triangle
        /// </summary>
        public async Task ApplyEffect()
        {
            foreach (var panel in _panels)
            {
                //For each panel, draw a rectangle around its midpoint, according to the set rectangle size
                //Then get the average color of that rectangle and apply the color to the panel
                var startX = (int)Math.Floor(panel.MidPoint.X - (_rectangleSize / 2));
                var startY = (int)Math.Floor(panel.MidPoint.Y - (_rectangleSize / 2));

                // In multi monitor setup, all screens are joined in one larger pixel area. For example, if you want to take a screenshot of the second from left monitor,
                // you need to start at the right of the first left monitor. Hence, we need to add _screenBounds X and Y here to the location of the rectangle we want to capture
                var bounds = new Rectangle(_screenBounds.X + startX, _screenBounds.Y + startY, _rectangleSize, _rectangleSize);
                var bitmap = ScreenGrabber.CaptureScreen(bounds);

                var color = ScreenGrabber.CalculateAverageColor(bitmap, _capturedBounds, 0);

                await _externalControlEndpoint.SetPanelColorAsync(panel.PanelId, color.R, color.G, color.B);
            }
        }