Checkpoint
This commit is contained in:
54 files changed
+6855
-526
No files matched your search
@@ -0,0 +1,48 @@
|
||||
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)
|
||||
}
|
||||
Reference in new issue
Block a user