display-test/components/components.go

58 lines
849 B
Go
Raw Permalink Normal View History

2024-09-22 18:53:22 +00:00
package components
2024-09-29 18:09:59 +00:00
import "io"
2024-09-22 18:53:22 +00:00
// Some general types
2024-09-29 18:09:59 +00:00
// Rectangle and its' suplements
2024-09-22 18:53:22 +00:00
type rect struct {
x int
y int
w int
h int
}
type RectGetter interface {
GetPos() (int, int)
GetSize() (int, int)
}
type RectSetter interface {
SetPos(x, y int)
SetSize(w, h int)
}
2024-09-29 18:09:59 +00:00
// Mask
// Implementation dependent !!!
// Now for mt12232
type mask struct {
bits uint32
}
func (m *mask) Update(r rect) {
m.bits = 0
y0 := min(3, max(0, int(r.y/8)))
y1 := min(3, max(0, int((r.y+r.h-1)/8)))
x0 := min(1, max(0, int(r.x/61)))
x1 := min(1, max(0, int((r.x+r.w-1)/61)))
//log.Println(x0, y0, x1, y1)
for y := y0; y <= y1; y++ {
for x := x0; x <= x1; x++ {
m.bits |= (1 << (x*4 + y))
}
}
}
// Component - all components should implement this interface
type Component interface {
RectGetter
Draw() // Draw and flush
io.Closer
}