display-test/drawer/drawer.go

74 lines
1020 B
Go
Raw Normal View History

package drawer
import (
"image"
2024-08-28 11:14:55 +00:00
"gitea.unprism.ru/yotia/display-test/display"
)
type drawer struct {
2024-09-18 19:32:47 +00:00
dev display.Display
img *image.Gray
}
type Drawer interface {
2024-09-18 19:32:47 +00:00
GetDisplay() display.Display
2024-09-22 18:53:22 +00:00
W() int
H() int
Clear()
2024-09-18 19:32:47 +00:00
Flush()
PutText(x, y int, text string)
2024-09-22 18:53:22 +00:00
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 {
2024-09-18 19:32:47 +00:00
d := &drawer{
dev: dev,
}
2024-09-18 19:32:47 +00:00
d.img = d.dev.GetImg()
return d
}
2024-09-18 19:32:47 +00:00
func (d *drawer) GetDisplay() display.Display {
return d.dev
}
2024-09-22 18:53:22 +00:00
func (d *drawer) W() int {
return d.img.Rect.Dx()
}
func (d *drawer) H() int {
return d.img.Rect.Dy()
}
func (d *drawer) Clear() {
2024-09-18 19:32:47 +00:00
d.dev.LockImg()
defer d.dev.UnlockImg()
for i := range d.img.Pix {
d.img.Pix[i] = 0
}
2024-09-29 18:09:59 +00:00
d.dev.FlushByMask(0xFF)
}
2024-09-18 19:32:47 +00:00
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)
}