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

Last change on this file since 265 was 265, checked in by Sam Hocevar, 19 years ago
  • src/graphics.c src/caca.c src/io.c: + Support for simultaneously compiled-in drivers. + Honour the CACA_DRIVER environment variable.
  • configure.ac: + Drivers are no longer mutually exclusive.
  • Property svn:keywords set to Id
File size: 8.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 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 265 2003-12-22 15:26:12Z 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. libcaca needs a terminal to work,
38 *   thus it should work on all Unix systems (including Mac OS X) using
39 *   either the slang library or the ncurses library, on DOS using the conio
40 *   library, and on Windows systems using either slang or ncurses (through
41 *   Cygwin emulation) or conio.
42 *
43 *   \e libcaca is free software, released under the GNU Lesser General
44 *   Public License. This ensures that \e libcaca will always remain free
45 *   software.
46 *
47 *   \section api The libcaca API
48 *
49 *   The complete \e libcaca programming interface is available from the
50 *   caca.h file.
51 *
52 *   \section env Environment variables
53 *
54 *   Some environment variables can be used to change the behaviour of
55 *   \e libcaca without having to modify the program which uses it. These
56 *   variables are:
57 *
58 *   \li \b CACA_DRIVER: set the backend video driver. In order of preference:
59 *       - \c conio uses the DOS conio.h interface.
60 *       - \c ncurses uses the ncurses library.
61 *       - \c slang uses the S-Lang library.
62 *       - \c x11 uses the native X11 driver.
63 *
64 *   \li \b CACA_BACKGROUND: set the background type.
65 *       - \c solid uses solid coloured backgrounds for all characters. This
66 *         feature does not work with all terminal emulators. This is the
67 *         default choice.
68 *       - \c black uses only black backgrounds to render characters.
69 *
70 *   \li \b CACA_ANTIALIASING: set the antialiasing mode. Antialiasing
71 *       smoothens the rendered image and avoids the commonly seen staircase
72 *       effect.
73 *       - \c none disables antialiasing.
74 *       - \c prefilter uses a simple prefilter antialiasing method. This is
75 *         the default choice.
76 *
77 *   \li \b CACA_DITHERING: set the dithering mode. Dithering is necessary
78 *       when rendering a picture that has more colours than the usually
79 *       available palette.
80 *       - \c none disables dithering.
81 *       - \c ordered2 uses a 2x2 bayer matrix for dithering.
82 *       - \c ordered4 uses a 4x4 bayer matrix for dithering. This is the
83 *         default choice.
84 *       - \c ordered8 uses a 8x8 bayer matrix for dithering.
85 *       - \c random uses random dithering.
86 */
87
88#ifndef __CACA_H__
89#define __CACA_H__
90
91#ifdef __cplusplus
92extern "C"
93{
94#endif
95
96/**
97 * The colour definitions to be used with caca_set_color().
98 */
99enum caca_color
100{
101    CACA_COLOR_BLACK = 0,
102    CACA_COLOR_BLUE = 1,
103    CACA_COLOR_GREEN = 2,
104    CACA_COLOR_CYAN = 3,
105    CACA_COLOR_RED = 4,
106    CACA_COLOR_MAGENTA = 5,
107    CACA_COLOR_BROWN = 6,
108    CACA_COLOR_LIGHTGRAY = 7,
109    CACA_COLOR_DARKGRAY = 8,
110    CACA_COLOR_LIGHTBLUE = 9,
111    CACA_COLOR_LIGHTGREEN = 10,
112    CACA_COLOR_LIGHTCYAN = 11,
113    CACA_COLOR_LIGHTRED = 12,
114    CACA_COLOR_LIGHTMAGENTA = 13,
115    CACA_COLOR_YELLOW = 14,
116    CACA_COLOR_WHITE = 15
117};
118
119const char *caca_get_color_name(enum caca_color);
120
121/**
122 * The internal libcaca features.
123 */
124enum caca_feature
125{
126    /* Properties of background characters */
127    CACA_BACKGROUND       = 0x10,
128    CACA_BACKGROUND_BLACK = 0x11,
129    CACA_BACKGROUND_SOLID = 0x12,
130#define CACA_BACKGROUND_MIN 0x11
131#define CACA_BACKGROUND_MAX 0x12
132
133    /* Antialiasing features */
134    CACA_ANTIALIASING           = 0x20,
135    CACA_ANTIALIASING_NONE      = 0x21,
136    CACA_ANTIALIASING_PREFILTER = 0x22,
137#define CACA_ANTIALIASING_MIN     0x21
138#define CACA_ANTIALIASING_MAX     0x22
139
140    /* Dithering methods */
141    CACA_DITHERING          = 0x30,
142    CACA_DITHERING_NONE     = 0x31,
143    CACA_DITHERING_ORDERED2 = 0x32,
144    CACA_DITHERING_ORDERED4 = 0x33,
145    CACA_DITHERING_ORDERED8 = 0x34,
146    CACA_DITHERING_RANDOM   = 0x35,
147#define CACA_DITHERING_MIN    0x31
148#define CACA_DITHERING_MAX    0x35
149
150    /* Unknown feature */
151    CACA_UNKNOWN_FEATURE = 0xffff
152};
153
154const char *caca_get_feature_name(enum caca_feature);
155
156/* Backwards compatibility */
157#define caca_dithering caca_feature
158#define caca_set_dithering caca_set_feature
159#define caca_get_dithering_name caca_get_feature_name
160#define CACA_DITHER_NONE    CACA_DITHERING_NONE
161#define CACA_DITHER_ORDERED CACA_DITHERING_ORDERED8
162#define CACA_DITHER_RANDOM  CACA_DITHERING_RANDOM
163
164/**
165 * The event types returned by caca_get_event().
166 */
167enum caca_event
168{
169    CACA_EVENT_NONE =        0x00000000,
170    CACA_EVENT_KEY_PRESS =   0x01000000,
171    CACA_EVENT_KEY_RELEASE = 0x02000000,
172    CACA_EVENT_MOUSE_CLICK = 0x04000000
173};
174
175/**
176 * The special key values returned by caca_get_event().
177 */
178enum caca_key
179{
180    CACA_KEY_UP = 273,
181    CACA_KEY_DOWN = 274,
182    CACA_KEY_LEFT = 275,
183    CACA_KEY_RIGHT = 276,
184
185    CACA_KEY_F1 = 282,
186    CACA_KEY_F2 = 283,
187    CACA_KEY_F3 = 284,
188    CACA_KEY_F4 = 285,
189    CACA_KEY_F5 = 286,
190    CACA_KEY_F6 = 287,
191    CACA_KEY_F7 = 288,
192    CACA_KEY_F8 = 289,
193    CACA_KEY_F9 = 290,
194    CACA_KEY_F10 = 291,
195    CACA_KEY_F11 = 292,
196    CACA_KEY_F12 = 293,
197    CACA_KEY_F13 = 294,
198    CACA_KEY_F14 = 295,
199    CACA_KEY_F15 = 296
200};
201
202/*
203 * Basic functions
204 */
205int caca_init(void);
206void caca_set_delay(unsigned int);
207enum caca_feature caca_get_feature(enum caca_feature);
208void caca_set_feature(enum caca_feature);
209unsigned int caca_get_rendertime(void);
210unsigned int caca_get_width(void);
211unsigned int caca_get_height(void);
212void caca_refresh(void);
213void caca_end(void);
214
215/*
216 * Events
217 */
218unsigned int caca_get_event(void);
219
220/*
221 * Character graphics
222 */
223void caca_set_color(enum caca_color, enum caca_color);
224enum caca_color caca_get_fg_color(void);
225enum caca_color caca_get_bg_color(void);
226void caca_putchar(int, int, char);
227void caca_putstr(int, int, const char *);
228void caca_printf(int, int, const char *, ...);
229void caca_clear(void);
230
231/*
232 * Graphics primitives
233 */
234void caca_draw_line(int, int, int, int, char);
235void caca_draw_polyline(const int x[], const int y[], int, char);
236void caca_draw_thin_line(int, int, int, int);
237void caca_draw_thin_polyline(const int x[], const int y[], int);
238
239void caca_draw_circle(int, int, int, char);
240void caca_draw_ellipse(int, int, int, int, char);
241void caca_draw_thin_ellipse(int, int, int, int);
242void caca_fill_ellipse(int, int, int, int, char);
243
244void caca_draw_box(int, int, int, int, char);
245void caca_draw_thin_box(int, int, int, int);
246void caca_fill_box(int, int, int, int, char);
247
248void caca_draw_triangle(int, int, int, int, int, int, char);
249void caca_draw_thin_triangle(int, int, int, int, int, int);
250void caca_fill_triangle(int, int, int, int, int, int, char);
251
252/*
253 * Maths
254 */
255int caca_rand(int, int);
256unsigned int caca_sqrt(unsigned int);
257
258/*
259 * Sprite handling
260 */
261struct caca_sprite;
262struct caca_sprite * caca_load_sprite(const char *);
263int caca_get_sprite_frames(const struct caca_sprite *);
264int caca_get_sprite_width(const struct caca_sprite *, int);
265int caca_get_sprite_height(const struct caca_sprite *, int);
266int caca_get_sprite_dx(const struct caca_sprite *, int);
267int caca_get_sprite_dy(const struct caca_sprite *, int);
268void caca_draw_sprite(int, int, const struct caca_sprite *, int);
269void caca_free_sprite(struct caca_sprite *);
270
271/*
272 * Bitmap handling
273 */
274struct caca_bitmap;
275struct caca_bitmap *caca_create_bitmap(unsigned int, unsigned int,
276                                       unsigned int, unsigned int,
277                                       unsigned int, unsigned int,
278                                       unsigned int, unsigned int);
279void caca_set_bitmap_palette(struct caca_bitmap *,
280                             unsigned int r[], unsigned int g[],
281                             unsigned int b[], unsigned int a[]);
282void caca_draw_bitmap(int, int, int, int, const struct caca_bitmap *, void *);
283void caca_free_bitmap(struct caca_bitmap *);
284
285#ifdef __cplusplus
286}
287#endif
288
289#endif /* __CACA_H__ */
Note: See TracBrowser for help on using the repository browser.