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 (*init)(WINDOW*);
29 void (*size)(int,int);
31 int (*run)(int,mmask_t,int,int);
38 { "Day", day_init, day_size, day_draw, day_run, {KEY_F(1), '1', } },
39 { "Week", week_init, week_size, week_draw, week_run, {KEY_F(2), '2', } },
40 { "Month", month_init, month_size, month_draw, month_run, {KEY_F(3), '3', } },
41 { "Year", year_init, year_size, year_draw, year_run, {KEY_F(4), '4', } },
42 { "|", NULL, NULL, NULL, NULL, { } },
43 { "Todo", todo_init, todo_size, todo_draw, todo_run, {KEY_F(5), '5', } },
44 { "Notes", notes_init, notes_size, notes_draw, notes_run, {KEY_F(6), '6', } },
45 { "|", NULL, NULL, NULL, NULL, { } },
46 { "Settings", settings_init, settings_size, settings_draw, settings_run, {KEY_F(7), '7', } },
47 { "Help", help_init, help_size, help_draw, help_run, {KEY_F(8), '8', '?'} },
53 void draw_header(void)
56 attron(COLOR_PAIR(COLOR_TITLE));
57 for (int i = 0; i < N_ELEMENTS(views); i++) {
60 printw("%s ", views[i].name);
64 attroff(COLOR_PAIR(COLOR_TITLE));
65 mvhline(1, 0, ACS_HLINE, COLS);
70 void screen_init(void)
72 for (int i = 0; i < N_ELEMENTS(views); i++) {
74 views[i].win = newwin(LINES-2, COLS, 2, 0);
75 views[i].init(views[i].win);
81 void screen_resize(void)
83 for (int i = 0; i < N_ELEMENTS(views); i++) {
85 wresize(views[i].win, LINES-2, COLS);
87 views[i].size(LINES-2, COLS);
92 void screen_draw(void)
95 werase(views[active].win);
97 wrefresh(views[active].win);
101 int screen_set(int num)
111 int screen_run(int key, mmask_t btn, int row, int col)
113 /* Check for mouse events */
114 if (key == KEY_MOUSE && row == 0) {
116 for (int i = 0; i < N_ELEMENTS(views); i++) {
117 int end = start + strlen(views[i].name) - 1;
118 if (start <= col && col <= end && views[i].draw)
119 return screen_set(i);
124 /* Check for view change */
125 for (int i = 0; i < N_ELEMENTS(views); i++) {
128 for (int j = 0; j < N_ELEMENTS(views[i].keys); j++)
129 if (views[i].keys[j] == key)
130 return screen_set(i);
135 int shift = key == KEY_RIGHT ? +1 :
136 key == KEY_LEFT ? -1 : 0;
139 num += N_ELEMENTS(views);
140 num %= N_ELEMENTS(views);
142 return screen_set(num);
145 /* Pass key to active view */
146 return views[active].run(key, btn, row, col);