Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

283 строки
6.6 KiB

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