Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

251 righe
5.8 KiB

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