Add the start of a view for objects in a set

This commit is contained in:
2018-03-18 20:41:17 +00:00
parent 257acd6127
commit 213b2d3eb1
5 changed files with 223 additions and 25 deletions

46
internal/ui/window.go Normal file
View File

@@ -0,0 +1,46 @@
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{
Title: title,
Bounds: pixel.R(0, 0, float64(*winX), float64(*winY)),
VSync: 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()
}
}