graphics.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. /* Copyright 2001-2003 by Norbert Freudemann, David Frese */
  2. #include "xlib.h"
  3. s48_ref_t scx_coord_mode_binding = NULL;
  4. #define scx_extract_coord_mode(c, x) \
  5. S48_EXTRACT_ENUM(c, x, scx_coord_mode_binding)
  6. s48_ref_t scx_polygon_shape_binding = NULL;
  7. #define scx_extract_polygon_shape(c, x) \
  8. S48_EXTRACT_ENUM(c, x, scx_polygon_shape_binding)
  9. s48_ref_t scx_Copy_Area(s48_call_t call, s48_ref_t display,
  10. s48_ref_t src, s48_ref_t dest, s48_ref_t gc, s48_ref_t srcx,
  11. s48_ref_t srcy, s48_ref_t width, s48_ref_t height,
  12. s48_ref_t destx, s48_ref_t desty) {
  13. XCopyArea(scx_extract_display(call, display),
  14. scx_extract_drawable(call, src),
  15. scx_extract_drawable(call, dest),
  16. scx_extract_gc(call, gc),
  17. (int)s48_extract_long_2(call, srcx),
  18. (int)s48_extract_long_2(call, srcy),
  19. (int)s48_extract_long_2(call, width),
  20. (int)s48_extract_long_2(call, height),
  21. (int)s48_extract_long_2(call, destx),
  22. (int)s48_extract_long_2(call, desty));
  23. return s48_unspecific_2(call);
  24. }
  25. s48_ref_t scx_Copy_Plane(s48_call_t call, s48_ref_t display,
  26. s48_ref_t src, s48_ref_t dest, s48_ref_t gc, s48_ref_t srcx,
  27. s48_ref_t srcy, s48_ref_t width, s48_ref_t height,
  28. s48_ref_t destx, s48_ref_t desty, s48_ref_t plane) {
  29. XCopyPlane(scx_extract_display(call, display),
  30. scx_extract_drawable(call, src),
  31. scx_extract_drawable(call, dest),
  32. scx_extract_gc(call, gc),
  33. (int)s48_extract_long_2(call, srcx),
  34. (int)s48_extract_long_2(call, srcy),
  35. (int)s48_extract_long_2(call, width),
  36. (int)s48_extract_long_2(call, height),
  37. (int)s48_extract_long_2(call, destx),
  38. (int)s48_extract_long_2(call, desty),
  39. (unsigned long)s48_extract_long_2(call, plane));
  40. return s48_unspecific_2(call);
  41. }
  42. s48_ref_t scx_Draw_Point(s48_call_t call, s48_ref_t display, s48_ref_t drawable,
  43. s48_ref_t gc, s48_ref_t x, s48_ref_t y)
  44. {
  45. XDrawPoint(scx_extract_display(call, display),
  46. scx_extract_drawable(call, drawable),
  47. scx_extract_gc(call, gc),
  48. (int)s48_extract_long_2(call, x),
  49. (int)s48_extract_long_2(call, y));
  50. return s48_unspecific_2(call);
  51. }
  52. static void List_To_XPoints(s48_call_t call, s48_ref_t l, XPoint* p, int n) {
  53. int i;
  54. for (i = 0; i < n; i++) {
  55. s48_ref_t point = s48_car_2(call, l);
  56. p[i].x = (int)s48_extract_long_2(call, s48_car_2(call, point));
  57. p[i].y = (int)s48_extract_long_2(call, s48_cdr_2(call, point));
  58. s48_ref_t temp = l;
  59. l = s48_cdr_2(call, l);
  60. s48_free_local_ref(call, temp);
  61. }
  62. }
  63. s48_ref_t scx_Draw_Points(s48_call_t call, s48_ref_t display,
  64. s48_ref_t drawable, s48_ref_t gc, s48_ref_t points, s48_ref_t mode)
  65. {
  66. int n = s48_extract_long_2(call, s48_length_2(call, points));
  67. XPoint p[n];
  68. List_To_XPoints(call, points, p, n);
  69. XDrawPoints(scx_extract_display(call, display),
  70. scx_extract_drawable(call, drawable),
  71. scx_extract_gc(call, gc), p, n,
  72. scx_extract_coord_mode(call, mode));
  73. return s48_unspecific_2(call);
  74. }
  75. s48_ref_t scx_Draw_Line(s48_call_t call, s48_ref_t display, s48_ref_t drawable,
  76. s48_ref_t gc, s48_ref_t x1, s48_ref_t y1, s48_ref_t x2,
  77. s48_ref_t y2)
  78. {
  79. XDrawLine(scx_extract_display(call, display),
  80. scx_extract_drawable(call, drawable),
  81. scx_extract_gc(call, gc),
  82. (int)s48_extract_long_2(call, x1),
  83. (int)s48_extract_long_2(call, y1),
  84. (int)s48_extract_long_2(call, x2),
  85. (int)s48_extract_long_2(call, y2));
  86. return s48_unspecific_2(call);
  87. }
  88. s48_ref_t scx_Draw_Lines(s48_call_t call, s48_ref_t display, s48_ref_t drawable,
  89. s48_ref_t gc, s48_ref_t points, s48_ref_t mode) {
  90. int n = s48_extract_long_2(call, s48_length_2(call,points));
  91. XPoint p[n];
  92. List_To_XPoints(call, points, p, n);
  93. XDrawLines(scx_extract_display(call, display),
  94. scx_extract_drawable(call, drawable),
  95. scx_extract_gc(call, gc), p, n,
  96. scx_extract_coord_mode(call, mode));
  97. return s48_unspecific_2(call);
  98. }
  99. s48_ref_t scx_segment_binding = NULL;
  100. static void List_To_XSegments(s48_call_t call, s48_ref_t l, XSegment* p, int n) {
  101. int i;
  102. for (i = 0; i < n; i++) {
  103. s48_ref_t s = s48_car_2(call, l);
  104. s48_check_record_type_2(call, s, scx_segment_binding);
  105. p[i].x1 = (int)s48_extract_long_2(call, s48_record_ref_2(call, s, 0));
  106. p[i].y1 = (int)s48_extract_long_2(call, s48_record_ref_2(call, s, 1));
  107. p[i].x2 = (int)s48_extract_long_2(call, s48_record_ref_2(call, s, 2));
  108. p[i].y2 = (int)s48_extract_long_2(call, s48_record_ref_2(call, s, 3));
  109. s48_ref_t temp = l;
  110. l = s48_cdr_2(call, l);
  111. s48_free_local_ref(call, temp);
  112. }
  113. }
  114. s48_ref_t scx_Draw_Segments(s48_call_t call, s48_ref_t display,
  115. s48_ref_t drawable, s48_ref_t gc, s48_ref_t segs) {
  116. int n = s48_extract_long_2(call, s48_length_2(call,segs));
  117. XSegment p[n];
  118. List_To_XSegments(call, segs, p, n);
  119. XDrawSegments(scx_extract_display(call, display),
  120. scx_extract_drawable(call, drawable),
  121. scx_extract_gc(call, gc), p, n);
  122. return s48_unspecific_2(call);
  123. }
  124. s48_ref_t scx_Draw_Rectangle(s48_call_t call, s48_ref_t display,
  125. s48_ref_t drawable, s48_ref_t gc, s48_ref_t x, s48_ref_t y,
  126. s48_ref_t width, s48_ref_t height) {
  127. XDrawRectangle(scx_extract_display(call, display),
  128. scx_extract_drawable(call, drawable),
  129. scx_extract_gc(call, gc),
  130. (int)s48_extract_long_2(call, x),
  131. (int)s48_extract_long_2(call, y),
  132. (int)s48_extract_long_2(call, width),
  133. (int)s48_extract_long_2(call, height));
  134. return s48_unspecific_2(call);
  135. }
  136. s48_ref_t scx_rectangle_binding = NULL;
  137. static void List_To_XRectangles(s48_call_t call, s48_ref_t l,
  138. XRectangle* p, int n)
  139. {
  140. int i;
  141. for (i = 0; i < n; i++) {
  142. s48_ref_t r = s48_car_2(call, l);
  143. s48_check_record_type_2(call, r, scx_rectangle_binding);
  144. p[i].x = (int)s48_extract_long_2(call, s48_record_ref_2(call, r, 0));
  145. p[i].y = (int)s48_extract_long_2(call, s48_record_ref_2(call, r, 1));
  146. p[i].width = (int)s48_extract_long_2(call, s48_record_ref_2(call, r, 2));
  147. p[i].height = (int)s48_extract_long_2(call, s48_record_ref_2(call, r, 3));
  148. s48_ref_t temp = l;
  149. l = s48_cdr_2(call, l);
  150. s48_free_local_ref(call, temp);
  151. }
  152. }
  153. s48_ref_t scx_Draw_Rectangles(s48_call_t call, s48_ref_t display,
  154. s48_ref_t drawable, s48_ref_t gc, s48_ref_t rects)
  155. {
  156. int n = s48_extract_long_2(call, s48_length_2(call, rects));
  157. XRectangle p[n];
  158. List_To_XRectangles(call, rects, p, n);
  159. XDrawRectangles(scx_extract_display(call, display),
  160. scx_extract_drawable(call, drawable),
  161. scx_extract_gc(call, gc), p, n);
  162. return s48_unspecific_2(call);
  163. }
  164. s48_ref_t scx_Draw_Arc(s48_call_t call, s48_ref_t display, s48_ref_t drawable,
  165. s48_ref_t gc, s48_ref_t x, s48_ref_t y, s48_ref_t w, s48_ref_t h,
  166. s48_ref_t a1, s48_ref_t a2) {
  167. XDrawArc(scx_extract_display(call, display),
  168. scx_extract_drawable(call, drawable),
  169. scx_extract_gc(call, gc), (int)s48_extract_long_2(call, x),
  170. (int)s48_extract_long_2(call, y),
  171. (int)s48_extract_long_2(call, w),
  172. (int)s48_extract_long_2(call, h),
  173. (int)s48_extract_long_2(call, a1),
  174. (int)s48_extract_long_2(call, a2));
  175. return s48_unspecific_2(call);
  176. }
  177. s48_ref_t scx_arc_binding = NULL;
  178. static void List_To_XArcs(s48_call_t call, s48_ref_t l, XArc* p, int n) {
  179. int i;
  180. for (i = 0; i < n; i++) {
  181. s48_ref_t r = s48_car_2(call, l);
  182. s48_check_record_type_2(call, r, scx_arc_binding);
  183. p[i].x = (int)s48_extract_long_2(call, s48_record_ref_2(call, r, 0));
  184. p[i].y = (int)s48_extract_long_2(call, s48_record_ref_2(call, r, 1));
  185. p[i].width = (int)s48_extract_long_2(call, s48_record_ref_2(call, r, 2));
  186. p[i].height = (int)s48_extract_long_2(call, s48_record_ref_2(call, r, 3));
  187. p[i].angle1 = (int)s48_extract_long_2(call, s48_record_ref_2(call, r, 4));
  188. p[i].angle2 = (int)s48_extract_long_2(call, s48_record_ref_2(call, r, 5));
  189. s48_ref_t temp = l;
  190. l = s48_cdr_2(call, l);
  191. s48_free_local_ref(call, temp);
  192. }
  193. }
  194. s48_ref_t scx_Draw_Arcs(s48_call_t call, s48_ref_t display, s48_ref_t drawable,
  195. s48_ref_t gc, s48_ref_t arcs) {
  196. int n = s48_extract_long_2(call, s48_length_2(call, arcs));
  197. XArc p[n];
  198. List_To_XArcs(call, arcs, p, n);
  199. XDrawArcs(scx_extract_display(call, display),
  200. scx_extract_drawable(call, drawable),
  201. scx_extract_gc(call, gc), p, n);
  202. return s48_unspecific_2(call);
  203. }
  204. s48_ref_t scx_Fill_Rectangle(s48_call_t call, s48_ref_t display,
  205. s48_ref_t drawable, s48_ref_t gc, s48_ref_t x, s48_ref_t y,
  206. s48_ref_t width, s48_ref_t height) {
  207. XFillRectangle(scx_extract_display(call, display),
  208. scx_extract_drawable(call, drawable),
  209. scx_extract_gc(call, gc),
  210. (int)s48_extract_long_2(call, x),
  211. (int)s48_extract_long_2(call, y),
  212. (int)s48_extract_long_2(call, width),
  213. (int)s48_extract_long_2(call, height));
  214. return s48_unspecific_2(call);
  215. }
  216. s48_ref_t scx_Fill_Rectangles(s48_call_t call, s48_ref_t display, s48_ref_t drawable,
  217. s48_ref_t gc, s48_ref_t rects)
  218. {
  219. int n = s48_extract_long_2(call, s48_length_2(call, rects));
  220. XRectangle p[n];
  221. List_To_XRectangles(call, rects, p, n);
  222. XFillRectangles(scx_extract_display(call, display),
  223. scx_extract_drawable(call, drawable),
  224. scx_extract_gc(call, gc), p, n);
  225. return s48_unspecific_2(call);
  226. }
  227. s48_ref_t scx_Fill_Polygon(s48_call_t call, s48_ref_t display,
  228. s48_ref_t drawable, s48_ref_t gc, s48_ref_t points,
  229. s48_ref_t shape, s48_ref_t mode)
  230. {
  231. int n = s48_extract_long_2(call, s48_length_2(call, points));
  232. XPoint p[n];
  233. List_To_XPoints(call, points, p, n);
  234. XFillPolygon(scx_extract_display(call, display),
  235. scx_extract_drawable(call, drawable),
  236. scx_extract_gc(call, gc), p, n,
  237. scx_extract_polygon_shape(call, shape),
  238. scx_extract_coord_mode(call, mode));
  239. return s48_unspecific_2(call);
  240. }
  241. s48_ref_t scx_Fill_Arc(s48_call_t call, s48_ref_t display, s48_ref_t drawable,
  242. s48_ref_t gc, s48_ref_t x, s48_ref_t y, s48_ref_t w,
  243. s48_ref_t h, s48_ref_t a1, s48_ref_t a2) {
  244. XFillArc(scx_extract_display(call, display),
  245. scx_extract_drawable(call, drawable),
  246. scx_extract_gc(call, gc), (int)s48_extract_long_2(call, x),
  247. (int)s48_extract_long_2(call, y),
  248. (int)s48_extract_long_2(call, w),
  249. (int)s48_extract_long_2(call, h),
  250. (int)s48_extract_long_2(call, a1),
  251. (int)s48_extract_long_2(call, a2));
  252. return s48_unspecific_2(call);
  253. }
  254. s48_ref_t scx_Fill_Arcs(s48_call_t call, s48_ref_t display, s48_ref_t drawable,
  255. s48_ref_t gc, s48_ref_t arcs) {
  256. int n = s48_extract_long_2(call, s48_length_2(call, arcs));
  257. XArc p[n];
  258. List_To_XArcs(call, arcs, p, n);
  259. XFillArcs(scx_extract_display(call, display),
  260. scx_extract_drawable(call, drawable),
  261. scx_extract_gc(call, gc), p, n);
  262. return s48_unspecific_2(call);
  263. }
  264. void scx_init_graphics(void) {
  265. scx_coord_mode_binding = s48_get_imported_binding_2("scx-coord-mode");
  266. scx_polygon_shape_binding = s48_get_imported_binding_2("scx-polygon-shape");
  267. scx_segment_binding = s48_get_imported_binding_2("scx-segment");
  268. scx_rectangle_binding = s48_get_imported_binding_2("scx-rectangle");
  269. scx_arc_binding = s48_get_imported_binding_2("scx-arc");
  270. S48_EXPORT_FUNCTION(scx_Copy_Area);
  271. S48_EXPORT_FUNCTION(scx_Copy_Plane);
  272. S48_EXPORT_FUNCTION(scx_Draw_Point);
  273. S48_EXPORT_FUNCTION(scx_Draw_Points);
  274. S48_EXPORT_FUNCTION(scx_Draw_Line);
  275. S48_EXPORT_FUNCTION(scx_Draw_Lines);
  276. S48_EXPORT_FUNCTION(scx_Draw_Segments);
  277. S48_EXPORT_FUNCTION(scx_Draw_Rectangle);
  278. S48_EXPORT_FUNCTION(scx_Draw_Rectangles);
  279. S48_EXPORT_FUNCTION(scx_Draw_Arc);
  280. S48_EXPORT_FUNCTION(scx_Draw_Arcs);
  281. S48_EXPORT_FUNCTION(scx_Fill_Rectangle);
  282. S48_EXPORT_FUNCTION(scx_Fill_Rectangles);
  283. S48_EXPORT_FUNCTION(scx_Fill_Polygon);
  284. S48_EXPORT_FUNCTION(scx_Fill_Arc);
  285. S48_EXPORT_FUNCTION(scx_Fill_Arcs);
  286. }