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.
func (w *Window) Delete() {
w.Do(func(pixelgl.Context) {
pixelgl.Do(func() {
w.window.Destroy()
})
pixelgl.Do(func() {
w.window.Destroy()
})
}
@ -161,50 +159,40 @@ func (w *Window) Update() {
// SetTitle changes the title of a window.
func (w *Window) SetTitle(title string) {
w.Do(func(pixelgl.Context) {
pixelgl.Do(func() {
w.window.SetTitle(title)
})
pixelgl.Do(func() {
w.window.SetTitle(title)
})
}
// SetSize resizes a window to the specified size in pixels.
// In case of a fullscreen window, it changes the resolution of that window.
func (w *Window) SetSize(width, height float64) {
w.Do(func(pixelgl.Context) {
pixelgl.Do(func() {
w.window.SetSize(int(width), int(height))
})
pixelgl.Do(func() {
w.window.SetSize(int(width), int(height))
})
}
// Size returns the size of the client area of a window (the part you can draw on).
func (w *Window) Size() (width, height float64) {
w.Do(func(pixelgl.Context) {
pixelgl.Do(func() {
wi, hi := w.window.GetSize()
width = float64(wi)
height = float64(hi)
})
pixelgl.Do(func() {
wi, hi := w.window.GetSize()
width = float64(wi)
height = float64(hi)
})
return width, height
}
// Show makes a window visible if it was hidden.
func (w *Window) Show() {
w.Do(func(pixelgl.Context) {
pixelgl.Do(func() {
w.window.Show()
})
pixelgl.Do(func() {
w.window.Show()
})
}
// Hide hides a window if it was visible.
func (w *Window) Hide() {
w.Do(func(pixelgl.Context) {
pixelgl.Do(func() {
w.window.Hide()
})
pixelgl.Do(func() {
w.window.Hide()
})
}
@ -215,35 +203,31 @@ func (w *Window) Hide() {
func (w *Window) SetFullscreen(monitor *Monitor) {
if w.Monitor() != monitor {
if monitor == nil {
w.Do(func(pixelgl.Context) {
pixelgl.Do(func() {
w.window.SetMonitor(
nil,
w.restore.xpos,
w.restore.ypos,
w.restore.width,
w.restore.height,
0,
)
})
pixelgl.Do(func() {
w.window.SetMonitor(
nil,
w.restore.xpos,
w.restore.ypos,
w.restore.width,
w.restore.height,
0,
)
})
} else {
w.Do(func(pixelgl.Context) {
pixelgl.Do(func() {
w.restore.xpos, w.restore.ypos = w.window.GetPos()
w.restore.width, w.restore.height = w.window.GetSize()
pixelgl.Do(func() {
w.restore.xpos, w.restore.ypos = w.window.GetPos()
w.restore.width, w.restore.height = w.window.GetSize()
width, height := monitor.Size()
refreshRate := monitor.RefreshRate()
w.window.SetMonitor(
monitor.monitor,
0,
0,
int(width),
int(height),
int(refreshRate),
)
})
width, height := monitor.Size()
refreshRate := monitor.RefreshRate()
w.window.SetMonitor(
monitor.monitor,
0,
0,
int(width),
int(height),
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.
func (w *Window) Monitor() *Monitor {
var monitor *glfw.Monitor
w.Do(func(pixelgl.Context) {
monitor = pixelgl.DoVal(func() interface{} {
return w.window.GetMonitor()
}).(*glfw.Monitor)
})
monitor := pixelgl.DoVal(func() interface{} {
return w.window.GetMonitor()
}).(*glfw.Monitor)
if monitor == nil {
return nil
}
@ -272,39 +253,30 @@ func (w *Window) Monitor() *Monitor {
// Focus brings a window to the front and sets input focus.
func (w *Window) Focus() {
w.Do(func(pixelgl.Context) {
pixelgl.Do(func() {
w.window.Focus()
})
pixelgl.Do(func() {
w.window.Focus()
})
}
// Focused returns true if a window has input focus.
func (w *Window) Focused() bool {
var focused bool
w.Do(func(pixelgl.Context) {
focused = pixelgl.DoVal(func() interface{} {
return w.window.GetAttrib(glfw.Focused) == glfw.True
}).(bool)
})
focused := pixelgl.DoVal(func() interface{} {
return w.window.GetAttrib(glfw.Focused) == glfw.True
}).(bool)
return focused
}
// Maximize puts a windowed window to a maximized state.
func (w *Window) Maximize() {
w.Do(func(pixelgl.Context) {
pixelgl.Do(func() {
w.window.Maximize()
})
pixelgl.Do(func() {
w.window.Maximize()
})
}
// Restore restores a windowed window from a maximized state.
func (w *Window) Restore() {
w.Do(func(pixelgl.Context) {
pixelgl.Do(func() {
w.window.Restore()
})
pixelgl.Do(func() {
w.window.Restore()
})
}