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.
 
 
 
 
 
 

238 lines
5.5 KiB

  1. /*
  2. * libcaca Colour ASCII-Art library
  3. * Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
  4. * All Rights Reserved
  5. *
  6. * $Id$
  7. *
  8. * This library is free software. It comes without any warranty, to
  9. * the extent permitted by applicable law. You can redistribute it
  10. * and/or modify it under the terms of the Do What The Fuck You Want
  11. * To Public License, Version 2, as published by Sam Hocevar. See
  12. * http://sam.zoy.org/wtfpl/COPYING for more details.
  13. */
  14. #ifndef __CACA_INTERNALS_H__
  15. #define __CACA_INTERNALS_H__
  16. #include "caca_stubs.h"
  17. typedef struct caca_timer caca_timer_t;
  18. typedef struct caca_privevent caca_privevent_t;
  19. typedef struct caca_figfont caca_figfont_t;
  20. #if !defined(_DOXYGEN_SKIP_ME)
  21. # define EVENTBUF_LEN 10
  22. #endif
  23. struct caca_frame
  24. {
  25. /* Frame size */
  26. int width, height;
  27. /* Cell information */
  28. uint32_t *chars;
  29. uint32_t *attrs;
  30. /* Painting context */
  31. int x, y;
  32. int handlex, handley;
  33. uint32_t curattr;
  34. /* Frame name */
  35. char *name;
  36. };
  37. struct caca_canvas
  38. {
  39. /* XXX: look at caca_set_canvas_boundaries() before adding anything
  40. * to this structure. The function is quite hacky. */
  41. /* Frame information */
  42. int frame, framecount;
  43. struct caca_frame *frames;
  44. /* Canvas management */
  45. int refcount;
  46. int autoinc;
  47. int (*resize_callback)(void *);
  48. void *resize_data;
  49. /* Shortcut to the active frame information */
  50. int width, height;
  51. uint32_t *chars;
  52. uint32_t *attrs;
  53. uint32_t curattr;
  54. /* FIGfont management */
  55. caca_figfont_t *ff;
  56. };
  57. /* Graphics driver */
  58. enum caca_driver
  59. {
  60. CACA_DRIVER_NONE = 0,
  61. CACA_DRIVER_RAW = 1,
  62. #if defined(USE_COCOA)
  63. CACA_DRIVER_COCOA = 2,
  64. #endif
  65. #if defined(USE_CONIO)
  66. CACA_DRIVER_CONIO = 3,
  67. #endif
  68. #if defined(USE_GL)
  69. CACA_DRIVER_GL = 4,
  70. #endif
  71. #if defined(USE_NCURSES)
  72. CACA_DRIVER_NCURSES = 5,
  73. #endif
  74. #if defined(USE_SLANG)
  75. CACA_DRIVER_SLANG = 6,
  76. #endif
  77. #if defined(USE_VGA)
  78. CACA_DRIVER_VGA = 7,
  79. #endif
  80. #if defined(USE_WIN32)
  81. CACA_DRIVER_WIN32 = 8,
  82. #endif
  83. #if defined(USE_X11)
  84. CACA_DRIVER_X11 = 9,
  85. #endif
  86. };
  87. /* Available external drivers */
  88. #if defined(USE_COCOA)
  89. int cocoa_install(caca_display_t *);
  90. #endif
  91. #if defined(USE_CONIO)
  92. int conio_install(caca_display_t *);
  93. #endif
  94. #if defined(USE_GL)
  95. int gl_install(caca_display_t *);
  96. #endif
  97. #if defined(USE_NCURSES)
  98. int ncurses_install(caca_display_t *);
  99. #endif
  100. int raw_install(caca_display_t *);
  101. #if defined(USE_SLANG)
  102. int slang_install(caca_display_t *);
  103. #endif
  104. #if defined(USE_VGA)
  105. int vga_install(caca_display_t *);
  106. #endif
  107. #if defined(USE_WIN32)
  108. int win32_install(caca_display_t *);
  109. #endif
  110. #if defined(USE_X11)
  111. int x11_install(caca_display_t *);
  112. #endif
  113. /* Timer structure */
  114. struct caca_timer
  115. {
  116. int last_sec, last_usec;
  117. };
  118. /* Private event structure */
  119. struct caca_privevent
  120. {
  121. enum caca_event_type type;
  122. union
  123. {
  124. struct { int x, y, button; } mouse;
  125. struct { int w, h; } resize;
  126. struct { int ch; uint32_t utf32; char utf8[8]; } key;
  127. } data;
  128. };
  129. /* Internal caca display context */
  130. struct caca_display
  131. {
  132. /* A link to our caca canvas */
  133. caca_canvas_t *cv;
  134. int autorelease;
  135. #if defined(USE_PLUGINS)
  136. void *plugin;
  137. #endif
  138. /* Device-specific functions */
  139. struct drv
  140. {
  141. char const * driver;
  142. enum caca_driver id;
  143. struct driver_private *p;
  144. int (* init_graphics) (caca_display_t *);
  145. int (* end_graphics) (caca_display_t *);
  146. int (* set_display_title) (caca_display_t *, char const *);
  147. int (* get_display_width) (caca_display_t const *);
  148. int (* get_display_height) (caca_display_t const *);
  149. void (* display) (caca_display_t *);
  150. void (* handle_resize) (caca_display_t *);
  151. int (* get_event) (caca_display_t *, caca_privevent_t *);
  152. void (* set_mouse) (caca_display_t *, int);
  153. void (* set_cursor) (caca_display_t *, int);
  154. } drv;
  155. /* Mouse position */
  156. struct mouse
  157. {
  158. int x, y;
  159. } mouse;
  160. /* Window resize handling */
  161. struct resize
  162. {
  163. int resized; /* A resize event was requested */
  164. int allow; /* The display driver allows resizing */
  165. int w, h; /* Requested width and height */
  166. } resize;
  167. /* Framerate handling */
  168. int delay, rendertime;
  169. caca_timer_t timer;
  170. int lastticks;
  171. struct events
  172. {
  173. #if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL)
  174. caca_privevent_t buf[EVENTBUF_LEN];
  175. int queue;
  176. #endif
  177. #if defined(USE_SLANG) || defined(USE_NCURSES)
  178. caca_timer_t key_timer;
  179. int last_key_ticks;
  180. int autorepeat_ticks;
  181. caca_privevent_t last_key_event;
  182. #endif
  183. #if defined(USE_WIN32)
  184. uint8_t not_empty_struct;
  185. #endif
  186. } events;
  187. };
  188. /* Colour functions */
  189. extern uint32_t _caca_attr_to_rgb24fg(uint32_t);
  190. extern uint32_t _caca_attr_to_rgb24bg(uint32_t);
  191. /* Frames functions */
  192. extern void _caca_save_frame_info(caca_canvas_t *);
  193. extern void _caca_load_frame_info(caca_canvas_t *);
  194. /* Internal timer functions */
  195. extern void _caca_sleep(int);
  196. extern int _caca_getticks(caca_timer_t *);
  197. /* Internal event functions */
  198. extern void _caca_handle_resize(caca_display_t *);
  199. #if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL)
  200. extern void _push_event(caca_display_t *, caca_privevent_t *);
  201. extern int _pop_event(caca_display_t *, caca_privevent_t *);
  202. #endif
  203. /* Internal window functions */
  204. extern void _caca_set_term_title(char const *);
  205. #endif /* __CACA_INTERNALS_H__ */