fullscreen support + several window handling functions
This commit is contained in:
parent
106471a126
commit
f6db65f213
33
window.go
33
window.go
|
@ -24,6 +24,9 @@ type WindowConfig struct {
|
||||||
// Height of a window in pixels.
|
// Height of a window in pixels.
|
||||||
Height float64
|
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.
|
// Whether a window is resizable.
|
||||||
Resizable bool
|
Resizable bool
|
||||||
|
|
||||||
|
@ -77,11 +80,19 @@ func NewWindow(config WindowConfig) (*Window, error) {
|
||||||
glfw.WindowHint(glfw.Maximized, bool2int[config.Maximized])
|
glfw.WindowHint(glfw.Maximized, bool2int[config.Maximized])
|
||||||
glfw.WindowHint(glfw.Samples, config.MSAASamples)
|
glfw.WindowHint(glfw.Samples, config.MSAASamples)
|
||||||
|
|
||||||
var err error
|
var (
|
||||||
w.window, err = glfw.CreateWindow(int(config.Width), int(config.Height), config.Title, nil, nil)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -91,6 +102,15 @@ func NewWindow(config WindowConfig) (*Window, error) {
|
||||||
return w, nil
|
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.
|
// Clear clears the window with a color.
|
||||||
func (w *Window) Clear(c color.Color) {
|
func (w *Window) Clear(c color.Color) {
|
||||||
w.Begin()
|
w.Begin()
|
||||||
|
@ -111,6 +131,15 @@ func (w *Window) Update() {
|
||||||
w.End()
|
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 {
|
var currentWindow struct {
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
handler *Window
|
handler *Window
|
||||||
|
|
Loading…
Reference in New Issue