diff --git a/_examples/imagebug/firefly.toml b/_examples/imagebug/firefly.toml new file mode 100644 index 0000000..abf10b9 --- /dev/null +++ b/_examples/imagebug/firefly.toml @@ -0,0 +1,7 @@ +author_id = "demo" +app_id = "go-imagebug" +author_name = "Demo" +app_name = "Image bug Demo (Go)" + +[files] +img = { path = "image.png" } diff --git a/_examples/imagebug/go.mod b/_examples/imagebug/go.mod new file mode 100644 index 0000000..88e1aad --- /dev/null +++ b/_examples/imagebug/go.mod @@ -0,0 +1,9 @@ +module demoimage + +go 1.24.0 + +replace github.com/firefly-zero/firefly-go => ../../ + +require github.com/firefly-zero/firefly-go v0.14.0 + +require github.com/orsinium-labs/tinymath v1.2.0 // indirect diff --git a/_examples/imagebug/go.sum b/_examples/imagebug/go.sum new file mode 100644 index 0000000..e8c4120 --- /dev/null +++ b/_examples/imagebug/go.sum @@ -0,0 +1,2 @@ +github.com/orsinium-labs/tinymath v1.2.0 h1:mxbQzDQz00XQvPqPmIRCgXvYMyPCgCng1kYWfvjXr6M= +github.com/orsinium-labs/tinymath v1.2.0/go.mod h1:WPXX6ei3KSXG7JfA03a+ekCYaY9SWN4I+JRl2p6ck+A= diff --git a/_examples/imagebug/image.go b/_examples/imagebug/image.go new file mode 100644 index 0000000..8ee22da --- /dev/null +++ b/_examples/imagebug/image.go @@ -0,0 +1,42 @@ +package main + +import "github.com/firefly-zero/firefly-go/firefly" + +func init() { + firefly.Boot = boot + firefly.Update = update + firefly.Render = render +} + +var ( + image firefly.Image + subimage firefly.SubImage + showImage bool + oldButtons firefly.Buttons +) + +func boot() { + // img is 240x160 + image = firefly.LoadFile("img", nil).Image() + subimage = image.Sub(firefly.P(0, 0), firefly.S(240, 160)) +} + +func update() { + buttons := firefly.ReadButtons(firefly.Combined) + if buttons.JustPressed(oldButtons).Any() { + showImage = !showImage + } + oldButtons = buttons +} + +func render() { + firefly.ClearScreen(firefly.ColorWhite) + + if showImage { + // Full image works: + image.Draw(firefly.Point{X: 0, Y: 16}) + } else { + // But drawing sub-image fails: + subimage.Draw(firefly.Point{X: 0, Y: 16}) + } +} diff --git a/_examples/imagebug/image.png b/_examples/imagebug/image.png new file mode 100644 index 0000000..7547789 Binary files /dev/null and b/_examples/imagebug/image.png differ