badges/info.go

74 lines
2.3 KiB
Go
Raw Normal View History

2026-04-15 20:50:12 +00:00
//go:build gopher_badge || nicenano
// +build gopher_badge nicenano
2026-04-14 17:21:59 +00:00
package main
import (
"image/color"
"time"
"tinygo.org/x/tinyfont"
"tinygo.org/x/tinyfont/freesans"
qrcode "github.com/skip2/go-qrcode"
)
func Info() {
2026-04-15 20:50:12 +00:00
qrSize := int16(180)
if displayHeight < 200 {
qrSize = displayHeight - 5
}
2026-04-14 17:21:59 +00:00
qr, err := qrcode.New("https://gopherbadge.com/", qrcode.Medium)
if err != nil {
println(err, 123)
}
qrbytes := qr.Bitmap()
size := int16(len(qrbytes))
2026-04-15 20:50:12 +00:00
factor := qrSize / size
2026-04-14 17:21:59 +00:00
2026-04-15 20:50:12 +00:00
bx := (qrSize - size*factor) / 2
by := (qrSize - size*factor) / 2
2026-04-14 17:21:59 +00:00
display.FillScreen(color.RGBA{109, 0, 140, 255})
for y := int16(0); y < size; y++ {
for x := int16(0); x < size; x++ {
if qrbytes[y][x] {
display.FillRectangle(bx+x*factor, by+y*factor, factor, factor, colorBlack)
} else {
display.FillRectangle(bx+x*factor, by+y*factor, factor, factor, colorWhite)
}
}
}
w32, _ := tinyfont.LineWidth(&freesans.Bold18pt7b, "SCAN")
2026-04-15 20:50:12 +00:00
tinyfont.WriteLine(&display, &freesans.Bold18pt7b, qrSize+((displayWidth-qrSize)-int16(w32))/2, 45, "SCAN", colorWhite)
2026-04-14 17:21:59 +00:00
w32, _ = tinyfont.LineWidth(&freesans.Bold18pt7b, "ME")
2026-04-15 20:50:12 +00:00
tinyfont.WriteLine(&display, &freesans.Bold18pt7b, qrSize+((displayWidth-qrSize)-int16(w32))/2, 80, "ME", colorWhite)
if displayHeight >= 200 {
w32, _ = tinyfont.LineWidth(&freesans.Bold9pt7b, "Press any")
tinyfont.WriteLine(&display, &freesans.Bold9pt7b, qrSize+((displayWidth-qrSize)-int16(w32))/2, 120, "Press any", colorWhite)
w32, _ = tinyfont.LineWidth(&freesans.Bold9pt7b, "button")
tinyfont.WriteLine(&display, &freesans.Bold9pt7b, qrSize+((displayWidth-qrSize)-int16(w32))/2, 140, "button", colorWhite)
w32, _ = tinyfont.LineWidth(&freesans.Bold9pt7b, "to continue")
tinyfont.WriteLine(&display, &freesans.Bold9pt7b, qrSize+((displayWidth-qrSize)-int16(w32))/2, 160, "to continue", colorWhite)
w32, _ = tinyfont.LineWidth(&freesans.Bold9pt7b, "Visit https://gopherbadge.com/")
tinyfont.WriteLine(&display, &freesans.Bold9pt7b, (displayWidth-int16(w32))/2, qrSize+25, "Visit https://gopherbadge.com/", colorWhite)
w32, _ = tinyfont.LineWidth(&freesans.Bold9pt7b, "for more information")
tinyfont.WriteLine(&display, &freesans.Bold9pt7b, (displayWidth-int16(w32))/2, qrSize+45, "for more information", colorWhite)
}
2026-04-14 17:21:59 +00:00
for {
time.Sleep(100 * time.Millisecond)
getInput()
2026-04-15 21:18:25 +00:00
if goBack() {
quit = true
return
2026-04-14 17:21:59 +00:00
}
}
}