Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
WindowStateController.cs
Go to the documentation of this file.
2using System.Windows.Forms;
3using ReLogic.OS;
4
5namespace Terraria.Graphics;
6
8{
10
11 public string ScreenDeviceName
12 {
13 get
14 {
16 {
17 return "";
18 }
19 return Main.instance.Window.ScreenDeviceName;
20 }
21 }
22
23 public void TryMovingToScreen(string screenDeviceName)
24 {
25 if (CanMoveWindowAcrossScreens && TryGetBounds(screenDeviceName, out var bounds) && IsVisibleOnAnyScreen(bounds))
26 {
27 Form form = (Form)Control.FromHandle(Main.instance.Window.Handle);
28 if (WouldViewFitInScreen(form.Bounds, bounds))
29 {
30 form.Location = new Point(bounds.Width / 2 - form.Width / 2 + bounds.X, bounds.Height / 2 - form.Height / 2 + bounds.Y);
31 }
32 }
33 }
34
35 private bool TryGetBounds(string screenDeviceName, out Rectangle bounds)
36 {
37 bounds = default(Rectangle);
38 Screen[] allScreens = Screen.AllScreens;
39 foreach (Screen screen in allScreens)
40 {
41 if (screen.DeviceName == screenDeviceName)
42 {
43 bounds = screen.Bounds;
44 return true;
45 }
46 }
47 return false;
48 }
49
50 private bool WouldViewFitInScreen(Rectangle view, Rectangle screen)
51 {
52 if (view.Width <= screen.Width)
53 {
54 return view.Height <= screen.Height;
55 }
56 return false;
57 }
58
60 {
61 Screen[] allScreens = Screen.AllScreens;
62 for (int i = 0; i < allScreens.Length; i++)
63 {
64 if (allScreens[i].WorkingArea.IntersectsWith(rect))
65 {
66 return true;
67 }
68 }
69 return false;
70 }
71}
static bool IsWindows
Definition Platform.cs:19
void TryMovingToScreen(string screenDeviceName)
bool TryGetBounds(string screenDeviceName, out Rectangle bounds)
bool WouldViewFitInScreen(Rectangle view, Rectangle screen)
static Main instance
Definition Main.cs:283