zntg/ui/context.go
2018-09-22 16:31:09 +02:00

73 lines
1.1 KiB
Go

package ui
import "opslag.de/schobers/zntg/allg5"
type Context interface {
Display() *allg5.Display
Fonts() Fonts
Palette() Palette
Debug() Debug
}
type Debug interface {
IsEnabled() bool
Rainbow() allg5.Color
}
var _ Context = &context{}
type context struct {
disp *allg5.Display
fts Fonts
pal Palette
dbg *debug
}
type debug struct {
enbl bool
rainb []allg5.Color
col int
}
func rainbow() []allg5.Color {
var colors = make([]allg5.Color, len(Colors500))
for i, c := range Colors500 {
colors[i] = NewColorAlpha(c, 0x7f)
}
return colors
}
func newContext(disp *allg5.Display, f Fonts) *context {
return &context{disp, f, DefaultPalette(), &debug{rainb: rainbow()}}
}
func (c *context) Display() *allg5.Display {
return c.disp
}
func (c *context) Fonts() Fonts {
return c.fts
}
func (c *context) Palette() Palette {
return c.pal
}
func (c *context) Debug() Debug {
return c.dbg
}
func (d *debug) IsEnabled() bool {
return d.enbl
}
func (d *debug) resetRainbow() {
d.col = 0
}
func (d *debug) Rainbow() allg5.Color {
var col = d.col
d.col = (col + 1) % len(d.rainb)
return d.rainb[col]
}