58 lines
849 B
Go
58 lines
849 B
Go
package components
|
|
|
|
import "io"
|
|
|
|
// Some general types
|
|
|
|
// Rectangle and its' suplements
|
|
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)
|
|
}
|
|
|
|
// 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
|
|
}
|