您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

388 行
12 KiB

  1. /**
  2. * libcaca Java bindings for libcaca
  3. * Copyright (c) 2009 Adrien Grand <jpountz@dinauz.org>
  4. *
  5. * This library is free software. It comes without any warranty, to
  6. * the extent permitted by applicable law. You can redistribute it
  7. * and/or modify it under the terms of the Do What the Fuck You Want
  8. * to Public License, Version 2, as published by Sam Hocevar. See
  9. * http://www.wtfpl.net/ for more details.
  10. */
  11. #include "org_zoy_caca_Canvas.h"
  12. #include "caca.h"
  13. JNIEXPORT jint JNICALL
  14. Java_org_zoy_caca_Canvas_getCursorX(JNIEnv *env, jclass cls, jlong ptr)
  15. {
  16. return caca_get_cursor_x((caca_canvas_t *)ptr);
  17. }
  18. JNIEXPORT jint JNICALL
  19. Java_org_zoy_caca_Canvas_getCursorY (JNIEnv *env, jclass cls, jlong ptr)
  20. {
  21. return caca_get_cursor_y((caca_canvas_t *)ptr);
  22. }
  23. JNIEXPORT void JNICALL
  24. Java_org_zoy_caca_Canvas_setCursorXY(JNIEnv *env, jclass cls, jlong ptr, jint x, jint y)
  25. {
  26. caca_gotoxy((caca_canvas_t *)ptr, x, y);
  27. }
  28. JNIEXPORT jint JNICALL
  29. Java_org_zoy_caca_Canvas_getHandleX(JNIEnv *env, jclass cls, jlong ptr)
  30. {
  31. return caca_get_canvas_handle_x((caca_canvas_t *)ptr);
  32. }
  33. JNIEXPORT jint JNICALL
  34. Java_org_zoy_caca_Canvas_getHandleY(JNIEnv *env, jclass cls, jlong ptr)
  35. {
  36. return caca_get_canvas_handle_x((caca_canvas_t *)ptr);
  37. }
  38. JNIEXPORT void JNICALL
  39. Java_org_zoy_caca_Canvas_setHandleXY(JNIEnv *env, jclass cls, jlong ptr, jint x, jint y)
  40. {
  41. caca_set_canvas_handle((caca_canvas_t *)ptr, x, y);
  42. }
  43. JNIEXPORT jlong JNICALL
  44. Java_org_zoy_caca_Canvas_createCanvas(JNIEnv *env, jclass cls, jint w, jint h)
  45. {
  46. return (jlong)caca_create_canvas(w, h);
  47. }
  48. JNIEXPORT jint JNICALL
  49. Java_org_zoy_caca_Canvas_getCanvasWidth(JNIEnv *env, jclass cls, jlong ptr)
  50. {
  51. return caca_get_canvas_width((caca_canvas_t *)ptr);
  52. }
  53. JNIEXPORT jint JNICALL
  54. Java_org_zoy_caca_Canvas_getCanvasHeight(JNIEnv *env, jclass cls, jlong ptr)
  55. {
  56. return caca_get_canvas_height((caca_canvas_t *)ptr);
  57. }
  58. JNIEXPORT void JNICALL
  59. Java_org_zoy_caca_Canvas_setCanvasSize(JNIEnv *env, jclass cls, jlong ptr, jint w, jint h)
  60. {
  61. caca_set_canvas_size((caca_canvas_t *)ptr, w, h);
  62. }
  63. JNIEXPORT void JNICALL
  64. Java_org_zoy_caca_Canvas_clearCanvas(JNIEnv *env, jclass cls, jlong ptr)
  65. {
  66. caca_clear_canvas((caca_canvas_t *)ptr);
  67. }
  68. JNIEXPORT jint JNICALL
  69. Java_org_zoy_caca_Canvas_getCanvasChar(JNIEnv *env, jclass cls, jlong ptr, jint x, jint y)
  70. {
  71. return caca_get_char((caca_canvas_t *)ptr, x, y);
  72. }
  73. JNIEXPORT void JNICALL
  74. Java_org_zoy_caca_Canvas_putCanvasChar(JNIEnv *env, jclass cls, jlong ptr, jint x, jint y, jint ch)
  75. {
  76. caca_put_char((caca_canvas_t *)ptr, x, y, ch);
  77. }
  78. JNIEXPORT void JNICALL
  79. Java_org_zoy_caca_Canvas_putCanvasString(JNIEnv *env, jclass cls, jlong ptr, jint x, jint y, jstring s)
  80. {
  81. const char *chars;
  82. chars = (*env)->GetStringUTFChars(env, s, 0);
  83. caca_put_str((caca_canvas_t *)ptr, x, y, chars);
  84. (*env)->ReleaseStringUTFChars(env, s, chars);
  85. }
  86. JNIEXPORT void JNICALL
  87. Java_org_zoy_caca_Canvas_blitCanvas(JNIEnv *env, jclass cls, jlong ptr, jint x,
  88. jint y, jlong cv, jlong mask)
  89. {
  90. caca_blit((caca_canvas_t *)ptr, x, y, (caca_canvas_t *)cv, (caca_canvas_t *)mask);
  91. }
  92. JNIEXPORT void JNICALL
  93. Java_org_zoy_caca_Canvas_setCanvasBoundaries(JNIEnv *env, jclass cls, jlong ptr,
  94. jint x, jint y, jint w, jint h)
  95. {
  96. caca_set_canvas_boundaries((caca_canvas_t *)ptr, x, y, w, h);
  97. }
  98. JNIEXPORT void JNICALL
  99. Java_org_zoy_caca_Canvas_invertCanvas(JNIEnv *env, jclass cls, jlong ptr)
  100. {
  101. caca_invert((caca_canvas_t *)ptr);
  102. }
  103. JNIEXPORT void JNICALL
  104. Java_org_zoy_caca_Canvas_flipCanvas(JNIEnv *env, jclass cls, jlong ptr)
  105. {
  106. caca_flip((caca_canvas_t *)ptr);
  107. }
  108. JNIEXPORT void JNICALL
  109. Java_org_zoy_caca_Canvas_flopCanvas(JNIEnv *env, jclass cls, jlong ptr)
  110. {
  111. caca_flop((caca_canvas_t *)ptr);
  112. }
  113. JNIEXPORT void JNICALL
  114. Java_org_zoy_caca_Canvas_rotateCanvas180(JNIEnv *env, jclass cls, jlong ptr)
  115. {
  116. caca_rotate_180((caca_canvas_t *)ptr);
  117. }
  118. JNIEXPORT void JNICALL
  119. Java_org_zoy_caca_Canvas_rotateCanvasLeft(JNIEnv *env, jclass cls, jlong ptr)
  120. {
  121. caca_rotate_left((caca_canvas_t *)ptr);
  122. }
  123. JNIEXPORT void JNICALL
  124. Java_org_zoy_caca_Canvas_rotateCanvasRight(JNIEnv *env, jclass cls, jlong ptr)
  125. {
  126. caca_rotate_right((caca_canvas_t *)ptr);
  127. }
  128. JNIEXPORT void JNICALL
  129. Java_org_zoy_caca_Canvas_stretchCanvasLeft(JNIEnv *env, jclass cls, jlong ptr)
  130. {
  131. caca_stretch_left((caca_canvas_t *)ptr);
  132. }
  133. JNIEXPORT void JNICALL
  134. Java_org_zoy_caca_Canvas_stretchCanvasRight(JNIEnv *env, jclass cls, jlong ptr)
  135. {
  136. caca_stretch_right((caca_canvas_t *)ptr);
  137. }
  138. JNIEXPORT jint JNICALL
  139. Java_org_zoy_caca_Canvas_getCanvasAttribute(JNIEnv *env, jclass cls, jlong ptr, jint x, jint y)
  140. {
  141. return caca_get_attr((caca_canvas_t *)ptr, x, y);
  142. }
  143. JNIEXPORT void JNICALL
  144. Java_org_zoy_caca_Canvas_setCanvasAttribute(JNIEnv *env, jclass cls, jlong ptr, jint attr)
  145. {
  146. caca_set_attr((caca_canvas_t *)ptr, attr);
  147. }
  148. JNIEXPORT void JNICALL
  149. Java_org_zoy_caca_Canvas_putCanvasAttribute(JNIEnv *env, jclass cls, jlong ptr,
  150. jint x, jint y, jint attr)
  151. {
  152. caca_put_attr((caca_canvas_t *)ptr, x, y, attr);
  153. }
  154. JNIEXPORT void JNICALL
  155. Java_org_zoy_caca_Canvas_setCanvasColorAnsi(JNIEnv *env, jclass cls, jlong ptr, jbyte fg, jbyte bg)
  156. {
  157. caca_set_color_ansi((caca_canvas_t *)ptr, fg, bg);
  158. }
  159. JNIEXPORT void JNICALL
  160. Java_org_zoy_caca_Canvas_setCanvasColorArgb(JNIEnv *env, jclass cls, jlong ptr, jshort fg, jshort bg)
  161. {
  162. caca_set_color_argb((caca_canvas_t *)ptr, fg, bg);
  163. }
  164. JNIEXPORT void JNICALL
  165. Java_org_zoy_caca_Canvas_canvasDrawLine(JNIEnv *env, jclass cls, jlong ptr, jint x1, jint y1,
  166. jint x2, jint y2, jint ch)
  167. {
  168. caca_draw_line((caca_canvas_t *)ptr, x1, y1, x2, y2, ch);
  169. }
  170. JNIEXPORT void JNICALL
  171. Java_org_zoy_caca_Canvas_canvasDrawPolyline(JNIEnv *env, jclass cls, jlong ptr,
  172. jintArray xs, jintArray ys, jint ch)
  173. {
  174. jsize size;
  175. jint *x_elems;
  176. jint *y_elems;
  177. size = (*env)->GetArrayLength(env, xs);
  178. x_elems = (*env)->GetIntArrayElements(env, xs, 0);
  179. y_elems = (*env)->GetIntArrayElements(env, ys, 0);
  180. caca_draw_polyline((caca_canvas_t *)ptr, x_elems, y_elems, size, ch);
  181. (*env)->ReleaseIntArrayElements(env, xs, x_elems, 0);
  182. (*env)->ReleaseIntArrayElements(env, ys, y_elems, 0);
  183. }
  184. JNIEXPORT void JNICALL
  185. Java_org_zoy_caca_Canvas_canvasDrawThinLine(JNIEnv *env, jclass cls, jlong ptr,
  186. jint x1, jint y1, jint x2, jint y2)
  187. {
  188. caca_draw_thin_line((caca_canvas_t *)ptr, x1, y1, x2, y2);
  189. }
  190. JNIEXPORT void JNICALL
  191. Java_org_zoy_caca_Canvas_canvasDrawThinPolyline(JNIEnv *env, jclass cls, jlong ptr,
  192. jintArray xs, jintArray ys)
  193. {
  194. jsize size;
  195. jint *x_elems;
  196. jint *y_elems;
  197. size = (*env)->GetArrayLength(env, xs);
  198. x_elems = (*env)->GetIntArrayElements(env, xs, 0);
  199. y_elems = (*env)->GetIntArrayElements(env, ys, 0);
  200. caca_draw_thin_polyline((caca_canvas_t *)ptr, x_elems, y_elems, size);
  201. (*env)->ReleaseIntArrayElements(env, xs, x_elems, 0);
  202. (*env)->ReleaseIntArrayElements(env, ys, y_elems, 0);
  203. }
  204. JNIEXPORT void JNICALL
  205. Java_org_zoy_caca_Canvas_canvasDrawCircle(JNIEnv * env, jclass cls, jlong ptr,
  206. jint x, jint y, jint r, jint ch)
  207. {
  208. caca_draw_circle((caca_canvas_t *)ptr, x, y, r, ch);
  209. }
  210. JNIEXPORT void JNICALL
  211. Java_org_zoy_caca_Canvas_canvasDrawEllipse(JNIEnv *env, jclass cls, jlong ptr,
  212. jint x, jint y, jint a, jint b, jint ch)
  213. {
  214. caca_draw_ellipse((caca_canvas_t *)ptr, x, y, a, b, ch);
  215. }
  216. JNIEXPORT void JNICALL
  217. Java_org_zoy_caca_Canvas_canvasDrawThinEllipse(JNIEnv *env, jclass cls, jlong ptr,
  218. jint x, jint y, jint a, jint b)
  219. {
  220. caca_draw_thin_ellipse((caca_canvas_t *)ptr, x, y, a, b);
  221. }
  222. JNIEXPORT void JNICALL
  223. Java_org_zoy_caca_Canvas_canvasFillEllipse(JNIEnv *env, jclass cls, jlong ptr, jint x,
  224. jint y, jint a, jint b, jint ch)
  225. {
  226. caca_fill_ellipse((caca_canvas_t *)ptr, x, y, a, b, ch);
  227. }
  228. JNIEXPORT void JNICALL
  229. Java_org_zoy_caca_Canvas_canvasDrawBox(JNIEnv *env, jclass cls, jlong ptr, jint x, jint y,
  230. jint w, jint h, jint ch)
  231. {
  232. caca_draw_box((caca_canvas_t *)ptr, x, y, w, h, ch);
  233. }
  234. JNIEXPORT void JNICALL
  235. Java_org_zoy_caca_Canvas_canvasDrawThinBox(JNIEnv *env, jclass cls, jlong ptr,
  236. jint x, jint y, jint w, jint h)
  237. {
  238. caca_draw_thin_box((caca_canvas_t *)ptr, x, y, w, h);
  239. }
  240. JNIEXPORT void JNICALL
  241. Java_org_zoy_caca_Canvas_canvasDrawCp437Box(JNIEnv *env, jclass cls, jlong ptr,
  242. jint x, jint y, jint w, jint h)
  243. {
  244. caca_draw_cp437_box((caca_canvas_t *)ptr, x, y, w, h);
  245. }
  246. JNIEXPORT void JNICALL
  247. Java_org_zoy_caca_Canvas_canvasFillBox(JNIEnv *env, jclass cls, jlong ptr,
  248. jint x, jint y, jint w, jint h, jint ch)
  249. {
  250. caca_fill_box((caca_canvas_t *)ptr, x, y, w, h, ch);
  251. }
  252. JNIEXPORT void JNICALL
  253. Java_org_zoy_caca_Canvas_canvasDrawTriangle(JNIEnv *env, jclass cls, jlong ptr,
  254. jint x1, jint y1, jint x2, jint y2,
  255. jint x3, jint y3, jint ch)
  256. {
  257. caca_draw_triangle((caca_canvas_t *)ptr, x1, y1, x2, y2, x3, y3, ch);
  258. }
  259. JNIEXPORT void JNICALL
  260. Java_org_zoy_caca_Canvas_canvasDrawThinTriangle(JNIEnv *env, jclass cls, jlong ptr,
  261. jint x1, jint y1, jint x2, jint y2,
  262. jint x3, jint y3)
  263. {
  264. caca_draw_thin_triangle((caca_canvas_t *)ptr, x1, y1, x2, y2, x3, y3);
  265. }
  266. JNIEXPORT void JNICALL
  267. Java_org_zoy_caca_Canvas_canvasFillTriangle(JNIEnv *env, jclass cls, jlong ptr,
  268. jint x1, jint y1, jint x2, jint y2,
  269. jint x3, jint y3, jint ch)
  270. {
  271. caca_fill_triangle((caca_canvas_t *)ptr, x1, y1, x2, y2, x3, y3, ch);
  272. }
  273. JNIEXPORT jint JNICALL
  274. Java_org_zoy_caca_Canvas_getCanvasFrameCount(JNIEnv *env, jclass cls, jlong ptr)
  275. {
  276. return caca_get_frame_count((caca_canvas_t *)ptr);
  277. }
  278. JNIEXPORT void JNICALL
  279. Java_org_zoy_caca_Canvas_setCanvasFrame(JNIEnv *env, jclass cls, jlong ptr, jint id)
  280. {
  281. caca_set_frame((caca_canvas_t *)ptr, id);
  282. }
  283. JNIEXPORT jstring JNICALL
  284. Java_org_zoy_caca_Canvas_getCanvasFrameName(JNIEnv *env, jclass cls, jlong ptr)
  285. {
  286. const char *frame_name = caca_get_frame_name((caca_canvas_t *)ptr);
  287. return (*env)->NewStringUTF(env, frame_name);
  288. }
  289. JNIEXPORT void JNICALL
  290. Java_org_zoy_caca_Canvas_setCanvasFrameName(JNIEnv *env, jclass cls, jlong ptr, jstring frame_name)
  291. {
  292. const char *frame_name_chars = (*env)->GetStringUTFChars(env, frame_name, 0);
  293. caca_set_frame_name((caca_canvas_t *)ptr, frame_name_chars);
  294. (*env)->ReleaseStringUTFChars(env, frame_name, frame_name_chars);
  295. }
  296. JNIEXPORT void JNICALL
  297. Java_org_zoy_caca_Canvas_createCanvasFrame(JNIEnv *env, jclass cls, jlong ptr, jint id)
  298. {
  299. caca_create_frame((caca_canvas_t *)ptr, id);
  300. }
  301. JNIEXPORT void JNICALL
  302. Java_org_zoy_caca_Canvas_freeCanvasFrame(JNIEnv *env, jclass cls, jlong ptr, jint id)
  303. {
  304. caca_free_frame((caca_canvas_t *)ptr, id);
  305. }
  306. JNIEXPORT void JNICALL
  307. Java_org_zoy_caca_Canvas_canvasRender(JNIEnv *env, jclass cls, jlong ptr, jlong font_ptr,
  308. jbyteArray buf, jint width, jint height, jint pitch)
  309. {
  310. jbyte *elems = (*env)->GetByteArrayElements(env, buf, 0);
  311. caca_render_canvas((caca_canvas_t *)ptr, (caca_font_t *)font_ptr, elems, width, height, pitch);
  312. (*env)->ReleaseByteArrayElements(env, buf, elems, 0);
  313. }
  314. JNIEXPORT void JNICALL
  315. Java_org_zoy_caca_Canvas_canvasDitherBitmap(JNIEnv *env, jclass cls, jlong ptr, jint x, jint y,
  316. jint w, jint h, jlong dither_ptr, jbyteArray pixels)
  317. {
  318. jbyte *elems = (*env)->GetByteArrayElements(env, pixels, 0);
  319. jsize size = (*env)->GetArrayLength(env, pixels);
  320. caca_dither_bitmap((caca_canvas_t *)ptr, x, y, w, h, (caca_dither_t *)dither_ptr, elems);
  321. (*env)->ReleaseByteArrayElements(env, pixels, elems, 0);
  322. }
  323. JNIEXPORT void JNICALL
  324. Java_org_zoy_caca_Canvas_freeCanvas(JNIEnv *env, jclass cls, jlong ptr)
  325. {
  326. caca_free_canvas((caca_canvas_t *)ptr);
  327. }