remove pixegl.Do from monitor stuff (unnecessary)

This commit is contained in:
faiface 2016-11-24 22:01:37 +01:00
parent f6db65f213
commit a1325c8a83
1 changed files with 29 additions and 52 deletions

View File

@ -1,9 +1,6 @@
package pixel package pixel
import ( import "github.com/go-gl/glfw/v3.2/glfw"
"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 {
@ -12,81 +9,61 @@ 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 {
m := &Monitor{} return &Monitor{
pixelgl.Do(func() { monitor: glfw.GetPrimaryMonitor(),
m.monitor = glfw.GetPrimaryMonitor() }
})
return m
} }
// Monitors returns a slice of all currently attached monitors. // Monitors returns a slice of all currently attached 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 {
return pixelgl.DoVal(func() interface{} { return m.monitor.GetName()
return m.monitor.GetName()
}).(string)
} }
// PhysicalSize returns the size of the display are of a monitor in millimeters. // PhysicalSize returns the size of the display are of a monitor in millimeters.
func (m *Monitor) PhysicalSize() (width, height float64) { func (m *Monitor) PhysicalSize() (width, height float64) {
var w, h float64 wi, hi := m.monitor.GetPhysicalSize()
pixelgl.Do(func() { width = float64(wi)
wi, hi := m.monitor.GetPhysicalSize() height = float64(hi)
w = float64(wi) return
h = float64(hi)
})
return w, h
} }
// 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) {
pixelgl.Do(func() { xi, yi := m.monitor.GetPos()
xi, yi := m.monitor.GetPos() x = float64(xi)
x = float64(xi) y = float64(yi)
y = float64(yi) return
})
return x, y
} }
// 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) {
var w, h float64 mode := m.monitor.GetVideoMode()
pixelgl.Do(func() { width = float64(mode.Width)
mode := m.monitor.GetVideoMode() height = float64(mode.Height)
w = float64(mode.Width) return
h = float64(mode.Height)
})
return w, h
} }
// 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) {
var r, g, b int mode := m.monitor.GetVideoMode()
pixelgl.Do(func() { red = mode.RedBits
mode := m.monitor.GetVideoMode() green = mode.GreenBits
r = mode.RedBits blue = mode.BlueBits
g = mode.GreenBits return
b = mode.BlueBits
})
return r, g, b
} }
// 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() float64 { func (m *Monitor) RefreshRate() (rate float64) {
var rate float64 mode := m.monitor.GetVideoMode()
pixelgl.Do(func() { rate = float64(mode.RefreshRate)
mode := m.monitor.GetVideoMode() return
rate = float64(mode.RefreshRate)
})
return rate
} }