2020-05-12 20:46:58 +00:00
|
|
|
package ui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"opslag.de/schobers/geom"
|
|
|
|
)
|
|
|
|
|
2020-05-17 06:29:02 +00:00
|
|
|
// RendererFactory can be used to inject a new factory for creating renderers.
|
2020-05-12 20:46:58 +00:00
|
|
|
type RendererFactory interface {
|
2020-05-17 06:29:02 +00:00
|
|
|
New(title string, width, height int, opts NewRendererOptions) (Renderer, error)
|
2020-05-12 20:46:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var rendererFactory RendererFactory
|
|
|
|
|
2020-05-17 06:29:02 +00:00
|
|
|
// NewRenderer creates a new renderer based on the registered renderer factory.
|
|
|
|
func NewRenderer(title string, width, height int, opts NewRendererOptions) (Renderer, error) {
|
2020-05-12 20:46:58 +00:00
|
|
|
if rendererFactory == nil {
|
|
|
|
return nil, errors.New("no renderer factory registered")
|
|
|
|
}
|
2020-05-25 20:24:06 +00:00
|
|
|
renderer, err := rendererFactory.New(title, width, height, opts)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-07-07 16:19:34 +00:00
|
|
|
renderer.SetResourceProvider(DefaultResources())
|
2020-05-25 20:24:06 +00:00
|
|
|
return renderer, nil
|
2020-05-17 06:29:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewRendererDefault creates a new renderer with default options set based on the registered renderer factory.
|
|
|
|
func NewRendererDefault(title string, width, height int) (Renderer, error) {
|
2020-05-25 20:24:06 +00:00
|
|
|
return NewRenderer(title, width, height, NewRendererOptions{
|
2020-05-17 06:29:02 +00:00
|
|
|
Resizable: true,
|
|
|
|
})
|
2020-05-12 20:46:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetRendererFactory sets the new factory that is used to create a new renderer.
|
|
|
|
func SetRendererFactory(factory RendererFactory) {
|
|
|
|
rendererFactory = factory
|
|
|
|
}
|
|
|
|
|
2020-05-17 06:29:02 +00:00
|
|
|
// NewRendererOptions provides options when creating a new renderer.
|
2020-05-12 20:46:58 +00:00
|
|
|
type NewRendererOptions struct {
|
2022-05-01 10:40:09 +00:00
|
|
|
Location *geom.PointF32
|
|
|
|
Borderless bool
|
|
|
|
Resizable bool
|
|
|
|
VSync bool
|
2020-05-12 20:46:58 +00:00
|
|
|
}
|