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"
|
2023-05-04 00:17:48 +00:00
|
|
|
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
|
2023-05-04 00:17:48 +00:00
|
|
|
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) {
|
2023-05-04 00:17:48 +00:00
|
|
|
element = &Image { buffer: art.FromImage(image) }
|
2023-05-03 05:07:44 +00:00
|
|
|
element.entity = tomo.GetBackend().NewEntity(element)
|
2023-04-15 05:14:36 +00:00
|
|
|
bounds := element.buffer.Bounds()
|
|
|
|
element.entity.SetMinimumSize(bounds.Dx(), bounds.Dy())
|
2023-02-09 23:34:53 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-04-15 05:14:36 +00:00
|
|
|
// 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.
|
2023-05-04 00:17:48 +00:00
|
|
|
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
|
|
|
}
|