您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

250 行
5.7 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. # define MAX_DIRTY_COUNT 1
  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;
  52. struct
  53. {
  54. int xmin, xmax, ymin, ymax;
  55. }
  56. dirty[MAX_DIRTY_COUNT];
  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_NONE = 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 raw_install(caca_display_t *);
  109. #if defined(USE_SLANG)
  110. int slang_install(caca_display_t *);
  111. #endif
  112. #if defined(USE_VGA)
  113. int vga_install(caca_display_t *);
  114. #endif
  115. #if defined(USE_WIN32)
  116. int win32_install(caca_display_t *);
  117. #endif
  118. #if defined(USE_X11)
  119. int x11_install(caca_display_t *);
  120. #endif
  121. /* Timer structure */
  122. struct caca_timer
  123. {
  124. int last_sec, last_usec;
  125. };
  126. /* Private event structure */
  127. struct caca_privevent
  128. {
  129. enum caca_event_type type;
  130. union
  131. {
  132. struct { int x, y, button; } mouse;
  133. struct { int w, h; } resize;
  134. struct { int ch; uint32_t utf32; char utf8[8]; } key;
  135. } data;
  136. };
  137. /* Internal caca display context */
  138. struct caca_display
  139. {
  140. /* A link to our caca canvas */
  141. caca_canvas_t *cv;
  142. int autorelease;
  143. #if defined(USE_PLUGINS)
  144. void *plugin;
  145. #endif
  146. /* Device-specific functions */
  147. struct drv
  148. {
  149. char const * driver;
  150. enum caca_driver id;
  151. struct driver_private *p;
  152. int (* init_graphics) (caca_display_t *);
  153. int (* end_graphics) (caca_display_t *);
  154. int (* set_display_title) (caca_display_t *, char const *);
  155. int (* get_display_width) (caca_display_t const *);
  156. int (* get_display_height) (caca_display_t const *);
  157. void (* display) (caca_display_t *);
  158. void (* handle_resize) (caca_display_t *);
  159. int (* get_event) (caca_display_t *, caca_privevent_t *);
  160. void (* set_mouse) (caca_display_t *, int);
  161. void (* set_cursor) (caca_display_t *, int);
  162. } drv;
  163. /* Mouse position */
  164. struct mouse
  165. {
  166. int x, y;
  167. } mouse;
  168. /* Window resize handling */
  169. struct resize
  170. {
  171. int resized; /* A resize event was requested */
  172. int allow; /* The display driver allows resizing */
  173. int w, h; /* Requested width and height */
  174. } resize;
  175. /* Framerate handling */
  176. int delay, rendertime;
  177. caca_timer_t timer;
  178. int lastticks;
  179. struct events
  180. {
  181. #if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL)
  182. caca_privevent_t buf[EVENTBUF_LEN];
  183. int queue;
  184. #endif
  185. #if defined(USE_SLANG) || defined(USE_NCURSES)
  186. caca_timer_t key_timer;
  187. int last_key_ticks;
  188. int autorepeat_ticks;
  189. caca_privevent_t last_key_event;
  190. #endif
  191. #if defined(USE_WIN32)
  192. uint8_t not_empty_struct;
  193. #endif
  194. } events;
  195. };
  196. /* Dirty rectangle functions */
  197. extern void _caca_clip_dirty_rect_list(caca_canvas_t *);
  198. /* Colour functions */
  199. extern uint32_t _caca_attr_to_rgb24fg(uint32_t);
  200. extern uint32_t _caca_attr_to_rgb24bg(uint32_t);
  201. /* Frames functions */
  202. extern void _caca_save_frame_info(caca_canvas_t *);
  203. extern void _caca_load_frame_info(caca_canvas_t *);
  204. /* Internal timer functions */
  205. extern void _caca_sleep(int);
  206. extern int _caca_getticks(caca_timer_t *);
  207. /* Internal event functions */
  208. extern void _caca_handle_resize(caca_display_t *);
  209. #if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL)
  210. extern void _push_event(caca_display_t *, caca_privevent_t *);
  211. extern int _pop_event(caca_display_t *, caca_privevent_t *);
  212. #endif
  213. /* Internal window functions */
  214. extern void _caca_set_term_title(char const *);
  215. #endif /* __CACA_INTERNALS_H__ */