-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbutton.go
47 lines (36 loc) · 890 Bytes
/
button.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
package main
import (
"github.com/hajimehoshi/ebiten/v2"
)
type Button struct {
game *Game
x, y int
width, height int
zindex int
onClick func(x, y int) bool
onDraw func(screen *ebiten.Image, x, y, width, height int)
}
func newButton(g *Game, x, y, width, height, zindex int, clickFn func(x, y int) bool, drawFn func(screen *ebiten.Image, x, y, width, height int)) *Button {
return &Button{
game: g,
x: x,
y: y,
width: width,
height: height,
zindex: zindex,
onClick: clickFn,
onDraw: drawFn,
}
}
func (b *Button) OnClick(x, y int) bool {
return b.onClick(x, y)
}
func (b *Button) IsClicked(x, y int) bool {
return b.x <= x && x <= b.x+b.width && b.y <= y && y <= b.y+b.height
}
func (b *Button) Draw(screen *ebiten.Image) {
b.onDraw(screen, b.x, b.y, b.width, b.height)
}
func (b *Button) ZIndex() int {
return b.zindex
}