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/>.
27 void (*init)(WINDOW*);
29 int (*run)(int,mmask_t,int,int);
36 { "Day", day_init, day_draw, day_run, {KEY_F(1), '1', } },
37 { "Week", week_init, week_draw, week_run, {KEY_F(2), '2', } },
38 { "Month", month_init, month_draw, month_run, {KEY_F(3), '3', } },
39 { "Year", year_init, year_draw, year_run, {KEY_F(4), '4', } },
40 { "|", NULL, NULL, NULL, { } },
41 { "Todo", todo_init, todo_draw, todo_run, {KEY_F(5), '5', } },
42 { "Notes", notes_init, notes_draw, notes_run, {KEY_F(6), '6', } },
43 { "|", NULL, NULL, NULL, { } },
44 { "Settings", settings_init, settings_draw, settings_run, {KEY_F(7), '7', } },
45 { "Help", help_init, help_draw, help_run, {KEY_F(8), '8', '?'} },
51 void draw_header(void)
54 attron(COLOR_PAIR(COLOR_TITLE));
55 for (int i = 0; i < N_ELEMENTS(views); i++) {
58 printw("%s ", views[i].name);
62 attroff(COLOR_PAIR(COLOR_TITLE));
63 mvhline(1, 0, ACS_HLINE, COLS);
68 void screen_init(void)
70 for (int i = 0; i < N_ELEMENTS(views); i++) {
72 views[i].win = newwin(LINES-2, COLS, 2, 0);
73 views[i].init(views[i].win);
79 void screen_resize(void)
81 for (int i = 0; i < N_ELEMENTS(views); i++)
83 wresize(views[i].win, LINES-2, COLS);
87 void screen_draw(void)
90 werase(views[active].win);
92 wrefresh(views[active].win);
96 int screen_set(int num)
106 int screen_run(int key, mmask_t btn, int row, int col)
108 /* Check for mouse events */
109 if (key == KEY_MOUSE && row == 0) {
111 for (int i = 0; i < N_ELEMENTS(views); i++) {
112 int end = start + strlen(views[i].name) - 1;
113 if (start <= col && col <= end && views[i].draw)
114 return screen_set(i);
119 /* Check for view change */
120 for (int i = 0; i < N_ELEMENTS(views); i++) {
123 for (int j = 0; j < N_ELEMENTS(views[i].keys); j++)
124 if (views[i].keys[j] == key)
125 return screen_set(i);
130 int shift = key == KEY_RIGHT ? +1 :
131 key == KEY_LEFT ? -1 : 0;
134 num += N_ELEMENTS(views);
135 num %= N_ELEMENTS(views);
137 return screen_set(num);
140 /* Pass key to active view */
141 return views[active].run(key, btn, row, col);