-
Notifications
You must be signed in to change notification settings - Fork 12
/
display.go
52 lines (45 loc) · 1.03 KB
/
display.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package tinyfont
import (
"image/color"
"tinygo.org/x/drivers"
)
type RotatedDisplay struct {
display drivers.Displayer
Rotation Rotation
X int16
Y int16
}
func NewRotatedDisplay(display drivers.Displayer, rotation Rotation, x, y int16) RotatedDisplay {
return RotatedDisplay{
display: display,
Rotation: rotation,
X: x,
Y: y,
}
}
func (d RotatedDisplay) Size() (int16, int16) {
x, y := d.display.Size()
if d.Rotation == NO_ROTATION {
return x, y
} else if d.Rotation == ROTATION_90 {
return y, x
} else if d.Rotation == ROTATION_180 {
return x, y
} else {
return y, x
}
}
func (d RotatedDisplay) SetPixel(x, y int16, c color.RGBA) {
if d.Rotation == NO_ROTATION {
d.display.SetPixel(d.X+x, d.Y+y, c)
} else if d.Rotation == ROTATION_90 {
d.display.SetPixel(d.X-y, d.Y+x, c)
} else if d.Rotation == ROTATION_180 {
d.display.SetPixel(d.X-x, d.Y-y, c)
} else {
d.display.SetPixel(d.X+y, d.Y-x, c)
}
}
func (d RotatedDisplay) Display() error {
return d.display.Display()
}