Example #1
0
func (ie *ImageElement) Render(size, offset mgl32.Vec2) mgl32.Vec2 {
	ie.size, ie.offset = size, offset
	width, height := ie.getWidth(size.X()), ie.getHeight(size.X())
	if ie.img != nil {
		if width <= 0 && height <= 0 {
			width = float32(ie.img.Bounds().Size().X)
			height = float32(ie.img.Bounds().Size().Y)
		} else if width <= 0 {
			width = height * float32(ie.img.Bounds().Size().X) / float32(ie.img.Bounds().Size().Y)
		} else if height <= 0 {
			height = width * float32(ie.img.Bounds().Size().Y) / float32(ie.img.Bounds().Size().X)
		}
	}
	imgSize := mgl32.Vec2{width, height}
	ie.node.SetScale(imgSize.Vec3(0))
	ie.node.SetTranslation(offset.Vec3(0))
	ie.offset = offset
	ie.Hitbox.SetSize(imgSize)
	return imgSize
}