2020-05-15 07:20:44 +00:00
|
|
|
package sdlui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"image"
|
|
|
|
"image/color"
|
|
|
|
|
|
|
|
"github.com/veandco/go-sdl2/sdl"
|
|
|
|
"opslag.de/schobers/zntg/ui"
|
|
|
|
)
|
|
|
|
|
|
|
|
type sdlTexture interface {
|
|
|
|
Native() *sdl.Texture
|
|
|
|
SetColor(color.Color)
|
|
|
|
Size() (int32, int32, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
type Texture struct {
|
|
|
|
*sdl.Texture
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ ui.Texture = &Texture{}
|
|
|
|
|
2020-12-12 13:40:50 +00:00
|
|
|
func (t *Texture) Height() int {
|
2020-05-15 07:20:44 +00:00
|
|
|
_, _, _, height, err := t.Texture.Query()
|
|
|
|
if err != nil {
|
2020-12-12 13:40:50 +00:00
|
|
|
return -1
|
2020-05-15 07:20:44 +00:00
|
|
|
}
|
2020-12-12 13:40:50 +00:00
|
|
|
return int(height)
|
2020-05-15 07:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *Texture) Native() *sdl.Texture { return t.Texture }
|
|
|
|
|
|
|
|
func (t *Texture) SetColor(c color.Color) {
|
|
|
|
color := ColorSDL(c)
|
|
|
|
t.SetColorMod(color.R, color.G, color.B)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *Texture) Size() (int32, int32, error) {
|
|
|
|
_, _, width, height, err := t.Texture.Query()
|
|
|
|
if err != nil {
|
|
|
|
return 0, 0, err
|
|
|
|
}
|
|
|
|
return width, height, err
|
|
|
|
}
|
|
|
|
|
2020-12-12 13:40:50 +00:00
|
|
|
func (t *Texture) Width() int {
|
2020-05-15 07:20:44 +00:00
|
|
|
_, _, width, _, err := t.Texture.Query()
|
|
|
|
if err != nil {
|
2020-12-12 13:40:50 +00:00
|
|
|
return -1
|
2020-05-15 07:20:44 +00:00
|
|
|
}
|
2020-12-12 13:40:50 +00:00
|
|
|
return int(width)
|
2020-05-15 07:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ ui.ImageSource = &TextureImageSource{}
|
|
|
|
|
|
|
|
type TextureImageSource struct {
|
|
|
|
*Texture
|
|
|
|
|
|
|
|
source ui.ImageSource
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s TextureImageSource) CreateImage() (image.Image, error) {
|
|
|
|
return s.source.CreateImage()
|
|
|
|
}
|