コード例 #1
0
ファイル: SpotSet.cs プロジェクト: iLLiac4/adrilight
        internal ISpot[] BuildSpots(Rectangle screen, IUserSettings userSettings)
        {
            ISpot[] spots = new Spot[CountLeds(userSettings.SpotsX, userSettings.SpotsY)];


            var canvasSizeX = screen.Width - 2 * userSettings.BorderDistanceX;
            var canvasSizeY = screen.Height - 2 * userSettings.BorderDistanceY;

            var xResolution      = userSettings.SpotsX > 1 ? (canvasSizeX - userSettings.SpotWidth) / (userSettings.SpotsX - 1) : 0;
            var xRemainingOffset = userSettings.SpotsX > 1 ? ((canvasSizeX - userSettings.SpotWidth) % (userSettings.SpotsX - 1)) / 2 : 0;
            var yResolution      = userSettings.SpotsY > 1 ? (canvasSizeY - userSettings.SpotHeight) / (userSettings.SpotsY - 1) : 0;
            var yRemainingOffset = userSettings.SpotsY > 1 ? ((canvasSizeY - userSettings.SpotHeight) % (userSettings.SpotsY - 1)) / 2 : 0;

            var counter       = 0;
            var relationIndex = userSettings.SpotsX - userSettings.SpotsY + 1;

            for (var j = 0; j < userSettings.SpotsY; j++)
            {
                for (var i = 0; i < userSettings.SpotsX; i++)
                {
                    var isFirstColumn = i == 0;
                    var isLastColumn  = i == userSettings.SpotsX - 1;
                    var isFirstRow    = j == 0;
                    var isLastRow     = j == userSettings.SpotsY - 1;

                    if (isFirstColumn || isLastColumn || isFirstRow || isLastRow) // needing only outer spots
                    {
                        var x = (xRemainingOffset + userSettings.BorderDistanceX + userSettings.OffsetX + i * xResolution)
                                .Clamp(0, screen.Width);

                        var y = (yRemainingOffset + userSettings.BorderDistanceY + userSettings.OffsetY + j * yResolution)
                                .Clamp(0, screen.Height);

                        var index = counter++; // in first row index is always counter

                        if (userSettings.SpotsX > 1 && userSettings.SpotsY > 1)
                        {
                            if (!isFirstRow && !isLastRow)
                            {
                                if (isFirstColumn)
                                {
                                    index += relationIndex + ((userSettings.SpotsY - 1 - j) * 3);
                                }
                                else if (isLastColumn)
                                {
                                    index -= j;
                                }
                            }

                            if (!isFirstRow && isLastRow)
                            {
                                index += relationIndex - i * 2;
                            }
                        }

                        spots[index] = new Spot(x, y, userSettings.SpotWidth, userSettings.SpotHeight);
                    }
                }
            }

            //TODO totally broken :(

            if (userSettings.OffsetLed != 0)
            {
                Offset(ref spots, userSettings.OffsetLed);
            }
            if (userSettings.SpotsY > 1 && userSettings.MirrorX)
            {
                MirrorX(spots, userSettings.SpotsX, userSettings.SpotsY);
            }
            if (userSettings.SpotsX > 1 && userSettings.MirrorY)
            {
                MirrorY(spots, userSettings.SpotsX, userSettings.SpotsY);
            }

            spots[0].IsFirst = true;
            return(spots);
        }
コード例 #2
0
ファイル: SpotSet.cs プロジェクト: uxDesign/adrilight
        internal ISpot[] BuildSpots(int screenWidth, int screenHeight, IUserSettings userSettings)
        {
            var spotsX = userSettings.SpotsX;
            var spotsY = userSettings.SpotsY;

            ISpot[] spots = new Spot[CountLeds(spotsX, spotsY)];


            var scalingFactor   = DesktopDuplicator.ScalingFactor;
            var borderDistanceX = userSettings.BorderDistanceX / scalingFactor;
            var borderDistanceY = userSettings.BorderDistanceY / scalingFactor;
            var spotWidth       = userSettings.SpotWidth / scalingFactor;
            var spotHeight      = userSettings.SpotHeight / scalingFactor;

            var canvasSizeX = screenWidth - 2 * borderDistanceX;
            var canvasSizeY = screenHeight - 2 * borderDistanceY;


            var xResolution      = spotsX > 1 ? (canvasSizeX - spotWidth) / (spotsX - 1) : 0;
            var xRemainingOffset = spotsX > 1 ? ((canvasSizeX - spotWidth) % (spotsX - 1)) / 2 : 0;
            var yResolution      = spotsY > 1 ? (canvasSizeY - spotHeight) / (spotsY - 1) : 0;
            var yRemainingOffset = spotsY > 1 ? ((canvasSizeY - spotHeight) % (spotsY - 1)) / 2 : 0;

            var counter       = 0;
            var relationIndex = spotsX - spotsY + 1;

            for (var j = 0; j < spotsY; j++)
            {
                for (var i = 0; i < spotsX; i++)
                {
                    var isFirstColumn = i == 0;
                    var isLastColumn  = i == spotsX - 1;
                    var isFirstRow    = j == 0;
                    var isLastRow     = j == spotsY - 1;

                    if (isFirstColumn || isLastColumn || isFirstRow || isLastRow) // needing only outer spots
                    {
                        var x = (xRemainingOffset + borderDistanceX + userSettings.OffsetX / scalingFactor + i * xResolution)
                                .Clamp(0, screenWidth);

                        var y = (yRemainingOffset + borderDistanceY + userSettings.OffsetY / scalingFactor + j * yResolution)
                                .Clamp(0, screenHeight);

                        var index = counter++; // in first row index is always counter

                        if (spotsX > 1 && spotsY > 1)
                        {
                            if (!isFirstRow && !isLastRow)
                            {
                                if (isFirstColumn)
                                {
                                    index += relationIndex + ((spotsY - 1 - j) * 3);
                                }
                                else if (isLastColumn)
                                {
                                    index -= j;
                                }
                            }

                            if (!isFirstRow && isLastRow)
                            {
                                index += relationIndex - i * 2;
                            }
                        }

                        spots[index] = new Spot(x, y, spotWidth, spotHeight);
                    }
                }
            }

            //TODO totally broken :(

            if (userSettings.OffsetLed != 0)
            {
                Offset(ref spots, userSettings.OffsetLed);
            }
            if (spotsY > 1 && userSettings.MirrorX)
            {
                MirrorX(spots, spotsX, spotsY);
            }
            if (spotsX > 1 && userSettings.MirrorY)
            {
                MirrorY(spots, spotsX, spotsY);
            }

            spots[0].IsFirst = true;
            return(spots);
        }
コード例 #3
0
ファイル: SpotSet.cs プロジェクト: zagunhy/adrilight
        public static void Refresh()
        {
            lock (Lock)
            {
                Spots = new Spot[CountLeds(Settings.SpotsX, Settings.SpotsY)];

                var rectangle = ExpectedScreenBound = Screen.PrimaryScreen.Bounds;

                var canvasSizeX  = (rectangle.Width - 2 * Settings.BorderDistanceX);
                var screenHeight = rectangle.Height;
                var canvasSizeY  = (screenHeight - 2 * Settings.BorderDistanceY);

                var xResolution      = Settings.SpotsX > 1 ? (canvasSizeX - Settings.SpotWidth) / (Settings.SpotsX - 1) : 0;
                var xRemainingOffset = Settings.SpotsX > 1 ? ((canvasSizeX - Settings.SpotWidth) % (Settings.SpotsX - 1)) / 2 : 0;
                var yResolution      = Settings.SpotsY > 1 ? (canvasSizeY - Settings.SpotHeight) / (Settings.SpotsY - 1) : 0;
                var yRemainingOffset = Settings.SpotsY > 1 ? ((canvasSizeY - Settings.SpotHeight) % (Settings.SpotsY - 1)) / 2 : 0;

                var counter       = 0;
                var relationIndex = Settings.SpotsX - Settings.SpotsY + 1;

                for (var j = 0; j < Settings.SpotsY; j++)
                {
                    for (var i = 0; i < Settings.SpotsX; i++)
                    {
                        var isFirstColumn = i == 0;
                        var isLastColumn  = i == Settings.SpotsX - 1;
                        var isFirstRow    = j == 0;
                        var isLastRow     = j == Settings.SpotsY - 1;

                        if (isFirstColumn || isLastColumn || isFirstRow || isLastRow) // needing only outer spots
                        {
                            var x = Math.Max(0,
                                             Math.Min(rectangle.Width,
                                                      xRemainingOffset + Settings.BorderDistanceX + Settings.OffsetX + i * (xResolution) + Settings.SpotWidth / 2));
                            var y = Math.Max(0,
                                             Math.Min(screenHeight, yRemainingOffset + Settings.BorderDistanceY + Settings.OffsetY + j * (yResolution) + Settings.SpotHeight / 2));

                            var index = counter++; // in first row index is always counter

                            if (Settings.SpotsX > 1 && Settings.SpotsY > 1)
                            {
                                if (!isFirstRow && !isLastRow)
                                {
                                    if (isFirstColumn)
                                    {
                                        index += relationIndex + ((Settings.SpotsY - 1 - j) * 3);
                                    }
                                    else if (isLastColumn)
                                    {
                                        index -= j;
                                    }
                                }

                                if (!isFirstRow && isLastRow)
                                {
                                    index += relationIndex - (i * 2);
                                }
                            }
                            var spotWidth  = Math.Min(Settings.SpotWidth, Math.Min(x, rectangle.Width - x));
                            var spotHeight = Math.Min(Settings.SpotHeight, Math.Min(y, screenHeight - y));
                            SpotSet.Spots[index] = new Spot(x, y, spotWidth, spotHeight);
                        }
                    }
                }


                if (Settings.OffsetLed != 0)
                {
                    Offset(Settings.OffsetLed);
                }
                if (Settings.SpotsY > 1 && Settings.MirrorX)
                {
                    MirrorX();
                }
                if (Settings.SpotsX > 1 && Settings.MirrorY)
                {
                    MirrorY();
                }
            }
        }