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/>.
28 void month_init(WINDOW *_win)
36 const char *name = month_to_string(MONTH);
37 const int start = start_of_month(YEAR, MONTH);
38 const int days = days_in_month(YEAR, MONTH);
39 const int weeks = weeks_in_month(YEAR, MONTH);
40 const float midpt = (float)COLS/2.0 - (strlen(name) + 1 + 4)/2.0;
41 const float hstep = (float)COLS/7.0;
42 const float vstep = (float)(LINES-4)/weeks;
45 mvwprintw(win, 0, midpt, "%s %d", name, YEAR);
46 for (int d = 0; d < 7; d++) {
47 const char *str = hstep >= 10 ? day_to_string(d+SUN) : day_to_str(d+SUN);
48 mvwprintw(win, 1, ROUND(d*hstep), "%s", str);
50 mvwhline(win, 2, 0, ACS_HLINE, COLS);
53 for (int d = 0; d < days; d++) {
54 int row = (start + d) / 7;
55 int col = (start + d) % 7;
56 mvwprintw(win, ROUND(3+row*vstep), ROUND(col*hstep), "%d", d+1);
60 for (int w = 1; w < weeks; w++)
61 mvwhline(win, ROUND(2+w*vstep), 0, ACS_HLINE, COLS);
62 for (int d = 1; d < 7; d++) {
63 int top = d >= start ? 0 : 1;
64 int bot = d <= (start+days)%7 ? weeks : weeks-1;
65 mvwvline(win, ROUND(3+top*vstep), ROUND(d*hstep-1),
66 ACS_VLINE, (bot-top)*vstep);
67 for (int w = 1; w < weeks; w++) {
68 int chr = w == top ? ACS_TTEE :
69 w == bot ? ACS_BTEE : ACS_PLUS;
70 mvwaddch(win, ROUND(2+w*vstep), ROUND(d*hstep-1), chr);
76 int month_run(int key, mmask_t btn, int row, int col)