Terraria
v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
WindowStateController.cs
Go to the documentation of this file.
1
using
System.Drawing
;
2
using
System.Windows.Forms;
3
using
ReLogic.OS
;
4
5
namespace
Terraria.Graphics
;
6
7
public
class
WindowStateController
8
{
9
public
bool
CanMoveWindowAcrossScreens
=>
Platform
.
IsWindows
;
10
11
public
string
ScreenDeviceName
12
{
13
get
14
{
15
if
(!
Platform
.
IsWindows
)
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
59
private
bool
IsVisibleOnAnyScreen
(
Rectangle
rect)
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
}
ReLogic.OS.Platform.IsWindows
static bool IsWindows
Definition
Platform.cs:19
ReLogic.OS.Platform
Definition
Platform.cs:10
Terraria.Graphics.WindowStateController.TryMovingToScreen
void TryMovingToScreen(string screenDeviceName)
Definition
WindowStateController.cs:23
Terraria.Graphics.WindowStateController.IsVisibleOnAnyScreen
bool IsVisibleOnAnyScreen(Rectangle rect)
Definition
WindowStateController.cs:59
Terraria.Graphics.WindowStateController.CanMoveWindowAcrossScreens
bool CanMoveWindowAcrossScreens
Definition
WindowStateController.cs:9
Terraria.Graphics.WindowStateController.TryGetBounds
bool TryGetBounds(string screenDeviceName, out Rectangle bounds)
Definition
WindowStateController.cs:35
Terraria.Graphics.WindowStateController.ScreenDeviceName
string ScreenDeviceName
Definition
WindowStateController.cs:12
Terraria.Graphics.WindowStateController.WouldViewFitInScreen
bool WouldViewFitInScreen(Rectangle view, Rectangle screen)
Definition
WindowStateController.cs:50
Terraria.Graphics.WindowStateController
Definition
WindowStateController.cs:8
Terraria.Main.instance
static Main instance
Definition
Main.cs:283
Terraria.Main
Definition
Main.cs:79
ReLogic.OS
Definition
Clipboard.cs:3
System.Drawing.KnownColor.Control
@ Control
System.Drawing
Definition
ColorConverter.cs:8
Terraria.Graphics
Definition
CameraInfo.cs:3
System.Drawing.Point
Definition
Point.cs:11
System.Drawing.Rectangle.Width
int Width
Definition
Rectangle.cs:75
System.Drawing.Rectangle.Height
int Height
Definition
Rectangle.cs:87
System.Drawing.Rectangle
Definition
Rectangle.cs:11
source
Terraria.Graphics
WindowStateController.cs
Generated by
1.10.0