fullscreen support + several window handling functions

This commit is contained in:
faiface 2016-11-24 17:24:38 +01:00
parent 106471a126
commit f6db65f213
1 changed files with 31 additions and 2 deletions

View File

@ -24,6 +24,9 @@ type WindowConfig struct {
// Height of a window in pixels.
Height float64
// If set to nil, a window will be windowed. Otherwise it will be fullscreen on the specified monitor.
Fullscreen *Monitor
// Whether a window is resizable.
Resizable bool
@ -77,11 +80,19 @@ func NewWindow(config WindowConfig) (*Window, error) {
glfw.WindowHint(glfw.Maximized, bool2int[config.Maximized])
glfw.WindowHint(glfw.Samples, config.MSAASamples)
var err error
w.window, err = glfw.CreateWindow(int(config.Width), int(config.Height), config.Title, nil, nil)
var (
err error
monitor *glfw.Monitor
)
if config.Fullscreen != nil {
monitor = config.Fullscreen.monitor
}
w.window, err = glfw.CreateWindow(int(config.Width), int(config.Height), config.Title, monitor, nil)
if err != nil {
return err
}
return nil
})
if err != nil {
@ -91,6 +102,15 @@ func NewWindow(config WindowConfig) (*Window, error) {
return w, nil
}
// Delete destroys a window. The window can't be used any further.
func (w *Window) Delete() {
w.Begin()
pixelgl.Do(func() {
w.window.Destroy()
})
w.End()
}
// Clear clears the window with a color.
func (w *Window) Clear(c color.Color) {
w.Begin()
@ -111,6 +131,15 @@ func (w *Window) Update() {
w.End()
}
// Focus brings a window to the front and sets input focus.
func (w *Window) Focus() {
w.Begin()
pixelgl.Do(func() {
w.window.Focus()
})
w.End()
}
var currentWindow struct {
sync.Mutex
handler *Window