summaryrefslogtreecommitdiff
path: root/bar/x.go
diff options
context:
space:
mode:
authorhhvn <dev@hhvn.uk>2023-11-16 20:45:11 +0000
committerhhvn <dev@hhvn.uk>2023-11-18 19:54:50 +0000
commit2b7504f96fcb8878ac5ed089940868517a74da79 (patch)
treeff0b24c32b5d037427ffa4a664caf48b8484046e /bar/x.go
parent2a8069eb9606af55f76ac43e187ca83a7dd6957f (diff)
Create x package
Diffstat (limited to 'bar/x.go')
-rw-r--r--bar/x.go79
1 files changed, 0 insertions, 79 deletions
diff --git a/bar/x.go b/bar/x.go
deleted file mode 100644
index e4aadae..0000000
--- a/bar/x.go
+++ /dev/null
@@ -1,79 +0,0 @@
-package bar // import "hhvn.uk/hbspbar/bar"
-
-import (
- "os"
- "image"
-
- "hhvn.uk/hbspbar/common"
-
- "github.com/jezek/xgbutil/xgraphics"
- "github.com/BurntSushi/freetype-go/freetype/truetype"
-)
-
-func getFont(path string) (*truetype.Font, error) {
- read, err := os.Open(path)
- if err != nil {
- return nil, common.Perror("os.Open", err)
- }
-
- font, err := xgraphics.ParseFont(read)
- if err != nil {
- return nil, common.Perror("xgraphics.ParseFont", err)
- }
-
- return font, nil
-}
-
-func int2BGRA(argb uint32) (xgraphics.BGRA) {
- return xgraphics.BGRA{
- B: uint8( argb & 0x000000ff),
- G: uint8((argb & 0x0000ff00) >> 8),
- R: uint8((argb & 0x00ff0000) >> 16),
- A: uint8((argb & 0xff000000) >> 24) }
-}
-
-func (b *bar) rect() image.Rectangle {
- return image.Rect( 0, 0,
- int(b.Mon.Rectangle.Width), int(conf.H))
-}
-
-func (b *bar) drawReInit() {
- if b.i != nil {
- b.i.Destroy()
- }
-
- b.i = xgraphics.New(b.Xu, b.rect())
-}
-
-func (b *bar) drawText(x int, col uint32, text string) (int, error) {
- nx, _, err := b.i.Text(x, conf.FontYPad,
- int2BGRA(col), conf.FontSize, font, text)
- return nx - x, err
-}
-
-func (b *bar) textWidth(str string) int {
- return len(str) * b.tw
-}
-
-func pointInRect(px, py, x, y, w, h int) bool {
- if px >= x && px <= x + w && py >= x && py <= y + h {
- return true
- } else {
- return false
- }
-}
-
-func (b *bar) drawRect(x, y, w, h int, c uint32, fill bool) {
- col := int2BGRA(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 {
- b.i.Set(ix, iy, col)
- }
- }
- }
-}