execute monitor stuff on main thread
This commit is contained in:
parent
2524fcc436
commit
8cd8d6d125
37
monitor.go
37
monitor.go
|
@ -1,6 +1,9 @@
|
||||||
package pixel
|
package pixel
|
||||||
|
|
||||||
import "github.com/go-gl/glfw/v3.2/glfw"
|
import (
|
||||||
|
"github.com/faiface/pixel/pixelgl"
|
||||||
|
"github.com/go-gl/glfw/v3.2/glfw"
|
||||||
|
)
|
||||||
|
|
||||||
// Monitor represents a physical display attached to your computer.
|
// Monitor represents a physical display attached to your computer.
|
||||||
type Monitor struct {
|
type Monitor struct {
|
||||||
|
@ -9,28 +12,39 @@ type Monitor struct {
|
||||||
|
|
||||||
// PrimaryMonitor returns the main monitor (usually the one with the taskbar and stuff).
|
// PrimaryMonitor returns the main monitor (usually the one with the taskbar and stuff).
|
||||||
func PrimaryMonitor() *Monitor {
|
func PrimaryMonitor() *Monitor {
|
||||||
|
monitor := pixelgl.DoVal(func() interface{} {
|
||||||
|
return glfw.GetPrimaryMonitor()
|
||||||
|
}).(*glfw.Monitor)
|
||||||
return &Monitor{
|
return &Monitor{
|
||||||
monitor: glfw.GetPrimaryMonitor(),
|
monitor: monitor,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Monitors returns a slice of all currently available monitors.
|
// Monitors returns a slice of all currently available monitors.
|
||||||
func Monitors() []*Monitor {
|
func Monitors() []*Monitor {
|
||||||
var monitors []*Monitor
|
var monitors []*Monitor
|
||||||
|
pixelgl.Do(func() {
|
||||||
for _, monitor := range glfw.GetMonitors() {
|
for _, monitor := range glfw.GetMonitors() {
|
||||||
monitors = append(monitors, &Monitor{monitor: monitor})
|
monitors = append(monitors, &Monitor{monitor: monitor})
|
||||||
}
|
}
|
||||||
|
})
|
||||||
return monitors
|
return monitors
|
||||||
}
|
}
|
||||||
|
|
||||||
// Name returns a human-readable name of a monitor.
|
// Name returns a human-readable name of a monitor.
|
||||||
func (m *Monitor) Name() string {
|
func (m *Monitor) Name() string {
|
||||||
|
name := pixelgl.DoVal(func() interface{} {
|
||||||
return m.monitor.GetName()
|
return m.monitor.GetName()
|
||||||
|
}).(string)
|
||||||
|
return name
|
||||||
}
|
}
|
||||||
|
|
||||||
// PhysicalSize returns the size of the display area of a monitor in millimeters.
|
// PhysicalSize returns the size of the display area of a monitor in millimeters.
|
||||||
func (m *Monitor) PhysicalSize() (width, height float64) {
|
func (m *Monitor) PhysicalSize() (width, height float64) {
|
||||||
wi, hi := m.monitor.GetPhysicalSize()
|
var wi, hi int
|
||||||
|
pixelgl.Do(func() {
|
||||||
|
wi, hi = m.monitor.GetPhysicalSize()
|
||||||
|
})
|
||||||
width = float64(wi)
|
width = float64(wi)
|
||||||
height = float64(hi)
|
height = float64(hi)
|
||||||
return
|
return
|
||||||
|
@ -38,7 +52,10 @@ func (m *Monitor) PhysicalSize() (width, height float64) {
|
||||||
|
|
||||||
// Position returns the position of the upper-left corner of a monitor in screen coordinates.
|
// Position returns the position of the upper-left corner of a monitor in screen coordinates.
|
||||||
func (m *Monitor) Position() (x, y float64) {
|
func (m *Monitor) Position() (x, y float64) {
|
||||||
xi, yi := m.monitor.GetPos()
|
var xi, yi int
|
||||||
|
pixelgl.Do(func() {
|
||||||
|
xi, yi = m.monitor.GetPos()
|
||||||
|
})
|
||||||
x = float64(xi)
|
x = float64(xi)
|
||||||
y = float64(yi)
|
y = float64(yi)
|
||||||
return
|
return
|
||||||
|
@ -46,7 +63,9 @@ func (m *Monitor) Position() (x, y float64) {
|
||||||
|
|
||||||
// Size returns the resolution of a monitor in pixels.
|
// Size returns the resolution of a monitor in pixels.
|
||||||
func (m *Monitor) Size() (width, height float64) {
|
func (m *Monitor) Size() (width, height float64) {
|
||||||
mode := m.monitor.GetVideoMode()
|
mode := pixelgl.DoVal(func() interface{} {
|
||||||
|
return m.monitor.GetVideoMode()
|
||||||
|
}).(*glfw.VidMode)
|
||||||
width = float64(mode.Width)
|
width = float64(mode.Width)
|
||||||
height = float64(mode.Height)
|
height = float64(mode.Height)
|
||||||
return
|
return
|
||||||
|
@ -54,7 +73,9 @@ func (m *Monitor) Size() (width, height float64) {
|
||||||
|
|
||||||
// BitDepth returns the number of bits per color of a monitor.
|
// BitDepth returns the number of bits per color of a monitor.
|
||||||
func (m *Monitor) BitDepth() (red, green, blue int) {
|
func (m *Monitor) BitDepth() (red, green, blue int) {
|
||||||
mode := m.monitor.GetVideoMode()
|
mode := pixelgl.DoVal(func() interface{} {
|
||||||
|
return m.monitor.GetVideoMode()
|
||||||
|
}).(*glfw.VidMode)
|
||||||
red = mode.RedBits
|
red = mode.RedBits
|
||||||
green = mode.GreenBits
|
green = mode.GreenBits
|
||||||
blue = mode.BlueBits
|
blue = mode.BlueBits
|
||||||
|
@ -63,7 +84,9 @@ func (m *Monitor) BitDepth() (red, green, blue int) {
|
||||||
|
|
||||||
// RefreshRate returns the refresh frequency of a monitor in Hz (refreshes/second).
|
// RefreshRate returns the refresh frequency of a monitor in Hz (refreshes/second).
|
||||||
func (m *Monitor) RefreshRate() (rate float64) {
|
func (m *Monitor) RefreshRate() (rate float64) {
|
||||||
mode := m.monitor.GetVideoMode()
|
mode := pixelgl.DoVal(func() interface{} {
|
||||||
|
return m.monitor.GetVideoMode()
|
||||||
|
}).(*glfw.VidMode)
|
||||||
rate = float64(mode.RefreshRate)
|
rate = float64(mode.RefreshRate)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue