2 * Copyright (C) 2012 Andy Spencer <andy753421@gmail.com>
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.
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.
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/>.
18 #define _XOPEN_SOURCE_EXTENDED
30 void week_init(WINDOW *_win)
40 const float hstep = (float)(COLS-x)/7.0;
45 /* Get start of week */
47 month_t month = MONTH;
49 int shift = day_of_week(year, month, day);
50 add_days(&year, &month, &day, -shift);
53 mvwprintw(win, 1, 0, "%s", month_to_str(MONTH));
54 for (int d = 0; d < 7; d++) {
55 const char *str = hstep >= 10 ? day_to_string(d) : day_to_str(d);
56 if (d == shift) wattron(win, A_BOLD);
57 mvwprintw(win, 0, x+ROUND(d*hstep), "%02d/%02d", month+1, day+1);
58 mvwprintw(win, 1, x+ROUND(d*hstep), "%s", str);
59 if (d == shift) wattroff(win, A_BOLD);
60 add_days(&year, &month, &day, 1);
65 for (int h = 0; h < (LINES-6)/4+1; h++)
66 mvwprintw(win, 3+h*4, 0,"%02d:%02d", (start+h)%12, 0);
69 mvwhline(win, y-1, 0, ACS_HLINE, COLS);
70 for (int d = 0; d < 7; d++)
71 mvwvline(win, y, x+ROUND(d*hstep)-1, ACS_VLINE, LINES-y-2);
74 int l = x+ROUND((shift+0)*hstep)-1;
75 int r = x+ROUND((shift+1)*hstep)-1;
76 mvwhline (win, y-1, l, ACS_BLOCK, r-l+1);
77 mvwvline_set(win, y, l, WACS_T_VLINE, LINES-y-2);
78 mvwvline_set(win, y, r, WACS_T_VLINE, LINES-y-2);
82 int week_run(int key, mmask_t btn, int row, int col)
87 case 'h': days = -1; break;
88 case 'l': days = 1; break;
89 case 'i': days = -7; break;
90 case 'o': days = 7; break;
93 add_days(&YEAR, &MONTH, &DAY, days);