2017-02-22 13:44:38 -06:00
|
|
|
package pixelgl
|
2016-11-24 10:19:43 -06:00
|
|
|
|
2016-12-15 18:11:00 -06:00
|
|
|
import (
|
2017-01-20 10:45:19 -06:00
|
|
|
"github.com/faiface/mainthread"
|
2016-12-15 18:11:00 -06:00
|
|
|
"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 {
|
2017-02-24 08:45:32 -06:00
|
|
|
var monitor *glfw.Monitor
|
|
|
|
mainthread.Call(func() {
|
|
|
|
monitor = glfw.GetPrimaryMonitor()
|
|
|
|
})
|
2016-11-24 15:01:37 -06:00
|
|
|
return &Monitor{
|
2016-12-15 18:11:00 -06:00
|
|
|
monitor: monitor,
|
2016-11-24 15:01:37 -06:00
|
|
|
}
|
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
|
2017-01-20 10:45:19 -06:00
|
|
|
mainthread.Call(func() {
|
2016-12-15 18:11:00 -06:00
|
|
|
for _, monitor := range glfw.GetMonitors() {
|
|
|
|
monitors = append(monitors, &Monitor{monitor: monitor})
|
|
|
|
}
|
|
|
|
})
|
2016-11-24 10:19:43 -06:00
|
|
|
return monitors
|
|
|
|
}
|
|
|
|
|
2017-01-25 11:55:17 -06:00
|
|
|
// Name returns a human-readable name of the Monitor.
|
2016-11-24 10:21:35 -06:00
|
|
|
func (m *Monitor) Name() string {
|
2017-02-24 08:45:32 -06:00
|
|
|
var name string
|
|
|
|
mainthread.Call(func() {
|
|
|
|
name = m.monitor.GetName()
|
|
|
|
})
|
2016-12-15 18:11:00 -06:00
|
|
|
return name
|
2016-11-24 10:19:43 -06:00
|
|
|
}
|
|
|
|
|
2017-01-25 11:55:17 -06:00
|
|
|
// PhysicalSize returns the size of the display area of the 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
|
2017-01-20 10:45:19 -06:00
|
|
|
mainthread.Call(func() {
|
2016-12-15 18:11:00 -06:00
|
|
|
wi, hi = m.monitor.GetPhysicalSize()
|
|
|
|
})
|
2016-11-24 15:01:37 -06:00
|
|
|
width = float64(wi)
|
|
|
|
height = float64(hi)
|
|
|
|
return
|
2016-11-24 10:19:43 -06:00
|
|
|
}
|
|
|
|
|
2017-01-25 11:55:17 -06:00
|
|
|
// Position returns the position of the upper-left corner of the 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
|
2017-01-20 10:45:19 -06:00
|
|
|
mainthread.Call(func() {
|
2016-12-15 18:11:00 -06:00
|
|
|
xi, yi = m.monitor.GetPos()
|
|
|
|
})
|
2016-11-24 15:01:37 -06:00
|
|
|
x = float64(xi)
|
|
|
|
y = float64(yi)
|
|
|
|
return
|
2016-11-24 10:19:43 -06:00
|
|
|
}
|
|
|
|
|
2017-01-25 11:55:17 -06:00
|
|
|
// Size returns the resolution of the Monitor in pixels.
|
2016-11-24 10:21:35 -06:00
|
|
|
func (m *Monitor) Size() (width, height float64) {
|
2017-02-24 08:45:32 -06:00
|
|
|
var mode *glfw.VidMode
|
|
|
|
mainthread.Call(func() {
|
|
|
|
mode = m.monitor.GetVideoMode()
|
|
|
|
})
|
2016-11-24 15:01:37 -06:00
|
|
|
width = float64(mode.Width)
|
|
|
|
height = float64(mode.Height)
|
|
|
|
return
|
2016-11-24 10:19:43 -06:00
|
|
|
}
|
|
|
|
|
2017-01-25 11:55:17 -06:00
|
|
|
// BitDepth returns the number of bits per color of the Monitor.
|
2016-11-24 10:21:35 -06:00
|
|
|
func (m *Monitor) BitDepth() (red, green, blue int) {
|
2017-02-24 08:45:32 -06:00
|
|
|
var mode *glfw.VidMode
|
|
|
|
mainthread.Call(func() {
|
|
|
|
mode = m.monitor.GetVideoMode()
|
|
|
|
})
|
2016-11-24 15:01:37 -06:00
|
|
|
red = mode.RedBits
|
|
|
|
green = mode.GreenBits
|
|
|
|
blue = mode.BlueBits
|
|
|
|
return
|
2016-11-24 10:19:43 -06:00
|
|
|
}
|
|
|
|
|
2017-01-25 11:55:17 -06:00
|
|
|
// RefreshRate returns the refresh frequency of the Monitor in Hz (refreshes/second).
|
2016-11-24 15:01:37 -06:00
|
|
|
func (m *Monitor) RefreshRate() (rate float64) {
|
2017-02-24 08:45:32 -06:00
|
|
|
var mode *glfw.VidMode
|
|
|
|
mainthread.Call(func() {
|
|
|
|
mode = m.monitor.GetVideoMode()
|
|
|
|
})
|
2016-11-24 15:01:37 -06:00
|
|
|
rate = float64(mode.RefreshRate)
|
|
|
|
return
|
2016-11-24 10:19:43 -06:00
|
|
|
}
|