source: libcaca/trunk/src/caca.h @ 274

Last change on this file since 274 was 274, checked in by Sam Hocevar, 16 years ago
  • src/graphics.c: + Replace CACA_WIDTH and CACA_HEIGHT with CACA_GEOMETRY.
  • src/caca.c: + Documented the CACA_GEOMETRY environment variable.
  • Property svn:keywords set to Id
File size: 11.9 KB
Line 
1/*
2 *  libcaca       ASCII-Art library
3 *  Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org>
4 *                All Rights Reserved
5 *
6 *  This library is free software; you can redistribute it and/or
7 *  modify it under the terms of the GNU Lesser General Public
8 *  License as published by the Free Software Foundation; either
9 *  version 2 of the License, or (at your option) any later version.
10 *
11 *  This library is distributed in the hope that it will be useful,
12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 *  Lesser General Public License for more details.
15 *
16 *  You should have received a copy of the GNU Lesser General Public
17 *  License along with this library; if not, write to the Free Software
18 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 *  02111-1307  USA
20 */
21
22/** \file caca.h
23 *  \version \$Id: caca.h 274 2003-12-24 15:43:45Z sam $
24 *  \author Sam Hocevar <sam@zoy.org>
25 *  \brief The \e libcaca public header.
26 *
27 *  This header contains the public types and functions that applications
28 *  using \e libcaca may use.
29 */
30
31/** \mainpage libcaca developer documentation
32 *
33 *  \section intro Introduction
34 *
35 *  \e libcaca is a graphics library that outputs text instead of pixels,
36 *  so that it can work on older video cards or text terminals. It is not
37 *  unlike the famous AAlib library. \e libcaca can use almost any virtual
38 *  terminal to work, thus it should work on all Unix systems (including
39 *  Mac OS X) using either the slang library or the ncurses library, on DOS
40 *  using the conio library, and on Windows systems using either slang or
41 *  ncurses (through Cygwin emulation) or conio. There is also a native X11
42 *  driver that does not require a text terminal.
43 *
44 *  \e libcaca is free software, released under the GNU Lesser General
45 *  Public License. This ensures that \e libcaca will always remain free
46 *  software.
47 *
48 *  \section api The libcaca API
49 *
50 *  The complete \e libcaca programming interface is available from the
51 *  caca.h header.
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 it. 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 *
65 *  \li \b CACA_GEOMETRY: set the video display size. The format of this
66 *      variable must be XxY, with X and Y being integer values. This option
67 *      currently only works with the X11 driver.
68 *
69 *  \li \b CACA_BACKGROUND: set the background type.
70 *      - \c solid uses solid coloured backgrounds for all characters. This
71 *        feature does not work with all terminal emulators. This is the
72 *        default choice.
73 *      - \c black uses only black backgrounds to render characters.
74 *
75 *  \li \b CACA_ANTIALIASING: set the antialiasing mode. Antialiasing
76 *      smoothens the rendered image and avoids the commonly seen staircase
77 *      effect.
78 *      - \c none disables antialiasing.
79 *      - \c prefilter uses a simple prefilter antialiasing method. This is
80 *        the default choice.
81 *
82 *  \li \b CACA_DITHERING: set the dithering mode. Dithering is necessary
83 *      when rendering a picture that has more colours than the usually
84 *      available palette.
85 *      - \c none disables dithering.
86 *      - \c ordered2 uses a 2x2 Bayer matrix for dithering.
87 *      - \c ordered4 uses a 4x4 Bayer matrix for dithering. This is the
88 *        default choice.
89 *      - \c ordered8 uses a 8x8 Bayer matrix for dithering.
90 *      - \c random uses random dithering.
91 */
92
93#ifndef __CACA_H__
94#define __CACA_H__
95
96#ifdef __cplusplus
97extern "C"
98{
99#endif
100
101/** \brief Colour definitions.
102 *
103 *  This enum lists all colours that can be used with caca_set_color().
104 */
105enum caca_color
106{
107    CACA_COLOR_BLACK = 0, /**< The colour index for black. */
108    CACA_COLOR_BLUE = 1, /**< The colour index for blue. */
109    CACA_COLOR_GREEN = 2, /**< The colour index for green. */
110    CACA_COLOR_CYAN = 3, /**< The colour index for cyan. */
111    CACA_COLOR_RED = 4, /**< The colour index for red. */
112    CACA_COLOR_MAGENTA = 5, /**< The colour index for magenta. */
113    CACA_COLOR_BROWN = 6, /**< The colour index for brown. */
114    CACA_COLOR_LIGHTGRAY = 7, /**< The colour index for light gray. */
115    CACA_COLOR_DARKGRAY = 8, /**< The colour index for dark gray. */
116    CACA_COLOR_LIGHTBLUE = 9, /**< The colour index for blue. */
117    CACA_COLOR_LIGHTGREEN = 10, /**< The colour index for light green. */
118    CACA_COLOR_LIGHTCYAN = 11, /**< The colour index for light cyan. */
119    CACA_COLOR_LIGHTRED = 12, /**< The colour index for light red. */
120    CACA_COLOR_LIGHTMAGENTA = 13, /**< The colour index for light magenta. */
121    CACA_COLOR_YELLOW = 14, /**< The colour index for yellow. */
122    CACA_COLOR_WHITE = 15 /**< The colour index for white. */
123};
124
125/** \brief Internal features.
126 *
127 *  This enum lists all possible internal libcaca features such as the
128 *  rendering method or the dithering mode.
129 */
130enum caca_feature
131{
132    CACA_BACKGROUND       = 0x10, /**< Properties of background characters. */
133    CACA_BACKGROUND_BLACK = 0x11, /**< Draw only black backgrounds. */
134    CACA_BACKGROUND_SOLID = 0x12, /**< Draw coloured solid backgorunds. */
135#define CACA_BACKGROUND_MIN 0x11 /**< First background property */
136#define CACA_BACKGROUND_MAX 0x12 /**< Last background property */
137
138    CACA_ANTIALIASING           = 0x20, /**< Antialiasing features. */
139    CACA_ANTIALIASING_NONE      = 0x21, /**< No antialiasing. */
140    CACA_ANTIALIASING_PREFILTER = 0x22, /**< Prefilter antialiasing. */
141#define CACA_ANTIALIASING_MIN     0x21 /**< First antialiasing feature. */
142#define CACA_ANTIALIASING_MAX     0x22 /**< Last antialiasing feature. */
143
144    CACA_DITHERING          = 0x30, /**< Dithering methods */
145    CACA_DITHERING_NONE     = 0x31, /**< No dithering. */
146    CACA_DITHERING_ORDERED2 = 0x32, /**< Ordered 2x2 Bayer dithering. */
147    CACA_DITHERING_ORDERED4 = 0x33, /**< Ordered 4x4 Bayer dithering. */
148    CACA_DITHERING_ORDERED8 = 0x34, /**< Ordered 8x8 Bayer dithering. */
149    CACA_DITHERING_RANDOM   = 0x35, /**< Random dithering. */
150#define CACA_DITHERING_MIN    0x31 /**< First dithering feature. */
151#define CACA_DITHERING_MAX    0x35 /**< Last dithering feature. */
152
153    CACA_UNKNOWN_FEATURE = 0xffff /**< Unknown feature. */
154};
155
156/*
157 * Backwards compatibility macros
158 */
159#ifndef _DOXYGEN_SKIP_ME
160#define caca_dithering caca_feature
161#define caca_set_dithering caca_set_feature
162#define caca_get_dithering_name caca_get_feature_name
163#define CACA_DITHER_NONE    CACA_DITHERING_NONE
164#define CACA_DITHER_ORDERED CACA_DITHERING_ORDERED8
165#define CACA_DITHER_RANDOM  CACA_DITHERING_RANDOM
166#endif
167
168/** \brief User events.
169 *
170 *  This enum lists all possible event types returned by caca_get_event().
171 */
172enum caca_event
173{
174    CACA_EVENT_NONE =        0x00000000, /**< No event. */
175    CACA_EVENT_KEY_PRESS =   0x01000000, /**< A key was pressed. */
176    CACA_EVENT_KEY_RELEASE = 0x02000000, /**< A key was released. */
177    CACA_EVENT_MOUSE_CLICK = 0x04000000 /**< A mouse button was clicked. */
178};
179
180/** \brief Special key values.
181 *
182 *  This enum lists special key values returned by caca_get_event() for
183 *  which there is no ASCII equivalent.
184 */
185enum caca_key
186{
187    CACA_KEY_UP = 273, /**< The up arrow key. */
188    CACA_KEY_DOWN = 274, /**< The down arrow key. */
189    CACA_KEY_LEFT = 275, /**< The left arrow key. */
190    CACA_KEY_RIGHT = 276, /**< The right arrow key. */
191
192    CACA_KEY_F1 = 282, /**< The F1 key. */
193    CACA_KEY_F2 = 283, /**< The F2 key. */
194    CACA_KEY_F3 = 284, /**< The F3 key. */
195    CACA_KEY_F4 = 285, /**< The F4 key. */
196    CACA_KEY_F5 = 286, /**< The F5 key. */
197    CACA_KEY_F6 = 287, /**< The F6 key. */
198    CACA_KEY_F7 = 288, /**< The F7 key. */
199    CACA_KEY_F8 = 289, /**< The F8 key. */
200    CACA_KEY_F9 = 290, /**< The F9 key. */
201    CACA_KEY_F10 = 291, /**< The F10 key. */
202    CACA_KEY_F11 = 292, /**< The F11 key. */
203    CACA_KEY_F12 = 293, /**< The F12 key. */
204    CACA_KEY_F13 = 294, /**< The F13 key. */
205    CACA_KEY_F14 = 295, /**< The F14 key. */
206    CACA_KEY_F15 = 296 /**< The F15 key. */
207};
208
209/** \defgroup basic Basic functions
210 *
211 *  These functions provide the basic \e libcaca routines for library
212 *  initialisation, system information retrieval and configuration.
213 *
214 *  @{ */
215int caca_init(void);
216void caca_set_delay(unsigned int);
217enum caca_feature caca_get_feature(enum caca_feature);
218void caca_set_feature(enum caca_feature);
219const char *caca_get_feature_name(enum caca_feature);
220unsigned int caca_get_rendertime(void);
221unsigned int caca_get_width(void);
222unsigned int caca_get_height(void);
223void caca_refresh(void);
224void caca_end(void);
225/*  @} */
226
227/** \defgroup event Event handling functions
228 *
229 *  These functions handle user events such as keyboard input and mouse
230 *  clicks.
231 *
232 *  @{ */
233unsigned int caca_get_event(void);
234unsigned int caca_wait_event(void);
235/*  @} */
236
237/** \defgroup char Character printing functions
238 *
239 *  These functions provide low-level character printing routines.
240 *
241 *  @{ */
242void caca_set_color(enum caca_color, enum caca_color);
243enum caca_color caca_get_fg_color(void);
244enum caca_color caca_get_bg_color(void);
245const char *caca_get_color_name(enum caca_color);
246void caca_putchar(int, int, char);
247void caca_putstr(int, int, const char *);
248void caca_printf(int, int, const char *, ...);
249void caca_clear(void);
250/*  @} */
251
252/** \defgroup prim Primitives drawing functions
253 *
254 *  These functions provide routines for primitive drawing, such as lines,
255 *  boxes, triangles and ellipses.
256 *
257 *  @{ */
258void caca_draw_line(int, int, int, int, char);
259void caca_draw_polyline(const int x[], const int y[], int, char);
260void caca_draw_thin_line(int, int, int, int);
261void caca_draw_thin_polyline(const int x[], const int y[], int);
262
263void caca_draw_circle(int, int, int, char);
264void caca_draw_ellipse(int, int, int, int, char);
265void caca_draw_thin_ellipse(int, int, int, int);
266void caca_fill_ellipse(int, int, int, int, char);
267
268void caca_draw_box(int, int, int, int, char);
269void caca_draw_thin_box(int, int, int, int);
270void caca_fill_box(int, int, int, int, char);
271
272void caca_draw_triangle(int, int, int, int, int, int, char);
273void caca_draw_thin_triangle(int, int, int, int, int, int);
274void caca_fill_triangle(int, int, int, int, int, int, char);
275/*  @} */
276
277/** \defgroup math Mathematical functions
278 *
279 *  These functions provide a few useful math-related routines.
280 *
281 *  @{ */
282int caca_rand(int, int);
283unsigned int caca_sqrt(unsigned int);
284/*  @} */
285
286/** \defgroup sprite Sprite handling functions
287 *
288 *  These functions provide high level routines for sprite loading, animation
289 *  and rendering.
290 *
291 *  @{ */
292struct caca_sprite;
293struct caca_sprite * caca_load_sprite(const char *);
294int caca_get_sprite_frames(const struct caca_sprite *);
295int caca_get_sprite_width(const struct caca_sprite *, int);
296int caca_get_sprite_height(const struct caca_sprite *, int);
297int caca_get_sprite_dx(const struct caca_sprite *, int);
298int caca_get_sprite_dy(const struct caca_sprite *, int);
299void caca_draw_sprite(int, int, const struct caca_sprite *, int);
300void caca_free_sprite(struct caca_sprite *);
301/*  @} */
302
303/** \defgroup bitmap Bitmap handling functions
304 *
305 *  These functions provide high level routines for bitmap allocation and
306 *  rendering.
307 *
308 *  @{ */
309struct caca_bitmap;
310struct caca_bitmap *caca_create_bitmap(unsigned int, unsigned int,
311                                       unsigned int, unsigned int,
312                                       unsigned int, unsigned int,
313                                       unsigned int, unsigned int);
314void caca_set_bitmap_palette(struct caca_bitmap *,
315                             unsigned int r[], unsigned int g[],
316                             unsigned int b[], unsigned int a[]);
317void caca_draw_bitmap(int, int, int, int, const struct caca_bitmap *, void *);
318void caca_free_bitmap(struct caca_bitmap *);
319/*  @} */
320
321#ifdef __cplusplus
322}
323#endif
324
325#endif /* __CACA_H__ */
Note: See TracBrowser for help on using the repository browser.