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

Last change on this file since 522 was 522, checked in by Sam Hocevar, 16 years ago
  • Changed the licensing to WTFPL, as per all copyright holders' permission.
  • Property svn:keywords set to Id
File size: 13.8 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 Do What The Fuck You Want To
8 *  Public License, Version 2, as published by Sam Hocevar. See
9 *  http://sam.zoy.org/wtfpl/COPYING for more details.
10 */
11
12/** \file caca.h
13 *  \version \$Id: caca.h 522 2006-03-04 00:35:45Z sam $
14 *  \author Sam Hocevar <sam@zoy.org>
15 *  \brief The \e libcaca public header.
16 *
17 *  This header contains the public types and functions that applications
18 *  using \e libcaca may use.
19 */
20
21/** \mainpage libcaca developer documentation
22 *
23 *  \section intro Introduction
24 *
25 *  \e libcaca is a graphics library that outputs text instead of pixels,
26 *  so that it can work on older video cards or text terminals. It is not
27 *  unlike the famous AAlib library. \e libcaca can use almost any virtual
28 *  terminal to work, thus it should work on all Unix systems (including
29 *  Mac OS X) using either the slang library or the ncurses library, on DOS
30 *  using the conio library, and on Windows systems using either slang or
31 *  ncurses (through Cygwin emulation) or conio. There is also a native X11
32 *  driver, and an OpenGL driver (through freeglut) that does not require a
33 *  text terminal.
34 *
35 *  \e libcaca is free software, released under the Do What The Fuck You
36 *  Want To Public License. This ensures that no one, not even the \e libcaca
37 *  developers, will ever have anything to say about what you do with the
38 *  software. It used to be licensed under the GNU Lesser General Public
39 *  License, but that was not free enough.
40 *
41 *  \section api The libcaca API
42 *
43 *  The complete \e libcaca programming interface is available from the
44 *  caca.h header.
45 *
46 *  \section env Environment variables
47 *
48 *  Some environment variables can be used to change the behaviour of
49 *  \e libcaca without having to modify the program which uses it. These
50 *  variables are:
51 *
52 *  \li \b CACA_DRIVER: set the backend video driver. In order of preference:
53 *      - \c conio uses the DOS conio.h interface.
54 *      - \c ncurses uses the ncurses library.
55 *      - \c slang uses the S-Lang library.
56 *      - \c x11 uses the native X11 driver.
57 *      - \c gl uses freeglut and opengl libraries.
58 *      - \c null uses nothing at all, and will display nothing as well.
59 *
60 *  \li \b CACA_GEOMETRY: set the video display size. The format of this
61 *      variable must be XxY, with X and Y being integer values. This option
62 *      currently only works with the X11 and the GL driver.
63 *
64 *  \li \b CACA_FONT: set the rendered font. The format of this variable is
65 *      implementation dependent, but since it currently only works with the
66 *      X11 driver, an X11 font name such as "fixed" or "5x7" is expected.
67 *
68 *  \li \b CACA_BACKGROUND: set the background type.
69 *      - \c solid uses solid coloured backgrounds for all characters. This
70 *        feature does not work with all terminal emulators. This is the
71 *        default choice.
72 *      - \c black uses only black backgrounds to render characters.
73 *
74 *  \li \b CACA_ANTIALIASING: set the antialiasing mode. Antialiasing
75 *      smoothens the rendered image and avoids the commonly seen staircase
76 *      effect.
77 *      - \c none disables antialiasing.
78 *      - \c prefilter uses a simple prefilter antialiasing method. This is
79 *        the default choice.
80 *
81 *  \li \b CACA_DITHERING: set the dithering mode. Dithering is necessary
82 *      when rendering a picture that has more colours than the usually
83 *      available palette.
84 *      - \c none disables dithering.
85 *      - \c ordered2 uses a 2x2 Bayer matrix for dithering.
86 *      - \c ordered4 uses a 4x4 Bayer matrix for dithering. This is the
87 *        default choice.
88 *      - \c ordered8 uses a 8x8 Bayer matrix for dithering.
89 *      - \c random uses random dithering.
90 */
91
92#ifndef __CACA_H__
93#define __CACA_H__
94
95#ifdef __cplusplus
96extern "C"
97{
98#endif
99
100/** \brief Colour definitions.
101 *
102 *  Colours that can be used with caca_set_color().
103 */
104enum caca_color
105{
106    CACA_COLOR_BLACK = 0, /**< The colour index for black. */
107    CACA_COLOR_BLUE = 1, /**< The colour index for blue. */
108    CACA_COLOR_GREEN = 2, /**< The colour index for green. */
109    CACA_COLOR_CYAN = 3, /**< The colour index for cyan. */
110    CACA_COLOR_RED = 4, /**< The colour index for red. */
111    CACA_COLOR_MAGENTA = 5, /**< The colour index for magenta. */
112    CACA_COLOR_BROWN = 6, /**< The colour index for brown. */
113    CACA_COLOR_LIGHTGRAY = 7, /**< The colour index for light gray. */
114    CACA_COLOR_DARKGRAY = 8, /**< The colour index for dark gray. */
115    CACA_COLOR_LIGHTBLUE = 9, /**< The colour index for blue. */
116    CACA_COLOR_LIGHTGREEN = 10, /**< The colour index for light green. */
117    CACA_COLOR_LIGHTCYAN = 11, /**< The colour index for light cyan. */
118    CACA_COLOR_LIGHTRED = 12, /**< The colour index for light red. */
119    CACA_COLOR_LIGHTMAGENTA = 13, /**< The colour index for light magenta. */
120    CACA_COLOR_YELLOW = 14, /**< The colour index for yellow. */
121    CACA_COLOR_WHITE = 15 /**< The colour index for white. */
122};
123
124/** \brief Internal features.
125 *
126 *  Internal libcaca features such as the rendering method or the dithering
127 *  mode.
128 */
129enum caca_feature
130{
131    CACA_BACKGROUND       = 0x10, /**< Properties of background characters. */
132    CACA_BACKGROUND_BLACK = 0x11, /**< Draw only black backgrounds. */
133    CACA_BACKGROUND_SOLID = 0x12, /**< Draw coloured solid backgorunds. */
134#define CACA_BACKGROUND_MIN 0x11 /**< First background property */
135#define CACA_BACKGROUND_MAX 0x12 /**< Last background property */
136
137    CACA_ANTIALIASING           = 0x20, /**< Antialiasing features. */
138    CACA_ANTIALIASING_NONE      = 0x21, /**< No antialiasing. */
139    CACA_ANTIALIASING_PREFILTER = 0x22, /**< Prefilter antialiasing. */
140#define CACA_ANTIALIASING_MIN     0x21 /**< First antialiasing feature. */
141#define CACA_ANTIALIASING_MAX     0x22 /**< Last antialiasing feature. */
142
143    CACA_DITHERING          = 0x30, /**< Dithering methods */
144    CACA_DITHERING_NONE     = 0x31, /**< No dithering. */
145    CACA_DITHERING_ORDERED2 = 0x32, /**< Ordered 2x2 Bayer dithering. */
146    CACA_DITHERING_ORDERED4 = 0x33, /**< Ordered 4x4 Bayer dithering. */
147    CACA_DITHERING_ORDERED8 = 0x34, /**< Ordered 8x8 Bayer dithering. */
148    CACA_DITHERING_RANDOM   = 0x35, /**< Random dithering. */
149    CACA_DITHERING_FSTEIN   = 0x36, /**< Floyd-Steinberg dithering. */
150#define CACA_DITHERING_MIN    0x31 /**< First dithering feature. */
151#define CACA_DITHERING_MAX    0x36 /**< Last dithering feature. */
152
153    CACA_FEATURE_UNKNOWN = 0xffff /**< Unknown feature. */
154};
155
156/*
157 * Backwards compatibility macros
158 */
159#if !defined(_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 *  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_PRESS =   0x04000000, /**< A mouse button was pressed. */
178    CACA_EVENT_MOUSE_RELEASE = 0x08000000, /**< A mouse button was released. */
179    CACA_EVENT_MOUSE_MOTION =  0x10000000, /**< The mouse was moved. */
180    CACA_EVENT_RESIZE =        0x20000000, /**< The window was resized. */
181    CACA_EVENT_ANY =           0xff000000  /**< Bitmask for any event. */
182};
183
184/** \brief Special key values.
185 *
186 *  Special key values returned by caca_get_event() for which there is no
187 *  ASCII equivalent.
188 */
189enum caca_key
190{
191    CACA_KEY_UNKNOWN = 0, /**< Unknown key. */
192
193    /* The following keys have ASCII equivalents */
194    CACA_KEY_BACKSPACE = 8, /**< The backspace key. */
195    CACA_KEY_TAB = 9, /**< The tabulation key. */
196    CACA_KEY_RETURN = 13, /**< The return key. */
197    CACA_KEY_PAUSE = 19, /**< The pause key. */
198    CACA_KEY_ESCAPE = 27, /**< The escape key. */
199    CACA_KEY_DELETE = 127, /**< The delete key. */
200
201    /* The following keys do not have ASCII equivalents but have been
202     * chosen to match the SDL equivalents */
203    CACA_KEY_UP = 273, /**< The up arrow key. */
204    CACA_KEY_DOWN = 274, /**< The down arrow key. */
205    CACA_KEY_LEFT = 275, /**< The left arrow key. */
206    CACA_KEY_RIGHT = 276, /**< The right arrow key. */
207
208    CACA_KEY_INSERT = 277, /**< The insert key. */
209    CACA_KEY_HOME = 278, /**< The home key. */
210    CACA_KEY_END = 279, /**< The end key. */
211    CACA_KEY_PAGEUP = 280, /**< The page up key. */
212    CACA_KEY_PAGEDOWN = 281, /**< The page down key. */
213
214    CACA_KEY_F1 = 282, /**< The F1 key. */
215    CACA_KEY_F2 = 283, /**< The F2 key. */
216    CACA_KEY_F3 = 284, /**< The F3 key. */
217    CACA_KEY_F4 = 285, /**< The F4 key. */
218    CACA_KEY_F5 = 286, /**< The F5 key. */
219    CACA_KEY_F6 = 287, /**< The F6 key. */
220    CACA_KEY_F7 = 288, /**< The F7 key. */
221    CACA_KEY_F8 = 289, /**< The F8 key. */
222    CACA_KEY_F9 = 290, /**< The F9 key. */
223    CACA_KEY_F10 = 291, /**< The F10 key. */
224    CACA_KEY_F11 = 292, /**< The F11 key. */
225    CACA_KEY_F12 = 293, /**< The F12 key. */
226    CACA_KEY_F13 = 294, /**< The F13 key. */
227    CACA_KEY_F14 = 295, /**< The F14 key. */
228    CACA_KEY_F15 = 296 /**< The F15 key. */
229};
230
231/** \defgroup basic Basic functions
232 *
233 *  These functions provide the basic \e libcaca routines for library
234 *  initialisation, system information retrieval and configuration.
235 *
236 *  @{ */
237int caca_init(void);
238void caca_set_delay(unsigned int);
239enum caca_feature caca_get_feature(enum caca_feature);
240void caca_set_feature(enum caca_feature);
241char const *caca_get_feature_name(enum caca_feature);
242unsigned int caca_get_rendertime(void);
243unsigned int caca_get_width(void);
244unsigned int caca_get_height(void);
245void caca_set_size(unsigned int width, unsigned int height);
246void caca_set_width(unsigned int width);
247void caca_set_height(unsigned int height);
248int caca_set_window_title(char const *);
249unsigned int caca_get_window_width(void);
250unsigned int caca_get_window_height(void);
251void caca_refresh(void);
252void caca_end(void);
253/*  @} */
254
255/** \defgroup event Event handling
256 *
257 *  These functions handle user events such as keyboard input and mouse
258 *  clicks.
259 *
260 *  @{ */
261unsigned int caca_get_event(unsigned int);
262unsigned int caca_wait_event(unsigned int);
263unsigned int caca_get_mouse_x(void);
264unsigned int caca_get_mouse_y(void);
265/*  @} */
266
267/** \defgroup char Character printing
268 *
269 *  These functions provide low-level character printing routines.
270 *
271 *  @{ */
272void caca_set_color(enum caca_color, enum caca_color);
273enum caca_color caca_get_fg_color(void);
274enum caca_color caca_get_bg_color(void);
275char const *caca_get_color_name(enum caca_color);
276void caca_putchar(int, int, char);
277void caca_putstr(int, int, char const *);
278void caca_printf(int, int, char const *, ...);
279void caca_get_screen(char *);
280void caca_clear(void);
281/*  @} */
282
283/** \defgroup prim Primitives drawing
284 *
285 *  These functions provide routines for primitive drawing, such as lines,
286 *  boxes, triangles and ellipses.
287 *
288 *  @{ */
289void caca_draw_line(int, int, int, int, char);
290void caca_draw_polyline(int const x[], int const y[], int, char);
291void caca_draw_thin_line(int, int, int, int);
292void caca_draw_thin_polyline(int const x[], int const y[], int);
293
294void caca_draw_circle(int, int, int, char);
295void caca_draw_ellipse(int, int, int, int, char);
296void caca_draw_thin_ellipse(int, int, int, int);
297void caca_fill_ellipse(int, int, int, int, char);
298
299void caca_draw_box(int, int, int, int, char);
300void caca_draw_thin_box(int, int, int, int);
301void caca_fill_box(int, int, int, int, char);
302
303void caca_draw_triangle(int, int, int, int, int, int, char);
304void caca_draw_thin_triangle(int, int, int, int, int, int);
305void caca_fill_triangle(int, int, int, int, int, int, char);
306/*  @} */
307
308/** \defgroup math Mathematical functions
309 *
310 *  These functions provide a few useful math-related routines.
311 *
312 *  @{ */
313int caca_rand(int, int);
314unsigned int caca_sqrt(unsigned int);
315float caca_powf(float x, float y);
316/*  @} */
317
318/** \defgroup sprite Sprite handling
319 *
320 *  These functions provide high level routines for sprite loading, animation
321 *  and rendering.
322 *
323 *  @{ */
324struct caca_sprite;
325struct caca_sprite * caca_load_sprite(char const *);
326int caca_get_sprite_frames(struct caca_sprite const *);
327int caca_get_sprite_width(struct caca_sprite const *, int);
328int caca_get_sprite_height(struct caca_sprite const *, int);
329int caca_get_sprite_dx(struct caca_sprite const *, int);
330int caca_get_sprite_dy(struct caca_sprite const *, int);
331void caca_draw_sprite(int, int, struct caca_sprite const *, int);
332void caca_free_sprite(struct caca_sprite *);
333/*  @} */
334
335/** \defgroup bitmap Bitmap handling
336 *
337 *  These functions provide high level routines for bitmap allocation and
338 *  rendering.
339 *
340 *  @{ */
341struct caca_bitmap;
342struct caca_bitmap *caca_create_bitmap(unsigned int, unsigned int,
343                                       unsigned int, unsigned int,
344                                       unsigned int, unsigned int,
345                                       unsigned int, unsigned int);
346void caca_set_bitmap_palette(struct caca_bitmap *,
347                             unsigned int r[], unsigned int g[],
348                             unsigned int b[], unsigned int a[]);
349void caca_set_bitmap_gamma(struct caca_bitmap *, float);
350void caca_draw_bitmap(int, int, int, int, struct caca_bitmap const *, void *);
351void caca_free_bitmap(struct caca_bitmap *);
352/*  @} */
353
354/** \defgroup exporter Exporters to various formats
355 *
356 *  These functions exports current image to various text formats
357 *
358 *  @{ */
359char* caca_get_html(void);
360char* caca_get_html3(void);
361char* caca_get_irc(void);
362char* caca_get_ansi(int trailing);
363/*  @} */
364
365#ifdef __cplusplus
366}
367#endif
368
369#endif /* __CACA_H__ */
Note: See TracBrowser for help on using the repository browser.