stop using mainthread.CallVal

This commit is contained in:
faiface 2017-02-24 15:45:32 +01:00
parent 812df66d62
commit 67529bf8fc
1 changed files with 20 additions and 15 deletions

View File

@ -12,9 +12,10 @@ 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 := mainthread.CallVal(func() interface{} { var monitor *glfw.Monitor
return glfw.GetPrimaryMonitor() mainthread.Call(func() {
}).(*glfw.Monitor) monitor = glfw.GetPrimaryMonitor()
})
return &Monitor{ return &Monitor{
monitor: monitor, monitor: monitor,
} }
@ -33,9 +34,10 @@ func Monitors() []*Monitor {
// Name returns a human-readable name of the Monitor. // Name returns a human-readable name of the Monitor.
func (m *Monitor) Name() string { func (m *Monitor) Name() string {
name := mainthread.CallVal(func() interface{} { var name string
return m.monitor.GetName() mainthread.Call(func() {
}).(string) name = m.monitor.GetName()
})
return name return name
} }
@ -63,9 +65,10 @@ func (m *Monitor) Position() (x, y float64) {
// Size returns the resolution of the Monitor in pixels. // Size returns the resolution of the Monitor in pixels.
func (m *Monitor) Size() (width, height float64) { func (m *Monitor) Size() (width, height float64) {
mode := mainthread.CallVal(func() interface{} { var mode *glfw.VidMode
return m.monitor.GetVideoMode() mainthread.Call(func() {
}).(*glfw.VidMode) mode = m.monitor.GetVideoMode()
})
width = float64(mode.Width) width = float64(mode.Width)
height = float64(mode.Height) height = float64(mode.Height)
return return
@ -73,9 +76,10 @@ func (m *Monitor) Size() (width, height float64) {
// BitDepth returns the number of bits per color of the Monitor. // BitDepth returns the number of bits per color of the Monitor.
func (m *Monitor) BitDepth() (red, green, blue int) { func (m *Monitor) BitDepth() (red, green, blue int) {
mode := mainthread.CallVal(func() interface{} { var mode *glfw.VidMode
return m.monitor.GetVideoMode() mainthread.Call(func() {
}).(*glfw.VidMode) mode = m.monitor.GetVideoMode()
})
red = mode.RedBits red = mode.RedBits
green = mode.GreenBits green = mode.GreenBits
blue = mode.BlueBits blue = mode.BlueBits
@ -84,9 +88,10 @@ func (m *Monitor) BitDepth() (red, green, blue int) {
// RefreshRate returns the refresh frequency of the Monitor in Hz (refreshes/second). // RefreshRate returns the refresh frequency of the Monitor in Hz (refreshes/second).
func (m *Monitor) RefreshRate() (rate float64) { func (m *Monitor) RefreshRate() (rate float64) {
mode := mainthread.CallVal(func() interface{} { var mode *glfw.VidMode
return m.monitor.GetVideoMode() mainthread.Call(func() {
}).(*glfw.VidMode) mode = m.monitor.GetVideoMode()
})
rate = float64(mode.RefreshRate) rate = float64(mode.RefreshRate)
return return
} }