diff --git a/ui/images.go b/ui/images.go index ddd8317..4bf0575 100644 --- a/ui/images.go +++ b/ui/images.go @@ -1,10 +1,14 @@ package ui import ( + "image" + "github.com/nfnt/resize" "opslag.de/schobers/geom" ) +type CreateImageFn func() (image.Image, error) + func ScaleImage(render Renderer, im Image, scale float32) Image { w := uint(im.Width() * scale) if w == 0 { @@ -36,6 +40,23 @@ func (i *Images) AddImage(name string, im Image) { i.ims[name] = im } +func (i *Images) AddImageFn(name string, create CreateImageFn) error { + im, err := create() + if err != nil { + return err + } + return i.AddImageNative(name, im) +} + +func (i *Images) AddImageNative(name string, im image.Image) error { + m, err := i.render.CreateImage(im) + if err != nil { + return err + } + i.AddImage(name, m) + return nil +} + func (i *Images) Destroy() { for _, im := range i.ims { im.Destroy()