Checkpoint
This commit is contained in:
160 files changed
+76293
-387
No files matched your search
@@ -0,0 +1,70 @@
|
||||
package hardware
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
"image/color"
|
||||
|
||||
"github.com/BeatGlow/display"
|
||||
)
|
||||
|
||||
// View is a (partial) view on the display.
|
||||
type View struct {
|
||||
display.Display
|
||||
Window image.Rectangle
|
||||
}
|
||||
|
||||
func MakeView(display display.Display, window image.Rectangle) View {
|
||||
return View{
|
||||
Display: display,
|
||||
Window: window,
|
||||
}
|
||||
}
|
||||
|
||||
func (d View) Bounds() image.Rectangle {
|
||||
return d.Window.Sub(d.Window.Min)
|
||||
}
|
||||
|
||||
func (d View) Clear() {
|
||||
if d.Window.Eq(d.Display.Bounds()) {
|
||||
d.Display.Clear()
|
||||
return
|
||||
}
|
||||
|
||||
for y := d.Window.Min.Y; y < d.Window.Max.Y; y++ {
|
||||
for x := d.Window.Min.X; x < d.Window.Max.X; x++ {
|
||||
d.Display.Set(x, y, color.Transparent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Close doesn't do anything.
|
||||
func (View) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d View) Type() string {
|
||||
return fmt.Sprintf("view:%s:%s", d.Display, 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