-
Notifications
You must be signed in to change notification settings - Fork 3
/
keys.go
72 lines (57 loc) · 1.83 KB
/
keys.go
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
72
package main
import (
"fmt"
"image"
"image/color"
"strconv"
"github.com/llgcode/draw2d"
"github.com/llgcode/draw2d/draw2dimg"
"github.com/stampzilla/stampzilla-go/v2/nodes/stampzilla-streamdeck/streamdeck"
)
func drawTempToKey(deck *streamdeck.StreamDeck, label string, value float32, key int) {
dest := image.NewRGBA(image.Rect(0, 0, ICON_SIZE, ICON_SIZE))
gc := draw2dimg.NewGraphicContext(dest)
gc.SetFillColor(color.RGBA{0xff, 0x66, 0x00, 0xff})
gc.SetStrokeColor(color.RGBA{0xff, 0xff, 0xff, 0xff})
gc.SetFontSize(28)
gc.SetFontData(draw2d.FontData{
Name: "Roboto",
})
text := fmt.Sprintf("%.0f", value)
left, top, right, bottom := gc.GetStringBounds(text)
gc.FillStringAt(text, 72/2-((right-left)/2), 72/2)
// Label
gc.SetFillColor(color.RGBA{0xff, 0xff, 0xff, 0xff})
gc.SetFontSize(14)
left, top, right, bottom = gc.GetStringBounds(label)
gc.FillStringAt(label, 72/2-((right-left)/2), 72-((bottom-top)/2))
deck.WriteImageToKey(dest, key)
}
func drawStateToKey(deck *streamdeck.StreamDeck, label string, value interface{}, key int) {
dest := image.NewRGBA(image.Rect(0, 0, ICON_SIZE, ICON_SIZE))
gc := draw2dimg.NewGraphicContext(dest)
text := ""
switch state := value.(type) {
case bool:
text = strconv.FormatBool(state)
case int:
text = "int"
default:
text = "unkn"
}
// State
gc.SetFillColor(color.RGBA{0xff, 0xff, 0xff, 0xff})
gc.SetStrokeColor(color.RGBA{0xff, 0xff, 0xff, 0xff})
gc.SetFontSize(28)
gc.SetFontData(draw2d.FontData{
Name: "Roboto",
})
left, top, right, bottom := gc.GetStringBounds(text)
gc.FillStringAt(text, 72/2-((right-left)/2), 72/2)
// Label
gc.SetFillColor(color.RGBA{0xff, 0xff, 0xff, 0xff})
gc.SetFontSize(14)
left, top, right, bottom = gc.GetStringBounds(label)
gc.FillStringAt(label, 72/2-((right-left)/2), 72-((bottom-top)/2))
deck.WriteImageToKey(dest, key)
}