42 lines
848 B
Go
42 lines
848 B
Go
package stone
|
|
|
|
import "image"
|
|
import "errors"
|
|
|
|
type Backend interface {
|
|
Run ()
|
|
SetTitle (title string) (err error)
|
|
SetIcon (icons []image.Image) (err error)
|
|
Draw ()
|
|
}
|
|
|
|
type BackendFactory func (
|
|
application *Application,
|
|
callbackManager *CallbackManager,
|
|
) (
|
|
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, &application.callbackManager)
|
|
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
|
|
}
|