traygent/icon.go

64 lines
1.0 KiB
Go
Raw Permalink Normal View History

2023-10-07 05:29:05 -06:00
package main
import (
"bytes"
"fmt"
"image"
"image/color"
"image/png"
"golang.org/x/image/font"
"golang.org/x/image/font/gofont/goregular"
"golang.org/x/image/font/opentype"
"golang.org/x/image/math/fixed"
)
var myFont, _ = opentype.Parse(goregular.TTF)
var fontFace, _ = opentype.NewFace(myFont, &opentype.FaceOptions{
2024-01-03 09:12:15 -07:00
Size: 230,
2023-10-07 05:29:05 -06:00
DPI: 72,
Hinting: font.HintingNone,
})
type myIcon struct {
data *image.RGBA
}
func (m *myIcon) Name() string {
return "tagent.png"
}
func (m *myIcon) Content() []byte {
buf := new(bytes.Buffer)
_ = png.Encode(buf, m.data)
return buf.Bytes()
}
func buildImage(length int, locked bool) *myIcon {
i := &myIcon{}
2024-01-03 09:12:15 -07:00
size := 256
2023-10-07 05:29:05 -06:00
i.data = image.NewRGBA(image.Rect(0, 0, size, size))
co := color.RGBA{A: 255}
d := &font.Drawer{
Dst: i.data,
Src: image.NewUniform(co),
2023-10-07 05:29:05 -06:00
Face: fontFace,
2024-01-03 09:12:15 -07:00
Dot: fixed.P(60, 210),
2023-10-07 05:29:05 -06:00
}
var r []rune
if !locked {
r = []rune(fmt.Sprintf("%d", length))
} else {
r = []rune("🔒")
}
l := string(r)
d.DrawString(l)
return i
}