2022-10-31 13:51:28 -06:00
|
|
|
package stone
|
|
|
|
|
2022-11-08 23:13:44 -07:00
|
|
|
import "image"
|
2022-10-31 13:51:28 -06:00
|
|
|
import "errors"
|
|
|
|
|
|
|
|
type Backend interface {
|
2022-11-09 13:52:49 -07:00
|
|
|
Run (channel chan(Event))
|
2022-11-10 00:02:08 -07:00
|
|
|
SetTitle (title string) (err error)
|
|
|
|
SetIcon (icons []image.Image) (err error)
|
2022-11-11 20:30:59 -07:00
|
|
|
Draw ()
|
2022-10-31 13:51:28 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
type BackendFactory func (application *Application) (backend Backend, err error)
|
|
|
|
|
|
|
|
var factories []BackendFactory
|
|
|
|
|
|
|
|
func RegisterBackend (factory BackendFactory) {
|
|
|
|
factories = append(factories, factory)
|
|
|
|
}
|
|
|
|
|
|
|
|
func instantiateBackend (application *Application) (backend Backend, err error) {
|
|
|
|
// find a suitable backend
|
|
|
|
for _, factory := range factories {
|
|
|
|
backend, err = factory(application)
|
|
|
|
if err == nil && backend != nil { return }
|
|
|
|
}
|
|
|
|
|
|
|
|
// if none were found, but there was no error produced, produce an
|
|
|
|
// error
|
|
|
|
if err == nil {
|
|
|
|
err = errors.New("no available backends")
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|