Add the start of a view for objects in a set
This commit is contained in:
46
internal/ui/window.go
Normal file
46
internal/ui/window.go
Normal 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()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user