remove unnecessary window.Do from window methods
This commit is contained in:
parent
1ee93eecb0
commit
ddfede847e
32
window.go
32
window.go
|
@ -126,11 +126,9 @@ 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()
|
||||||
})
|
})
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear clears the window with a color.
|
// Clear clears the window with a color.
|
||||||
|
@ -161,51 +159,41 @@ 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()
|
||||||
})
|
})
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetFullscreen sets a window fullscreen on a given monitor. If the monitor is nil, the window will be resored to windowed instead.
|
// SetFullscreen sets a window fullscreen on a given monitor. If the monitor is nil, the window will be resored to windowed instead.
|
||||||
|
@ -215,7 +203,6 @@ 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,
|
||||||
|
@ -226,9 +213,7 @@ func (w *Window) SetFullscreen(monitor *Monitor) {
|
||||||
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()
|
||||||
|
@ -244,7 +229,6 @@ func (w *Window) SetFullscreen(monitor *Monitor) {
|
||||||
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) {
|
|
||||||
monitor = pixelgl.DoVal(func() interface{} {
|
|
||||||
return w.window.GetMonitor()
|
return w.window.GetMonitor()
|
||||||
}).(*glfw.Monitor)
|
}).(*glfw.Monitor)
|
||||||
})
|
|
||||||
if monitor == nil {
|
if monitor == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -272,40 +253,31 @@ 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) {
|
|
||||||
focused = pixelgl.DoVal(func() interface{} {
|
|
||||||
return w.window.GetAttrib(glfw.Focused) == glfw.True
|
return w.window.GetAttrib(glfw.Focused) == glfw.True
|
||||||
}).(bool)
|
}).(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()
|
||||||
})
|
})
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentWindow struct {
|
var currentWindow struct {
|
||||||
|
|
Loading…
Reference in New Issue