您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

290 行
8.8 KiB

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