protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); mousePos = e.Location; if (dragging) { var players = config.Players; PlayerInfo player = players[draggingIndex]; Rectangle p = player.editBounds; if (draggingScreen == -1) { for (int i = 0; i < screens.Length; i++) { UserScreen screen = screens[i]; Rectangle s = screen.bounds; float pc = RectangleUtil.PcInside(p, s); // bigger than 60% = major part inside this screen if (pc > 0.6f) { float offset = s.Width * 0.05f; // check if there's space available on this screen var playas = config.Players; Rectangle?editor; Rectangle?monitor; GetFreeSpace(i, out editor, out monitor); if (editor != null) { draggingScreenRec = editor.Value; draggingScreenBounds = monitor.Value; draggingScreen = i; } break; } } } else { Rectangle s = screens[draggingScreen].bounds; float pc = RectangleUtil.PcInside(p, s); if (pc < 0.6f) { draggingScreen = -1; } } p = new Rectangle(mousePos.X + draggingOffset.X, mousePos.Y + draggingOffset.Y, p.Width, p.Height); players[draggingIndex].editBounds = p; Invalidate(); } }
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 = config.Players; 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 PositionsForm() { config = new GameConfig();//testcode InitializeComponent(); playerFont = new Font("Segoe UI", 40); playerTextFont = new Font("Segoe UI", 18); RemoveFlicker(); float playersWidth = this.Width * 0.5f; int playerCount = 4; 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; config.Players.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)); } }