1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
package drw // import "hhvn.uk/hbspbar/drw"
import (
"image"
"image/draw"
"image/color"
"hhvn.uk/hbspbar/config"
"github.com/jezek/xgbutil/xgraphics"
col "github.com/lucasb-eyer/go-colorful"
"github.com/BurntSushi/freetype-go/freetype"
)
func DrawText(i *image.RGBA, x int, col color.Color, text string) (int, error) {
ft := freetype.NewContext()
ft.SetDPI(72)
ft.SetFont(font)
ft.SetFontSize(config.FontSize)
ft.SetClip(i.Bounds())
ft.SetDst(i)
src := image.NewUniform(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 color.Color, fill bool) {
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, c)
}
}
}
}
func AddImg(dst *image.RGBA, x, w int, src *image.RGBA) {
r := image.Rect(x, 0, x + w, int(config.H))
draw.Draw(dst, r, src, image.Pt(0,0), draw.Src)
}
func Blend3(a, b, c color.Color, percent int) color.Color {
if percent <= 50 {
return Blend(a, b, percent * 2)
} else {
return Blend(b, c, (percent - 50) * 2)
}
}
// Conversion hell, I know
func Blend(a, b color.Color, percent int) color.Color {
ac, _ := col.MakeColor(a)
bc, _ := col.MakeColor(b)
return color.Color(ac.BlendHcl(bc, float64(percent) / 100).Clamped())
}
|