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

36 lines
1.0 KiB
Go
Raw Normal View History

2023-03-30 21:19:04 -06:00
package elements
2023-02-09 16:34:53 -07:00
import "image"
2023-04-14 20:03:22 -06:00
import "git.tebibyte.media/sashakoshka/tomo"
2023-02-26 20:20:17 -07:00
import "git.tebibyte.media/sashakoshka/tomo/canvas"
import "git.tebibyte.media/sashakoshka/tomo/artist/patterns"
2023-02-09 16:34:53 -07:00
2023-04-14 20:03:22 -06:00
// TODO: this element is lame need to make it better
// Image is an element capable of displaying an image.
2023-02-09 16:34:53 -07:00
type Image struct {
2023-04-14 20:03:22 -06:00
entity tomo.Entity
2023-02-26 20:20:17 -07:00
buffer canvas.Canvas
2023-02-09 16:34:53 -07:00
}
2023-04-14 20:03:22 -06:00
// NewImage creates a new image element.
2023-02-09 16:34:53 -07:00
func NewImage (image image.Image) (element *Image) {
2023-02-26 20:20:17 -07:00
element = &Image { buffer: canvas.FromImage(image) }
element.entity = tomo.NewEntity(element)
bounds := element.buffer.Bounds()
element.entity.SetMinimumSize(bounds.Dx(), bounds.Dy())
2023-02-09 16:34:53 -07:00
return
}
// Entity returns this element's entity.
func (element *Image) Entity () tomo.Entity {
return element.entity
2023-04-14 20:03:22 -06:00
}
// Draw causes the element to draw to the specified destination canvas.
func (element *Image) Draw (destination canvas.Canvas) {
if element.entity == nil { return }
2023-02-26 20:20:17 -07:00
(patterns.Texture { Canvas: element.buffer }).
2023-04-14 20:03:22 -06:00
Draw(destination, element.entity.Bounds())
2023-02-09 16:34:53 -07:00
}