]> Pileus Git - lackey/blob - view/day.c
37f9e2f4b6d7d289f6144dec9ad2578e5bb922ea
[lackey] / view / day.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 <ncurses.h>
19
20 #include "date.h"
21
22 /* Static data */
23 static WINDOW *win;
24
25 /* Day init */
26 void day_init(WINDOW *_win)
27 {
28         win = _win;
29 }
30
31 /* Day size */
32 void day_size(int rows, int cols)
33 {
34 }
35
36 /* Day draw */
37 void day_draw(void)
38 {
39         const char *mstr = month_to_string(MONTH);
40         const char *dstr = day_to_string(day_of_week(YEAR, MONTH, DAY));
41
42         /* Clear */
43         werase(win);
44
45         /* Print Header */
46         mvwprintw(win, 0, 0, "%s, %s %d", dstr, mstr, DAY+1);
47         mvwprintw(win, 0, COLS-10, "%d-%02d-%02d", YEAR, MONTH, DAY+1);
48         mvwhline(win, 1, 0, ACS_HLINE, COLS);
49
50         /* Print times */
51         int start = 8;
52         for (int h = 0; h < (LINES-5)/4+1; h++)
53                 mvwprintw(win, 2+h*4, 0,"%02d:%02d", (start+h)%12, 0);
54         mvwvline(win, 2, 5, ACS_VLINE, LINES-4);
55 }
56
57 /* Day run */
58 int day_run(int key, mmask_t btn, int row, int col)
59 {
60         int days = 0;
61         switch (key)
62         {
63                 case 'h': days = -1; break;
64                 case 'l': days =  1; break;
65                 case 'i': days = -7; break;
66                 case 'o': days =  7; break;
67         }
68         if (days) {
69                 add_days(&YEAR, &MONTH, &DAY, days);
70                 day_draw();
71                 wrefresh(win);
72         }
73         return 0;
74 }