Overhauled event system
This commit is contained in:
@@ -10,7 +10,7 @@ var application = &stone.Application { }
|
||||
var mousePressed bool
|
||||
|
||||
func main () {
|
||||
application.SetTitle("hellorld")
|
||||
application.SetTitle("drawing canvas")
|
||||
application.SetSize(32, 16)
|
||||
|
||||
iconFile16, err := os.Open("assets/scaffold16.png")
|
||||
@@ -26,42 +26,37 @@ func main () {
|
||||
|
||||
application.SetIcon([]image.Image { icon16, icon32 })
|
||||
|
||||
channel, err := application.Run()
|
||||
if err != nil { panic(err) }
|
||||
application.OnPress(onPress)
|
||||
application.OnRelease(onRelease)
|
||||
application.OnMouseMove(onMouseMove)
|
||||
application.OnQuit(onQuit)
|
||||
|
||||
application.Draw()
|
||||
err = application.Run()
|
||||
if err != nil { panic(err) }
|
||||
}
|
||||
|
||||
for {
|
||||
event := <- channel
|
||||
switch event.(type) {
|
||||
case stone.EventQuit:
|
||||
os.Exit(0)
|
||||
|
||||
case stone.EventPress:
|
||||
button := event.(stone.EventPress).Button
|
||||
if button == stone.MouseButtonLeft {
|
||||
mousePressed = true
|
||||
application.SetRune(0, 0, '+')
|
||||
application.Draw()
|
||||
}
|
||||
|
||||
case stone.EventRelease:
|
||||
button := event.(stone.EventRelease).Button
|
||||
if button == stone.MouseButtonLeft {
|
||||
mousePressed = false
|
||||
application.SetRune(0, 0, 0)
|
||||
application.Draw()
|
||||
}
|
||||
|
||||
case stone.EventMouseMove:
|
||||
event := event.(stone.EventMouseMove)
|
||||
if mousePressed {
|
||||
application.SetRune(event.X, event.Y, '#')
|
||||
application.Draw()
|
||||
}
|
||||
|
||||
case stone.EventResize:
|
||||
application.Draw()
|
||||
}
|
||||
func onPress (button stone.Button) {
|
||||
if button == stone.MouseButtonLeft {
|
||||
mousePressed = true
|
||||
application.SetRune(0, 0, '+')
|
||||
application.Draw()
|
||||
}
|
||||
}
|
||||
|
||||
func onRelease (button stone.Button) {
|
||||
if button == stone.MouseButtonLeft {
|
||||
mousePressed = false
|
||||
application.SetRune(0, 0, 0)
|
||||
application.Draw()
|
||||
}
|
||||
}
|
||||
|
||||
func onMouseMove (x, y int) { if mousePressed {
|
||||
application.SetRune(x, y, '#')
|
||||
application.Draw()
|
||||
}
|
||||
}
|
||||
|
||||
func onQuit () {
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user