stonecal/event.go

105 lines
1.7 KiB
Go

package main
import "time"
import "git.tebibyte.media/sashakoshka/stone"
func onScroll (x, y int) {
drawMutex.Lock()
defer drawMutex.Unlock()
viewingMonth += y * columns
application.Clear()
redraw()
application.Draw()
}
func onPress (button stone.Button, modifiers stone.Modifiers) {
switch button {
case stone.KeyUp:
drawMutex.Lock()
defer drawMutex.Unlock()
viewingMonth -= columns
application.Clear()
redraw()
application.Draw()
case stone.KeyDown:
drawMutex.Lock()
defer drawMutex.Unlock()
viewingMonth += columns
application.Clear()
redraw()
application.Draw()
case stone.KeyPageUp:
drawMutex.Lock()
defer drawMutex.Unlock()
viewingMonth -= columns * rows
application.Clear()
redraw()
application.Draw()
case stone.KeyPageDown:
drawMutex.Lock()
defer drawMutex.Unlock()
viewingMonth += columns * rows
application.Clear()
redraw()
application.Draw()
}
}
func onStart () {
drawMutex.Lock()
defer drawMutex.Unlock()
currentMonth = canonMonth(time.Now())
viewingMonth = currentMonth
redraw()
go func () {
for {
time.Sleep(time.Second)
onTick()
}
} ()
}
func onResize () {
drawMutex.Lock()
defer drawMutex.Unlock()
redraw()
}
func onTick () {
drawMutex.Lock()
defer drawMutex.Unlock()
pageSize := columns * rows
within :=
currentMonth >= viewingMonth &&
currentMonth < viewingMonth + pageSize
newMonth := canonMonth(time.Now())
if currentMonth != newMonth {
currentMonth = newMonth
if within {
if currentMonth < viewingMonth {
viewingMonth -= pageSize
} else if currentMonth >= viewingMonth + pageSize {
viewingMonth += pageSize
}
}
application.Clear()
redraw()
application.Draw()
}
}