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
36 void week_init(WINDOW *_win)
38 win = _win; // lines cols y x
39 head = derwin(win, 2, COLS, 0, 0);
40 times = derwin(win, LINES-2-3, 5, 3, 0);
41 body = derwin(win, LINES-2-3, COLS-6, 3, 6);
46 void week_size(int rows, int cols)
48 wresize(head, 2, cols );
49 wresize(times, rows-3, 5);
50 wresize(body, rows-3, cols-6);
58 const float hstep = (float)(COLS-x)/7.0;
60 /* Get start of week */
62 month_t month = MONTH;
64 int shift = day_of_week(year, month, day);
65 add_days(&year, &month, &day, -shift);
68 mvwprintw(head, 0, 0, "%s", month_to_str(MONTH));
69 mvwprintw(head, 1, 0, "%04d", YEAR);
70 for (int d = 0; d < 7; d++) {
71 const char *str = hstep >= 10 ? day_to_string(d) : day_to_str(d);
72 if (d == shift) wattron(head, A_BOLD);
73 mvwprintw(head, 0, x+ROUND(d*hstep), "%s", str);
74 mvwprintw(head, 1, x+ROUND(d*hstep), "%02d/%02d", month+1, day+1);
75 if (d == shift) wattroff(head, A_BOLD);
76 add_days(&year, &month, &day, 1);
80 mvwprintw(times, 0, 0, "%02d:%02d", ((line/4)-1)%12+1, (line*15)%60);
81 for (int h = 0; h < 24; h++)
82 mvwprintw(times, h*4-line, 0, "%02d:%02d", (h-1)%12+1, 0);
85 event_t *event = EVENTS;
86 add_days(&year, &month, &day, -7);
87 for (int d = 0; d < 7; d++, add_days(&year,&month,&day,1))
88 for (int h = 0; h < 24; h++)
89 for (int m = 0; m < 60; m+=15)
90 while (event && before(&event->start,
91 year, month, day, h+(m+15)/60, (m+15)%60)) {
92 if (!before(&event->start, year, month, day, h, m)) {
93 int y = h*4 + m/15 - line;
94 int x = ROUND(d*hstep);
95 int h = (get_mins(&event->start, &event->end)-1)/15+1;
96 int w = ROUND((d+1)*hstep) - 1 - x;
97 event_box(body, event, y, x, h, w);
103 mvwhline(win, y-1, 0, ACS_HLINE, COLS);
104 for (int d = 0; d < 7; d++)
105 mvwvline(win, y, x+ROUND(d*hstep)-1, ACS_VLINE, LINES-y-2);
109 int l = x+ROUND((shift+0)*hstep)-1;
110 int r = x+ROUND((shift+1)*hstep)-1;
111 mvwhline (win, y-1, l, ACS_BLOCK, r-l+1);
112 mvwvline_set(win, y, l, WACS_T_VLINE, LINES-y-2);
113 mvwvline_set(win, y, r, WACS_T_VLINE, LINES-y-2);
114 for (int h = (line+3)/4; h < 24; h++) {
115 mvwadd_wch(win, y+h*4-line, l, WACS_T_LTEE);
116 mvwadd_wch(win, y+h*4-line, r, WACS_T_RTEE);
121 int week_run(int key, mmask_t btn, int row, int col)
123 int days = 0, ref = 0;
126 case 'h': ref = 1; days = -1; break;
127 case 'l': ref = 1; days = 1; break;
128 case 'i': ref = 1; days = -7; break;
129 case 'o': ref = 1; days = 7; break;
130 case 'k': ref = 1; line--; break;
131 case 'j': ref = 1; line++; break;
133 line = CLAMP(line, 0, 24*4);
135 add_days(&YEAR, &MONTH, &DAY, days);