1 /*
2 Copyright (c) 2003 Bruno T. C. de Oliveira
3 
4 LICENSE INFORMATION:
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9 
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 GNU
13 General Public License for more details.
14 
15 You should have received a copy of the GNU General Public
16 License along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18 Copyright (c) 2002 Bruno T. C. de Oliveira
19 
20 INFORMA��ES DE LICEN�A:
21 Este programa � um software de livre distribui��o; voc� pode
22 redistribu�-lo e/ou modific�-lo sob os termos da GNU General
23 Public License, conforme publicado pela Free Software Foundation,
24 pela vers�o 2 da licen�a ou qualquer vers�o posterior.
25 
26 Este programa � distribu�do na esperan�a de que ele ser� �til
27 aos seus usu�rios, por�m, SEM QUAISQUER GARANTIAS; sem sequer
28 a garantia impl�cita de COMERCIABILIDADE ou DE ADEQUA��O A
29 QUALQUER FINALIDADE ESPEC�FICA. Consulte a GNU General Public
30 License para obter mais detalhes (uma c�pia acompanha este
31 programa, armazenada no arquivo COPYING).
32 */
33 
34 
35 #ifndef _btco_bores_kurses_h
36 #define _btco_bores_kurses_h
37 
38 /* Color codes are 4-bit values. The bits are SBGR, where B, G and R are
39  * the blue, green and red components, and the S bit is the bold attribute
40  * for foreground colors, or the blink attribute for background colors.
41  *
42  * Refer to the implementation file for information about how color code
43  * pairs are mapped to curses pairs */
44 
45 /* Initializes curses, sets screen mode, initializes pairs, and so on.  */
46 void kurses_init();
47 
48 /* Finalize curses */
49 void kurses_finalize();
50 
51 /* Sets the active color to (fg, bg). Either can be -1, in which case
52  * the previous value is kept. */
53 void kurses_color(int fg, int bg);
54 
55 /* Same as kurses_color(attr >> 4, attr & 0x0F) */
56 void kurses_color_at(int attr);
57 
58 /* Returns the screen width */
59 int kurses_width();
60 
61 /* Returns the screen height */
62 int kurses_height();
63 
64 /* Moves cursor to position (x, y). Returns true if motion was successful,
65  * false if given coordinates are invalid */
66 int kurses_move(int x, int y);
67 
68 /* Returns whether position x,y falls within screen bounds */
69 int kurses_pos_valid(int x, int y);
70 
71 /* Reads a line of input from the keyboard, storing read characters in
72  * <buf>. At most <buf_size> characters are stored in the buffer.
73  * Interprets the "backspace" and "kill" keys. Returns true if the
74  * user ended input by pressing RETURN; false if the user cancelled
75  * input by means of ESC, Ctrl+C or Ctrl+G. */
76 int kurses_line_input(char *buf, int buf_size);
77 
78 /* Does the same as kurses_line_input, but with an extended feature:
79  * the array skeys of ints specifies special keys; when the user
80  * presses any of those special keys, input will stop and the negative
81  * of the value of the key will be returned. Character '\0' must
82  * be at the end the skeys array. The flags parameter are an OR'ed
83  * combination of the KURSES_LI_* flags defined below.
84  *
85  * If the user cancels input, returns 0.
86  * If the user confirms input without pressing any special key,
87  * returns 1.
88  */
89 int kurses_line_input_ex(char *buf, int buf_size, int* skeys, int flags);
90          #define KURSES_LI_HIDE 1  /* echoes '*' instead of characters */
91 
92 /* Draws a window with the specified position, dimensions and title.
93  * Uses currently active color. After operation, cursor will be
94  * placed on top-left character of CLIENT AREA of window. */
95 void draw_window(int x, int y, int w, int h, const char *title);
96 
97 /* Draws a window centered onscreen. Returns in *x and *y the position
98  * of the top-left character cell within the window's CLIENT AREA,
99  * which is also where the cursor is located after the call. */
100 void draw_centered_window(int w, int h, const char *title, int *x, int *y);
101 
102 /* Draws a horizontal row of <w> characters starting at position x0, y0.
103  * The first character draw will be left_endpt; then character interim
104  * will be drawn w-2 times, then the right_endpt will be drawn. */
105 void draw_hline(int x0, int y0, int w,
106                 int left_endpt, int interim, int right_endpt);
107 
108 /* Same idea as draw_hline, but draws a vertical line instead. */
109 void draw_vline(int x0, int y0, int h,
110                 int upper_endpt, int interim, int lower_endpt);
111 
112 /* Saves a snapshot of the screen (stdscr) onto an internal stack.
113  * That snapshot can be later restored through a call to
114  * pop_screen */
115 void push_screen(void);
116 
117 /* Restores a screen snapshot previously saved with push_screen.
118  * Does NOT pop it from the stack: it will stay there in case
119  * you want to restore it again. To discard it from the stack,
120  * call pop_screen(void)
121  *
122  * Does NOT call refresh; you will have to do that yourself. */
123 void restore_screen(void);
124 
125 /* Removes the top of the internal screen snapshot stack.
126  * Does NOT paint the removed snapshot to the screen. If you
127  * want that, call restore_screen() _before_ calling
128  * pop_screen */
129 void pop_screen(void);
130 
131 
132 #endif
133 
134