2018-07-26 02:38:54 +00:00
|
|
|
package doodle
|
|
|
|
|
|
|
|
import (
|
2018-08-05 19:54:57 +00:00
|
|
|
"git.kirsle.net/apps/doodle/balance"
|
2018-07-26 02:38:54 +00:00
|
|
|
"git.kirsle.net/apps/doodle/events"
|
|
|
|
"git.kirsle.net/apps/doodle/render"
|
|
|
|
"git.kirsle.net/apps/doodle/ui"
|
|
|
|
)
|
|
|
|
|
|
|
|
// MainScene implements the main menu of Doodle.
|
|
|
|
type MainScene struct {
|
2018-07-26 03:25:02 +00:00
|
|
|
Supervisor *ui.Supervisor
|
2018-08-01 00:18:13 +00:00
|
|
|
frame *ui.Frame
|
2018-07-26 02:38:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Name of the scene.
|
|
|
|
func (s *MainScene) Name() string {
|
|
|
|
return "Main"
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setup the scene.
|
|
|
|
func (s *MainScene) Setup(d *Doodle) error {
|
2018-07-26 03:25:02 +00:00
|
|
|
s.Supervisor = ui.NewSupervisor()
|
|
|
|
|
2018-08-02 01:52:52 +00:00
|
|
|
frame := ui.NewFrame("frame")
|
2018-08-01 00:18:13 +00:00
|
|
|
s.frame = frame
|
|
|
|
|
2018-08-05 19:54:57 +00:00
|
|
|
button1 := ui.NewButton("Button1", ui.NewLabel(ui.Label{
|
|
|
|
Text: "New Map",
|
|
|
|
Font: balance.StatusFont,
|
2018-07-26 03:25:02 +00:00
|
|
|
}))
|
2018-08-17 03:37:19 +00:00
|
|
|
button1.Handle(ui.Click, func(p render.Point) {
|
2018-07-26 03:25:02 +00:00
|
|
|
d.NewMap()
|
|
|
|
})
|
|
|
|
|
2018-08-05 19:54:57 +00:00
|
|
|
button2 := ui.NewButton("Button2", ui.NewLabel(ui.Label{
|
|
|
|
Text: "New Map",
|
|
|
|
Font: balance.StatusFont,
|
2018-07-26 03:25:02 +00:00
|
|
|
}))
|
|
|
|
button2.SetText("Load Map")
|
2018-08-01 00:18:13 +00:00
|
|
|
|
|
|
|
frame.Pack(button1, ui.Pack{
|
2018-08-05 19:54:57 +00:00
|
|
|
Anchor: ui.N,
|
|
|
|
Fill: true,
|
2018-08-01 00:18:13 +00:00
|
|
|
})
|
|
|
|
frame.Pack(button2, ui.Pack{
|
2018-08-05 19:54:57 +00:00
|
|
|
Anchor: ui.N,
|
|
|
|
PadY: 12,
|
|
|
|
Fill: true,
|
2018-07-26 03:25:02 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
s.Supervisor.Add(button1)
|
|
|
|
s.Supervisor.Add(button2)
|
|
|
|
|
2018-07-26 02:38:54 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Loop the editor scene.
|
|
|
|
func (s *MainScene) Loop(d *Doodle, ev *events.State) error {
|
2018-07-26 03:25:02 +00:00
|
|
|
s.Supervisor.Loop(ev)
|
2018-07-26 02:38:54 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw the pixels on this frame.
|
|
|
|
func (s *MainScene) Draw(d *Doodle) error {
|
|
|
|
// Clear the canvas and fill it with white.
|
|
|
|
d.Engine.Clear(render.White)
|
|
|
|
|
2018-08-05 19:54:57 +00:00
|
|
|
label := ui.NewLabel(ui.Label{
|
|
|
|
Text: "Doodle v" + Version,
|
|
|
|
Font: render.Text{
|
|
|
|
Size: 26,
|
|
|
|
Color: render.Pink,
|
|
|
|
Stroke: render.SkyBlue,
|
|
|
|
Shadow: render.Black,
|
|
|
|
},
|
2018-07-26 02:38:54 +00:00
|
|
|
})
|
|
|
|
label.Compute(d.Engine)
|
|
|
|
label.MoveTo(render.Point{
|
2018-10-19 20:31:58 +00:00
|
|
|
X: (int32(d.width) / 2) - (label.Size().W / 2),
|
2018-07-26 02:38:54 +00:00
|
|
|
Y: 120,
|
|
|
|
})
|
2018-08-05 19:54:57 +00:00
|
|
|
label.Present(d.Engine, label.Point())
|
2018-07-26 02:38:54 +00:00
|
|
|
|
2018-08-01 00:18:13 +00:00
|
|
|
s.frame.Compute(d.Engine)
|
|
|
|
s.frame.MoveTo(render.Point{
|
2018-10-19 20:31:58 +00:00
|
|
|
X: (int32(d.width) / 2) - (s.frame.Size().W / 2),
|
2018-08-01 00:18:13 +00:00
|
|
|
Y: 200,
|
|
|
|
})
|
2018-08-05 19:54:57 +00:00
|
|
|
s.frame.Present(d.Engine, s.frame.Point())
|
2018-07-26 02:38:54 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Destroy the scene.
|
|
|
|
func (s *MainScene) Destroy() error {
|
|
|
|
return nil
|
|
|
|
}
|