go-opengl-pixel/monitor.go

93 lines
2.3 KiB
Go
Raw Normal View History

2016-11-24 10:19:43 -06:00
package pixel
2016-12-15 18:11:00 -06:00
import (
"github.com/faiface/pixel/pixelgl"
"github.com/go-gl/glfw/v3.2/glfw"
)
2016-11-24 10:19:43 -06:00
// 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).
2016-11-24 10:21:35 -06:00
func PrimaryMonitor() *Monitor {
2016-12-15 18:11:00 -06:00
monitor := pixelgl.DoVal(func() interface{} {
return glfw.GetPrimaryMonitor()
}).(*glfw.Monitor)
return &Monitor{
2016-12-15 18:11:00 -06:00
monitor: monitor,
}
2016-11-24 10:19:43 -06:00
}
2016-12-01 18:02:57 -06:00
// Monitors returns a slice of all currently available monitors.
2016-11-24 10:21:35 -06:00
func Monitors() []*Monitor {
var monitors []*Monitor
2016-12-15 18:11:00 -06:00
pixelgl.Do(func() {
for _, monitor := range glfw.GetMonitors() {
monitors = append(monitors, &Monitor{monitor: monitor})
}
})
2016-11-24 10:19:43 -06:00
return monitors
}
// Name returns a human-readable name of a monitor.
2016-11-24 10:21:35 -06:00
func (m *Monitor) Name() string {
2016-12-15 18:11:00 -06:00
name := pixelgl.DoVal(func() interface{} {
return m.monitor.GetName()
}).(string)
return name
2016-11-24 10:19:43 -06:00
}
2016-12-01 18:50:31 -06:00
// PhysicalSize returns the size of the display area of a monitor in millimeters.
2016-11-24 10:21:35 -06:00
func (m *Monitor) PhysicalSize() (width, height float64) {
2016-12-15 18:11:00 -06:00
var wi, hi int
pixelgl.Do(func() {
wi, hi = m.monitor.GetPhysicalSize()
})
width = float64(wi)
height = float64(hi)
return
2016-11-24 10:19:43 -06:00
}
// Position returns the position of the upper-left corner of a monitor in screen coordinates.
2016-11-24 10:21:35 -06:00
func (m *Monitor) Position() (x, y float64) {
2016-12-15 18:11:00 -06:00
var xi, yi int
pixelgl.Do(func() {
xi, yi = m.monitor.GetPos()
})
x = float64(xi)
y = float64(yi)
return
2016-11-24 10:19:43 -06:00
}
// Size returns the resolution of a monitor in pixels.
2016-11-24 10:21:35 -06:00
func (m *Monitor) Size() (width, height float64) {
2016-12-15 18:11:00 -06:00
mode := pixelgl.DoVal(func() interface{} {
return m.monitor.GetVideoMode()
}).(*glfw.VidMode)
width = float64(mode.Width)
height = float64(mode.Height)
return
2016-11-24 10:19:43 -06:00
}
// BitDepth returns the number of bits per color of a monitor.
2016-11-24 10:21:35 -06:00
func (m *Monitor) BitDepth() (red, green, blue int) {
2016-12-15 18:11:00 -06:00
mode := pixelgl.DoVal(func() interface{} {
return m.monitor.GetVideoMode()
}).(*glfw.VidMode)
red = mode.RedBits
green = mode.GreenBits
blue = mode.BlueBits
return
2016-11-24 10:19:43 -06:00
}
// RefreshRate returns the refresh frequency of a monitor in Hz (refreshes/second).
func (m *Monitor) RefreshRate() (rate float64) {
2016-12-15 18:11:00 -06:00
mode := pixelgl.DoVal(func() interface{} {
return m.monitor.GetVideoMode()
}).(*glfw.VidMode)
rate = float64(mode.RefreshRate)
return
2016-11-24 10:19:43 -06:00
}