Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

375 rader
14 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. \e libcaca can use almost any virtual
  36. * terminal to work, thus it should work on all Unix systems (including
  37. * Mac OS X) using either the slang library or the ncurses library, on DOS
  38. * using the conio library, and on Windows systems using either slang or
  39. * ncurses (through Cygwin emulation) or conio. There is also a native X11
  40. * driver, and an OpenGL driver (through freeglut) that does not require a
  41. * text terminal.
  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 header.
  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. * - \c gl uses freeglut and opengl libraries.
  64. * - \c null uses nothing at all, and will display nothing as well.
  65. *
  66. * \li \b CACA_GEOMETRY: set the video display size. The format of this
  67. * variable must be XxY, with X and Y being integer values. This option
  68. * currently only works with the X11 and the GL driver.
  69. *
  70. * \li \b CACA_FONT: set the rendered font. The format of this variable is
  71. * implementation dependent, but since it currently only works with the
  72. * X11 driver, an X11 font name such as "fixed" or "5x7" is expected.
  73. *
  74. * \li \b CACA_BACKGROUND: set the background type.
  75. * - \c solid uses solid coloured backgrounds for all characters. This
  76. * feature does not work with all terminal emulators. This is the
  77. * default choice.
  78. * - \c black uses only black backgrounds to render characters.
  79. *
  80. * \li \b CACA_ANTIALIASING: set the antialiasing mode. Antialiasing
  81. * smoothens the rendered image and avoids the commonly seen staircase
  82. * effect.
  83. * - \c none disables antialiasing.
  84. * - \c prefilter uses a simple prefilter antialiasing method. This is
  85. * the default choice.
  86. *
  87. * \li \b CACA_DITHERING: set the dithering mode. Dithering is necessary
  88. * when rendering a picture that has more colours than the usually
  89. * available palette.
  90. * - \c none disables dithering.
  91. * - \c ordered2 uses a 2x2 Bayer matrix for dithering.
  92. * - \c ordered4 uses a 4x4 Bayer matrix for dithering. This is the
  93. * default choice.
  94. * - \c ordered8 uses a 8x8 Bayer matrix for dithering.
  95. * - \c random uses random dithering.
  96. */
  97. #ifndef __CACA_H__
  98. #define __CACA_H__
  99. #ifdef __cplusplus
  100. extern "C"
  101. {
  102. #endif
  103. /** \brief Colour definitions.
  104. *
  105. * Colours that can be used with caca_set_color().
  106. */
  107. enum caca_color
  108. {
  109. CACA_COLOR_BLACK = 0, /**< The colour index for black. */
  110. CACA_COLOR_BLUE = 1, /**< The colour index for blue. */
  111. CACA_COLOR_GREEN = 2, /**< The colour index for green. */
  112. CACA_COLOR_CYAN = 3, /**< The colour index for cyan. */
  113. CACA_COLOR_RED = 4, /**< The colour index for red. */
  114. CACA_COLOR_MAGENTA = 5, /**< The colour index for magenta. */
  115. CACA_COLOR_BROWN = 6, /**< The colour index for brown. */
  116. CACA_COLOR_LIGHTGRAY = 7, /**< The colour index for light gray. */
  117. CACA_COLOR_DARKGRAY = 8, /**< The colour index for dark gray. */
  118. CACA_COLOR_LIGHTBLUE = 9, /**< The colour index for blue. */
  119. CACA_COLOR_LIGHTGREEN = 10, /**< The colour index for light green. */
  120. CACA_COLOR_LIGHTCYAN = 11, /**< The colour index for light cyan. */
  121. CACA_COLOR_LIGHTRED = 12, /**< The colour index for light red. */
  122. CACA_COLOR_LIGHTMAGENTA = 13, /**< The colour index for light magenta. */
  123. CACA_COLOR_YELLOW = 14, /**< The colour index for yellow. */
  124. CACA_COLOR_WHITE = 15 /**< The colour index for white. */
  125. };
  126. /** \brief Internal features.
  127. *
  128. * Internal libcaca features such as the rendering method or the dithering
  129. * mode.
  130. */
  131. enum caca_feature
  132. {
  133. CACA_BACKGROUND = 0x10, /**< Properties of background characters. */
  134. CACA_BACKGROUND_BLACK = 0x11, /**< Draw only black backgrounds. */
  135. CACA_BACKGROUND_SOLID = 0x12, /**< Draw coloured solid backgorunds. */
  136. #define CACA_BACKGROUND_MIN 0x11 /**< First background property */
  137. #define CACA_BACKGROUND_MAX 0x12 /**< Last background property */
  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. 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. CACA_FEATURE_UNKNOWN = 0xffff /**< Unknown feature. */
  153. };
  154. /*
  155. * Backwards compatibility macros
  156. */
  157. #if !defined(_DOXYGEN_SKIP_ME)
  158. #define caca_dithering caca_feature
  159. #define caca_set_dithering caca_set_feature
  160. #define caca_get_dithering_name caca_get_feature_name
  161. #define CACA_DITHER_NONE CACA_DITHERING_NONE
  162. #define CACA_DITHER_ORDERED CACA_DITHERING_ORDERED8
  163. #define CACA_DITHER_RANDOM CACA_DITHERING_RANDOM
  164. #endif
  165. /** \brief User events.
  166. *
  167. * Event types returned by caca_get_event().
  168. */
  169. enum caca_event
  170. {
  171. CACA_EVENT_NONE = 0x00000000, /**< No event. */
  172. CACA_EVENT_KEY_PRESS = 0x01000000, /**< A key was pressed. */
  173. CACA_EVENT_KEY_RELEASE = 0x02000000, /**< A key was released. */
  174. CACA_EVENT_MOUSE_PRESS = 0x04000000, /**< A mouse button was pressed. */
  175. CACA_EVENT_MOUSE_RELEASE = 0x08000000, /**< A mouse button was released. */
  176. CACA_EVENT_MOUSE_MOTION = 0x10000000, /**< The mouse was moved. */
  177. CACA_EVENT_RESIZE = 0x20000000, /**< The window was resized. */
  178. CACA_EVENT_ANY = 0xff000000 /**< Bitmask for any event. */
  179. };
  180. /** \brief Special key values.
  181. *
  182. * Special key values returned by caca_get_event() for which there is no
  183. * ASCII equivalent.
  184. */
  185. enum caca_key
  186. {
  187. CACA_KEY_UNKNOWN = 0, /**< Unknown key. */
  188. /* The following keys have ASCII equivalents */
  189. CACA_KEY_BACKSPACE = 8, /**< The backspace key. */
  190. CACA_KEY_TAB = 9, /**< The tabulation key. */
  191. CACA_KEY_RETURN = 13, /**< The return key. */
  192. CACA_KEY_PAUSE = 19, /**< The pause key. */
  193. CACA_KEY_ESCAPE = 27, /**< The escape key. */
  194. CACA_KEY_DELETE = 127, /**< The delete key. */
  195. /* The following keys do not have ASCII equivalents but have been
  196. * chosen to match the SDL equivalents */
  197. CACA_KEY_UP = 273, /**< The up arrow key. */
  198. CACA_KEY_DOWN = 274, /**< The down arrow key. */
  199. CACA_KEY_LEFT = 275, /**< The left arrow key. */
  200. CACA_KEY_RIGHT = 276, /**< The right arrow key. */
  201. CACA_KEY_INSERT = 277, /**< The insert key. */
  202. CACA_KEY_HOME = 278, /**< The home key. */
  203. CACA_KEY_END = 279, /**< The end key. */
  204. CACA_KEY_PAGEUP = 280, /**< The page up key. */
  205. CACA_KEY_PAGEDOWN = 281, /**< The page down key. */
  206. CACA_KEY_F1 = 282, /**< The F1 key. */
  207. CACA_KEY_F2 = 283, /**< The F2 key. */
  208. CACA_KEY_F3 = 284, /**< The F3 key. */
  209. CACA_KEY_F4 = 285, /**< The F4 key. */
  210. CACA_KEY_F5 = 286, /**< The F5 key. */
  211. CACA_KEY_F6 = 287, /**< The F6 key. */
  212. CACA_KEY_F7 = 288, /**< The F7 key. */
  213. CACA_KEY_F8 = 289, /**< The F8 key. */
  214. CACA_KEY_F9 = 290, /**< The F9 key. */
  215. CACA_KEY_F10 = 291, /**< The F10 key. */
  216. CACA_KEY_F11 = 292, /**< The F11 key. */
  217. CACA_KEY_F12 = 293, /**< The F12 key. */
  218. CACA_KEY_F13 = 294, /**< The F13 key. */
  219. CACA_KEY_F14 = 295, /**< The F14 key. */
  220. CACA_KEY_F15 = 296 /**< The F15 key. */
  221. };
  222. /** \defgroup basic Basic functions
  223. *
  224. * These functions provide the basic \e libcaca routines for library
  225. * initialisation, system information retrieval and configuration.
  226. *
  227. * @{ */
  228. int caca_init(void);
  229. void caca_set_delay(unsigned int);
  230. enum caca_feature caca_get_feature(enum caca_feature);
  231. void caca_set_feature(enum caca_feature);
  232. char const *caca_get_feature_name(enum caca_feature);
  233. unsigned int caca_get_rendertime(void);
  234. unsigned int caca_get_width(void);
  235. unsigned int caca_get_height(void);
  236. int caca_set_window_title(char const *);
  237. unsigned int caca_get_window_width(void);
  238. unsigned int caca_get_window_height(void);
  239. void caca_refresh(void);
  240. void caca_end(void);
  241. /* @} */
  242. /** \defgroup event Event handling
  243. *
  244. * These functions handle user events such as keyboard input and mouse
  245. * clicks.
  246. *
  247. * @{ */
  248. unsigned int caca_get_event(unsigned int);
  249. unsigned int caca_wait_event(unsigned int);
  250. unsigned int caca_get_mouse_x(void);
  251. unsigned int caca_get_mouse_y(void);
  252. /* @} */
  253. /** \defgroup char Character printing
  254. *
  255. * These functions provide low-level character printing routines.
  256. *
  257. * @{ */
  258. void caca_set_color(enum caca_color, enum caca_color);
  259. enum caca_color caca_get_fg_color(void);
  260. enum caca_color caca_get_bg_color(void);
  261. char const *caca_get_color_name(enum caca_color);
  262. void caca_putchar(int, int, char);
  263. void caca_putstr(int, int, char const *);
  264. void caca_printf(int, int, char const *, ...);
  265. void caca_get_screen(char *);
  266. void caca_clear(void);
  267. /* @} */
  268. /** \defgroup prim Primitives drawing
  269. *
  270. * These functions provide routines for primitive drawing, such as lines,
  271. * boxes, triangles and ellipses.
  272. *
  273. * @{ */
  274. void caca_draw_line(int, int, int, int, char);
  275. void caca_draw_polyline(int const x[], int const y[], int, char);
  276. void caca_draw_thin_line(int, int, int, int);
  277. void caca_draw_thin_polyline(int const x[], int const y[], int);
  278. void caca_draw_circle(int, int, int, char);
  279. void caca_draw_ellipse(int, int, int, int, char);
  280. void caca_draw_thin_ellipse(int, int, int, int);
  281. void caca_fill_ellipse(int, int, int, int, char);
  282. void caca_draw_box(int, int, int, int, char);
  283. void caca_draw_thin_box(int, int, int, int);
  284. void caca_fill_box(int, int, int, int, char);
  285. void caca_draw_triangle(int, int, int, int, int, int, char);
  286. void caca_draw_thin_triangle(int, int, int, int, int, int);
  287. void caca_fill_triangle(int, int, int, int, int, int, char);
  288. /* @} */
  289. /** \defgroup math Mathematical functions
  290. *
  291. * These functions provide a few useful math-related routines.
  292. *
  293. * @{ */
  294. int caca_rand(int, int);
  295. unsigned int caca_sqrt(unsigned int);
  296. float caca_powf(float x, float y);
  297. /* @} */
  298. /** \defgroup sprite Sprite handling
  299. *
  300. * These functions provide high level routines for sprite loading, animation
  301. * and rendering.
  302. *
  303. * @{ */
  304. struct caca_sprite;
  305. struct caca_sprite * caca_load_sprite(char const *);
  306. int caca_get_sprite_frames(struct caca_sprite const *);
  307. int caca_get_sprite_width(struct caca_sprite const *, int);
  308. int caca_get_sprite_height(struct caca_sprite const *, int);
  309. int caca_get_sprite_dx(struct caca_sprite const *, int);
  310. int caca_get_sprite_dy(struct caca_sprite const *, int);
  311. void caca_draw_sprite(int, int, struct caca_sprite const *, int);
  312. void caca_free_sprite(struct caca_sprite *);
  313. /* @} */
  314. /** \defgroup bitmap Bitmap handling
  315. *
  316. * These functions provide high level routines for bitmap allocation and
  317. * rendering.
  318. *
  319. * @{ */
  320. struct caca_bitmap;
  321. struct caca_bitmap *caca_create_bitmap(unsigned int, unsigned int,
  322. unsigned int, unsigned int,
  323. unsigned int, unsigned int,
  324. unsigned int, unsigned int);
  325. void caca_set_bitmap_palette(struct caca_bitmap *,
  326. unsigned int r[], unsigned int g[],
  327. unsigned int b[], unsigned int a[]);
  328. void caca_set_bitmap_gamma(struct caca_bitmap *, float);
  329. void caca_draw_bitmap(int, int, int, int, struct caca_bitmap const *, void *);
  330. void caca_free_bitmap(struct caca_bitmap *);
  331. /* @} */
  332. /** \defgroup exporter Exporters to various formats
  333. *
  334. * These functions exports current image to various text formats
  335. *
  336. * @{ */
  337. char* caca_get_html(void);
  338. char* caca_get_html3(void);
  339. char* caca_get_irc(void);
  340. char* caca_get_ansi(int trailing);
  341. /* @} */
  342. #ifdef __cplusplus
  343. }
  344. #endif
  345. #endif /* __CACA_H__ */