1 | /* |
---|
2 | * libcaca Colour ASCII-Art library |
---|
3 | * Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org> |
---|
4 | * All Rights Reserved |
---|
5 | * |
---|
6 | * $Id: caca.h 810 2006-04-18 12:59:07Z sam $ |
---|
7 | * |
---|
8 | * This library is free software; you can redistribute it and/or |
---|
9 | * modify it under the terms of the Do What The Fuck You Want To |
---|
10 | * Public License, Version 2, as published by Sam Hocevar. See |
---|
11 | * http://sam.zoy.org/wtfpl/COPYING for more details. |
---|
12 | */ |
---|
13 | |
---|
14 | /** \file caca.h |
---|
15 | * \version \$Id: caca.h 810 2006-04-18 12:59:07Z sam $ |
---|
16 | * \author Sam Hocevar <sam@zoy.org> |
---|
17 | * \brief The \e libcaca public header. |
---|
18 | * |
---|
19 | * This header contains the public types and functions that applications |
---|
20 | * using \e libcaca may use. |
---|
21 | */ |
---|
22 | |
---|
23 | /** \mainpage libcaca developer documentation |
---|
24 | * |
---|
25 | * \section intro Introduction |
---|
26 | * |
---|
27 | * \e libcaca is a graphics library that outputs text instead of pixels, |
---|
28 | * so that it can work on older video cards or text terminals. It is not |
---|
29 | * unlike the famous AAlib library. \e libcaca can use almost any virtual |
---|
30 | * terminal to work, thus it should work on all Unix systems (including |
---|
31 | * Mac OS X) using either the slang library or the ncurses library, on DOS |
---|
32 | * using the conio library, and on Windows systems using either slang or |
---|
33 | * ncurses (through Cygwin emulation) or conio. There is also a native X11 |
---|
34 | * driver, and an OpenGL driver (through freeglut) that does not require a |
---|
35 | * text terminal. For machines without a screen, the raw driver can be used |
---|
36 | * to send the output to another machine, using for instance cacaserver. |
---|
37 | * |
---|
38 | * \e libcaca is free software, released under the Do What The Fuck You |
---|
39 | * Want To Public License. This ensures that no one, not even the \e libcaca |
---|
40 | * developers, will ever have anything to say about what you do with the |
---|
41 | * software. It used to be licensed under the GNU Lesser General Public |
---|
42 | * License, but that was not free enough. |
---|
43 | * |
---|
44 | * \section api The libcaca API |
---|
45 | * |
---|
46 | * \e libcaca relies on a low-level, device independent library, called |
---|
47 | * \e libcucul. \e libcucul can be used alone as a simple ASCII and/or |
---|
48 | * Unicode compositing canvas. |
---|
49 | * |
---|
50 | * The complete \e libcucul and \e libcaca programming interface is |
---|
51 | * available from the cucul.h and caca.h headers. |
---|
52 | * |
---|
53 | * \section env Environment variables |
---|
54 | * |
---|
55 | * Some environment variables can be used to change the behaviour of |
---|
56 | * \e libcaca without having to modify the program which uses them. These |
---|
57 | * variables are: |
---|
58 | * |
---|
59 | * \li \b CACA_DRIVER: set the backend video driver. In order of preference: |
---|
60 | * - \c conio uses the DOS conio.h interface. |
---|
61 | * - \c ncurses uses the ncurses library. |
---|
62 | * - \c slang uses the S-Lang library. |
---|
63 | * - \c x11 uses the native X11 driver. |
---|
64 | * - \c gl uses freeglut and opengl libraries. |
---|
65 | * - \c raw outputs to the standard output instead of rendering the |
---|
66 | * canvas. This is can be used together with cacaserver. |
---|
67 | * |
---|
68 | * \li \b CACA_GEOMETRY: set the video display size. The format of this |
---|
69 | * variable must be XxY, with X and Y being integer values. This option |
---|
70 | * currently works with the network, X11 and GL drivers. |
---|
71 | * |
---|
72 | * \li \b CACA_FONT: set the rendered font. The format of this variable is |
---|
73 | * implementation dependent, but since it currently only works with the |
---|
74 | * X11 driver, an X11 font name such as "fixed" or "5x7" is expected. |
---|
75 | */ |
---|
76 | |
---|
77 | #ifndef __CACA_H__ |
---|
78 | #define __CACA_H__ |
---|
79 | |
---|
80 | /** libcaca API version */ |
---|
81 | #define CACA_API_VERSION_1 |
---|
82 | |
---|
83 | #include <cucul.h> |
---|
84 | |
---|
85 | #ifdef __cplusplus |
---|
86 | extern "C" |
---|
87 | { |
---|
88 | #endif |
---|
89 | |
---|
90 | /** \e libcaca context */ |
---|
91 | typedef struct caca caca_t; |
---|
92 | /** event structure */ |
---|
93 | typedef struct caca_event caca_event_t; |
---|
94 | |
---|
95 | /** \brief User events. |
---|
96 | * |
---|
97 | * This structure is filled by caca_get_event() when an event is received. |
---|
98 | * The \e type field is always valid. The validity of the \e data union |
---|
99 | * depends on the value of the \e type field: |
---|
100 | * |
---|
101 | * \li \b CACA_EVENT_NONE: no other field is valid. |
---|
102 | * |
---|
103 | * \li \b CACA_EVENT_KEY_PRESS, \b CACA_EVENT_KEY_RELEASE: the \e data.key.ch |
---|
104 | * field is valid and contains either the ASCII value for the key, or |
---|
105 | * an \e enum \e caca_key value. If the value is a printable ASCII |
---|
106 | * character, the \e data.key.ucs4 and \e data.key.utf8 fields are |
---|
107 | * also filled and contain respectively the UCS-4/UTF-32 and the UTF-8 |
---|
108 | * representations of the character. Otherwise, their content is |
---|
109 | * undefined. |
---|
110 | * |
---|
111 | * \li \b CACA_EVENT_MOUSE_PRESS, \b CACA_EVENT_MOUSE_RELEASE: the |
---|
112 | * \e data.mouse.button field is valid and contains the index of the |
---|
113 | * mouse button that was pressed. |
---|
114 | * |
---|
115 | * \li \b CACA_EVENT_MOUSE_MOTION: the \e data.mouse.x and \e data.mouse.y |
---|
116 | * fields are valid and contain the mouse coordinates in character |
---|
117 | * cells. |
---|
118 | * |
---|
119 | * \li \b CACA_EVENT_RESIZE: the \e data.resize.w and \e data.resize.h |
---|
120 | * fields are valid and contain the new width and height values of |
---|
121 | * the \e libcucul canvas attached to \e libcaca. |
---|
122 | * |
---|
123 | * \li \b CACA_EVENT_QUIT: no other field is valid. |
---|
124 | * |
---|
125 | * The result of accessing data members outside the above conditions is |
---|
126 | * undefined. |
---|
127 | */ |
---|
128 | struct caca_event |
---|
129 | { |
---|
130 | enum caca_event_type |
---|
131 | { |
---|
132 | CACA_EVENT_NONE = 0x0000, /**< No event. */ |
---|
133 | |
---|
134 | CACA_EVENT_KEY_PRESS = 0x0001, /**< A key was pressed. */ |
---|
135 | CACA_EVENT_KEY_RELEASE = 0x0002, /**< A key was released. */ |
---|
136 | CACA_EVENT_MOUSE_PRESS = 0x0004, /**< A mouse button was pressed. */ |
---|
137 | CACA_EVENT_MOUSE_RELEASE = 0x0008, /**< A mouse button was released. */ |
---|
138 | CACA_EVENT_MOUSE_MOTION = 0x0010, /**< The mouse was moved. */ |
---|
139 | CACA_EVENT_RESIZE = 0x0020, /**< The window was resized. */ |
---|
140 | CACA_EVENT_QUIT = 0x0040, /**< The user requested to quit. */ |
---|
141 | |
---|
142 | CACA_EVENT_ANY = 0xffff /**< Bitmask for any event. */ |
---|
143 | } type; |
---|
144 | |
---|
145 | union |
---|
146 | { |
---|
147 | struct { unsigned int x, y, button; } mouse; |
---|
148 | struct { unsigned int w, h; } resize; |
---|
149 | struct { unsigned int ch; unsigned long int ucs4; char utf8[8]; } key; |
---|
150 | } data; |
---|
151 | }; |
---|
152 | |
---|
153 | /** \brief Special key values. |
---|
154 | * |
---|
155 | * Special key values returned by caca_get_event() for which there is no |
---|
156 | * ASCII equivalent. |
---|
157 | */ |
---|
158 | enum caca_key |
---|
159 | { |
---|
160 | CACA_KEY_UNKNOWN = 0x00, /**< Unknown key. */ |
---|
161 | |
---|
162 | /* The following keys have ASCII equivalents */ |
---|
163 | CACA_KEY_BACKSPACE = 0x08, /**< The backspace key. */ |
---|
164 | CACA_KEY_TAB = 0x09, /**< The tabulation key. */ |
---|
165 | CACA_KEY_RETURN = 0x0d, /**< The return key. */ |
---|
166 | CACA_KEY_PAUSE = 0x13, /**< The pause key. */ |
---|
167 | CACA_KEY_ESCAPE = 0x1b, /**< The escape key. */ |
---|
168 | CACA_KEY_DELETE = 0x7f, /**< The delete key. */ |
---|
169 | |
---|
170 | /* The following keys do not have ASCII equivalents but have been |
---|
171 | * chosen to match the SDL equivalents */ |
---|
172 | CACA_KEY_UP = 0x111, /**< The up arrow key. */ |
---|
173 | CACA_KEY_DOWN = 0x112, /**< The down arrow key. */ |
---|
174 | CACA_KEY_LEFT = 0x113, /**< The left arrow key. */ |
---|
175 | CACA_KEY_RIGHT = 0x114, /**< The right arrow key. */ |
---|
176 | |
---|
177 | CACA_KEY_INSERT = 0x115, /**< The insert key. */ |
---|
178 | CACA_KEY_HOME = 0x116, /**< The home key. */ |
---|
179 | CACA_KEY_END = 0x117, /**< The end key. */ |
---|
180 | CACA_KEY_PAGEUP = 0x118, /**< The page up key. */ |
---|
181 | CACA_KEY_PAGEDOWN = 0x119, /**< The page down key. */ |
---|
182 | |
---|
183 | CACA_KEY_F1 = 0x11a, /**< The F1 key. */ |
---|
184 | CACA_KEY_F2 = 0x11b, /**< The F2 key. */ |
---|
185 | CACA_KEY_F3 = 0x11c, /**< The F3 key. */ |
---|
186 | CACA_KEY_F4 = 0x11d, /**< The F4 key. */ |
---|
187 | CACA_KEY_F5 = 0x11e, /**< The F5 key. */ |
---|
188 | CACA_KEY_F6 = 0x11f, /**< The F6 key. */ |
---|
189 | CACA_KEY_F7 = 0x120, /**< The F7 key. */ |
---|
190 | CACA_KEY_F8 = 0x121, /**< The F8 key. */ |
---|
191 | CACA_KEY_F9 = 0x122, /**< The F9 key. */ |
---|
192 | CACA_KEY_F10 = 0x123, /**< The F10 key. */ |
---|
193 | CACA_KEY_F11 = 0x124, /**< The F11 key. */ |
---|
194 | CACA_KEY_F12 = 0x125, /**< The F12 key. */ |
---|
195 | CACA_KEY_F13 = 0x126, /**< The F13 key. */ |
---|
196 | CACA_KEY_F14 = 0x127, /**< The F14 key. */ |
---|
197 | CACA_KEY_F15 = 0x128 /**< The F15 key. */ |
---|
198 | }; |
---|
199 | |
---|
200 | /** \defgroup caca Basic libcaca functions |
---|
201 | * |
---|
202 | * These functions provide the basic \e libcaca routines for driver |
---|
203 | * initialisation, system information retrieval and configuration. |
---|
204 | * |
---|
205 | * @{ */ |
---|
206 | caca_t * caca_attach(cucul_canvas_t *); |
---|
207 | void caca_detach(caca_t *); |
---|
208 | void caca_set_delay(caca_t *, unsigned int); |
---|
209 | void caca_display(caca_t *); |
---|
210 | unsigned int caca_get_rendertime(caca_t *); |
---|
211 | unsigned int caca_get_window_width(caca_t *); |
---|
212 | unsigned int caca_get_window_height(caca_t *); |
---|
213 | int caca_set_window_title(caca_t *, char const *); |
---|
214 | /* @} */ |
---|
215 | |
---|
216 | /** \defgroup event Event handling |
---|
217 | * |
---|
218 | * These functions handle user events such as keyboard input and mouse |
---|
219 | * clicks. |
---|
220 | * |
---|
221 | * @{ */ |
---|
222 | int caca_get_event(caca_t *, unsigned int, caca_event_t *, int); |
---|
223 | unsigned int caca_get_mouse_x(caca_t *); |
---|
224 | unsigned int caca_get_mouse_y(caca_t *); |
---|
225 | void caca_set_mouse(caca_t *, int); |
---|
226 | /* @} */ |
---|
227 | |
---|
228 | #ifdef __cplusplus |
---|
229 | } |
---|
230 | #endif |
---|
231 | |
---|
232 | #endif /* __CACA_H__ */ |
---|