Files
ordoor/internal/ui/window.go

48 lines
955 B
Go
Raw Normal View History

package ui
import (
"flag"
"github.com/faiface/pixel"
"github.com/faiface/pixel/pixelgl"
)
var (
winX = flag.Int("win-x", 1280, "width of the view-map window")
winY = flag.Int("win-y", 1024, "height of the view-map window")
)
type Window struct {
PixelWindow *pixelgl.Window
ButtonEventHandlers map[pixelgl.Button][]func()
}
// WARE! 0,0 is the *bottom left* of the window
//
// To invert things so 0,0 is the *top left*, apply the InvertY` matrix
func NewWindow(title string) (*Window, error) {
cfg := pixelgl.WindowConfig{
2018-12-30 23:19:21 +00:00
Title: title,
Bounds: pixel.R(0, 0, float64(*winX), float64(*winY)),
VSync: true,
Resizable: true,
}
pixelWindow, err := pixelgl.NewWindow(cfg)
if err != nil {
return nil, err
}
return &Window{
PixelWindow: pixelWindow,
}, nil
}
// TODO: a stop or other cancellation mechanism
func (w *Window) Run(f func()) {
for !w.PixelWindow.Closed() {
f()
w.PixelWindow.Update()
}
}