protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics g = e.Graphics; #if DEBUG //g.FillRectangle(Brushes.Green, playersArea); //g.FillRectangle(Brushes.CornflowerBlue, screensArea); //g.FillRectangle(Brushes.CornflowerBlue, new RectangleF(0, 0, Width, Height)); #endif UpdateScreens(); for (int i = 0; i < screens.Length; i++) { UserScreen s = screens[i]; g.DrawRectangle(Pens.White, s.UIBounds); g.DrawRectangle(Pens.White, s.SwapTypeBounds); switch (s.Type) { case UserScreenType.FullScreen: g.DrawImage(Resources.fullscreen, s.SwapTypeBounds); break; case UserScreenType.DualHorizontal: g.DrawImage(Resources.horizontal, s.SwapTypeBounds); break; case UserScreenType.DualVertical: g.DrawImage(Resources.vertical, s.SwapTypeBounds); break; case UserScreenType.FourPlayers: g.DrawImage(Resources._4players, s.SwapTypeBounds); break; case UserScreenType.SixteenPlayers: g.DrawImage(Resources._16players, s.SwapTypeBounds); break; } } var players = profile.PlayerData; if (players.Count == 0) { g.DrawString("No Gamepads connected", playerTextFont, Brushes.Red, new PointF(20, 40)); } else { for (int i = 0; i < players.Count; i++) { PlayerInfo info = players[i]; Rectangle s = info.EditBounds; g.ResetClip(); g.Clip = new Region(new RectangleF(s.X, s.Y, s.Width + 1, s.Height + 1)); Rectangle gamepadRect = RectangleUtil.ScaleAndCenter(gamepadImg.Size, s); string str = (i + 1).ToString(); SizeF size = g.MeasureString(str, playerFont); PointF loc = RectangleUtil.Center(size, s); if (info.IsXInput) { loc.Y -= gamepadRect.Height * 0.1f; GamepadButtonFlags flags = (GamepadButtonFlags)info.GamepadMask; //g.DrawString(flags.ToString(), smallTextFont, Brushes.White, new PointF(loc.X, loc.Y + gamepadRect.Height * 0.01f)); g.DrawString((info.GamepadId + 1).ToString(), playerFont, Brushes.White, loc); g.DrawImage(gamepadImg, gamepadRect); } else if (info.IsKeyboardPlayer) { g.DrawImage(keyboardImg, gamepadRect); } else { loc.X = s.X; g.DrawString(info.GamepadName, playerTextFont, Brushes.White, loc); g.DrawImage(genericImg, gamepadRect); } if (info.ScreenIndex != -1) { UserScreen screen = screens[info.ScreenIndex]; if ((s.Height + s.Y) - (screen.UIBounds.Height + screen.UIBounds.Y) == -1) { s.Height += 1; } g.Clip = new Region(new RectangleF(s.X, s.Y, s.Width + 1, s.Height + 1)); g.DrawRectangle(Pens.Green, s); } } } g.ResetClip(); if (dragging && draggingScreen != -1) { g.DrawRectangle(Pens.Red, draggingScreenRec); } g.DrawString("Gamepads", playerTextFont, Brushes.White, new PointF(10, 10)); SizeF dragEachGamepadSize; string dragEachGamepad = "Drag each gamepad to a screen"; dragEachGamepad = StringUtil.WrapString(Width * 0.6f, dragEachGamepad, g, playerTextFont, out dragEachGamepadSize); g.DrawString(dragEachGamepad, playerTextFont, Brushes.White, new PointF(Width - dragEachGamepadSize.Width, playersArea.Y)); SizeF bottomTextSize; string bottomText = "Click on screen's top-left corner to change players on that screen. (4-player only) Right click player to change size"; bottomText = StringUtil.WrapString(Width - 20, bottomText, g, playerTextFont, out bottomTextSize); g.DrawString(bottomText, playerTextFont, Brushes.White, new PointF(10, Height - bottomTextSize.Height - 10)); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics g = e.Graphics; for (int i = 0; i < screens.Length; i++) { UserScreen s = screens[i]; g.DrawRectangle(Pens.White, s.bounds); g.DrawRectangle(Pens.White, s.swapTypeRect); switch (s.type) { case UserScreenType.FullScreen: g.DrawImage(Resources.fullscreen, s.swapTypeRect); break; case UserScreenType.DualHorizontal: g.DrawImage(Resources.horizontal, s.swapTypeRect); break; case UserScreenType.DualVertical: g.DrawImage(Resources.vertical, s.swapTypeRect); break; case UserScreenType.FourPlayers: g.DrawImage(Resources._4players, s.swapTypeRect); break; } } var players = profile.PlayerData; for (int i = 0; i < players.Count; i++) { PlayerInfo info = players[i]; Rectangle s = info.editBounds; if (info.screenIndex == -1) { g.DrawRectangle(Pens.White, s); } else { g.DrawRectangle(Pens.Green, s); } string str = (i + 1).ToString(); SizeF size = g.MeasureString(str, playerFont); PointF loc = RectangleUtil.Center(size, s); g.DrawString((i + 1).ToString(), playerFont, Brushes.White, loc); } if (dragging && draggingScreen != -1) { g.DrawRectangle(Pens.Red, draggingScreenRec); } g.DrawString("Drag each player to\ntheir respective screen", playerTextFont, Brushes.White, new PointF(470, 100)); g.DrawString("Players", playerTextFont, Brushes.White, new PointF(50, 50)); g.DrawString("Right click player to change size", playerTextFont, Brushes.White, new PointF(20, 450)); g.DrawString("Click on screen's top-left corner to change players on that screen", playerTextFont, Brushes.White, new PointF(20, 490)); //g.DrawRectangle(Pens.Red, playersArea.X, playersArea.Y, playersArea.Width, playersArea.Height); }
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)); } }
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); } } } }