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/>.
32 /* Helper functions */
33 static void print_month(month_t month, int y, int x)
35 event_t *event = EVENTS;
36 const char *name = month_to_string(month);
37 const int start = start_of_month(YEAR, month);
38 const char days = days_in_month(YEAR, month);
39 mvwprintw(win, y, x+MW/2-strlen(name)/2, "%s", name);
41 for (int d = 0; d < 7; d++)
42 wprintw(win, "%-3s", day_to_st(d));
43 for (int d = 0; d < days; d++) {
44 int row = (start + d) / 7;
45 int col = (start + d) % 7;
48 while (event && before(&event->start, YEAR, month, d, 24, 0)) {
49 if (!before(&event->start, YEAR, month, d, 0, 0))
54 int today = month == MONTH && d == DAY;
56 int attr = (busy ? A_BOLD|A_UNDERLINE : A_DIM)
57 | (today ? A_REVERSE : 0 );
60 mvwprintw(win, y+2+row, x+col*3, "%2d", d+1);
66 void year_init(WINDOW *_win)
72 void year_size(int rows, int cols)
84 /* Determine heights */
85 for (int m = 0; m < 12; m++) {
86 int weeks = weeks_in_month(YEAR, m);
87 h[m/3] = MAX(h[m/3], weeks+2);
89 int sum = h[0]+h[1]+h[2]+h[3];
92 if (COMPACT) wattron(win, A_REVERSE | A_BOLD);
93 if (COMPACT) mvwhline(win, y, 0, A_REVERSE | A_BOLD, COLS);
94 mvwprintw(win, y++, COLS/2-2, "%d", YEAR);
95 if (COMPACT) wattroff(win, A_REVERSE | A_BOLD);
98 for (int m = 0; m < 12; m++) {
110 mvwvline(win, y, x+(MW+3)*1-2, ACS_VLINE, sum+3);
111 mvwvline(win, y, x+(MW+3)*2-2, ACS_VLINE, sum+3);
112 for (int i = 0; i < 3; i++) {
114 mvwhline(win, y, x, ACS_HLINE, w);
115 mvwaddch(win, y, x+(MW+3)*1-2, ACS_PLUS);
116 mvwaddch(win, y, x+(MW+3)*2-2, ACS_PLUS);
122 int year_run(int key, mmask_t btn, int row, int col)
127 wday_t day = day_of_week(YEAR, MONTH, DAY);
128 int week = (start_of_month(y, m) + d) / 7;
138 if (key == 'h' || key == 'k')
140 if (key == 'j' || key == 'l')
144 if (key == 'j' || key == 'k') {
145 for (int i = 0; i < 90/7; i++) {
146 add_days(&y, &m, &d, dir*7);
147 if (day_of_week(y, m, d) == day &&
148 y == YEAR && m%3 == MONTH%3) {
156 /* Step left/right */
157 if (key == 'h' || key == 'l') {
158 for (int i = 0; i < 90; i++) {
159 add_days(&y, &m, &d, dir);
160 if ((start_of_month(y, m) + d) / 7 == week &&
161 y == YEAR && m/3 == MONTH/3) {
170 if (dir || y != YEAR) {
175 return dir || y != YEAR;