Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

271 rinda
6.3 KiB

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