Version 0.7.4.
[cboard.git] / src / window.h
blob617e5f59ea617d570e1b8914719de9a9dbd108f8
1 /* vim:tw=78:ts=8:sw=4:set ft=c: */
2 /*
3 Copyright (C) 2002-2018 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 - (int)wcslen (str) / 2))
28 #define CENTER_INT(x, n) (x / 2 - n / 2)
30 typedef struct window_s WIN;
31 typedef int (window_func) (WIN *);
32 typedef void (window_exit_func) (WIN *);
33 typedef void (window_resize_func) (WIN *);
35 struct window_s
37 WINDOW *w;
38 PANEL *p;
39 int rows;
40 int cols;
41 int posy;
42 int posx;
43 char *title;
45 * Function that is called when a key is pressed from game_loop(). This is
46 * the only place where a key is gotten from. This is for the top window
47 * (LIFO). When the function returns -1, the window is destroyed and the
48 * top becomes top - 1.
50 window_func *func;
51 window_exit_func *efunc;
52 window_resize_func *rfunc;
53 void *data;
54 wint_t c;
55 int keep;
56 int freedata; // Whether or not to free() .data when destroying
59 WIN **wins;
60 wint_t pushkey;
62 WIN *window_create (const char *title, int h, int w, int y, int x,
63 window_func, void *data, window_exit_func,
64 window_resize_func);
65 void window_destroy (WIN *);
66 void window_draw_title (WINDOW *, const char *, int, chtype, chtype);
67 void window_draw_prompt (WINDOW *, int, int, const char *, chtype);
68 void window_resize_all ();
70 #endif