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.
 
 
 
 
 
 

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