Update copyright year to 2015.
[cboard.git] / src / window.h
blob91888dfa6ee27d2bdd9f266853cb9054c9ad65ac
1 /* vim:tw=78:ts=8:sw=4:set ft=c: */
2 /*
3 Copyright (C) 2002-2015 Ben Kibbey <bjk@luxsci.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef WINDOW_H
20 #define WINDOW_H
22 #define WINDOW_TIMEOUT 70
23 #define CTRL_KEY(x) ((x) & 0x1f)
24 #define KEY_ESCAPE CTRL_KEY('[')
25 #define CALCPOSY(y) ((y > LINES - 1) ? 0 : LINES / 2 - y / 2)
26 #define CALCPOSX(x) (COLS / 2 - x / 2)
27 #define CENTERX(x, str) abs((x / 2 - wcslen (str) / 2))
28 #define CENTER_INT(x, n) abs((x / 2 - n / 2))
30 typedef struct window_s WIN;
31 typedef int (window_func) (WIN *);
32 typedef void (window_exit_func) (WIN *);
34 struct window_s {
35 WINDOW *w;
36 PANEL *p;
37 int rows;
38 int cols;
39 int posy;
40 int posx;
41 char *title;
43 * Function that is called when a key is pressed from game_loop(). This is
44 * the only place where a key is gotten from. This is for the top window
45 * (LIFO). When the function returns -1, the window is destroyed and the
46 * top becomes top - 1.
48 window_func *func;
49 window_exit_func *efunc;
50 void *data;
51 wint_t c;
52 int keep;
53 int freedata; // Whether or not to free() .data when destroying
56 WIN **wins;
57 wint_t pushkey;
59 WIN *window_create(const char *title, int h, int w, int y, int x, window_func,
60 void *data, window_exit_func);
61 void window_destroy(WIN *);
62 void window_draw_title(WINDOW *, const char *, int, chtype, chtype);
63 void window_draw_prompt(WINDOW *, int, int, const char *, chtype);
65 #endif