You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

219 lines
4.7 KiB

  1. /*
  2. * libcaca 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_internals.h
  12. * \version \$Id$
  13. * \author Sam Hocevar <sam@zoy.org>
  14. * \brief The \e libcaca private header.
  15. *
  16. * This header contains the private types and functions used by \e libcaca.
  17. */
  18. #ifndef __CACA_INTERNALS_H__
  19. #define __CACA_INTERNALS_H__
  20. #if defined(HAVE_INTTYPES_H) || defined(_DOXYGEN_SKIP_ME)
  21. # include <inttypes.h>
  22. #elif !defined(CUSTOM_INTTYPES)
  23. # define CUSTOM_INTTYPES
  24. typedef unsigned char uint8_t;
  25. typedef unsigned short uint16_t;
  26. typedef unsigned int uint32_t;
  27. #endif
  28. #if defined(USE_CONIO)
  29. # include <conio.h>
  30. #endif
  31. #if defined(USE_GL)
  32. # include <GL/glut.h>
  33. #endif
  34. #if defined(USE_NCURSES)
  35. # if defined(HAVE_NCURSES_H)
  36. # include <ncurses.h>
  37. # else
  38. # include <curses.h>
  39. # endif
  40. #endif
  41. #if defined(USE_WIN32)
  42. # include <windows.h>
  43. #endif
  44. #if defined(USE_X11)
  45. # include <X11/Xlib.h>
  46. #endif
  47. #if !defined(_DOXYGEN_SKIP_ME)
  48. # define EVENTBUF_LEN 10
  49. #endif
  50. /* Graphics driver */
  51. enum caca_driver
  52. {
  53. #if defined(USE_CONIO)
  54. CACA_DRIVER_CONIO = 1,
  55. #endif
  56. #if defined(USE_NCURSES)
  57. CACA_DRIVER_NCURSES = 2,
  58. #endif
  59. #if defined(USE_SLANG)
  60. CACA_DRIVER_SLANG = 3,
  61. #endif
  62. #if defined(USE_X11)
  63. CACA_DRIVER_X11 = 4,
  64. #endif
  65. #if defined(USE_WIN32)
  66. CACA_DRIVER_WIN32 = 5,
  67. #endif
  68. #if defined(USE_GL)
  69. CACA_DRIVER_GL = 6,
  70. #endif
  71. CACA_DRIVER_NONE = 0
  72. };
  73. /* Available drivers */
  74. #if defined(USE_CONIO)
  75. void conio_init_driver(caca_t *);
  76. #endif
  77. #if defined(USE_GL)
  78. void gl_init_driver(caca_t *);
  79. #endif
  80. #if defined(USE_NCURSES)
  81. void ncurses_init_driver(caca_t *);
  82. #endif
  83. #if defined(USE_SLANG)
  84. void slang_init_driver(caca_t *);
  85. #endif
  86. #if defined(USE_WIN32)
  87. void win32_init_driver(caca_t *);
  88. #endif
  89. #if defined(USE_X11)
  90. void x11_init_driver(caca_t *);
  91. #endif
  92. /* Timer structure */
  93. struct caca_timer
  94. {
  95. int last_sec, last_usec;
  96. };
  97. /* Internal caca context */
  98. struct caca_context
  99. {
  100. cucul_t *qq;
  101. struct driver
  102. {
  103. enum caca_driver driver;
  104. int (* init_graphics) (caca_t *);
  105. int (* end_graphics) (caca_t *);
  106. int (* set_window_title) (caca_t *, char const *);
  107. unsigned int (* get_window_width) (caca_t *);
  108. unsigned int (* get_window_height) (caca_t *);
  109. void (* display) (caca_t *);
  110. void (* handle_resize) (caca_t *, unsigned int *, unsigned int *);
  111. } driver;
  112. //unsigned int width, height;
  113. unsigned int mouse_x, mouse_y;
  114. int resize;
  115. int resize_event;
  116. unsigned int delay, rendertime;
  117. struct caca_timer timer;
  118. int lastticks;
  119. struct events
  120. {
  121. #if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO)
  122. unsigned int buf[EVENTBUF_LEN];
  123. int queue;
  124. #endif
  125. #if defined(USE_SLANG) || defined(USE_NCURSES)
  126. struct caca_timer key_timer;
  127. unsigned int last_key_ticks;
  128. unsigned int autorepeat_ticks;
  129. unsigned int last_key;
  130. #endif
  131. } events;
  132. /* FIXME: maybe this should go away */
  133. #if defined(USE_X11) && !defined(_DOXYGEN_SKIP_ME)
  134. struct x11
  135. {
  136. Display *dpy;
  137. Window window;
  138. Pixmap pixmap;
  139. GC gc;
  140. long int event_mask;
  141. int font_width, font_height;
  142. unsigned int new_width, new_height;
  143. int colors[16];
  144. Font font;
  145. XFontStruct *font_struct;
  146. int font_offset;
  147. #if defined(HAVE_X11_XKBLIB_H)
  148. Bool autorepeat;
  149. #endif
  150. } x11;
  151. #endif
  152. #if defined(USE_NCURSES)
  153. struct ncurses
  154. {
  155. int attr[16*16];
  156. mmask_t oldmask;
  157. } ncurses;
  158. #endif
  159. #if defined(USE_CONIO)
  160. struct conio
  161. {
  162. struct text_info ti;
  163. char *screen;
  164. } conio;
  165. #endif
  166. #if defined(USE_WIN32)
  167. struct win32
  168. {
  169. HANDLE hin, hout;
  170. HANDLE front, back;
  171. CHAR_INFO *buffer;
  172. CONSOLE_CURSOR_INFO cci;
  173. } win32;
  174. #endif
  175. #if defined(USE_GL)
  176. struct gl
  177. {
  178. int window;
  179. unsigned int width, height;
  180. float font_width, font_height;
  181. float incx, incy;
  182. int id[94];
  183. unsigned char resized, bit;
  184. unsigned char mouse_changed, mouse_clicked;
  185. unsigned int mouse_x, mouse_y;
  186. unsigned int mouse_button, mouse_state;
  187. unsigned char key;
  188. int special_key;
  189. int new_width;
  190. int new_height;
  191. float sw, sh;
  192. } gl;
  193. #endif
  194. };
  195. /* Timer functions */
  196. extern void _caca_sleep(unsigned int);
  197. extern unsigned int _caca_getticks(struct caca_timer *);
  198. #endif /* __CACA_INTERNALS_H__ */