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-31 03:19:04 +00:00
package elements
2023-02-09 23:34:53 +00:00
import "image"
2023-04-15 02:03:22 +00:00
import "git.tebibyte.media/sashakoshka/tomo"
2023-02-27 03:20:17 +00:00
import "git.tebibyte.media/sashakoshka/tomo/canvas"
import "git.tebibyte.media/sashakoshka/tomo/artist/patterns"
2023-02-09 23:34:53 +00:00
2023-04-15 02:03:22 +00:00
// TODO: this element is lame need to make it better
// Image is an element capable of displaying an image.
2023-02-09 23:34:53 +00:00
type Image struct {
2023-04-15 02:03:22 +00:00
entity tomo.Entity
2023-02-27 03:20:17 +00:00
buffer canvas.Canvas
2023-02-09 23:34:53 +00:00
}
2023-04-15 02:03:22 +00:00
// NewImage creates a new image element.
2023-02-09 23:34:53 +00:00
func NewImage (image image.Image) (element *Image) {
2023-02-27 03:20:17 +00: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 23:34:53 +00:00
return
}
// Entity returns this element's entity.
func (element *Image) Entity () tomo.Entity {
return element.entity
2023-04-15 02:03:22 +00: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-27 03:20:17 +00:00
(patterns.Texture { Canvas: element.buffer }).
2023-04-15 02:03:22 +00:00
Draw(destination, element.entity.Bounds())
2023-02-09 23:34:53 +00:00
}