package drawer import ( "image" "sync" "gitea.unprism.ru/yotia/display-test/display" ) type drawer struct { dev display.Display img *image.Gray imgMutex sync.Mutex } type Drawer interface { // Lowlevel image GetImg() *image.Gray Lock() Unlock() Clear() Flush() error PutText(x, y int, text string) PutBar(x0, y0, x1, y1, color int) FillBar(x0, y0, x1, y1, color int) } func New(dev display.Display) Drawer { return &drawer{ dev: dev, img: image.NewGray(dev.GetBounds()), } } func (d *drawer) GetImg() *image.Gray { return d.img } func (d *drawer) Lock() { d.imgMutex.Lock() } func (d *drawer) Unlock() { d.imgMutex.Unlock() } func (d *drawer) Clear() { d.Lock() defer d.Unlock() for i := range d.img.Pix { d.img.Pix[i] = 0 } } func (d *drawer) Flush() error { d.Lock() defer d.Unlock() return d.dev.Flush(d.img) }