Add: image, signal and service status output

This commit is contained in:
Andrey Egorov
2024-10-06 20:20:22 +03:00
parent 0976b5c8d0
commit 0495860996
4 changed files with 309 additions and 14 deletions

View File

@ -25,6 +25,8 @@ type Drawer interface {
PutBar(x0, y0, x1, y1 int, color byte)
FillBar(x0, y0, x1, y1 int, color byte)
CopyImg(x0, y0 int, img Image)
}
func New(dev display.Display) Drawer {

167
drawer/image.go Normal file
View File

@ -0,0 +1,167 @@
package drawer
// Simple glyphs like signal or service status that are too simple to be whole image
const (
SignalStatusGlyphI = 0 // first of 5
ServiceStatusGlyphI = 5 // first of 5
)
type Image struct {
W int
H int
Bits []byte
}
var CommonGlyphs = []Image{
{ // Signal 0/0
W: 7,
H: 7,
Bits: []byte{
1, 0, 0, 0, 1, 0, 0,
0, 1, 0, 1, 0, 0, 0,
0, 0, 1, 0, 0, 0, 0,
0, 1, 0, 1, 0, 0, 1,
1, 0, 0, 0, 1, 0, 1,
0, 0, 1, 0, 0, 0, 1,
1, 0, 1, 0, 1, 0, 1,
},
},
{ // Signal 1/4
W: 7,
H: 7,
Bits: []byte{
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0,
},
},
{ // Signal 2/4
W: 7,
H: 7,
Bits: []byte{
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0, 0,
1, 0, 1, 0, 0, 0, 0,
},
},
{ // Signal 3/4
W: 7,
H: 7,
Bits: []byte{
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0,
0, 0, 0, 0, 1, 0, 0,
0, 0, 1, 0, 1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1, 0, 0, 0, 0, 0, 1, 0,
0, 0, 0, 1, 1, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0, 0,
},
},
{ // Service 4/4
W: 9,
H: 7,
Bits: []byte{
0, 1, 1, 1, 1, 1, 1, 1, 0,
1, 0, 0, 0, 0, 0, 0, 0, 1,
0, 0, 1, 1, 1, 1, 1, 0, 0,
0, 1, 0, 0, 0, 0, 0, 1, 0,
0, 0, 0, 1, 1, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0, 0,
},
},
}
func (d *drawer) CopyImg(x0, y0 int, img Image) {
d.dev.LockImg()
defer d.dev.UnlockImg()
// Coords in img coord space
minX := IntMax(x0, 0) - x0
minY := IntMax(y0, 0) - y0
maxX := IntMin(x0+img.W, d.img.Rect.Dx()) - x0
maxY := IntMin(y0+img.H, d.img.Rect.Dy()) - y0
w := maxX - minX
if w <= 0 {
return
}
for yi := minY; yi < maxY; yi++ {
copy(d.img.Pix[(y0+yi)*d.img.Stride+x0:], img.Bits[yi*img.W:yi*img.W+w])
}
}