2022-10-31 13:51:28 -06:00
|
|
|
package main
|
|
|
|
|
2022-11-09 13:52:49 -07:00
|
|
|
import "os"
|
2022-11-06 12:17:43 -07:00
|
|
|
import "fmt"
|
|
|
|
import "time"
|
2022-11-10 00:02:08 -07:00
|
|
|
import "image"
|
|
|
|
import _ "image/png"
|
2022-10-31 13:51:28 -06:00
|
|
|
import "git.tebibyte.media/sashakoshka/stone"
|
2022-11-09 16:53:14 -07:00
|
|
|
import _ "git.tebibyte.media/sashakoshka/stone/backends/x"
|
2022-10-31 13:51:28 -06:00
|
|
|
|
2022-11-11 20:30:59 -07:00
|
|
|
var application = &stone.Application { }
|
|
|
|
var currentTime = time.Time { }
|
|
|
|
|
2022-10-31 13:51:28 -06:00
|
|
|
func main () {
|
2022-11-10 00:02:08 -07:00
|
|
|
application.SetTitle("hellorld")
|
|
|
|
application.SetSize(12, 2)
|
|
|
|
|
|
|
|
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-16 09:08:30 -07:00
|
|
|
application.OnStart(onStart)
|
|
|
|
application.OnResize(onResize)
|
2022-11-06 12:17:43 -07:00
|
|
|
|
2022-11-16 09:08:30 -07:00
|
|
|
err = application.Run()
|
|
|
|
if err != nil { panic(err) }
|
|
|
|
}
|
|
|
|
|
|
|
|
func onStart () {
|
2022-11-11 20:30:59 -07:00
|
|
|
redraw()
|
|
|
|
go tick()
|
2022-11-16 09:08:30 -07:00
|
|
|
}
|
2022-11-09 13:52:49 -07:00
|
|
|
|
2022-11-16 09:08:30 -07:00
|
|
|
func onResize () {
|
|
|
|
redraw()
|
2022-10-31 13:51:28 -06:00
|
|
|
}
|
2022-11-11 20:30:59 -07:00
|
|
|
|
|
|
|
func redraw () {
|
|
|
|
currentTime = time.Now()
|
|
|
|
|
2022-11-15 15:41:08 -07:00
|
|
|
application.SetDot(0, 0)
|
2022-11-11 20:30:59 -07:00
|
|
|
fmt.Fprintln(application, "hellorld!")
|
|
|
|
|
|
|
|
hour := currentTime.Hour()
|
|
|
|
minute := currentTime.Minute()
|
|
|
|
second := currentTime.Second()
|
|
|
|
|
|
|
|
application.SetRune(0, 1, rune(hour / 10 + 48))
|
|
|
|
application.SetRune(1, 1, rune(hour % 10 + 48))
|
|
|
|
application.SetRune(2, 1, ':')
|
|
|
|
application.SetRune(3, 1, rune(minute / 10 + 48))
|
|
|
|
application.SetRune(4, 1, rune(minute % 10 + 48))
|
|
|
|
application.SetRune(5, 1, ':')
|
|
|
|
application.SetRune(6, 1, rune(second / 10 + 48))
|
|
|
|
application.SetRune(7, 1, rune(second % 10 + 48))
|
|
|
|
}
|
|
|
|
|
|
|
|
func tick () {
|
|
|
|
for {
|
2022-11-16 09:08:30 -07:00
|
|
|
redraw()
|
|
|
|
application.Draw()
|
2022-11-11 20:30:59 -07:00
|
|
|
time.Sleep(time.Second)
|
|
|
|
}
|
|
|
|
}
|