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/>.
33 void events_init(WINDOW *_win)
39 void events_size(int rows, int cols)
44 void events_draw(void)
49 date_t start = {YEAR, MONTH, DAY, 0, 0};
50 date_t cur = {YEAR, MONTH, DAY-1, 0, 0};
51 date_t end = {YEAR, MONTH, DAY, 24, 0};
52 add_days(&end.year, &end.month, &end.day, days);
53 cal_load(YEAR, MONTH, DAY, days);
57 event_t *event = EVENTS;
58 while (event && (count < min || compare(&event->start, &end) < 0)) {
59 if (compare(&start, &event->start) <= 0) {
60 date_t next = event->start;
61 int newdate = cur.year != next.year ||
62 cur.month != next.month ||
64 int newtime = cur.hour != next.hour ||
66 if ((newdate || newtime) && row != 0)
68 if (newdate && row != 0)
71 wday_t wday = day_of_week(next.year, next.month, next.day);
72 wattron(win, A_UNDERLINE);
73 mvwprintw(win, row-line, 0, "%04d-%02d-%02d",
74 next.year, next.month+1, next.day+1);
75 mvwprintw(win, row-line, 13, "%s, %s %d",
76 day_to_string(wday), month_to_string(next.month), next.day);
77 wattroff(win, A_UNDERLINE);
80 event_line(win, event, row++-line, 4, COLS-2, 1);
81 if (event->name && event->desc)
82 mvwprintw(win, row++-line, 14, "%s", event->desc);
92 int events_run(int key, mmask_t btn, int row, int col)
97 case 'g': scroll = -line; break;
98 case 'G': scroll = rows; break;
99 case 'j': scroll = 1; break;
100 case 'k': scroll = -1; break;
101 case 'd': scroll = LINES/2; break;
102 case 'u': scroll = -LINES/2; break;
103 case 'D': scroll = LINES; break;
104 case 'U': scroll = -LINES; break;
106 line = CLAMP(line+scroll, 0, rows-1);