7 #define ROUND(x) ((int)((x)+0.5))
13 const static int YEAR = 2012;
14 const static int MONTH = SEP;
15 const static int DAY = 29;
18 void month_init(WINDOW *_win)
26 const char *name = month_to_string(MONTH);
27 const int start = start_of_month(YEAR, MONTH);
28 const int days = days_in_month(YEAR, MONTH);
29 const int weeks = weeks_in_month(YEAR, MONTH);
30 const float midpt = (float)COLS/2.0 - (strlen(name) + 1 + 4)/2.0;
31 const float hstep = (float)COLS/7.0;
32 const float vstep = (float)(LINES-4)/weeks;
35 mvwprintw(win, 0, midpt, "%s %d", name, YEAR);
36 for (int d = 0; d < 7; d++)
37 mvwprintw(win, 1, ROUND(d*hstep), "%s", day_to_str(d+SUN));
38 mvwhline(win, 2, 0, ACS_HLINE, COLS);
41 for (int d = 0; d < days; d++) {
42 int row = (start + d) / 7;
43 int col = (start + d) % 7;
44 mvwprintw(win, ROUND(3+row*vstep), ROUND(col*hstep), "%d", d+1);
48 for (int w = 1; w < weeks; w++)
49 mvwhline(win, ROUND(2+w*vstep), 0, ACS_HLINE, COLS);
50 for (int d = 1; d < 7; d++) {
51 int top = d >= start ? 0 : 1;
52 int bot = d <= (start+days)%7 ? weeks : weeks-1;
53 mvwvline(win, ROUND(3+top*vstep), ROUND(d*hstep-1),
54 ACS_VLINE, (bot-top)*vstep);
55 for (int w = 1; w < weeks; w++) {
56 int chr = w == top ? ACS_TTEE :
57 w == bot ? ACS_BTEE : ACS_PLUS;
58 mvwaddch(win, ROUND(2+w*vstep), ROUND(d*hstep-1), chr);
64 int month_run(int key, mmask_t btn, int row, int col)