diff options
| author | hhvn <dev@hhvn.uk> | 2023-11-18 14:13:25 +0000 |
|---|---|---|
| committer | hhvn <dev@hhvn.uk> | 2023-11-18 19:55:08 +0000 |
| commit | 6117c8a98a39cd8bc1ca6b2436b6dab8873053f9 (patch) | |
| tree | f122e56d14c4d7f4facb154186443e932e21026f /drw/drw.go | |
| parent | 2b7504f96fcb8878ac5ed089940868517a74da79 (diff) | |
Draw to an image.RGBA
Diffstat (limited to 'drw/drw.go')
| -rw-r--r-- | drw/drw.go | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/drw/drw.go b/drw/drw.go new file mode 100644 index 0000000..a0844c8 --- /dev/null +++ b/drw/drw.go @@ -0,0 +1,44 @@ +package drw // import "hhvn.uk/hbspbar/drw" + +import ( + "image" + + "hhvn.uk/hbspbar/config" + + "github.com/jezek/xgbutil/xgraphics" + "github.com/BurntSushi/freetype-go/freetype" +) + +func DrawText(i *image.RGBA, x int, col uint32, text string) (int, error) { + ft.SetClip(i.Bounds()) + ft.SetDst(i) + + src := image.NewUniform(int2rgb(col)) + ft.SetSrc(src) + + pt := freetype.Pt(x, config.FontYPad+ + int(ft.PointToFix32(config.FontSize)>>8)) + npt, err := ft.DrawString(text, pt) + + return int(npt.X / 256) - x, err +} + +func TextWidth(text string) (int) { + w, _ := xgraphics.Extents(font, config.FontSize, text) + return w +} + +func DrawRect(i *image.RGBA, x, y, w, h int, c uint32, fill bool) { + col := int2rgb(c) + + var ix, iy int + + for ix = x; ix < x + w; ix++ { + for iy = y; iy < y + h; iy++ { + if fill || ix == x || ix == x + w - 1 || + iy == y || iy == y + h - 1 { + i.Set(ix, iy, col) + } + } + } +} |