]> Pileus Git - lackey/blob - view/week.c
Fix some time keeping bugs
[lackey] / view / week.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 /* Week init */
28 void week_init(WINDOW *_win)
29 {
30         win = _win;
31 }
32
33 /* Week draw */
34 void week_draw(void)
35 {
36         int x = 6;
37         int y = 3;
38         const float hstep = (float)(COLS-x)/5.0;
39
40         /* Get start of week */
41         year_t  year  = YEAR;
42         month_t month = MONTH;
43         day_t   day   = DAY;
44         int shift = day_of_week(year, month, day);
45         add_days(&year, &month, &day, -shift+MON);
46
47         /* Print Header */
48         mvwprintw(win, 1, 0, "%s", month_to_str(MONTH));
49         for (int d = 0; d < 5; d++) {
50                 // FIXME..
51                 const char *str = hstep >= 10 ? day_to_string(d+MON) : day_to_str(d+MON);
52                 mvwprintw(win, 0, x+ROUND(d*hstep), "%02d/%02d", month+1, day+1);
53                 mvwprintw(win, 1, x+ROUND(d*hstep), "%s", str);
54                 add_days(&year, &month, &day, 1);
55         }
56
57         /* Print times */
58         int start = 8;
59         for (int h = 0; h < (LINES-6)/4+1; h++)
60                 mvwprintw(win, 3+h*4, 0,"%02d:%02d", (start+h)%12, 0);
61
62         /* Print lines */
63         mvwhline(win, y-1, 0, ACS_HLINE, COLS);
64         for (int d = 0; d < 5; d++)
65                 mvwvline(win, y, x+ROUND(d*hstep)-1, ACS_VLINE, LINES-y-2);
66 }
67
68 /* Week run */
69 int week_run(int key, mmask_t btn, int row, int col)
70 {
71         return 0;
72 }