stonecal/draw.go

86 lines
2.2 KiB
Go

package main
import "fmt"
import "time"
import "git.tebibyte.media/sashakoshka/stone"
func redraw () {
width, height := application.Size()
state.columns = (width - 20) / 23 + 1
state.rows = height / 10 + 1
state.pageSize = state.columns * state.rows
monthIter := state.viewingMonth
xOffset := (width - state.columns * 23) / 2 + 1
for y := 0; y < state.rows; y ++ {
for x := 0; x < state.columns; x ++ {
drawMonth (
x * 23 + xOffset, y * 10,
monthIter / 12,
time.Month(wrap(monthIter, 12) + 1))
monthIter ++
}
}
}
func drawMonth (xOffset, yOffset, year int, month time.Month) {
current := int(month) - 1 + year * 12 == state.currentMonth
bce := year < 0
if bce { year *= -1 }
var dateString string
dateString = fmt.Sprintf("%d ", year)
if bce { dateString += "BCE " }
dateString += month.String()
application.SetDot(xOffset + (20 - len(dateString)) / 2, yOffset)
fmt.Fprint(application, dateString)
var headerColor stone.Color
if current {
headerColor = stone.ColorRed
} else {
headerColor = stone.ColorForeground
}
for x := xOffset; x < 20 + xOffset; x ++ {
application.SetColor(x, yOffset, headerColor)
}
application.SetDot(xOffset, yOffset + 2)
fmt.Fprint (
application,
"S M T W Þ F S\n")
application.SetColor(xOffset, yOffset + 2, stone.ColorDim)
application.SetColor(xOffset + 18, yOffset + 2, stone.ColorDim)
dayIter := 0 - int(firstOfMonth(year, month).Weekday())
if dayIter <= -6 {
dayIter = 1
}
x, y, weekday := xOffset, yOffset + 3, 0
totalDays := daysInMonth(year, month)
for ; dayIter <= totalDays; dayIter ++ {
if dayIter > 0 {
application.SetDot(x, y)
fmt.Fprint(application, dayIter)
}
if current && dayIter == int(time.Now().Day()) {
application.SetColor(x, y, stone.ColorRed)
application.SetColor(x + 1, y, stone.ColorRed)
application.SetStyle(x , y, stone.StyleHighlight)
application.SetStyle(x + 1, y, stone.StyleHighlight)
} else if weekday == 0 || weekday == 6 {
application.SetColor(x, y, stone.ColorDim)
application.SetColor(x + 1, y, stone.ColorDim)
}
weekday = (weekday + 1) % 7
x += 3
if x > xOffset + 20 {
x = xOffset
y ++
}
}
}