Newer
Older
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package pixel
import (
"github.com/faiface/pixel/pixelgl"
"github.com/go-gl/glfw/v3.2/glfw"
)
// Monitor represents a physical display attached to your computer.
type Monitor struct {
monitor *glfw.Monitor
}
// PrimaryMonitor returns the main monitor (usually the one with the taskbar and stuff).
func PrimaryMonitor() Monitor {
m := Monitor{}
pixelgl.Do(func() {
m.monitor = glfw.GetPrimaryMonitor()
})
return m
}
// Monitors returns a slice of all currently attached monitors.
func Monitors() []Monitor {
var monitors []Monitor
pixelgl.Do(func() {
for _, monitor := range glfw.GetMonitors() {
monitors = append(monitors, Monitor{monitor: monitor})
}
})
return monitors
}
// Name returns a human-readable name of a monitor.
func (m Monitor) Name() string {
return pixelgl.DoVal(func() interface{} {
return m.monitor.GetName()
}).(string)
}
// PhysicalSize returns the size of the display are of a monitor in millimeters.
func (m Monitor) PhysicalSize() (width, height float64) {
var w, h float64
pixelgl.Do(func() {
wi, hi := m.monitor.GetPhysicalSize()
w = float64(wi)
h = float64(hi)
})
return w, h
}
// Position returns the position of the upper-left corner of a monitor in screen coordinates.
func (m Monitor) Position() (x, y float64) {
pixelgl.Do(func() {
xi, yi := m.monitor.GetPos()
x = float64(xi)
y = float64(yi)
})
return x, y
}
// Size returns the resolution of a monitor in pixels.
func (m Monitor) Size() (width, height float64) {
var w, h float64
pixelgl.Do(func() {
mode := m.monitor.GetVideoMode()
w = float64(mode.Width)
h = float64(mode.Height)
})
return w, h
}
// BitDepth returns the number of bits per color of a monitor.
func (m Monitor) BitDepth() (red, green, blue int) {
var r, g, b int
pixelgl.Do(func() {
mode := m.monitor.GetVideoMode()
r = mode.RedBits
g = mode.GreenBits
b = mode.BlueBits
})
return r, g, b
}
// RefreshRate returns the refresh frequency of a monitor in Hz (refreshes/second).
func (m Monitor) RefreshRate() float64 {
var rate float64
pixelgl.Do(func() {
mode := m.monitor.GetVideoMode()
rate = float64(mode.RefreshRate)
})
return rate
}