diff options
| author | hhvn <dev@hhvn.uk> | 2023-11-19 13:49:28 +0000 |
|---|---|---|
| committer | hhvn <dev@hhvn.uk> | 2023-11-19 13:49:28 +0000 |
| commit | 4722a069233b35efd0b600c973e7a7e9bca01d16 (patch) | |
| tree | e7caa92c65932651e81b201edfcf704886aa2660 /drw | |
| parent | 1c46de9342a93cf8284d2bd4ed58f524cda60b29 (diff) | |
Do int2rgb conversions once. In config.go.
Diffstat (limited to 'drw')
| -rw-r--r-- | drw/drw.go | 21 | ||||
| -rw-r--r-- | drw/x.go | 29 |
2 files changed, 11 insertions, 39 deletions
@@ -3,6 +3,7 @@ package drw // import "hhvn.uk/hbspbar/drw" import ( "image" "image/draw" + "image/color" "hhvn.uk/hbspbar/config" @@ -11,7 +12,7 @@ import ( "github.com/BurntSushi/freetype-go/freetype" ) -func DrawText(i *image.RGBA, x int, col uint32, text string) (int, error) { +func DrawText(i *image.RGBA, x int, col color.Color, text string) (int, error) { ft := freetype.NewContext() ft.SetDPI(72) ft.SetFont(font) @@ -19,7 +20,7 @@ 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)) + src := image.NewUniform(col) ft.SetSrc(src) pt := freetype.Pt(x, config.FontYPad+ @@ -34,16 +35,14 @@ func TextWidth(text string) (int) { return w } -func DrawRect(i *image.RGBA, x, y, w, h int, c uint32, fill bool) { - col := int2rgb(c) - +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, col) + i.Set(ix, iy, c) } } } @@ -54,7 +53,7 @@ func AddImg(dst *image.RGBA, x, w int, src *image.RGBA) { draw.Draw(dst, r, src, image.Pt(0,0), draw.Src) } -func Blend3(a, b, c uint32, percent int) uint32 { +func Blend3(a, b, c color.Color, percent int) color.Color { if percent <= 50 { return Blend(a, b, percent * 2) } else { @@ -63,10 +62,10 @@ func Blend3(a, b, c uint32, percent int) uint32 { } // Conversion hell, I know -func Blend(a, b uint32, percent int) uint32 { - ac, _ := col.MakeColor(int2rgb(a)) - bc, _ := col.MakeColor(int2rgb(b)) +func Blend(a, b color.Color, percent int) color.Color { + ac, _ := col.MakeColor(a) + bc, _ := col.MakeColor(b) - return rgb2int(ac.BlendHcl(bc, float64(percent) / 100).Clamped()) + return color.Color(ac.BlendHcl(bc, float64(percent) / 100).Clamped()) } @@ -3,7 +3,6 @@ package drw // import "hhvn.uk/hbspbar/drw" import ( "os" "image" - "image/color" "hhvn.uk/hbspbar/config" "hhvn.uk/hbspbar/common" @@ -69,32 +68,6 @@ func init() { }}() } -func int2rgb(argb uint32) (color.RGBA) { - return color.RGBA{ - B: uint8( argb & 0x000000ff), - G: uint8((argb & 0x0000ff00) >> 8), - R: uint8((argb & 0x00ff0000) >> 16), - A: uint8((argb & 0xff000000) >> 24) } -} - -func rgb2int(c color.Color) uint32 { - r, g, b, a := c.RGBA() - - r /= 256 - g /= 256 - b /= 256 - a /= 256 - - var ret uint32 = 0 - - ret |= (a << 24) - ret |= (r << 16) - ret |= (g << 8) - ret |= b - - return ret -} - type Window struct { id xproto.Window } @@ -112,7 +85,7 @@ func WindowCreate(x, y, w, h uint) (*Window, error) { int16(x), int16(y), uint16(w), uint16(h), 0, xproto.WindowClassInputOutput, screen.RootVisual, xproto.CwBackPixel|xproto.CwEventMask, []uint32{ - config.Bg, + 0x00000000, xproto.EventMaskStructureNotify }) class := icccm.WmClass{"hbspbar", "hbspbar"} |