Sander Schobers
cdfb863ab0
Added Action{,s}. List of actions that can be used to defer cleanup code (see NewRenderer implementations). Added TextInputEvent (replaces the old KeyPressEvent) and added to new events KeyDown & KeyUp. Added VSync to NewRendererOptions. Removed IconScale from button. Added ImageSource interface that replaces the Image/Texture method on the Texture interface. This makes converting back a texture to an image optional (since this is atypical for a hardware texture for instance). Added new KeyModifier: OSCommand (Windows/Command key). Added KeyState that can keep the state of keys (pressed or not). Added KeyEnter, representing the Enter key. Changed signatures of CreateTexture methods in Renderer. Changed signatures of icon related method (removed factories). Basic example now depends on sdlgui.
66 lines
1.1 KiB
Go
66 lines
1.1 KiB
Go
package sdlui
|
|
|
|
import (
|
|
"image"
|
|
"image/color"
|
|
|
|
"github.com/veandco/go-sdl2/sdl"
|
|
"opslag.de/schobers/geom"
|
|
"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{}
|
|
|
|
func (t *Texture) Height() float32 {
|
|
_, _, _, height, err := t.Texture.Query()
|
|
if err != nil {
|
|
return geom.NaN32()
|
|
}
|
|
return float32(height)
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
func (t *Texture) Width() float32 {
|
|
_, _, width, _, err := t.Texture.Query()
|
|
if err != nil {
|
|
return geom.NaN32()
|
|
}
|
|
return float32(width)
|
|
}
|
|
|
|
var _ ui.ImageSource = &TextureImageSource{}
|
|
|
|
type TextureImageSource struct {
|
|
*Texture
|
|
|
|
source ui.ImageSource
|
|
}
|
|
|
|
func (s TextureImageSource) CreateImage() (image.Image, error) {
|
|
return s.source.CreateImage()
|
|
}
|