예제 #1
0
        /// <summary>
        /// Position the form on the same monitor the user has put our app!
        /// (by default, forms are open on the primary monitor, but if the user dragged
        /// our form to another monitor the child forms still get created on the main monitor.
        /// This is a small quality of life fix)
        /// </summary>
        /// <param name="f">The form to move</param>
        protected void SetUpForm()
        {
            UserScreen[] screens = ScreensUtil.AllScreens();
            Point        pos     = Cursor.Position;

            Rectangle cursorScreen = Rectangle.Empty;

            for (int i = 0; i < screens.Length; i++)
            {
                UserScreen user   = screens[i];
                Rectangle  bounds = user.MonitorBounds;

                if (bounds.Contains(pos))
                {
                    cursorScreen = bounds;
                    break;
                }
            }

            this.SetDesktopLocation(cursorScreen.X + 100, cursorScreen.Y + 100);
        }
예제 #2
0
        private void UpdateScreens()
        {
            if (screens == null)
            {
                screens     = ScreensUtil.AllScreens();
                totalBounds = RectangleUtil.Union(screens);
            }
            else
            {
                UserScreen[] newScreens = ScreensUtil.AllScreens();
                Rectangle    newBounds  = RectangleUtil.Union(newScreens);
                if (newBounds.Equals(totalBounds))
                {
                    return;
                }

                // screens got updated, need to reflect in our window
                screens     = newScreens;
                totalBounds = newBounds;

                // remove all players screens
                List <PlayerInfo> playerData = profile.PlayerData;
                if (playerData != null)
                {
                    for (int i = 0; i < playerData.Count; i++)
                    {
                        PlayerInfo player = playerData[i];
                        player.EditBounds  = GetDefaultBounds(draggingIndex);
                        player.ScreenIndex = -1;
                    }
                }
            }

            screensArea = new RectangleF(10, 50 + Height * 0.2f + 10, Width - 20, Height * 0.5f);
            if (totalBounds.Width > totalBounds.Height)
            {
                // horizontal monitor setup
                scale = screensArea.Width / (float)totalBounds.Width;
                if (totalBounds.Height * scale > screensArea.Height)
                {
                    scale = screensArea.Height / (float)totalBounds.Height;
                }
            }
            else
            {
                // vertical monitor setup
                scale = screensArea.Height / (float)totalBounds.Height;
                if (totalBounds.Width * scale > screensArea.Width)
                {
                    scale = screensArea.Width / (float)totalBounds.Width;
                }
            }

            Rectangle scaledBounds = RectangleUtil.Scale(totalBounds, scale);

            scaledBounds.X = (int)screensArea.X;
            scaledBounds.Y = (int)screensArea.Y;
            //scaledBounds = RectangleUtil.Center(scaledBounds, RectangleUtil.Float(0, this.Height * 0.25f, this.Width, this.Height * 0.7f));

            int minY = 0;

            for (int i = 0; i < screens.Length; i++)
            {
                UserScreen screen = screens[i];

                Rectangle bounds   = RectangleUtil.Scale(screen.MonitorBounds, scale);
                Rectangle uiBounds = new Rectangle(bounds.X, bounds.Y + scaledBounds.Y, bounds.Width, bounds.Height);
                screen.UIBounds = uiBounds;

                minY = Math.Min(minY, uiBounds.X);
            }

            // remove negative monitors
            minY = -minY;
            for (int i = 0; i < screens.Length; i++)
            {
                UserScreen screen = screens[i];

                Rectangle uiBounds = screen.UIBounds;
                uiBounds.X           += minY + scaledBounds.X;
                screen.UIBounds       = uiBounds;
                screen.SwapTypeBounds = RectangleUtil.Float(uiBounds.X, uiBounds.Y, uiBounds.Width * 0.1f, uiBounds.Width * 0.1f);
            }
        }
예제 #3
0
        public void Initialize(UserGameInfo game, GameProfile profile)
        {
            this.profile = profile;
            profile.PlayerData.Clear();// reset profile

            playerFont     = new Font("Segoe UI", 40);
            playerTextFont = new Font("Segoe UI", 18);

            RemoveFlicker();

            float playersWidth = this.Width * 0.5f;

            int   playerCount  = profile.PlayerCount;
            float playerWidth  = (playersWidth * 0.9f) / (float)playerCount;
            float playerHeight = playerWidth * 0.5625f;
            float offset       = (playersWidth * 0.1f) / (float)playerCount;

            playersArea = new RectangleF(50, 100, playersWidth, playerHeight);

            for (int i = 0; i < playerCount; i++)
            {
                Rectangle  r     = new Rectangle((int)(50 + ((playerWidth + offset) * i)), 100, (int)playerWidth, (int)playerHeight);
                PlayerInfo playa = new PlayerInfo();
                playa.editBounds = r;
                profile.PlayerData.Add(playa);
            }

            screens = ScreensUtil.AllScreens();
            Rectangle totalBounds = RectangleUtil.Union(ScreensUtil.AllScreensRec());

            // see if most screens are either vertical or horizontal
            int vertical   = 0;
            int horizontal = 0;

            for (int i = 0; i < screens.Length; i++)
            {
                UserScreen s = screens[i];
                if (s.bounds.Width > s.bounds.Height)
                {
                    horizontal++;
                }
                else
                {
                    vertical++;
                }
            }


            if (horizontal > vertical)
            {
                // horizontal setup
                scale = (this.Width * 0.9f) / (float)totalBounds.Width;
            }
            else
            {
                // vertical setup
                scale = (this.Height * 0.6f) / (float)totalBounds.Height;
                //scale = (this.Width * 0.9f) / (float)totalBounds.Width;
            }

            totalBounds = new Rectangle(
                (int)(totalBounds.X * scale),
                (int)(totalBounds.Y * scale),
                (int)(totalBounds.Width * scale),
                (int)(totalBounds.Height * scale));
            int offsetViewsX = totalBounds.X;
            int offsetViewsY = totalBounds.Y;

            totalBounds = RectangleUtil.Center(totalBounds, new Rectangle(0, (int)(this.Height * 0.25f), this.Width, (int)(this.Height * 0.7f)));

            for (int i = 0; i < screens.Length; i++)
            {
                UserScreen screen = screens[i];

                Rectangle s      = screen.bounds;
                int       width  = (int)(s.Width * scale);
                int       height = (int)(s.Height * scale);
                int       x      = (int)(s.X * scale);
                int       y      = (int)(s.Y * scale);
                screen.bounds       = new Rectangle(x + totalBounds.X - offsetViewsX, y + totalBounds.Y - offsetViewsY, width, height);
                screen.swapTypeRect = new Rectangle(screen.bounds.X, screen.bounds.Y, (int)(screen.bounds.Width * 0.1f), (int)(screen.bounds.Width * 0.1f));
            }
        }
예제 #4
0
        public override void Initialize(UserGameInfo game, GameProfile profile)
        {
            base.Initialize(game, profile);

            canProceed = false;

            playerFont     = new Font("Segoe UI", 40);
            playerTextFont = new Font("Segoe UI", 18);

            RemoveFlicker();

            float playersWidth = this.Width * 0.5f;

            int   playerCount  = profile.PlayerCount;
            float playerWidth  = (playersWidth * 0.9f) / (float)playerCount;
            float playerHeight = playerWidth * 0.5625f;
            float offset       = (playersWidth * 0.1f) / (float)playerCount;

            playersArea = new RectangleF(50, 100, playersWidth, playerHeight);

            screens = ScreensUtil.AllScreens();
            Rectangle totalBounds = RectangleUtil.Union(ScreensUtil.AllScreensRec());

            // see if most screens are either vertical or horizontal
            int vertical   = 0;
            int horizontal = 0;

            for (int i = 0; i < screens.Length; i++)
            {
                UserScreen s = screens[i];
                if (s.bounds.Width > s.bounds.Height)
                {
                    horizontal++;
                }
                else
                {
                    vertical++;
                }
            }


            if (horizontal > vertical)
            {
                // horizontal setup
                scale = (this.Width * 0.9f) / (float)totalBounds.Width;
            }
            else
            {
                // vertical setup
                scale = (this.Height * 0.6f) / (float)totalBounds.Height;
                //scale = (this.Width * 0.9f) / (float)totalBounds.Width;
            }

            totalBounds = new Rectangle(
                (int)(totalBounds.X * scale),
                (int)(totalBounds.Y * scale),
                (int)(totalBounds.Width * scale),
                (int)(totalBounds.Height * scale));
            int offsetViewsX = totalBounds.X;
            int offsetViewsY = totalBounds.Y;

            totalBounds = RectangleUtil.Center(totalBounds, new Rectangle(0, (int)(this.Height * 0.25f), this.Width, (int)(this.Height * 0.7f)));

            for (int i = 0; i < screens.Length; i++)
            {
                UserScreen screen = screens[i];

                Rectangle s      = screen.bounds;
                int       width  = (int)(s.Width * scale);
                int       height = (int)(s.Height * scale);
                int       x      = (int)(s.X * scale);
                int       y      = (int)(s.Y * scale);
                screen.bounds       = new Rectangle(x + totalBounds.X - offsetViewsX, y + totalBounds.Y - offsetViewsY, width, height);
                screen.swapTypeRect = new Rectangle(screen.bounds.X, screen.bounds.Y, (int)(screen.bounds.Width * 0.1f), (int)(screen.bounds.Width * 0.1f));
            }

            List <PlayerInfo> playerData = profile.PlayerData;

            if (playerData.Count == 0)
            {
                for (int i = 0; i < playerCount; i++)
                {
                    AddPlayer(i, playerWidth, playerHeight, offset);
                }
            }
            else
            {
                for (int i = 0; i < playerCount; i++)
                {
                    if (i >= playerData.Count)
                    {
                        // additional players
                        AddPlayer(i, playerWidth, playerHeight, offset);
                    }
                    else
                    {
                        PlayerInfo info   = playerData[i];
                        Rectangle  s      = info.MonitorBounds;
                        int        width  = (int)(s.Width * scale);
                        int        height = (int)(s.Height * scale);
                        int        x      = (int)(s.X * scale);
                        int        y      = (int)(s.Y * scale);
                        info.EditBounds = new Rectangle(x, y, width, height);
                    }
                }
            }
        }