This repository has been archived on 2023-08-08. You can view files and clone it, but cannot push or open issues or pull requests.
tomo-old/elements/image.go
Sasha Koshka 437aef0c27 Redid the entity system a bit to make it more reliable
Now it supports things like parenting elements before they are
added to a window and elements no longer have to constantly check
for a nil entity
2023-04-15 01:14:36 -04:00

36 lines
1.0 KiB
Go

package elements
import "image"
import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/canvas"
import "git.tebibyte.media/sashakoshka/tomo/artist/patterns"
// TODO: this element is lame need to make it better
// Image is an element capable of displaying an image.
type Image struct {
entity tomo.Entity
buffer canvas.Canvas
}
// NewImage creates a new image element.
func NewImage (image image.Image) (element *Image) {
element = &Image { buffer: canvas.FromImage(image) }
element.entity = tomo.NewEntity(element)
bounds := element.buffer.Bounds()
element.entity.SetMinimumSize(bounds.Dx(), bounds.Dy())
return
}
// Entity returns this element's entity.
func (element *Image) Entity () tomo.Entity {
return element.entity
}
// Draw causes the element to draw to the specified destination canvas.
func (element *Image) Draw (destination canvas.Canvas) {
if element.entity == nil { return }
(patterns.Texture { Canvas: element.buffer }).
Draw(destination, element.entity.Bounds())
}