Files
beatglow/hardware/display/view.go
T
2026-10-29 17:29:41 +01:00

49 lines
910 B
Go

package display
import (
"fmt"
"image"
"image/color"
"go.maze.io/harmon/hardware"
)
// View is a (partial) view on the display.
type View struct {
hardware.Display
Window image.Rectangle
}
func MakeView(display hardware.Display, window image.Rectangle) View {
return View{
Display: display,
Window: window,
}
}
func (d View) Type() string {
return fmt.Sprintf("view:%s:%s", d.Display.Type(), d.Window)
}
func (d View) Size() image.Point {
return d.Window.Size()
}
func (d View) At(x, y int) color.Color {
if x < 0 || y < 0 || x >= d.Window.Dx() || y >= d.Window.Dy() {
return d.Display.ColorModel().Convert(color.Black)
}
x -= d.Window.Min.X
y -= d.Window.Min.Y
return d.Display.At(x, y)
}
func (d View) Set(x, y int, c color.Color) {
if x < 0 || y < 0 || x >= d.Window.Dx() || y >= d.Window.Dy() {
return
}
x -= d.Window.Min.X
y -= d.Window.Min.Y
d.Display.Set(x, y, c)
}