47 lines
889 B
Go
47 lines
889 B
Go
package tins2020
|
|
|
|
import (
|
|
rice "github.com/GeertJohan/go.rice"
|
|
"github.com/veandco/go-sdl2/sdl"
|
|
)
|
|
|
|
type Context struct {
|
|
Renderer *sdl.Renderer
|
|
Fonts Fonts
|
|
Resources Resources
|
|
Textures Textures
|
|
Settings Settings
|
|
MousePosition Point
|
|
ShouldQuit bool
|
|
}
|
|
|
|
func NewContext(res *rice.Box) (*Context, error) {
|
|
ctx := &Context{}
|
|
err := ctx.Settings.Init()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
err = ctx.Resources.Open(res)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return ctx, nil
|
|
}
|
|
|
|
func (c *Context) Destroy() {
|
|
c.Fonts.Destroy()
|
|
c.Resources.Destroy()
|
|
c.Textures.Destroy()
|
|
c.Settings.Store()
|
|
}
|
|
|
|
func (c *Context) Init(renderer *sdl.Renderer) {
|
|
c.Renderer = renderer
|
|
c.Fonts.Init(c.Resources.Copy())
|
|
c.Textures.Init(renderer, c.Resources.Copy())
|
|
|
|
c.Renderer.SetDrawBlendMode(sdl.BLENDMODE_BLEND)
|
|
}
|
|
|
|
func (c *Context) Quit() { c.ShouldQuit = true }
|