2022-11-12 17:02:24 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import "os"
|
|
|
|
import "image"
|
|
|
|
import _ "image/png"
|
|
|
|
import "git.tebibyte.media/sashakoshka/stone"
|
|
|
|
import _ "git.tebibyte.media/sashakoshka/stone/backends/x"
|
|
|
|
|
|
|
|
var application = &stone.Application { }
|
|
|
|
var mousePressed bool
|
|
|
|
|
|
|
|
func main () {
|
2022-11-15 22:29:23 -07:00
|
|
|
application.SetTitle("drawing canvas")
|
2022-11-12 17:02:24 -07:00
|
|
|
application.SetSize(32, 16)
|
|
|
|
|
|
|
|
iconFile16, err := os.Open("assets/scaffold16.png")
|
|
|
|
if err != nil { panic(err) }
|
|
|
|
icon16, _, err := image.Decode(iconFile16)
|
|
|
|
if err != nil { panic(err) }
|
|
|
|
iconFile16.Close()
|
|
|
|
iconFile32, err := os.Open("assets/scaffold32.png")
|
|
|
|
if err != nil { panic(err) }
|
|
|
|
icon32, _, err := image.Decode(iconFile32)
|
|
|
|
if err != nil { panic(err) }
|
|
|
|
iconFile16.Close()
|
|
|
|
|
|
|
|
application.SetIcon([]image.Image { icon16, icon32 })
|
|
|
|
|
2022-11-15 22:29:23 -07:00
|
|
|
application.OnPress(onPress)
|
|
|
|
application.OnRelease(onRelease)
|
|
|
|
application.OnMouseMove(onMouseMove)
|
2022-11-12 17:02:24 -07:00
|
|
|
|
2022-11-15 22:29:23 -07:00
|
|
|
err = application.Run()
|
|
|
|
if err != nil { panic(err) }
|
|
|
|
}
|
2022-11-12 17:02:24 -07:00
|
|
|
|
2022-11-15 22:29:23 -07:00
|
|
|
func onPress (button stone.Button) {
|
|
|
|
if button == stone.MouseButtonLeft {
|
|
|
|
mousePressed = true
|
|
|
|
application.SetRune(0, 0, '+')
|
|
|
|
application.Draw()
|
|
|
|
}
|
|
|
|
}
|
2022-11-12 17:02:24 -07:00
|
|
|
|
2022-11-15 22:29:23 -07:00
|
|
|
func onRelease (button stone.Button) {
|
|
|
|
if button == stone.MouseButtonLeft {
|
|
|
|
mousePressed = false
|
|
|
|
application.SetRune(0, 0, 0)
|
|
|
|
application.Draw()
|
|
|
|
}
|
|
|
|
}
|
2022-11-12 17:02:24 -07:00
|
|
|
|
2022-11-15 22:29:23 -07:00
|
|
|
func onMouseMove (x, y int) { if mousePressed {
|
|
|
|
application.SetRune(x, y, '#')
|
|
|
|
application.Draw()
|
2022-11-12 17:02:24 -07:00
|
|
|
}
|
|
|
|
}
|