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
928 B
Go
Raw Permalink Normal View History

2023-03-31 03:19:04 +00:00
package elements
2023-02-09 23:34:53 +00:00
import "image"
2023-05-03 23:40:30 +00:00
import "tomo"
import "art"
import "art/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
buffer art.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) {
element = &Image { buffer: art.FromImage(image) }
2023-05-03 05:07:44 +00:00
element.entity = tomo.GetBackend().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 art.Canvas) {
2023-04-15 02:03:22 +00:00
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
}