display-test/drawer/drawer.go
2024-10-06 20:20:22 +03:00

74 lines
1020 B
Go

package drawer
import (
"image"
"gitea.unprism.ru/yotia/display-test/display"
)
type drawer struct {
dev display.Display
img *image.Gray
}
type Drawer interface {
GetDisplay() display.Display
W() int
H() int
Clear()
Flush()
PutText(x, y int, text string)
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 {
d := &drawer{
dev: dev,
}
d.img = d.dev.GetImg()
return d
}
func (d *drawer) GetDisplay() display.Display {
return d.dev
}
func (d *drawer) W() int {
return d.img.Rect.Dx()
}
func (d *drawer) H() int {
return d.img.Rect.Dy()
}
func (d *drawer) Clear() {
d.dev.LockImg()
defer d.dev.UnlockImg()
for i := range d.img.Pix {
d.img.Pix[i] = 0
}
d.dev.FlushByMask(0xFF)
}
func (d *drawer) Flush() {
// Flush all pages
d.dev.Flush(0, 0)
d.dev.Flush(0, 1)
d.dev.Flush(0, 2)
d.dev.Flush(0, 3)
d.dev.Flush(1, 0)
d.dev.Flush(1, 1)
d.dev.Flush(1, 2)
d.dev.Flush(1, 3)
}