Migrated over some elements
This commit is contained in:
@@ -1,25 +1,35 @@
|
||||
package elements
|
||||
|
||||
import "image"
|
||||
import "git.tebibyte.media/sashakoshka/tomo"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/canvas"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/elements/core"
|
||||
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 {
|
||||
*core.Core
|
||||
core core.CoreControl
|
||||
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.Core, element.core = core.NewCore(element, element.draw)
|
||||
bounds := image.Bounds()
|
||||
element.core.SetMinimumSize(bounds.Dx(), bounds.Dy())
|
||||
return
|
||||
}
|
||||
|
||||
func (element *Image) draw () {
|
||||
(patterns.Texture { Canvas: element.buffer }).
|
||||
Draw(element.core, element.Bounds())
|
||||
// Bind binds this element to an entity.
|
||||
func (element *Image) Bind (entity tomo.Entity) {
|
||||
if entity == nil { element.entity = nil; return }
|
||||
element.entity = entity
|
||||
bounds := element.buffer.Bounds()
|
||||
element.entity.SetMinimumSize(bounds.Dx(), bounds.Dy())
|
||||
}
|
||||
|
||||
// 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())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user