-
Notifications
You must be signed in to change notification settings - Fork 0
/
layout.go
60 lines (50 loc) · 1.29 KB
/
layout.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
53
54
55
56
57
58
59
60
package spin
import "image/color"
var (
ColorLampBlue = color.RGBA{R: 0x00, G: 0x40, B: 0xff, A: 0xc0}
ColorLampGreen = color.RGBA{R: 0x00, G: 0xa0, B: 0x00, A: 0xc0}
ColorLampOrange = color.RGBA{R: 0xff, G: 0x80, B: 0x00, A: 0xc0}
ColorLampRed = color.RGBA{R: 0xff, G: 0x00, B: 0x00, A: 0xc0}
ColorLampWhite = color.RGBA{R: 0xff, G: 0xff, B: 0xff, A: 0xc0}
ColorLampYellow = color.RGBA{R: 0xff, G: 0xff, B: 0x00, A: 0xc0}
)
type LayoutShape interface {
shape()
}
type LayoutRect struct {
LayoutShape
X int
Y int
W int
H int
Color color.RGBA
}
func NewLayoutRect(x int, y int, w int, h int, color color.RGBA) LayoutRect {
return LayoutRect{X: x, Y: y, W: w, H: h, Color: color}
}
type LayoutCircle struct {
LayoutShape
X int
Y int
R int
Color color.RGBA
}
func NewLayoutCircle(x int, y int, r int, color color.RGBA) LayoutCircle {
return LayoutCircle{X: x, Y: y, R: r, Color: color}
}
func NewLayoutCircleFromRect(x int, y int, w int, h int, color color.RGBA) LayoutCircle {
cx := x + (w / 2)
cy := y + (h / 2)
r := w
if h < w {
r = h
}
return LayoutCircle{X: cx, Y: cy, R: r, Color: color}
}
type LayoutMulti struct {
LayoutShape
Shapes []LayoutShape
}
func NewLayoutMulti(shapes ...LayoutShape) LayoutMulti {
return LayoutMulti{Shapes: shapes}
}