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(); } }
public static UserScreen[] AllScreens() { Screen[] all = Screen.AllScreens; //UserScreen[] rects = new UserScreen[all.Length]; Rectangle[] test = GetSetup_Triple4kHorizontal(); UserScreen[] rects = new UserScreen[test.Length]; for (int i = 0; i < rects.Length; i++) { UserScreen u = new UserScreen(); //u.monitorBounds = all[i].Bounds; u.monitorBounds = test[i]; u.bounds = u.monitorBounds; rects[i] = u; } return rects; }
protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); var players = config.Players; if (e.Button == MouseButtons.Left) { if (dragging) { } else { for (int i = 0; i < screens.Length; i++) { UserScreen screen = screens[i]; if (screen.swapTypeRect.Contains(e.Location)) { if (screen.type == UserScreenType.FourPlayers) { screen.type = 0; } else { screen.type++; } // invalidate all players inside screen for (int j = 0; j < players.Count; j++) { // return to default position PlayerInfo p = players[j]; if (p.screenIndex == i) { p.editBounds = getDefaultBounds(j); p.screenIndex = -1; } } Invalidate(); return; } } for (int i = 0; i < players.Count; i++) { Rectangle r = players[i].editBounds; if (r.Contains(e.Location)) { dragging = true; draggingIndex = i; draggingOffset = new Point(r.X - e.X, r.Y - e.Y); Rectangle newBounds = getDefaultBounds(draggingIndex); config.Players[draggingIndex].editBounds = newBounds; if (draggingOffset.X < -newBounds.Width || draggingOffset.Y < -newBounds.Height) { draggingOffset = new Point(0, 0); } break; } } } } else if (e.Button == MouseButtons.Right || e.Button == MouseButtons.Middle) { // if over a player on a screen, change the type for (int i = 0; i < players.Count; i++) { PlayerInfo p = players[i]; Rectangle r = p.editBounds; if (r.Contains(e.Location)) { if (p.screenIndex != -1) { UserScreen screen = screens[p.screenIndex]; int halfWidth = screen.monitorBounds.Width / 2; int halfHeight = screen.monitorBounds.Height / 2; Rectangle bounds = p.monitorBounds; if (screen.type == UserScreenType.FourPlayers) { // check if the size is 1/4th of screen if (bounds.Width == halfWidth && bounds.Height == halfHeight) { bool hasLeftRightSpace = true; bool hasTopBottomSpace = true; // check if we have something left/right or top/bottom for (int j = 0; j < players.Count; j++) { if (i == j) { continue; } PlayerInfo other = players[j]; if (other.screenIndex != p.screenIndex) { continue; } if (other.monitorBounds.Y == p.monitorBounds.Y) { hasLeftRightSpace = false; } if (other.monitorBounds.X == p.monitorBounds.X) { hasTopBottomSpace = false; } if (other.monitorBounds.X == screen.monitorBounds.X + halfWidth && other.monitorBounds.Height == screen.monitorBounds.Height) { hasLeftRightSpace = false; } if (other.monitorBounds.X == screen.monitorBounds.X && other.monitorBounds.Width == screen.monitorBounds.Width) { hasTopBottomSpace = false; } } if (hasLeftRightSpace) { Rectangle edit = p.editBounds; if (bounds.X == screen.monitorBounds.X + bounds.Width) { bounds.X -= bounds.Width; edit.X -= edit.Width; } bounds.Width *= 2; edit.Width *= 2; p.editBounds = edit; p.monitorBounds = bounds; Invalidate(); } else if (hasTopBottomSpace) { bounds.Height *= 2; p.monitorBounds = bounds; Rectangle edit = p.editBounds; edit.Height *= 2; p.editBounds = edit; Invalidate(); } } else { bounds.Width = screen.monitorBounds.Width / 2; bounds.Height = screen.monitorBounds.Height / 2; p.monitorBounds = bounds; Rectangle edit = p.editBounds; edit.Width = screen.bounds.Width / 2; edit.Height = screen.bounds.Height / 2; p.editBounds = edit; Invalidate(); } } } } } } }
private void GetFreeSpace(int screenIndex, out Rectangle?editorBounds, out Rectangle?monitorBounds) { editorBounds = null; monitorBounds = null; var players = config.Players; UserScreen screen = screens[screenIndex]; Rectangle bounds = screen.monitorBounds; Rectangle ebounds = screen.bounds; switch (screen.type) { case UserScreenType.FullScreen: for (int i = 0; i < players.Count; i++) { PlayerInfo p = players[i]; if (p.screenIndex == screenIndex) { return; } } monitorBounds = screen.monitorBounds; editorBounds = screen.bounds; break; case UserScreenType.DualHorizontal: { int playersUsing = 0; Rectangle areaUsed = new Rectangle(); for (int i = 0; i < players.Count; i++) { PlayerInfo p = players[i]; if (p.screenIndex == screenIndex) { playersUsing++; areaUsed = Rectangle.Union(areaUsed, p.monitorBounds); } } if (playersUsing == 2) { return; } int half = (int)(bounds.Height / 2.0f); for (int i = 0; i < 2; i++) { Rectangle area = new Rectangle(bounds.X, bounds.Y + (half * i), bounds.Width, half); if (!areaUsed.Contains(area)) { monitorBounds = area; int halfe = (int)(ebounds.Height / 2.0f); editorBounds = new Rectangle(ebounds.X, ebounds.Y + (halfe * i), ebounds.Width, halfe); return; } } } break; case UserScreenType.DualVertical: { int playersUsing = 0; Rectangle areaUsed = new Rectangle(); for (int i = 0; i < players.Count; i++) { PlayerInfo p = players[i]; if (p.screenIndex == screenIndex) { playersUsing++; areaUsed = Rectangle.Union(areaUsed, p.monitorBounds); } } if (playersUsing == 2) { return; } int half = (int)(bounds.Width / 2.0f); for (int i = 0; i < 2; i++) { Rectangle area = new Rectangle(bounds.X + (half * i), bounds.Y, half, bounds.Height); if (!areaUsed.Contains(area)) { monitorBounds = area; int halfe = (int)(ebounds.Width / 2.0f); editorBounds = new Rectangle(ebounds.X + (halfe * i), ebounds.Y, halfe, ebounds.Height); return; } } } break; case UserScreenType.FourPlayers: { int playersUsing = 0; Rectangle areaUsed = new Rectangle(); for (int i = 0; i < players.Count; i++) { PlayerInfo p = players[i]; if (p.screenIndex == screenIndex) { playersUsing++; areaUsed = Rectangle.Union(areaUsed, p.monitorBounds); } } if (playersUsing == 4) { return; } int halfw = (int)(bounds.Width / 2.0f); int halfh = (int)(bounds.Height / 2.0f); for (int x = 0; x < 2; x++) { for (int y = 0; y < 2; y++) { Rectangle area = new Rectangle(bounds.X + (halfw * x), bounds.Y + (halfh * y), halfw, halfh); bool goNext = false; // check if there's any player with the area's x,y coord for (int i = 0; i < players.Count; i++) { PlayerInfo p = players[i]; if (p.screenIndex == screenIndex) { if (p.monitorBounds.X == area.X && p.monitorBounds.Y == area.Y) { goNext = true; break; } } } if (goNext) { continue; } monitorBounds = area; int halfwe = (int)(ebounds.Width / 2.0f); int halfhe = (int)(ebounds.Height / 2.0f); editorBounds = new Rectangle(ebounds.X + (halfwe * x), ebounds.Y + (halfhe * y), halfwe, halfhe); return; } } } break; } }