Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

223 строки
8.1 KiB

  1. /*
  2. * libcaca Colour ASCII-Art library
  3. * Copyright (c) 2002-2006 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. /** \file caca.h
  12. * \version \$Id$
  13. * \author Sam Hocevar <sam@zoy.org>
  14. * \brief The \e libcaca public header.
  15. *
  16. * This header contains the public types and functions that applications
  17. * using \e libcaca may use.
  18. */
  19. /** \mainpage libcaca developer documentation
  20. *
  21. * \section intro Introduction
  22. *
  23. * \e libcaca is a graphics library that outputs text instead of pixels,
  24. * so that it can work on older video cards or text terminals. It is not
  25. * unlike the famous AAlib library. \e libcaca can use almost any virtual
  26. * terminal to work, thus it should work on all Unix systems (including
  27. * Mac OS X) using either the slang library or the ncurses library, on DOS
  28. * using the conio library, and on Windows systems using either slang or
  29. * ncurses (through Cygwin emulation) or conio. There is also a native X11
  30. * driver, and an OpenGL driver (through freeglut) that does not require a
  31. * text terminal. For machines without a screen, and with a valid tcp stack,
  32. * the network driver (BSD sockets) should perfectly fit your needs.
  33. *
  34. * \e libcaca is free software, released under the Do What The Fuck You
  35. * Want To Public License. This ensures that no one, not even the \e libcaca
  36. * developers, will ever have anything to say about what you do with the
  37. * software. It used to be licensed under the GNU Lesser General Public
  38. * License, but that was not free enough.
  39. *
  40. * \section api The libcaca API
  41. *
  42. * \e libcaca relies on a low-level, device independent library, called
  43. * \e libcucul. \e libcucul can be used alone as a simple ASCII and/or
  44. * Unicode compositing canvas.
  45. *
  46. * The complete \e libcucul and \e libcaca programming interface is
  47. * available from the cucul.h and caca.h headers.
  48. *
  49. * \section env Environment variables
  50. *
  51. * Some environment variables can be used to change the behaviour of
  52. * \e libcaca or \e libcucul without having to modify the program which
  53. * uses them. These variables are:
  54. *
  55. * \li \b CACA_DRIVER: set the backend video driver. In order of preference:
  56. * - \c conio uses the DOS conio.h interface.
  57. * - \c ncurses uses the ncurses library.
  58. * - \c slang uses the S-Lang library.
  59. * - \c x11 uses the native X11 driver.
  60. * - \c gl uses freeglut and opengl libraries.
  61. * - \c network uses BSD sockets calls.
  62. *
  63. * \li \b CUCUL_BACKGROUND: set the background type.
  64. * - \c solid uses solid coloured backgrounds for all characters. This
  65. * feature does not work with all terminal emulators. This is the
  66. * default choice.
  67. * - \c black uses only black backgrounds to render characters.
  68. *
  69. * \li \b CUCUL_ANTIALIASING: set the antialiasing mode. Antialiasing
  70. * smoothens the rendered image and avoids the commonly seen staircase
  71. * effect.
  72. * - \c none disables antialiasing.
  73. * - \c prefilter uses a simple prefilter antialiasing method. This is
  74. * the default choice.
  75. *
  76. * \li \b CUCUL_DITHERING: set the dithering mode. Dithering is necessary
  77. * when rendering a picture that has more colours than the usually
  78. * available palette.
  79. * - \c none disables dithering.
  80. * - \c ordered2 uses a 2x2 Bayer matrix for dithering.
  81. * - \c ordered4 uses a 4x4 Bayer matrix for dithering. This is the
  82. * default choice.
  83. * - \c ordered8 uses a 8x8 Bayer matrix for dithering.
  84. * - \c random uses random dithering.
  85. *
  86. * \li \b CACA_GEOMETRY: set the video display size. The format of this
  87. * variable must be XxY, with X and Y being integer values. This option
  88. * currently works with the network, X11 and GL drivers.
  89. *
  90. * \li \b CACA_FONT: set the rendered font. The format of this variable is
  91. * implementation dependent, but since it currently only works with the
  92. * X11 driver, an X11 font name such as "fixed" or "5x7" is expected.
  93. *
  94. * \li \b CACA_PORT: set the port the network driver will listen on, when
  95. * the output driver is "network". Default port is 51914 (0xCACA).
  96. */
  97. #ifndef __CACA_H__
  98. #define __CACA_H__
  99. #define CACA_API_VERSION_1
  100. #include <cucul.h>
  101. #ifdef __cplusplus
  102. extern "C"
  103. {
  104. #endif
  105. /** \brief User events.
  106. *
  107. * Event types returned by caca_get_event().
  108. */
  109. enum caca_event_type
  110. {
  111. CACA_EVENT_NONE = 0x0000, /**< No event. */
  112. CACA_EVENT_KEY_PRESS = 0x0001, /**< A key was pressed. */
  113. CACA_EVENT_KEY_RELEASE = 0x0002, /**< A key was released. */
  114. CACA_EVENT_MOUSE_PRESS = 0x0004, /**< A mouse button was pressed. */
  115. CACA_EVENT_MOUSE_RELEASE = 0x0008, /**< A mouse button was released. */
  116. CACA_EVENT_MOUSE_MOTION = 0x0010, /**< The mouse was moved. */
  117. CACA_EVENT_RESIZE = 0x0020, /**< The window was resized. */
  118. CACA_EVENT_ANY = 0xffff /**< Bitmask for any event. */
  119. };
  120. struct caca_event
  121. {
  122. enum caca_event_type type;
  123. union
  124. {
  125. struct { unsigned int x, y, button; } mouse;
  126. struct { unsigned int w, h; } resize;
  127. struct { unsigned int c; unsigned long int ucs4; char utf8[8]; } key;
  128. } data;
  129. };
  130. /** \brief Special key values.
  131. *
  132. * Special key values returned by caca_get_event() for which there is no
  133. * ASCII equivalent.
  134. */
  135. enum caca_key
  136. {
  137. CACA_KEY_UNKNOWN = 0, /**< Unknown key. */
  138. /* The following keys have ASCII equivalents */
  139. CACA_KEY_BACKSPACE = 8, /**< The backspace key. */
  140. CACA_KEY_TAB = 9, /**< The tabulation key. */
  141. CACA_KEY_RETURN = 13, /**< The return key. */
  142. CACA_KEY_PAUSE = 19, /**< The pause key. */
  143. CACA_KEY_ESCAPE = 27, /**< The escape key. */
  144. CACA_KEY_DELETE = 127, /**< The delete key. */
  145. /* The following keys do not have ASCII equivalents but have been
  146. * chosen to match the SDL equivalents */
  147. CACA_KEY_UP = 273, /**< The up arrow key. */
  148. CACA_KEY_DOWN = 274, /**< The down arrow key. */
  149. CACA_KEY_LEFT = 275, /**< The left arrow key. */
  150. CACA_KEY_RIGHT = 276, /**< The right arrow key. */
  151. CACA_KEY_INSERT = 277, /**< The insert key. */
  152. CACA_KEY_HOME = 278, /**< The home key. */
  153. CACA_KEY_END = 279, /**< The end key. */
  154. CACA_KEY_PAGEUP = 280, /**< The page up key. */
  155. CACA_KEY_PAGEDOWN = 281, /**< The page down key. */
  156. CACA_KEY_F1 = 282, /**< The F1 key. */
  157. CACA_KEY_F2 = 283, /**< The F2 key. */
  158. CACA_KEY_F3 = 284, /**< The F3 key. */
  159. CACA_KEY_F4 = 285, /**< The F4 key. */
  160. CACA_KEY_F5 = 286, /**< The F5 key. */
  161. CACA_KEY_F6 = 287, /**< The F6 key. */
  162. CACA_KEY_F7 = 288, /**< The F7 key. */
  163. CACA_KEY_F8 = 289, /**< The F8 key. */
  164. CACA_KEY_F9 = 290, /**< The F9 key. */
  165. CACA_KEY_F10 = 291, /**< The F10 key. */
  166. CACA_KEY_F11 = 292, /**< The F11 key. */
  167. CACA_KEY_F12 = 293, /**< The F12 key. */
  168. CACA_KEY_F13 = 294, /**< The F13 key. */
  169. CACA_KEY_F14 = 295, /**< The F14 key. */
  170. CACA_KEY_F15 = 296 /**< The F15 key. */
  171. };
  172. typedef struct caca_context caca_t;
  173. /** \defgroup basic Basic functions
  174. *
  175. * These functions provide the basic \e libcaca routines for library
  176. * initialisation, system information retrieval and configuration.
  177. *
  178. * @{ */
  179. caca_t * caca_attach(cucul_t *qq);
  180. void caca_detach(caca_t *kk);
  181. void caca_set_delay(caca_t *kk, unsigned int);
  182. void caca_display(caca_t *kk);
  183. unsigned int caca_get_rendertime(caca_t *kk);
  184. unsigned int caca_get_window_width(caca_t *kk);
  185. unsigned int caca_get_window_height(caca_t *kk);
  186. int caca_set_window_title(caca_t *kk, char const *);
  187. /* @} */
  188. /** \defgroup event Event handling
  189. *
  190. * These functions handle user events such as keyboard input and mouse
  191. * clicks.
  192. *
  193. * @{ */
  194. int caca_get_event(caca_t *kk, unsigned int, struct caca_event *);
  195. int caca_wait_event(caca_t *kk, unsigned int, struct caca_event *);
  196. unsigned int caca_get_mouse_x(caca_t *kk);
  197. unsigned int caca_get_mouse_y(caca_t *kk);
  198. /* @} */
  199. #ifdef __cplusplus
  200. }
  201. #endif
  202. #endif /* __CACA_H__ */