remove unnecessary window.Do from window methods

This commit is contained in:
faiface 2016-12-16 20:27:40 +01:00
parent 1ee93eecb0
commit ddfede847e
1 changed files with 48 additions and 76 deletions

124
window.go
View File

@ -126,10 +126,8 @@ func NewWindow(config WindowConfig) (*Window, error) {
// Delete destroys a window. The window can't be used any further. // Delete destroys a window. The window can't be used any further.
func (w *Window) Delete() { func (w *Window) Delete() {
w.Do(func(pixelgl.Context) { pixelgl.Do(func() {
pixelgl.Do(func() { w.window.Destroy()
w.window.Destroy()
})
}) })
} }
@ -161,50 +159,40 @@ func (w *Window) Update() {
// SetTitle changes the title of a window. // SetTitle changes the title of a window.
func (w *Window) SetTitle(title string) { func (w *Window) SetTitle(title string) {
w.Do(func(pixelgl.Context) { pixelgl.Do(func() {
pixelgl.Do(func() { w.window.SetTitle(title)
w.window.SetTitle(title)
})
}) })
} }
// SetSize resizes a window to the specified size in pixels. // SetSize resizes a window to the specified size in pixels.
// In case of a fullscreen window, it changes the resolution of that window. // In case of a fullscreen window, it changes the resolution of that window.
func (w *Window) SetSize(width, height float64) { func (w *Window) SetSize(width, height float64) {
w.Do(func(pixelgl.Context) { pixelgl.Do(func() {
pixelgl.Do(func() { w.window.SetSize(int(width), int(height))
w.window.SetSize(int(width), int(height))
})
}) })
} }
// Size returns the size of the client area of a window (the part you can draw on). // Size returns the size of the client area of a window (the part you can draw on).
func (w *Window) Size() (width, height float64) { func (w *Window) Size() (width, height float64) {
w.Do(func(pixelgl.Context) { pixelgl.Do(func() {
pixelgl.Do(func() { wi, hi := w.window.GetSize()
wi, hi := w.window.GetSize() width = float64(wi)
width = float64(wi) height = float64(hi)
height = float64(hi)
})
}) })
return width, height return width, height
} }
// Show makes a window visible if it was hidden. // Show makes a window visible if it was hidden.
func (w *Window) Show() { func (w *Window) Show() {
w.Do(func(pixelgl.Context) { pixelgl.Do(func() {
pixelgl.Do(func() { w.window.Show()
w.window.Show()
})
}) })
} }
// Hide hides a window if it was visible. // Hide hides a window if it was visible.
func (w *Window) Hide() { func (w *Window) Hide() {
w.Do(func(pixelgl.Context) { pixelgl.Do(func() {
pixelgl.Do(func() { w.window.Hide()
w.window.Hide()
})
}) })
} }
@ -215,35 +203,31 @@ func (w *Window) Hide() {
func (w *Window) SetFullscreen(monitor *Monitor) { func (w *Window) SetFullscreen(monitor *Monitor) {
if w.Monitor() != monitor { if w.Monitor() != monitor {
if monitor == nil { if monitor == nil {
w.Do(func(pixelgl.Context) { pixelgl.Do(func() {
pixelgl.Do(func() { w.window.SetMonitor(
w.window.SetMonitor( nil,
nil, w.restore.xpos,
w.restore.xpos, w.restore.ypos,
w.restore.ypos, w.restore.width,
w.restore.width, w.restore.height,
w.restore.height, 0,
0, )
)
})
}) })
} else { } else {
w.Do(func(pixelgl.Context) { pixelgl.Do(func() {
pixelgl.Do(func() { w.restore.xpos, w.restore.ypos = w.window.GetPos()
w.restore.xpos, w.restore.ypos = w.window.GetPos() w.restore.width, w.restore.height = w.window.GetSize()
w.restore.width, w.restore.height = w.window.GetSize()
width, height := monitor.Size() width, height := monitor.Size()
refreshRate := monitor.RefreshRate() refreshRate := monitor.RefreshRate()
w.window.SetMonitor( w.window.SetMonitor(
monitor.monitor, monitor.monitor,
0, 0,
0, 0,
int(width), int(width),
int(height), int(height),
int(refreshRate), int(refreshRate),
) )
})
}) })
} }
} }
@ -256,12 +240,9 @@ func (w *Window) IsFullscreen() bool {
// Monitor returns a monitor a fullscreen window is on. If the window is not fullscreen, this function returns nil. // Monitor returns a monitor a fullscreen window is on. If the window is not fullscreen, this function returns nil.
func (w *Window) Monitor() *Monitor { func (w *Window) Monitor() *Monitor {
var monitor *glfw.Monitor monitor := pixelgl.DoVal(func() interface{} {
w.Do(func(pixelgl.Context) { return w.window.GetMonitor()
monitor = pixelgl.DoVal(func() interface{} { }).(*glfw.Monitor)
return w.window.GetMonitor()
}).(*glfw.Monitor)
})
if monitor == nil { if monitor == nil {
return nil return nil
} }
@ -272,39 +253,30 @@ func (w *Window) Monitor() *Monitor {
// Focus brings a window to the front and sets input focus. // Focus brings a window to the front and sets input focus.
func (w *Window) Focus() { func (w *Window) Focus() {
w.Do(func(pixelgl.Context) { pixelgl.Do(func() {
pixelgl.Do(func() { w.window.Focus()
w.window.Focus()
})
}) })
} }
// Focused returns true if a window has input focus. // Focused returns true if a window has input focus.
func (w *Window) Focused() bool { func (w *Window) Focused() bool {
var focused bool focused := pixelgl.DoVal(func() interface{} {
w.Do(func(pixelgl.Context) { return w.window.GetAttrib(glfw.Focused) == glfw.True
focused = pixelgl.DoVal(func() interface{} { }).(bool)
return w.window.GetAttrib(glfw.Focused) == glfw.True
}).(bool)
})
return focused return focused
} }
// Maximize puts a windowed window to a maximized state. // Maximize puts a windowed window to a maximized state.
func (w *Window) Maximize() { func (w *Window) Maximize() {
w.Do(func(pixelgl.Context) { pixelgl.Do(func() {
pixelgl.Do(func() { w.window.Maximize()
w.window.Maximize()
})
}) })
} }
// Restore restores a windowed window from a maximized state. // Restore restores a windowed window from a maximized state.
func (w *Window) Restore() { func (w *Window) Restore() {
w.Do(func(pixelgl.Context) { pixelgl.Do(func() {
pixelgl.Do(func() { w.window.Restore()
w.window.Restore()
})
}) })
} }