Sander Schobers
3591e22c97
- Fonts are now managed by context instead of the implementation specific renderers.
76 lines
1.2 KiB
Go
76 lines
1.2 KiB
Go
package ui
|
|
|
|
type Context interface {
|
|
Animate()
|
|
Fonts() *Fonts
|
|
HasQuit() bool
|
|
Quit()
|
|
Renderer() Renderer
|
|
Style() *Style
|
|
Textures() *Textures
|
|
}
|
|
|
|
var _ Context = &context{}
|
|
var _ EventTarget = &context{}
|
|
|
|
type context struct {
|
|
animate bool
|
|
quit chan struct{}
|
|
renderer Renderer
|
|
view Control
|
|
fonts *Fonts
|
|
textures *Textures
|
|
style *Style
|
|
}
|
|
|
|
func newContext(r Renderer, s *Style, view Control) *context {
|
|
return &context{
|
|
quit: make(chan struct{}),
|
|
renderer: r,
|
|
style: s,
|
|
view: view,
|
|
fonts: NewFonts(r),
|
|
textures: NewTextures(r)}
|
|
}
|
|
|
|
func (c *context) Animate() { c.animate = true }
|
|
|
|
func (c *context) Destroy() {
|
|
c.fonts.Destroy()
|
|
c.textures.Destroy()
|
|
}
|
|
|
|
func (c *context) Fonts() *Fonts { return c.fonts }
|
|
|
|
func (c *context) HasQuit() bool {
|
|
select {
|
|
case <-c.quit:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
func (c *context) Renderer() Renderer { return c.renderer }
|
|
|
|
func (c *context) Style() *Style { return c.style }
|
|
|
|
func (c *context) Quit() {
|
|
if !c.HasQuit() {
|
|
close(c.quit)
|
|
}
|
|
}
|
|
|
|
func (c *context) Textures() *Textures { return c.textures }
|
|
|
|
// Handle implement EventTarget
|
|
|
|
func (c *context) Handle(e Event) {
|
|
switch e.(type) {
|
|
case *DisplayCloseEvent:
|
|
c.Quit()
|
|
return
|
|
}
|
|
c.view.Handle(c, e)
|
|
}
|