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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /*
  2. * libcaca Colour ASCII-Art library
  3. * Copyright © 2002—2018 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. /*
  13. * This header contains glue code for applications using the pre-1.0
  14. * libcaca API.
  15. */
  16. #ifndef __CACA0_H__
  17. #define __CACA0_H__
  18. #include <caca.h>
  19. #undef __extern
  20. #if defined _DOXYGEN_SKIP_ME
  21. #elif defined _WIN32 && defined __LIBCACA__ && defined DLL_EXPORT
  22. # define __extern extern __declspec(dllexport)
  23. #elif defined _WIN32 && !defined __LIBCACA__
  24. # define __extern extern __declspec(dllimport)
  25. #elif defined CACA_ENABLE_VISIBILITY
  26. # define __extern extern __attribute__((visibility("default")))
  27. #else
  28. # define __extern extern
  29. #endif
  30. #ifdef __cplusplus
  31. extern "C"
  32. {
  33. #endif
  34. /* Function emulation */
  35. __extern int __caca0_init(void);
  36. __extern void __caca0_end(void);
  37. __extern unsigned int __caca0_get_event(unsigned int, int);
  38. __extern unsigned int __caca0_sqrt(unsigned int);
  39. __extern int __caca0_get_feature(int);
  40. __extern void __caca0_set_feature(int);
  41. __extern char const *__caca0_get_feature_name(int);
  42. __extern caca_canvas_t *__caca0_load_sprite(char const *);
  43. __extern caca_dither_t *__caca0_create_bitmap(unsigned int, unsigned int,
  44. unsigned int, unsigned int, unsigned long int, unsigned long int,
  45. unsigned long int, unsigned long int);
  46. __extern void __caca0_free_bitmap(caca_dither_t *);
  47. __extern char const *__caca0_get_color_name(unsigned char);
  48. /* These variables are needed to emulate old non-thread safe behaviour */
  49. __extern caca_canvas_t *__caca0_cv;
  50. __extern caca_display_t *__caca0_dp;
  51. __extern unsigned char __caca0_fg;
  52. __extern unsigned char __caca0_bg;
  53. /* This enum still exists in libcaca 1.x, thus cannot be redefined */
  54. #define CACA_COLOR_BLACK CACA_BLACK
  55. #define CACA_COLOR_BLUE CACA_BLUE
  56. #define CACA_COLOR_GREEN CACA_GREEN
  57. #define CACA_COLOR_CYAN CACA_CYAN
  58. #define CACA_COLOR_RED CACA_RED
  59. #define CACA_COLOR_MAGENTA CACA_MAGENTA
  60. #define CACA_COLOR_BROWN CACA_BROWN
  61. #define CACA_COLOR_LIGHTGRAY CACA_LIGHTGRAY
  62. #define CACA_COLOR_DARKGRAY CACA_DARKGRAY
  63. #define CACA_COLOR_LIGHTBLUE CACA_LIGHTBLUE
  64. #define CACA_COLOR_LIGHTGREEN CACA_LIGHTGREEN
  65. #define CACA_COLOR_LIGHTCYAN CACA_LIGHTCYAN
  66. #define CACA_COLOR_LIGHTRED CACA_LIGHTRED
  67. #define CACA_COLOR_LIGHTMAGENTA CACA_LIGHTMAGENTA
  68. #define CACA_COLOR_YELLOW CACA_YELLOW
  69. #define CACA_COLOR_WHITE CACA_WHITE
  70. /* These enums and macros changed names or values */
  71. enum caca_feature
  72. {
  73. CACA_BACKGROUND = 0x10,
  74. CACA_BACKGROUND_BLACK = 0x11,
  75. CACA_BACKGROUND_SOLID = 0x12,
  76. #define CACA_BACKGROUND_MIN 0x11
  77. #define CACA_BACKGROUND_MAX 0x12
  78. CACA_ANTIALIASING = 0x20,
  79. CACA_ANTIALIASING_NONE = 0x21,
  80. CACA_ANTIALIASING_PREFILTER = 0x22,
  81. #define CACA_ANTIALIASING_MIN 0x21
  82. #define CACA_ANTIALIASING_MAX 0x22
  83. CACA_DITHERING = 0x30,
  84. CACA_DITHERING_NONE = 0x31,
  85. CACA_DITHERING_ORDERED2 = 0x32,
  86. CACA_DITHERING_ORDERED4 = 0x33,
  87. CACA_DITHERING_ORDERED8 = 0x34,
  88. CACA_DITHERING_RANDOM = 0x35,
  89. #define CACA_DITHERING_MIN 0x31
  90. #define CACA_DITHERING_MAX 0x35
  91. CACA_FEATURE_UNKNOWN = 0xffff
  92. };
  93. #if ! defined __LIBCACA__
  94. /* This enum still exists in libcaca 1.x, thus cannot be redefined */
  95. #define CACA_EVENT_NONE 0x00000000
  96. #define CACA_EVENT_KEY_PRESS 0x01000000
  97. #define CACA_EVENT_KEY_RELEASE 0x02000000
  98. #define CACA_EVENT_MOUSE_PRESS 0x04000000
  99. #define CACA_EVENT_MOUSE_RELEASE 0x08000000
  100. #define CACA_EVENT_MOUSE_MOTION 0x10000000
  101. #define CACA_EVENT_RESIZE 0x20000000
  102. #define CACA_EVENT_ANY 0xff000000
  103. /* Backwards compatibility macros for even older shit */
  104. #define caca_dithering caca_feature
  105. #define caca_set_dithering caca_set_feature
  106. #define caca_get_dithering_name caca_get_feature_name
  107. #define CACA_DITHER_NONE CACA_DITHERING_NONE
  108. #define CACA_DITHER_ORDERED CACA_DITHERING_ORDERED8
  109. #define CACA_DITHER_RANDOM CACA_DITHERING_RANDOM
  110. /* Macros to redefine all the shit */
  111. #define caca_init __caca0_init
  112. #define caca_set_delay(x) caca_set_display_time(__caca0_dp, x)
  113. #define caca_get_feature __caca0_get_feature
  114. #define caca_set_feature __caca0_set_feature
  115. #define caca_get_feature_name __caca0_get_feature_name
  116. #define caca_get_rendertime() caca_get_display_time(__caca0_dp)
  117. #define caca_get_width() caca_get_canvas_width(__caca0_cv)
  118. #define caca_get_height() caca_get_canvas_height(__caca0_cv)
  119. #define caca_set_window_title(s) caca_set_display_title(__caca0_dp, s)
  120. #define caca_get_window_width() caca_get_display_width(__caca0_dp)
  121. #define caca_get_window_height() caca_get_display_height(__caca0_dp)
  122. #define caca_refresh() caca_refresh_display(__caca0_dp)
  123. #define caca_end __caca0_end
  124. #define caca_get_event(x) __caca0_get_event(x, 0)
  125. #define caca_wait_event(x) __caca0_get_event(x, -1)
  126. #define caca_get_mouse_x() caca_get_mouse_x(__caca0_dp)
  127. #define caca_get_mouse_y() caca_get_mouse_y(__caca0_dp)
  128. #define caca_set_color(x, y) \
  129. (__caca0_fg = (x), __caca0_bg = (y), caca_set_color_ansi(__caca0_cv, x, y))
  130. #define caca_get_fg_color() __caca0_fg
  131. #define caca_get_bg_color() __caca0_bg
  132. #define caca_get_color_name __caca0_get_color_name
  133. #define caca_putchar(x, y, c) caca_put_char(__caca0_cv, x, y, c)
  134. #define caca_putstr(x, y, s) caca_put_str(__caca0_cv, x, y, s)
  135. #define caca_printf(x, y, f, z...) caca_printf(__caca0_cv, x, y, f, ##z)
  136. #define caca_clear() caca_clear_canvas(__caca0_cv)
  137. #define caca_draw_line(x, y, z, t, c) \
  138. caca_draw_line(__caca0_cv, x, y, z, t, c)
  139. #define caca_draw_polyline(x, y, z, c) \
  140. caca_draw_polyline(__caca0_cv, x, y, z, c)
  141. #define caca_draw_thin_line(x, y, z, t) \
  142. caca_draw_thin_line(__caca0_cv, x, y, z, t)
  143. #define caca_draw_thin_polyline(x, y, z) \
  144. caca_draw_thin_polyline(__caca0_cv, x, y, z)
  145. #define caca_draw_circle(x, y, z, c) \
  146. caca_draw_circle(__caca0_cv, x, y, z, c)
  147. #define caca_draw_ellipse(x, y, z, t, c) \
  148. caca_draw_ellipse(__caca0_cv, x, y, z, t, c)
  149. #define caca_draw_thin_ellipse(x, y, z, t) \
  150. caca_draw_thin_ellipse(__caca0_cv, x, y, z, t)
  151. #define caca_fill_ellipse(x, y, z, t, c) \
  152. caca_fill_ellipse(__caca0_cv, x, y, z, t, c)
  153. #define caca_draw_box(x, y, z, t, c) \
  154. caca_draw_box(__caca0_cv, x, y, z, t, c)
  155. #define caca_draw_thin_box(x, y, z, t) \
  156. caca_draw_thin_box(__caca0_cv, x, y, z, t)
  157. #define caca_fill_box(x, y, z, t, c) \
  158. caca_fill_box(__caca0_cv, x, y, z, t, c)
  159. #define caca_draw_triangle(x, y, z, t, u, v, c) \
  160. caca_draw_triangle(__caca0_cv, x, y, z, t, u, v, c)
  161. #define caca_draw_thin_triangle(x, y, z, t, u, v) \
  162. caca_draw_thin_triangle(__caca0_cv, x, y, z, t, u, v)
  163. #define caca_fill_triangle(x, y, z, t, u, v, c) \
  164. caca_fill_triangle(__caca0_cv, x, y, z, t, u, v, c)
  165. #define caca_rand(a, b) caca_rand(a, (b)+1)
  166. #define caca_sqrt __caca0_sqrt
  167. #define caca_sprite caca_canvas
  168. #define caca_load_sprite __caca0_load_sprite
  169. #define caca_get_sprite_frames(c) 1
  170. #define caca_get_sprite_width(c, f) caca_get_canvas_width(c)
  171. #define caca_get_sprite_height(c, f) caca_get_canvas_height(c)
  172. #define caca_get_sprite_dx(c, f) 0
  173. #define caca_get_sprite_dx(c, f) 0
  174. #define caca_draw_sprite(x, y, c, f) caca_blit(__caca0_cv, x, y, c, NULL)
  175. #define caca_free_sprite caca_free_canvas
  176. #define caca_bitmap caca_dither
  177. #define caca_create_bitmap __caca0_create_bitmap
  178. #define caca_set_bitmap_palette caca_set_dither_palette
  179. #define caca_draw_bitmap(x, y, z, t, b, p) \
  180. caca_dither_bitmap(__caca0_cv, x, y, z, t, b, p)
  181. #define caca_free_bitmap __caca0_free_bitmap
  182. #endif /* ! defined __LIBCACA__ */
  183. #ifdef __cplusplus
  184. }
  185. #endif
  186. #undef __extern
  187. #endif /* __CACA0_H__ */