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

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