]> Pileus Git - lackey/blob - view/month.c
fb2be064a2612e38a39ffd8a555840aec161f86b
[lackey] / view / month.c
1 /*
2  * Copyright (C) 2012 Andy Spencer <andy753421@gmail.com>
3  * 
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  * 
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 #include <string.h>
19 #include <ncurses.h>
20
21 #include "main.h"
22 #include "util.h"
23
24 /* Static data */
25 static WINDOW *win;
26
27 /* Month init */
28 void month_init(WINDOW *_win)
29 {
30         win = _win;
31 }
32
33 /* Month draw */
34 void month_draw(void)
35 {
36         const char *name  = month_to_string(MONTH);
37         const int   start = start_of_month(YEAR, MONTH);
38         const int   days  = days_in_month(YEAR, MONTH);
39         const int   weeks = weeks_in_month(YEAR, MONTH);
40         const float midpt = (float)COLS/2.0 - (strlen(name) + 1 + 4)/2.0;
41         const float hstep = (float)COLS/7.0;
42         const float vstep = (float)(LINES-4)/weeks;
43
44         /* Print Header */
45         mvwprintw(win, 0, midpt, "%s %d", name, YEAR);
46         for (int d = 0; d < 7; d++) {
47                 const char *str = hstep >= 10 ? day_to_string(d+SUN) : day_to_str(d+SUN);
48                 mvwprintw(win, 1, ROUND(d*hstep), "%s", str);
49         }
50         mvwhline(win, 2, 0, ACS_HLINE, COLS);
51
52         /* Print days */
53         for (int d = 0; d < days; d++) {
54                 int row = (start + d) / 7;
55                 int col = (start + d) % 7;
56                 mvwprintw(win, ROUND(3+row*vstep), ROUND(col*hstep), "%d", d+1);
57         }
58
59         /* Print lines */
60         for (int w = 1; w < weeks; w++)
61                 mvwhline(win, ROUND(2+w*vstep), 0, ACS_HLINE, COLS);
62         for (int d = 1; d < 7; d++) {
63                 int top = d >=  start         ? 0     : 1;
64                 int bot = d <= (start+days)%7 ? weeks : weeks-1;
65                 mvwvline(win, ROUND(3+top*vstep), ROUND(d*hstep-1),
66                                 ACS_VLINE, (bot-top)*vstep);
67                 for (int w = 1; w < weeks; w++) {
68                         int chr = w == top ? ACS_TTEE :
69                                   w == bot ? ACS_BTEE : ACS_PLUS;
70                         mvwaddch(win, ROUND(2+w*vstep), ROUND(d*hstep-1), chr);
71                 }
72         }
73 }
74
75 /* Month run */
76 int month_run(int key, mmask_t btn, int row, int col)
77 {
78         return 0;
79 }