-
Notifications
You must be signed in to change notification settings - Fork 1
/
gamepage.go
46 lines (36 loc) · 1.06 KB
/
gamepage.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
package pages
import (
"github.com/hculpan/go-scape/app/components"
"github.com/hculpan/go-scape/app/model"
"github.com/hculpan/go-sdl-lib/component"
"github.com/veandco/go-sdl2/sdl"
)
type GamePage struct {
component.BasePage
}
func NewGamePage(name string, x, y, width, height int32) *GamePage {
p := GamePage{}
p.Name = "GamePage"
p.SetPosition(0, 0)
p.SetSize(width, height)
p.AddChild(components.NewSugarscapeComponent(3, 43, 803, 803))
p.AddChild(components.NewHeaderComponent(0, 0, width, 40))
return &p
}
func (g *GamePage) KeyEvent(event *sdl.KeyboardEvent) bool {
keycode := sdl.GetKeyFromScancode(event.Keysym.Scancode)
if keycode == sdl.K_r {
model.Sugarscape.Reset()
return true
}
return component.PassKeyEventToChildren(event, g.Children)
}
func (c *GamePage) Draw(r *sdl.Renderer) error {
return component.DrawParentAndChildren(r, c)
}
func (c *GamePage) MouseButtonEvent(event *sdl.MouseButtonEvent) bool {
if c.IsPointInComponent(event.X, event.Y) {
return component.PassMouseButtonEventToChildren(event, c.Children)
}
return false
}