summaryrefslogtreecommitdiff
path: root/status/00-status.go
diff options
context:
space:
mode:
authorhhvn <dev@hhvn.uk>2023-11-18 19:50:26 +0000
committerhhvn <dev@hhvn.uk>2023-11-18 19:56:13 +0000
commit19781aeb974bd20c421a6b4677ffab348df8faf9 (patch)
tree22bde9a97fdc36f6d412203319f797cf168986d9 /status/00-status.go
parent505685c6d546cab46f919f6b5296ca73b80d09b2 (diff)
Statuses
Diffstat (limited to 'status/00-status.go')
-rw-r--r--status/00-status.go97
1 files changed, 97 insertions, 0 deletions
diff --git a/status/00-status.go b/status/00-status.go
new file mode 100644
index 0000000..d508eab
--- /dev/null
+++ b/status/00-status.go
@@ -0,0 +1,97 @@
+package status // import "hhvn.uk/hbspbar/status"
+
+import (
+ "time"
+ "sync"
+ "image"
+
+ "hhvn.uk/hbspbar/config"
+ "hhvn.uk/hbspbar/drw"
+)
+
+var Status map[int]*status
+var Mutex sync.Mutex
+var statusid map[string]int
+var Updated chan bool
+var updates chan *status
+
+const (
+ Red = 0xffaa2222
+ Orange = 0xffaa7700
+ Green = 0xff00aa00
+ Black = 0xff000000
+ Grey = 0xff888888
+ Yellow = 0xffaaaa00
+ White = 0xffcccccc
+)
+
+func init() {
+ Status = make(map[int]*status)
+ statusid = make(map[string]int)
+ Updated = make(chan bool)
+ updates = make(chan *status)
+
+ go func() {
+ for {
+ s := <- updates
+
+ id := statusid[s.Name]
+
+ Mutex.Lock()
+ Status[id] = s
+ Mutex.Unlock()
+
+ Updated <- true
+ }
+ }()
+}
+
+func register(name string) {
+ nid := 0
+ for _, id := range statusid {
+ if id >= nid {
+ nid = id + 1
+ }
+ }
+ statusid[name] = nid
+}
+
+type status struct {
+ Name string
+ I *image.RGBA
+ W int
+}
+
+func newUpdate(name string) (*status) {
+ var s status
+
+ s.Name = name
+ s.W = 0
+ s.I = image.NewRGBA(image.Rect(0, 0, 1000, int(config.H)))
+
+ // Use drw's in order not to modify s.W
+ drw.DrawRect(s.I, 0, 0, 1000, int(config.H), config.Status, true)
+
+ return &s
+}
+
+func sleep(s int) {
+ time.Sleep(time.Duration(s) * time.Second)
+}
+
+func (s *status) furthest(x int) {
+ if x > s.W {
+ s.W = x
+ }
+}
+
+func (s *status) drawText(x int, col uint32, text string) (int, error) {
+ w, err := drw.DrawText(s.I, x, col, text)
+ s.furthest(x + w)
+ return w, err
+}
+
+func (s *status) drawRect(x, y, w, h int, c uint32, fill bool) {
+ drw.DrawRect(s.I, x, y, w, h, c, fill)
+ s.furthest(x + w)
+}