Added a texture interface

This commit is contained in:
Sasha Koshka 2023-08-20 17:54:06 -04:00
parent dc377c36a5
commit 35c6e167be
4 changed files with 27 additions and 0 deletions

View File

@ -16,6 +16,10 @@ type Backend interface {
NewCanvasBox () CanvasBox
NewContainerBox () ContainerBox
// NewTexture creates a new texture from an image. The backend must
// reject any texture that was not made by it.
NewTexture (image.Image) Texture
// Run runs the event loop until Stop() is called, or the backend
// experiences a fatal error.
Run () error

View File

@ -238,6 +238,8 @@ type TextBox interface {
// SetSelectable sets whether or not the text content can be
// highlighted/selected.
SetSelectable (bool)
// SetDotColor sets the highlight color of the text selection.
SetDotColor (color.Color)
// Select sets the text cursor or selection.
Select (text.Dot)
// Dot returns the text cursor or selection.

14
texture.go Normal file
View File

@ -0,0 +1,14 @@
package tomo
import "io"
import "image"
// Texture is a handle that points to a 2D raster image managed by the backend.
type Texture interface {
io.Closer
// Clip returns a smaller section of this texture, pointing to the same
// internal data. Becaue of this, closing a clipped section will close
// the original texture as well.
Clip (image.Rectangle) Texture
}

View File

@ -79,3 +79,10 @@ func NewContainerBox () ContainerBox {
assertBackend()
return backend.NewContainerBox()
}
// NewTexture creates a new texture from an image. When no longer in use, it
// must be freed using Close().
func NewTexture (source image.Image) Texture {
assertBackend()
return backend.NewTexture(source)
}