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.
 
 
 
 
 
 

241 regels
5.6 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. /* Dirty rectangle */
  50. int dirty_xmin, dirty_xmax, dirty_ymin, dirty_ymax;
  51. /* Shortcut to the active frame information */
  52. int width, height;
  53. uint32_t *chars;
  54. uint32_t *attrs;
  55. uint32_t curattr;
  56. /* FIGfont management */
  57. caca_figfont_t *ff;
  58. };
  59. /* Graphics driver */
  60. enum caca_driver
  61. {
  62. CACA_DRIVER_NONE = 0,
  63. CACA_DRIVER_RAW = 1,
  64. #if defined(USE_COCOA)
  65. CACA_DRIVER_COCOA = 2,
  66. #endif
  67. #if defined(USE_CONIO)
  68. CACA_DRIVER_CONIO = 3,
  69. #endif
  70. #if defined(USE_GL)
  71. CACA_DRIVER_GL = 4,
  72. #endif
  73. #if defined(USE_NCURSES)
  74. CACA_DRIVER_NCURSES = 5,
  75. #endif
  76. #if defined(USE_SLANG)
  77. CACA_DRIVER_SLANG = 6,
  78. #endif
  79. #if defined(USE_VGA)
  80. CACA_DRIVER_VGA = 7,
  81. #endif
  82. #if defined(USE_WIN32)
  83. CACA_DRIVER_WIN32 = 8,
  84. #endif
  85. #if defined(USE_X11)
  86. CACA_DRIVER_X11 = 9,
  87. #endif
  88. };
  89. /* Available external drivers */
  90. #if defined(USE_COCOA)
  91. int cocoa_install(caca_display_t *);
  92. #endif
  93. #if defined(USE_CONIO)
  94. int conio_install(caca_display_t *);
  95. #endif
  96. #if defined(USE_GL)
  97. int gl_install(caca_display_t *);
  98. #endif
  99. #if defined(USE_NCURSES)
  100. int ncurses_install(caca_display_t *);
  101. #endif
  102. int raw_install(caca_display_t *);
  103. #if defined(USE_SLANG)
  104. int slang_install(caca_display_t *);
  105. #endif
  106. #if defined(USE_VGA)
  107. int vga_install(caca_display_t *);
  108. #endif
  109. #if defined(USE_WIN32)
  110. int win32_install(caca_display_t *);
  111. #endif
  112. #if defined(USE_X11)
  113. int x11_install(caca_display_t *);
  114. #endif
  115. /* Timer structure */
  116. struct caca_timer
  117. {
  118. int last_sec, last_usec;
  119. };
  120. /* Private event structure */
  121. struct caca_privevent
  122. {
  123. enum caca_event_type type;
  124. union
  125. {
  126. struct { int x, y, button; } mouse;
  127. struct { int w, h; } resize;
  128. struct { int ch; uint32_t utf32; char utf8[8]; } key;
  129. } data;
  130. };
  131. /* Internal caca display context */
  132. struct caca_display
  133. {
  134. /* A link to our caca canvas */
  135. caca_canvas_t *cv;
  136. int autorelease;
  137. #if defined(USE_PLUGINS)
  138. void *plugin;
  139. #endif
  140. /* Device-specific functions */
  141. struct drv
  142. {
  143. char const * driver;
  144. enum caca_driver id;
  145. struct driver_private *p;
  146. int (* init_graphics) (caca_display_t *);
  147. int (* end_graphics) (caca_display_t *);
  148. int (* set_display_title) (caca_display_t *, char const *);
  149. int (* get_display_width) (caca_display_t const *);
  150. int (* get_display_height) (caca_display_t const *);
  151. void (* display) (caca_display_t *);
  152. void (* handle_resize) (caca_display_t *);
  153. int (* get_event) (caca_display_t *, caca_privevent_t *);
  154. void (* set_mouse) (caca_display_t *, int);
  155. void (* set_cursor) (caca_display_t *, int);
  156. } drv;
  157. /* Mouse position */
  158. struct mouse
  159. {
  160. int x, y;
  161. } mouse;
  162. /* Window resize handling */
  163. struct resize
  164. {
  165. int resized; /* A resize event was requested */
  166. int allow; /* The display driver allows resizing */
  167. int w, h; /* Requested width and height */
  168. } resize;
  169. /* Framerate handling */
  170. int delay, rendertime;
  171. caca_timer_t timer;
  172. int lastticks;
  173. struct events
  174. {
  175. #if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL)
  176. caca_privevent_t buf[EVENTBUF_LEN];
  177. int queue;
  178. #endif
  179. #if defined(USE_SLANG) || defined(USE_NCURSES)
  180. caca_timer_t key_timer;
  181. int last_key_ticks;
  182. int autorepeat_ticks;
  183. caca_privevent_t last_key_event;
  184. #endif
  185. #if defined(USE_WIN32)
  186. uint8_t not_empty_struct;
  187. #endif
  188. } events;
  189. };
  190. /* Colour functions */
  191. extern uint32_t _caca_attr_to_rgb24fg(uint32_t);
  192. extern uint32_t _caca_attr_to_rgb24bg(uint32_t);
  193. /* Frames functions */
  194. extern void _caca_save_frame_info(caca_canvas_t *);
  195. extern void _caca_load_frame_info(caca_canvas_t *);
  196. /* Internal timer functions */
  197. extern void _caca_sleep(int);
  198. extern int _caca_getticks(caca_timer_t *);
  199. /* Internal event functions */
  200. extern void _caca_handle_resize(caca_display_t *);
  201. #if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL)
  202. extern void _push_event(caca_display_t *, caca_privevent_t *);
  203. extern int _pop_event(caca_display_t *, caca_privevent_t *);
  204. #endif
  205. /* Internal window functions */
  206. extern void _caca_set_term_title(char const *);
  207. #endif /* __CACA_INTERNALS_H__ */