]> Pileus Git - lackey/blob - src/view/year.c
Add day and week view
[lackey] / src / view / year.c
1 #include <string.h>
2 #include <ncurses.h>
3
4 #include "main.h"
5 #include "util.h"
6
7 /* Constants */
8 #define MW (2*7+6)
9
10 /* Static data */
11 static WINDOW *win;
12
13 /* Helper functions */
14 static void print_month(month_t month, int y, int x)
15 {
16         const char *name  = month_to_string(month);
17         const int   start = start_of_month(YEAR, month);
18         const char  days  = days_in_month(YEAR, month);
19         mvwprintw(win, y, x+MW/2-strlen(name)/2, "%s", name);
20         wmove(win, y+1, x);
21         for (int d = 0; d < 7; d++)
22                 wprintw(win, "%-3s", day_to_st(d));
23         for (int d = 0; d < days; d++) {
24                 int row = (start + d) / 7;
25                 int col = (start + d) % 7;
26                 mvwprintw(win, y+2+row, x+col*3, "%d", d+1);
27         }
28 }
29
30 /* Year init */
31 void year_init(WINDOW *_win)
32 {
33         win = _win;
34 }
35
36 /* Year draw */
37 void year_draw(void)
38 {
39         int w = MW*3 + 2*3;
40         int x = COLS/2 - w/2;
41         int y = 0;
42         int h[4] = {};
43
44         /* Determine heights */
45         for (int m = 0; m < 12; m++) {
46                 int weeks = weeks_in_month(YEAR, m);
47                 h[m/3] = MAX(h[m/3], weeks+2);
48         }
49         int sum = h[0]+h[1]+h[2]+h[3];
50
51         /* Print Header */
52         mvwprintw(win, y++, COLS/2-2, "%d", YEAR);
53
54         /* Print Months */
55         for (int m = 0; m < 12; m++) {
56                 print_month(m, y, x);
57                 if (m % 3 == 2) {
58                         x  = COLS/2 - w/2;
59                         y += h[m/3]+1;
60                 } else {
61                         x += 3+MW;
62                 }
63         }
64
65         /* Print Lines */
66         y = 1;
67         mvwvline(win, y, x+(MW+3)*1-2, ACS_VLINE, sum+3);
68         mvwvline(win, y, x+(MW+3)*2-2, ACS_VLINE, sum+3);
69         for (int i = 0; i < 3; i++) {
70                 y += h[i];
71                 mvwhline(win, y, x,        ACS_HLINE, w);
72                 mvwaddch(win, y, x+(MW+3)*1-2, ACS_PLUS);
73                 mvwaddch(win, y, x+(MW+3)*2-2, ACS_PLUS);
74                 y++;
75         }
76 }
77
78 /* Year run */
79 int year_run(int key, mmask_t btn, int row, int col)
80 {
81         return 0;
82 }