2 * Copyright (C) 2012-2013 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/>.
31 void events_init(WINDOW *_win)
37 void events_size(int rows, int cols)
42 void events_draw(void)
47 date_t start = {SEL.year, SEL.month, SEL.day, 0, 0};
48 date_t cur = {SEL.year, SEL.month, SEL.day-1, 0, 0};
49 date_t end = {SEL.year, SEL.month, SEL.day, 24, 0};
50 add_days(&end.year, &end.month, &end.day, days);
51 cal_load(SEL.year, SEL.month, SEL.day, days);
55 event_t *event = EVENTS;
56 while (event && (count < min || compare(&event->start, &end) < 0)) {
57 if (compare(&start, &event->start) <= 0) {
58 date_t next = event->start;
59 int newdate = cur.year != next.year ||
60 cur.month != next.month ||
62 int newtime = cur.hour != next.hour ||
64 if ((newdate || newtime) && row != 0)
66 if (newdate && row != 0)
69 wday_t wday = day_of_week(next.year, next.month, next.day);
71 mvwprintw(win, row-line, 0, "%04d-%02d-%02d",
72 next.year, next.month+1, next.day+1);
73 mvwprintw(win, row-line, 13, "%s, %s %d",
74 day_to_string(wday), month_to_string(next.month), next.day);
75 wattroff(win, A_BOLD);
78 event_line(win, event, row++-line, 4, COLS-4, SHOW_DETAILS);
79 if (event->name && event->desc)
80 mvwprintw(win, row++-line, 14, "%s", event->desc);
90 int events_run(int key, mmask_t btn, int row, int col)
95 case 'g': scroll = -line; break;
96 case 'G': scroll = rows; break;
97 case 'j': scroll = 1; break;
98 case 'k': scroll = -1; break;
99 case 'd': scroll = LINES/2; break;
100 case 'u': scroll = -LINES/2; break;
101 case 'D': scroll = LINES; break;
102 case 'U': scroll = -LINES; break;
104 line = CLAMP(line+scroll, 0, rows-1);