-
Notifications
You must be signed in to change notification settings - Fork 0
/
monitors.odin
47 lines (35 loc) · 1.01 KB
/
monitors.odin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
/*
Center the window on the center monitor.
Supports any amount of monitors.
### Usage
```odin
raylib.InitWindow(width, height, "My Window")
SetWindowToPrimaryMonitor()
```
*/
import "vendor:glfw"
import "vendor:raylib"
// Sets a raylib window to the primary monitor
SetWindowToPrimaryMonitor :: proc(setFps: bool = false) {
assert(raylib.GetMonitorCount() > 0, "Error: No monitors detected")
monitorIndex := GetPrimaryMonitor()
assert(monitorIndex >= 0, "Error: No primary monitor detected")
raylib.SetWindowMonitor(monitorIndex)
if setFps {raylib.SetTargetFPS(raylib.GetMonitorRefreshRate(monitorIndex))}
}
// Returns the index of the primary monitor
GetPrimaryMonitor :: proc() -> i32 {
primary := glfw.GetPrimaryMonitor()
name := glfw.GetMonitorName(primary)
for i in 0 ..< raylib.GetMonitorCount() {
if string(raylib.GetMonitorName(i)) == name {
return i
}
}
return -1
}
// SetWindowToCenterMonitor is a deprecated function
SetWindowToCenterMonitor :: proc() {
SetWindowToPrimaryMonitor()
}